Skip to content

Commit

Permalink
jsonrpc: correctly serialize bcsName field
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Dec 17, 2024
1 parent 851b6a6 commit 756d56d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
14 changes: 14 additions & 0 deletions crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ pub enum BcsName {
Base64 {
#[serde_as(as = "Base64")]
#[schemars(with = "Base64")]
#[serde(rename = "bcsName")]
bcs_name: Vec<u8>,
},
Base58 {
#[serde_as(as = "Base58")]
#[schemars(with = "Base58")]
#[serde(rename = "bcsName")]
bcs_name: Vec<u8>,
},
}
Expand Down Expand Up @@ -212,5 +214,17 @@ mod test {
.unwrap()
.into_bytes()
);

// Roundtrip base64
let name = serde_json::from_str::<BcsName>(tagged_base64).unwrap();
let json = serde_json::to_string(&name).unwrap();
let from_json = serde_json::from_str::<BcsName>(&json).unwrap();
assert_eq!(name, from_json);

// Roundtrip base58
let name = serde_json::from_str::<BcsName>(tagged_base58).unwrap();
let json = serde_json::to_string(&name).unwrap();
let from_json = serde_json::from_str::<BcsName>(&json).unwrap();
assert_eq!(name, from_json);
}
}
12 changes: 12 additions & 0 deletions crates/sui-json-rpc-types/src/sui_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,17 @@ mod test {
.unwrap()
.into_bytes()
);

// Roundtrip base64
let event = serde_json::from_str::<BcsEvent>(tagged_base64).unwrap();
let json = serde_json::to_string(&event).unwrap();
let from_json = serde_json::from_str::<BcsEvent>(&json).unwrap();
assert_eq!(event, from_json);

// Roundtrip base58
let event = serde_json::from_str::<BcsEvent>(tagged_base58).unwrap();
let json = serde_json::to_string(&event).unwrap();
let from_json = serde_json::from_str::<BcsEvent>(&json).unwrap();
assert_eq!(event, from_json);
}
}
14 changes: 7 additions & 7 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3557,7 +3557,7 @@
"value": "some_value"
},
"bcsEncoding": "base64",
"bcs_name": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk",
"bcsName": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk",
"type": "DynamicField",
"objectType": "test",
"objectId": "0x82b2fd67344691abd0efc771941b948ad35360b08e449fbbc28b0641175bf60b",
Expand All @@ -3570,7 +3570,7 @@
"value": "some_value"
},
"bcsEncoding": "base64",
"bcs_name": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk",
"bcsName": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk",
"type": "DynamicField",
"objectType": "test",
"objectId": "0x21564fc5a68ace997461b098c1d1f3ccbde241d8fdf562db36bc1423ee10cecb",
Expand All @@ -3583,7 +3583,7 @@
"value": "some_value"
},
"bcsEncoding": "base64",
"bcs_name": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk",
"bcsName": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk",
"type": "DynamicField",
"objectType": "test",
"objectId": "0x7e00acf5386662fa062483ba507b1e9e3039750f0a270f2e12441ad7f611a5f7",
Expand Down Expand Up @@ -5964,7 +5964,7 @@
"type": "object",
"required": [
"bcsEncoding",
"bcs_name"
"bcsName"
],
"properties": {
"bcsEncoding": {
Expand All @@ -5973,7 +5973,7 @@
"base64"
]
},
"bcs_name": {
"bcsName": {
"$ref": "#/components/schemas/Base64"
}
}
Expand All @@ -5982,7 +5982,7 @@
"type": "object",
"required": [
"bcsEncoding",
"bcs_name"
"bcsName"
],
"properties": {
"bcsEncoding": {
Expand All @@ -5991,7 +5991,7 @@
"base58"
]
},
"bcs_name": {
"bcsName": {
"$ref": "#/components/schemas/Base58"
}
}
Expand Down

0 comments on commit 756d56d

Please sign in to comment.