Skip to content

Commit

Permalink
[PR 2921] - Make event's move struct fields optional as gateway might…
Browse files Browse the repository at this point in the history
… not have layout for the event object (MystenLabs#3260)

* [PR 2921] - Making event's move struct fields optional as gateway might not have layout for the event object

* balance check fix
  • Loading branch information
patrickkuo authored Jul 19, 2022
1 parent 85c4908 commit 7c3a8d7
Show file tree
Hide file tree
Showing 7 changed files with 656 additions and 638 deletions.
20 changes: 16 additions & 4 deletions crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,8 @@ pub enum SuiEvent {
transaction_module: String,
sender: SuiAddress,
type_: String,
fields: SuiMoveStruct,
#[serde(skip_serializing_if = "Option::is_none")]
fields: Option<SuiMoveStruct>,
#[serde_as(as = "Base64")]
#[schemars(with = "Base64")]
bcs: Vec<u8>,
Expand Down Expand Up @@ -1320,9 +1321,20 @@ impl SuiEvent {
contents,
} => {
let bcs = contents.to_vec();
let move_struct = Event::move_event_to_move_struct(&type_, &contents, resolver)?;
let (type_, fields) =
SuiParsedMoveObject::try_type_and_fields_from_move_struct(&type_, move_struct)?;

// Resolver is not guaranteed to have knowledge of the event struct layout in the gateway server.
let (type_, fields) = if let Ok(move_struct) =
Event::move_event_to_move_struct(&type_, &contents, resolver)
{
let (type_, field) = SuiParsedMoveObject::try_type_and_fields_from_move_struct(
&type_,
move_struct,
)?;
(type_, Some(field))
} else {
(type_.to_string(), None)
};

SuiEvent::MoveEvent {
package_id,
transaction_module: transaction_module.to_string(),
Expand Down
48 changes: 24 additions & 24 deletions crates/sui-open-rpc/samples/objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
"fields": {
"description": "An NFT created by the Sui Command Line Tool",
"id": {
"id": "0xc3e9d83dcae448e0dd11e4b6f335ff5c799e8634",
"id": "0xd2cb542d697f4d4eb46bbf9895f57ec0d292a624",
"version": 1
},
"name": "Example NFT",
"url": "ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"
}
},
"owner": {
"AddressOwner": "0x64a8871979a7c12fa56d9c5945d31be65dc13981"
"AddressOwner": "0x6b2ea8ccfd5ddfd9e8bd60ea02b8a95eb423c7b1"
},
"previousTransaction": "BS3pH4QhbMQWt0iodI4SRQbwSMImIlq5RIx+6SOxpKA=",
"previousTransaction": "6fDbda+AKObGCTE1MGJIH7qh1jqB6/zXgKmo0koCYEw=",
"storageRebate": 25,
"reference": {
"objectId": "0xc3e9d83dcae448e0dd11e4b6f335ff5c799e8634",
"objectId": "0xd2cb542d697f4d4eb46bbf9895f57ec0d292a624",
"version": 1,
"digest": "aeR++MH+pI6gzvEqhLFeejiNdX012jTdUD0wXIAcsq0="
"digest": "ZGuaq8kzqYDRyHm2FAUlfg4TujTV2RG851HZaErqfs0="
}
}
},
Expand All @@ -36,22 +36,22 @@
"type": "0x2::coin::Coin<0x2::sui::SUI>",
"has_public_transfer": true,
"fields": {
"balance": 100000,
"balance": 100000000,
"id": {
"id": "0x0b0b40a1d5504cb2f86973a474820e5d219b03ee",
"id": "0x041aa7ce3014836ee1222429dce10b096906245f",
"version": 0
}
}
},
"owner": {
"AddressOwner": "0x64a8871979a7c12fa56d9c5945d31be65dc13981"
"AddressOwner": "0x6b2ea8ccfd5ddfd9e8bd60ea02b8a95eb423c7b1"
},
"previousTransaction": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"storageRebate": 0,
"reference": {
"objectId": "0x0b0b40a1d5504cb2f86973a474820e5d219b03ee",
"objectId": "0x041aa7ce3014836ee1222429dce10b096906245f",
"version": 0,
"digest": "vWqDtJF8FhuZ934U+kiMnnyoM4BE91luGYn/ekH6qtE="
"digest": "yLTxLBNlJGe1Jr8jIlP2tVU7Nv1dIQjwp5JvsiE6N48="
}
}
},
Expand All @@ -61,16 +61,16 @@
"data": {
"dataType": "package",
"disassembled": {
"m1": "// Move bytecode v5\nmodule 60de1533a407dd511fc3db239d7151c6bbefad6.m1 {\nstruct Forge has store, key {\n\tid: VersionedID,\n\tswords_created: u64\n}\nstruct Sword has store, key {\n\tid: VersionedID,\n\tmagic: u64,\n\tstrength: u64\n}\n\ninit(Arg0: &mut TxContext) {\nB0:\n\t0: CopyLoc[0](Arg0: &mut TxContext)\n\t1: Call[6](new_id(&mut TxContext): VersionedID)\n\t2: LdU64(0)\n\t3: Pack[0](Forge)\n\t4: StLoc[1](loc0: Forge)\n\t5: MoveLoc[1](loc0: Forge)\n\t6: MoveLoc[0](Arg0: &mut TxContext)\n\t7: FreezeRef\n\t8: Call[7](sender(&TxContext): address)\n\t9: Call[0](transfer<Forge>(Forge, address))\n\t10: Ret\n}\npublic magic(Arg0: &Sword): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Sword)\n\t1: ImmBorrowField[0](Sword.magic: u64)\n\t2: ReadRef\n\t3: Ret\n}\npublic strength(Arg0: &Sword): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Sword)\n\t1: ImmBorrowField[1](Sword.strength: u64)\n\t2: ReadRef\n\t3: Ret\n}\nentry public sword_create(Arg0: &mut Forge, Arg1: u64, Arg2: u64, Arg3: address, Arg4: &mut TxContext) {\nB0:\n\t0: MoveLoc[4](Arg4: &mut TxContext)\n\t1: Call[6](new_id(&mut TxContext): VersionedID)\n\t2: MoveLoc[1](Arg1: u64)\n\t3: MoveLoc[2](Arg2: u64)\n\t4: Pack[1](Sword)\n\t5: StLoc[5](loc0: Sword)\n\t6: MoveLoc[5](loc0: Sword)\n\t7: MoveLoc[3](Arg3: address)\n\t8: Call[1](transfer<Sword>(Sword, address))\n\t9: CopyLoc[0](Arg0: &mut Forge)\n\t10: ImmBorrowField[2](Forge.swords_created: u64)\n\t11: ReadRef\n\t12: LdU64(1)\n\t13: Add\n\t14: MoveLoc[0](Arg0: &mut Forge)\n\t15: MutBorrowField[2](Forge.swords_created: u64)\n\t16: WriteRef\n\t17: Ret\n}\nentry public sword_transfer(Arg0: Sword, Arg1: address) {\nB0:\n\t0: MoveLoc[0](Arg0: Sword)\n\t1: MoveLoc[1](Arg1: address)\n\t2: Call[1](transfer<Sword>(Sword, address))\n\t3: Ret\n}\npublic swords_created(Arg0: &Forge): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Forge)\n\t1: ImmBorrowField[2](Forge.swords_created: u64)\n\t2: ReadRef\n\t3: Ret\n}\n}"
"m1": "// Move bytecode v5\nmodule 53a29d8dfaebba39f946e48569942c17ce7f0346.m1 {\nstruct Forge has store, key {\n\tid: VersionedID,\n\tswords_created: u64\n}\nstruct Sword has store, key {\n\tid: VersionedID,\n\tmagic: u64,\n\tstrength: u64\n}\n\ninit(Arg0: &mut TxContext) {\nB0:\n\t0: CopyLoc[0](Arg0: &mut TxContext)\n\t1: Call[6](new_id(&mut TxContext): VersionedID)\n\t2: LdU64(0)\n\t3: Pack[0](Forge)\n\t4: StLoc[1](loc0: Forge)\n\t5: MoveLoc[1](loc0: Forge)\n\t6: MoveLoc[0](Arg0: &mut TxContext)\n\t7: FreezeRef\n\t8: Call[7](sender(&TxContext): address)\n\t9: Call[0](transfer<Forge>(Forge, address))\n\t10: Ret\n}\npublic magic(Arg0: &Sword): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Sword)\n\t1: ImmBorrowField[0](Sword.magic: u64)\n\t2: ReadRef\n\t3: Ret\n}\npublic strength(Arg0: &Sword): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Sword)\n\t1: ImmBorrowField[1](Sword.strength: u64)\n\t2: ReadRef\n\t3: Ret\n}\nentry public sword_create(Arg0: &mut Forge, Arg1: u64, Arg2: u64, Arg3: address, Arg4: &mut TxContext) {\nB0:\n\t0: MoveLoc[4](Arg4: &mut TxContext)\n\t1: Call[6](new_id(&mut TxContext): VersionedID)\n\t2: MoveLoc[1](Arg1: u64)\n\t3: MoveLoc[2](Arg2: u64)\n\t4: Pack[1](Sword)\n\t5: StLoc[5](loc0: Sword)\n\t6: MoveLoc[5](loc0: Sword)\n\t7: MoveLoc[3](Arg3: address)\n\t8: Call[1](transfer<Sword>(Sword, address))\n\t9: CopyLoc[0](Arg0: &mut Forge)\n\t10: ImmBorrowField[2](Forge.swords_created: u64)\n\t11: ReadRef\n\t12: LdU64(1)\n\t13: Add\n\t14: MoveLoc[0](Arg0: &mut Forge)\n\t15: MutBorrowField[2](Forge.swords_created: u64)\n\t16: WriteRef\n\t17: Ret\n}\nentry public sword_transfer(Arg0: Sword, Arg1: address) {\nB0:\n\t0: MoveLoc[0](Arg0: Sword)\n\t1: MoveLoc[1](Arg1: address)\n\t2: Call[1](transfer<Sword>(Sword, address))\n\t3: Ret\n}\npublic swords_created(Arg0: &Forge): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Forge)\n\t1: ImmBorrowField[2](Forge.swords_created: u64)\n\t2: ReadRef\n\t3: Ret\n}\n}"
}
},
"owner": "Immutable",
"previousTransaction": "jit8/FCUeexC6c3AxvodzpZN3KO0zbNZr2LSLGvePBw=",
"previousTransaction": "TLdo1wCY0vWfnsrmgiHyR1K19Uv1QxWloa7mTZl1dic=",
"storageRebate": 0,
"reference": {
"objectId": "0x060de1533a407dd511fc3db239d7151c6bbefad6",
"objectId": "0x53a29d8dfaebba39f946e48569942c17ce7f0346",
"version": 1,
"digest": "Vc/LZ5Fg8h8EI+xXKy0qPA+pKHorwLXsT1WAwEB1JHQ="
"digest": "+w4Hg26HkypuAhtYWREs3Hs1s10K6tUb59+OTU2iPO0="
}
}
},
Expand All @@ -79,22 +79,22 @@
"details": {
"data": {
"dataType": "moveObject",
"type": "0x5080e4b96668d771ae39b56654e3fa6f60e6a15f::hero::Hero",
"type": "0x5f3e7d80754b3219e4795852962cf8c9936eda99::hero::Hero",
"has_public_transfer": true,
"fields": {
"experience": 0,
"game_id": "0x74be45916e9d52761368e0bcbe1054040cc50351",
"game_id": "0x31e1f3bca5e98f08262a6c0bfa54907a318a86f9",
"hp": 100,
"id": {
"id": "0x49f462194d72e920a5e8d440f02c241a0a8669c3",
"id": "0xaff16e1ecfd47239dbec05c36c20a665e2d6a624",
"version": 1
},
"sword": {
"type": "0x5080e4b96668d771ae39b56654e3fa6f60e6a15f::hero::Sword",
"type": "0x5f3e7d80754b3219e4795852962cf8c9936eda99::hero::Sword",
"fields": {
"game_id": "0x74be45916e9d52761368e0bcbe1054040cc50351",
"game_id": "0x31e1f3bca5e98f08262a6c0bfa54907a318a86f9",
"id": {
"id": "0x22719afff0b9f17b0ae2b55748e124db4324d408",
"id": "0x32cba6c7e55122b36e042c262c65a628112fe72c",
"version": 0
},
"magic": 10,
Expand All @@ -104,14 +104,14 @@
}
},
"owner": {
"AddressOwner": "0x64a8871979a7c12fa56d9c5945d31be65dc13981"
"AddressOwner": "0x6b2ea8ccfd5ddfd9e8bd60ea02b8a95eb423c7b1"
},
"previousTransaction": "NCqxzq13uYrpPJMvisOuNzbjizHQ+OSv6zrEb2NJCfE=",
"previousTransaction": "jpxXRW9uvwcLFsWr0ypm0WS35VVaBOskvzqdQ1Ud0q0=",
"storageRebate": 22,
"reference": {
"objectId": "0x49f462194d72e920a5e8d440f02c241a0a8669c3",
"objectId": "0xaff16e1ecfd47239dbec05c36c20a665e2d6a624",
"version": 1,
"digest": "zoeUQeBURGL4TvslreVZ44GZXCwvslSTiSprKeZemlg="
"digest": "6rb4gSpt/iorPaCAN9GDMe3Bmtvyexp2Oy6G6C6xmS0="
}
}
}
Expand Down
Loading

0 comments on commit 7c3a8d7

Please sign in to comment.