From bafc514b8e67ee00da421d3de76b10eb68acfe3e Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 17 Dec 2024 10:38:53 -0600 Subject: [PATCH] jsonrpc: correctly serialize bcsName field Correctly serialize bcsName field which was unintentially changed to `bcs_name` in 8a992f0f7f (jsonrpc: introduce bcsEncoding tag to ease migration to base64, 2024-12-12) --- crates/sui-json-rpc-types/src/lib.rs | 14 ++++++++++++++ crates/sui-json-rpc-types/src/sui_event.rs | 12 ++++++++++++ crates/sui-open-rpc/spec/openrpc.json | 14 +++++++------- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/crates/sui-json-rpc-types/src/lib.rs b/crates/sui-json-rpc-types/src/lib.rs index 3e4b17f242417..8e5b40d31a825 100644 --- a/crates/sui-json-rpc-types/src/lib.rs +++ b/crates/sui-json-rpc-types/src/lib.rs @@ -104,11 +104,13 @@ pub enum BcsName { Base64 { #[serde_as(as = "Base64")] #[schemars(with = "Base64")] + #[serde(rename = "bcsName")] bcs_name: Vec, }, Base58 { #[serde_as(as = "Base58")] #[schemars(with = "Base58")] + #[serde(rename = "bcsName")] bcs_name: Vec, }, } @@ -212,5 +214,17 @@ mod test { .unwrap() .into_bytes() ); + + // Roundtrip base64 + let name = serde_json::from_str::(tagged_base64).unwrap(); + let json = serde_json::to_string(&name).unwrap(); + let from_json = serde_json::from_str::(&json).unwrap(); + assert_eq!(name, from_json); + + // Roundtrip base58 + let name = serde_json::from_str::(tagged_base58).unwrap(); + let json = serde_json::to_string(&name).unwrap(); + let from_json = serde_json::from_str::(&json).unwrap(); + assert_eq!(name, from_json); } } diff --git a/crates/sui-json-rpc-types/src/sui_event.rs b/crates/sui-json-rpc-types/src/sui_event.rs index eb9aace4ac409..abb84301f0353 100644 --- a/crates/sui-json-rpc-types/src/sui_event.rs +++ b/crates/sui-json-rpc-types/src/sui_event.rs @@ -403,5 +403,17 @@ mod test { .unwrap() .into_bytes() ); + + // Roundtrip base64 + let event = serde_json::from_str::(tagged_base64).unwrap(); + let json = serde_json::to_string(&event).unwrap(); + let from_json = serde_json::from_str::(&json).unwrap(); + assert_eq!(event, from_json); + + // Roundtrip base58 + let event = serde_json::from_str::(tagged_base58).unwrap(); + let json = serde_json::to_string(&event).unwrap(); + let from_json = serde_json::from_str::(&json).unwrap(); + assert_eq!(event, from_json); } } diff --git a/crates/sui-open-rpc/spec/openrpc.json b/crates/sui-open-rpc/spec/openrpc.json index 027082a9bc8df..3ebaf3efbb2a3 100644 --- a/crates/sui-open-rpc/spec/openrpc.json +++ b/crates/sui-open-rpc/spec/openrpc.json @@ -3557,7 +3557,7 @@ "value": "some_value" }, "bcsEncoding": "base64", - "bcs_name": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk", + "bcsName": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk", "type": "DynamicField", "objectType": "test", "objectId": "0x82b2fd67344691abd0efc771941b948ad35360b08e449fbbc28b0641175bf60b", @@ -3570,7 +3570,7 @@ "value": "some_value" }, "bcsEncoding": "base64", - "bcs_name": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk", + "bcsName": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk", "type": "DynamicField", "objectType": "test", "objectId": "0x21564fc5a68ace997461b098c1d1f3ccbde241d8fdf562db36bc1423ee10cecb", @@ -3583,7 +3583,7 @@ "value": "some_value" }, "bcsEncoding": "base64", - "bcs_name": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk", + "bcsName": "FDB4OTo6dGVzdDo6VGVzdEZpZWxk", "type": "DynamicField", "objectType": "test", "objectId": "0x7e00acf5386662fa062483ba507b1e9e3039750f0a270f2e12441ad7f611a5f7", @@ -5964,7 +5964,7 @@ "type": "object", "required": [ "bcsEncoding", - "bcs_name" + "bcsName" ], "properties": { "bcsEncoding": { @@ -5973,7 +5973,7 @@ "base64" ] }, - "bcs_name": { + "bcsName": { "$ref": "#/components/schemas/Base64" } } @@ -5982,7 +5982,7 @@ "type": "object", "required": [ "bcsEncoding", - "bcs_name" + "bcsName" ], "properties": { "bcsEncoding": { @@ -5991,7 +5991,7 @@ "base58" ] }, - "bcs_name": { + "bcsName": { "$ref": "#/components/schemas/Base58" } }