@@ -5,7 +5,7 @@ use sp1_sdk::{SP1ProofWithPublicValues, SP1VerifyingKey};
55
66use crate :: {
77 gateway:: types:: {
8- GatewayResponse , NonceResponse , Receipt , ReceiptsQueryParams , ReceiptsResponse ,
8+ EmptyData , GatewayResponse , NonceResponse , Receipt , ReceiptsQueryParams ,
99 SubmitProofResponse , SubmitSP1ProofMessage ,
1010 } ,
1111 types:: Network ,
@@ -56,18 +56,19 @@ impl<S: Signer> AggregationModeGatewayProvider<S> {
5656 & self . gateway_url
5757 }
5858
59- pub async fn get_nonce_for ( & self , address : String ) -> Result < u64 , GatewayError > {
59+ pub async fn get_nonce_for (
60+ & self ,
61+ address : String ,
62+ ) -> Result < GatewayResponse < NonceResponse > , GatewayError > {
6063 let url = format ! ( "{}/nonce/{}" , self . gateway_url, address) ;
61- let response: NonceResponse = self . send_request ( self . http_client . get ( url) ) . await ?;
62-
63- Ok ( response. nonce )
64+ self . send_request ( self . http_client . get ( url) ) . await
6465 }
6566
6667 pub async fn get_receipts_for (
6768 & self ,
6869 address : String ,
6970 nonce : Option < u64 > ,
70- ) -> Result < Vec < Receipt > , GatewayError > {
71+ ) -> Result < GatewayResponse < Vec < Receipt > > , GatewayError > {
7172 let query = ReceiptsQueryParams {
7273 address : address,
7374 nonce,
@@ -78,16 +79,14 @@ impl<S: Signer> AggregationModeGatewayProvider<S> {
7879 . get ( format ! ( "{}/receipts" , self . gateway_url) )
7980 . query ( & query) ;
8081
81- let response: ReceiptsResponse = self . send_request ( request) . await ?;
82-
83- Ok ( response. receipts )
82+ self . send_request ( request) . await
8483 }
8584
8685 pub async fn submit_sp1_proof (
8786 & self ,
8887 proof : & SP1ProofWithPublicValues ,
8988 vk : & SP1VerifyingKey ,
90- ) -> Result < SubmitProofResponse , GatewayError > {
89+ ) -> Result < GatewayResponse < SubmitProofResponse > , GatewayError > {
9190 let serialized_proof = bincode:: serialize ( proof)
9291 . map_err ( |e| GatewayError :: ProofSerialization ( e. to_string ( ) ) ) ?;
9392 let serialized_vk =
@@ -97,11 +96,12 @@ impl<S: Signer> AggregationModeGatewayProvider<S> {
9796 return Err ( GatewayError :: SignerNotConfigured ) ;
9897 } ;
9998 let signer_address = signer. address ( ) . to_string ( ) ;
100- let nonce = self . get_nonce_for ( signer_address) . await ?;
101- let message = SubmitSP1ProofMessage :: new ( nonce, serialized_proof, serialized_vk)
102- . sign ( signer, & self . network )
103- . await
104- . map_err ( |e| GatewayError :: MessageSignature ( e) ) ?;
99+ let nonce_response = self . get_nonce_for ( signer_address) . await ?;
100+ let message =
101+ SubmitSP1ProofMessage :: new ( nonce_response. data . nonce , serialized_proof, serialized_vk)
102+ . sign ( signer, & self . network )
103+ . await
104+ . map_err ( |e| GatewayError :: MessageSignature ( e) ) ?;
105105
106106 let form = multipart:: Form :: new ( )
107107 . text ( "nonce" , message. nonce . to_string ( ) )
@@ -128,24 +128,29 @@ impl<S: Signer> AggregationModeGatewayProvider<S> {
128128 async fn send_request < T : DeserializeOwned > (
129129 & self ,
130130 request : reqwest:: RequestBuilder ,
131- ) -> Result < T , GatewayError > {
131+ ) -> Result < GatewayResponse < T > , GatewayError > {
132132 let response = request
133133 . send ( )
134134 . await
135135 . map_err ( |e| GatewayError :: Request ( e. to_string ( ) ) ) ?;
136136
137- let payload: GatewayResponse < T > = response
138- . json ( )
139- . await
140- . map_err ( |e| GatewayError :: Request ( e. to_string ( ) ) ) ?;
137+ if !( 200 ..300 ) . contains ( & response. status ( ) . as_u16 ( ) ) {
138+ let payload: GatewayResponse < EmptyData > = response
139+ . json ( )
140+ . await
141+ . map_err ( |e| GatewayError :: Request ( e. to_string ( ) ) ) ?;
141142
142- if payload. status != 200 {
143143 return Err ( GatewayError :: Api {
144144 status : payload. status ,
145145 message : payload. message ,
146146 } ) ;
147147 }
148148
149- Ok ( payload. data )
149+ let payload: GatewayResponse < T > = response
150+ . json ( )
151+ . await
152+ . map_err ( |e| GatewayError :: Request ( e. to_string ( ) ) ) ?;
153+
154+ Ok ( payload)
150155 }
151156}
0 commit comments