public-awesome / cw-ics721

CosmWasm IBC NFT Transfers
MIT License
56 stars 30 forks source link

Serde doesn't optout None value #80

Open yito88 opened 5 months ago

yito88 commented 5 months ago

As discussed here, I had null values in the encoded NonFungibleTokenPacketData. We can opt-out them by #[serde(skip_serializing_if = "Option::is_none")].

{
  "classId": "wasm14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0phg4d",
  "classUri": null,
  "classData": "eyJvd25lciI6Indhc20xNHpwMzVhdzl3Y256dGxoazUycGpjbHI2enJ2bXJja3pldXJhNWMiLCJjb250cmFjdF9pbmZvIjp7ImNvZGVfaWQiOjEsImNyZWF0b3IiOiJ3YXNtMTR6cDM1YXc5d2NuenRsaGs1MnBqY2xyNnpydm1yY2t6ZXVyYTVjIiwiYWRtaW4iOm51bGwsInBpbm5lZCI6ZmFsc2UsImliY19wb3J0IjpudWxsfSwibmFtZSI6InRlc3RfbmZ0Iiwic3ltYm9sIjoiVEVTVF9ORlQiLCJudW1fdG9rZW5zIjoxfQ==",
  "tokenIds": [
    "test_nft_0"
  ],
  "tokenUris": [
    "http://example.com"
  ],
  "tokenData": null,
  "sender": "wasm14zp35aw9wcnztlhk52pjclr6zrvmrckzeura5c",
  "receiver": "tnam1qq485cszjczr3379p4tme4u94c8q3la04gne5ft3",
  "memo": null
}
@@ -14,9 +14,11 @@ pub struct NonFungibleTokenPacketData {
     pub class_id: ClassId,
     /// Optional URL that points to metadata about the
     /// collection. Must be non-empty if provided.
+    #[serde(skip_serializing_if = "Option::is_none")]
     pub class_uri: Option<String>,
     /// Optional base64 encoded field which contains on-chain metadata
     /// about the NFT class. Must be non-empty if provided.
+    #[serde(skip_serializing_if = "Option::is_none")]
     pub class_data: Option<Binary>,
     /// Uniquely identifies the tokens in the NFT collection being
     /// transfered. This MUST be non-empty.
@@ -25,11 +27,13 @@ pub struct NonFungibleTokenPacketData {
     /// transfered. `tokenUris[N]` should hold the metadata for
     /// `tokenIds[N]` and both lists should have the same if
     /// provided. Must be non-empty if provided.
+    #[serde(skip_serializing_if = "Option::is_none")]
     pub token_uris: Option<Vec<String>>,
     /// Optional base64 encoded metadata for the tokens being
     /// transfered. `tokenData[N]` should hold metadata for
     /// `tokenIds[N]` and both lists should have the same length if
     /// provided. Must be non-empty if provided.
+    #[serde(skip_serializing_if = "Option::is_none")]
     pub token_data: Option<Vec<Binary>>,

     /// The address sending the tokens on the sending chain.
@@ -38,6 +42,7 @@ pub struct NonFungibleTokenPacketData {
     /// chain.
     pub receiver: String,
     /// Memo to add custom string to the msg
+    #[serde(skip_serializing_if = "Option::is_none")]
     pub memo: Option<String>,
 }