Currently I am developing a Fat Contract (Native to Phala Network) that also supports Ink Based Smart Contracts to be written within the Fat Contracts which is what my example is doing.
To describe the problem, I am able to send HTTP requests from my Fat Contract that will return a JSON format response. This is where I get stuck bc in the runtime, I can usually parse the response using serde
, but serde
is not able to be used when writing these contracts due to a float being used in the library that causes the contract to get rejected during the upload. Typically this piece of code would be able to parse this response:
{"id":"12196238-420ae612726839da09-🐤-DREAMLIKE_BIRD_007-00000007","forsale":0,"owner":"Gy2SSkZWXq3jHwmSEBSpqVpKN8cWEAECwKnvS7j3srV7sZ9","rootowner":"Gy2SSkZWXq3jHwmSEBSpqVpKN8cWEAECwKnvS7j3srV7sZ9","collectionId":"420ae612726839da09-🐤","metadata":"ipfs://ipfs/bafkreiduurl6jkqxqx3h5nhmegdkxq2smq7hbmbaryaudrz2xw563xtrza","sn":"00000007","updated_at":"2022-04-18T05:53:02.409768+00:00","image":"https://kanaria-img.rmrk.link/1650261182409/jpeg/12196238-420ae612726839da09-🐤-DREAMLIKE_BIRD_007-00000007.jpg"}
With this piece of code:
let response = http_get!(api_url);
if response.status_code != 200 {
return Err(Error::TokenValidationFailed);
}
let body = response.body;
let json_body = json!(body);
let rmrk_nft: RmrkNft =
serde_json::from_value(json_body).or(Err(Error::TokenValidationFailed))?;
Where RmrkNft
struct is defined as:
/// RMRK NFT structure
#[derive(Deserialize, Debug, Eq, PartialEq)]
pub struct RmrkNft {
id: String,
metadata: String,
image: String,
rootowner: String,
}
My question is if there is an alternative to serde
that will allow me to parse the JSON response from my HTTP request to be able to load into my RmrkNft
struct?