11// shadowharvester/src/api.rs
22
3- use serde:: Deserialize ;
3+ use serde:: { Deserialize , Serialize } ;
44use reqwest;
55use reqwest:: blocking;
66use serde_json;
@@ -23,7 +23,7 @@ pub struct RegistrationReceipt {
2323 pub registration_receipt : serde_json:: Value ,
2424}
2525
26- #[ derive( Debug , Deserialize , Clone ) ]
26+ #[ derive( Debug , Deserialize , Serialize , Clone ) ]
2727pub struct ChallengeData {
2828 pub challenge_id : String ,
2929 pub difficulty : String ,
@@ -51,14 +51,14 @@ pub struct ChallengeResponse { // Made struct public for use in main.rs
5151 pub next_challenge_starts_at : Option < String > ,
5252}
5353
54- #[ derive( Debug , Deserialize ) ]
55- struct SolutionReceipt {
54+ #[ derive( Debug , Deserialize , PartialEq ) ]
55+ pub struct SolutionReceipt {
5656 #[ serde( rename = "crypto_receipt" ) ]
5757 pub crypto_receipt : serde_json:: Value ,
5858}
5959
60- #[ derive( Debug , Deserialize ) ]
61- struct DonateResponse {
60+ #[ derive( Debug , Deserialize , PartialEq ) ]
61+ pub struct DonateResponse {
6262 pub status : String ,
6363 #[ serde( rename = "donation_id" ) ]
6464 pub donation_id : String ,
@@ -228,7 +228,7 @@ pub fn submit_solution(
228228 address : & str ,
229229 challenge_id : & str ,
230230 nonce : & str ,
231- ) -> Result < ( ) , String > {
231+ ) -> Result < serde_json :: Value , String > {
232232 let url = format ! (
233233 "{}/solution/{}/{}/{}" ,
234234 api_url,
@@ -248,8 +248,8 @@ pub fn submit_solution(
248248
249249 if status. is_success ( ) {
250250 // Successful submission
251- let _ : SolutionReceipt = response. json ( ) . map_err ( |e| format ! ( "Failed to parse successful receipt JSON: {}" , e) ) ?;
252- Ok ( ( ) )
251+ let receipt : SolutionReceipt = response. json ( ) . map_err ( |e| format ! ( "Failed to parse successful receipt JSON: {}" , e) ) ?;
252+ Ok ( receipt . crypto_receipt )
253253 } else {
254254 // Submission failed (4xx or 5xx)
255255 let body_text = response. text ( ) . unwrap_or_else ( |_| format ! ( "Could not read response body for status {}" , status) ) ;
@@ -277,7 +277,7 @@ pub fn donate_to(
277277 original_address : & str ,
278278 destination_address : & str ,
279279 donation_signature : & str ,
280- ) -> Result < ( ) , String > {
280+ ) -> Result < String , String > {
281281
282282 let url = format ! (
283283 "{}/donate_to/{}/{}/{}" ,
@@ -301,7 +301,7 @@ pub fn donate_to(
301301 if status. is_success ( ) {
302302 let donation_response: DonateResponse = response. json ( ) . map_err ( |e| format ! ( "Failed to parse successful donation JSON: {}" , e) ) ?;
303303 println ! ( "✅ Donation successful. Donation ID: {}" , donation_response. donation_id) ;
304- Ok ( ( ) )
304+ Ok ( donation_response . donation_id )
305305 } else {
306306 let body_text = response. text ( ) . unwrap_or_else ( |_| format ! ( "Could not read response body for status {}" , status) ) ;
307307 let api_error: Result < ApiErrorResponse , _ > = serde_json:: from_str ( & body_text) ;
0 commit comments