File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -57,8 +57,8 @@ struct MutationRoot {
5757
5858#[ async_graphql:: Object ]
5959impl MutationRoot {
60- async fn send_transaction ( & self , tx_type : String , body : String ) -> async_graphql:: Result < String > {
61- let tx = coordinator:: Transaction :: new ( tx_type, hex :: decode ( body) . map_err ( |_| "Failed to parse body" ) ? ) ;
60+ async fn send_transaction ( & self , tx_type : String , body : GqlBytes ) -> async_graphql:: Result < String > {
61+ let tx = coordinator:: Transaction :: new ( tx_type, body. 0 ) ;
6262 // NOTE: Check `queue_own_transaction()` won't cause a deadlock, especially when called by the async runtime.
6363 Ok ( match self . client . queue_own_transaction ( tx) {
6464 Ok ( _) => "Done" . to_owned ( ) ,
Original file line number Diff line number Diff line change @@ -80,3 +80,20 @@ impl ScalarType for GqlH256 {
8080 GqlValue :: String ( hex:: encode ( self . 0 . as_ref ( ) ) )
8181 }
8282}
83+
84+ pub struct GqlBytes ( pub Vec < u8 > ) ;
85+
86+ #[ Scalar ]
87+ impl ScalarType for GqlBytes {
88+ fn parse ( value : GqlValue ) -> InputValueResult < Self > {
89+ if let GqlValue :: String ( s) = value {
90+ Ok ( GqlBytes ( hex:: decode ( & s) . map_err ( |_| InputValueError :: custom ( "Invalid hex-encoded bytes" . to_owned ( ) ) ) ?) )
91+ } else {
92+ Err ( InputValueError :: custom ( "String expected" . to_owned ( ) ) )
93+ }
94+ }
95+
96+ fn to_value ( & self ) -> GqlValue {
97+ GqlValue :: String ( hex:: encode ( & self . 0 ) )
98+ }
99+ }
You can’t perform that action at this time.
0 commit comments