11mod trigger;
2- use bindings:: wavs:: worker:: layer_types:: { TriggerData , TriggerSource } ;
3- use trigger:: { decode_trigger_event, encode_trigger_output} ;
2+ use trigger:: { decode_trigger_event, encode_trigger_output, Destination } ;
43pub mod bindings;
54use crate :: bindings:: { export, Guest , TriggerAction } ;
65use serde:: { Deserialize , Serialize } ;
@@ -14,22 +13,9 @@ struct Component;
1413export ! ( Component with_types_in bindings) ;
1514
1615impl Guest for Component {
17- fn run ( trigger_action : TriggerAction ) -> std:: result:: Result < Vec < u8 > , String > {
18- enum Destination {
19- Ethereum ,
20- CliOutput
21- }
22- let ( ( trigger_id, req) , dest) = match & trigger_action. data {
23- // When the trigger comes from WAVS, it's from an ethereum contract event
24- TriggerData :: EthContractEvent ( _) => {
25- ( decode_trigger_event ( trigger_action. data ) . map_err ( |e| e. to_string ( ) ) ?, Destination :: Ethereum )
26- } ,
27- // When we test in a CLI exec command, it's just raw bytes (we can make-up the trigger_id)
28- TriggerData :: Raw ( data) => ( ( 0 , data. clone ( ) ) , Destination :: CliOutput ) ,
29- TriggerData :: CosmosContractEvent ( _) => {
30- return Err ( "Unsupported trigger data type" . to_string ( ) ) ;
31- } ,
32- } ;
16+ fn run ( action : TriggerAction ) -> std:: result:: Result < Vec < u8 > , String > {
17+ let ( trigger_id, req, dest) =
18+ decode_trigger_event ( action. data ) . map_err ( |e| e. to_string ( ) ) ?;
3319
3420 // Convert bytes to string and parse first char as u64
3521 let input = std:: str:: from_utf8 ( & req) . map_err ( |e| e. to_string ( ) ) ?;
@@ -53,9 +39,7 @@ impl Guest for Component {
5339
5440 match res {
5541 Ok ( data) => match dest {
56- Destination :: Ethereum => {
57- Ok ( encode_trigger_output ( trigger_id, & data) )
58- } ,
42+ Destination :: Ethereum => Ok ( encode_trigger_output ( trigger_id, & data) ) ,
5943 Destination :: CliOutput => Ok ( data) ,
6044 } ,
6145 Err ( e) => Err ( e) ,
0 commit comments