Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sui Json RPC Types: Return strings for u64 #6608

Merged
merged 5 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
return strings for u64
  • Loading branch information
oxade committed Dec 6, 2022
commit 4107e754f838cd6b3d5b070cf9d2f496876afed4
12 changes: 6 additions & 6 deletions crates/sui-core/src/unit_tests/event_handler_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ fn test_to_json_value() {
let json_value = sui_move_struct.to_json_value().unwrap();
dbg!(&json_value);
assert_eq!(
Some(&json!(1000000)),
Some(&json!("1000000")),
json_value.pointer("/coins/0/balance")
);
assert_eq!(
Some(&json!(2000000)),
Some(&json!("2000000")),
json_value.pointer("/coins/1/balance")
);
assert_eq!(
Some(&json!(3000000)),
Some(&json!("3000000")),
json_value.pointer("/coins/2/balance")
);
assert_eq!(
Expand All @@ -59,9 +59,9 @@ fn test_to_json_value() {
Some(&json!(format!("{:#x}", move_event.creator))),
json_value.pointer("/creator")
);
assert_eq!(Some(&json!(100)), json_value.pointer("/data/0"));
assert_eq!(Some(&json!(200)), json_value.pointer("/data/1"));
assert_eq!(Some(&json!(300)), json_value.pointer("/data/2"));
assert_eq!(Some(&json!("100")), json_value.pointer("/data/0"));
assert_eq!(Some(&json!("200")), json_value.pointer("/data/1"));
assert_eq!(Some(&json!("300")), json_value.pointer("/data/2"));
assert_eq!(Some(&json!("test_event")), json_value.pointer("/name"));
}

Expand Down
10 changes: 6 additions & 4 deletions crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,11 @@ impl TryFrom<&SuiMoveStruct> for GasCoin {
fn try_from(move_struct: &SuiMoveStruct) -> Result<Self, Self::Error> {
match move_struct {
SuiMoveStruct::WithFields(fields) | SuiMoveStruct::WithTypes { type_: _, fields } => {
if let Some(SuiMoveValue::Number(balance)) = fields.get("balance") {
if let Some(SuiMoveValue::UID { id }) = fields.get("id") {
return Ok(GasCoin::new(*id, *balance));
if let Some(SuiMoveValue::String(balance)) = fields.get("balance") {
if let Ok(balance) = balance.parse::<u64>() {
if let Some(SuiMoveValue::UID { id }) = fields.get("id") {
return Ok(GasCoin::new(*id, balance));
}
}
}
}
Expand Down Expand Up @@ -1207,7 +1209,7 @@ impl From<MoveValue> for SuiMoveValue {
MoveValue::U8(value) => SuiMoveValue::Number(value.into()),
MoveValue::U16(value) => SuiMoveValue::Number(value.into()),
MoveValue::U32(value) => SuiMoveValue::Number(value.into()),
MoveValue::U64(value) => SuiMoveValue::Number(value),
MoveValue::U64(value) => SuiMoveValue::String(format!("{value}")),
MoveValue::U128(value) => SuiMoveValue::String(format!("{value}")),
MoveValue::U256(value) => SuiMoveValue::String(format!("{value}")),
MoveValue::Bool(value) => SuiMoveValue::Bool(value),
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
"type": "0x2::coin::Coin<0x2::coin::Coin<0x2::sui::SUI>>",
"has_public_transfer": true,
"fields": {
"balance": 10000,
"balance": "10000",
"id": {
"id": "0x686464524a876b463d1297603568c40e814d9d53"
}
Expand Down Expand Up @@ -2241,7 +2241,7 @@
"type": "0x2::coin::Coin<0x2::coin::Coin<0x2::sui::SUI>>",
"has_public_transfer": true,
"fields": {
"balance": 10000,
"balance": "10000",
"id": {
"id": "0x818dd7234e049913233eb918c11638af89d575be"
}
Expand Down