11mod trigger;
2+ use alloy_sol_types:: { SolType , SolValue } ;
23use trigger:: { decode_trigger_event, encode_trigger_output, Destination } ;
34use wavs_wasi_utils:: http:: { fetch_json, http_request_get} ;
45pub mod bindings;
56use crate :: bindings:: { export, Guest , TriggerAction , WasmResponse } ;
67use serde:: { Deserialize , Serialize } ;
78use wstd:: { http:: HeaderValue , runtime:: block_on} ;
9+ // import solidity from triggers
10+ use trigger:: solidity;
811
912struct Component ;
1013export ! ( Component with_types_in bindings) ;
@@ -30,11 +33,24 @@ impl Guest for Component {
3033 let ( trigger_id, req, dest) =
3134 decode_trigger_event ( action. data ) . map_err ( |e| e. to_string ( ) ) ?;
3235
33- // Convert bytes to string and parse first char as u64
34- let input = std:: str:: from_utf8 ( & req) . map_err ( |e| e. to_string ( ) ) ?;
35- println ! ( "input id: {}" , input) ;
36-
37- let id = input. chars ( ) . next ( ) . ok_or ( "Empty input" ) ?;
36+ // Decode the string using proper ABI decoding
37+ let string_data: String =
38+ if let Ok ( decoded) = <solidity:: DataWithId as SolType >:: abi_decode ( & req) {
39+ // If it has a function selector (from cast abi-encode "f(string)" format)
40+ decoded. data . to_string ( )
41+ } else {
42+ // Fallback: try decoding just as a string parameter (no function selector)
43+ match String :: abi_decode ( & req) {
44+ Ok ( s) => s,
45+ Err ( e) => return Err ( format ! ( "Failed to decode input as ABI string: {}" , e) ) ,
46+ }
47+ // alloy_primitives::Bytes::from(s.into_bytes())
48+ } ;
49+
50+ println ! ( "Decoded string input: {}" , string_data) ;
51+
52+ // Parse the first character as a hex digit for the ID
53+ let id = string_data. chars ( ) . next ( ) . ok_or ( "Empty input" ) ?;
3854 let id = id. to_digit ( 16 ) . ok_or ( "Invalid hex digit" ) ? as u64 ;
3955
4056 let res = block_on ( async move {
0 commit comments