Skip to content

Commit

Permalink
move to fullnode api and rename maybe -> try
Browse files Browse the repository at this point in the history
  • Loading branch information
longbowlu committed Sep 9, 2022
1 parent 3479642 commit d1fb2db
Show file tree
Hide file tree
Showing 9 changed files with 820 additions and 2,999 deletions.
26 changes: 13 additions & 13 deletions crates/sui-json-rpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,6 @@ pub trait RpcReadApi {
/// the ID of the queried object
object_id: ObjectID,
) -> RpcResult<GetObjectDataResponse>;

/// Note there is no software-level guarantee/SLA that objects with past versions
/// can be retrieved with this API, even if the object and version exists/existed.
/// The result may vary across nodes depending on their pruning policies.
/// Return the object information for a specified version
#[method(name = "getPastObjectMaybe")]
async fn get_past_object_maybe(
&self,
/// the ID of the queried object
object_id: ObjectID,
/// the version of the queried object. If None, default to the latest known version
version: SequenceNumber,
) -> RpcResult<GetPastObjectDataResponse>;
}

#[open_rpc(namespace = "sui", tag = "Full Node API")]
Expand Down Expand Up @@ -216,6 +203,19 @@ pub trait RpcFullNodeReadApi {
/// the recipient's Sui address
addr: SuiAddress,
) -> RpcResult<Vec<(GatewayTxSeqNumber, TransactionDigest)>>;

/// Note there is no software-level guarantee/SLA that objects with past versions
/// can be retrieved by this API, even if the object and version exists/existed.
/// The result may vary across nodes depending on their pruning policies.
/// Return the object information for a specified version
#[method(name = "tryGetPastObject")]
async fn try_get_past_object(
&self,
/// the ID of the queried object
object_id: ObjectID,
/// the version of the queried object. If None, default to the latest known version
version: SequenceNumber,
) -> RpcResult<GetPastObjectDataResponse>;
}

#[open_rpc(namespace = "sui", tag = "Transaction Builder API")]
Expand Down
10 changes: 0 additions & 10 deletions crates/sui-json-rpc/src/gateway_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ use jsonrpsee_core::server::rpc_module::RpcModule;
use signature::Signature;
use sui_core::gateway_state::{GatewayClient, GatewayTxSeqNumber};
use sui_json::SuiJsonValue;
use sui_json_rpc_types::GetPastObjectDataResponse;
use sui_json_rpc_types::{
GetObjectDataResponse, RPCTransactionRequestParams, SuiObjectInfo, SuiTransactionResponse,
SuiTypeTag, TransactionBytes,
};
use sui_open_rpc::Module;
use sui_types::base_types::SequenceNumber;
use sui_types::crypto::SignatureScheme;
use sui_types::sui_serde::Base64;
use sui_types::{
Expand Down Expand Up @@ -142,14 +140,6 @@ impl RpcReadApiServer for GatewayReadApiImpl {
Ok(self.client.get_object(object_id).await?)
}

async fn get_past_object_maybe(
&self,
_object_id: ObjectID,
_seq_num: SequenceNumber,
) -> RpcResult<GetPastObjectDataResponse> {
unimplemented!("Gateway is being deprecated and does not support this api")
}

async fn get_recent_transactions(
&self,
count: u64,
Expand Down
26 changes: 13 additions & 13 deletions crates/sui-json-rpc/src/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,6 @@ impl RpcReadApiServer for ReadApi {
.try_into()?)
}

async fn get_past_object_maybe(
&self,
object_id: ObjectID,
version: SequenceNumber,
) -> RpcResult<GetPastObjectDataResponse> {
Ok(self
.state
.get_past_object_read(&object_id, version)
.await
.map_err(|e| anyhow!("{e}"))?
.try_into()?)
}

async fn get_total_transaction_number(&self) -> RpcResult<u64> {
Ok(self.state.get_total_transaction_number()?)
}
Expand Down Expand Up @@ -291,6 +278,19 @@ impl RpcFullNodeReadApiServer for FullNodeApi {
) -> RpcResult<Vec<(GatewayTxSeqNumber, TransactionDigest)>> {
Ok(self.state.get_transactions_to_addr(addr).await?)
}

async fn try_get_past_object(
&self,
object_id: ObjectID,
version: SequenceNumber,
) -> RpcResult<GetPastObjectDataResponse> {
Ok(self
.state
.get_past_object_read(&object_id, version)
.await
.map_err(|e| anyhow!("{e}"))?
.try_into()?)
}
}

impl SuiRpcModule for FullNodeApi {
Expand Down
117 changes: 23 additions & 94 deletions crates/sui-open-rpc/samples/objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,21 @@
"fields": {
"description": "An NFT created by the Sui Command Line Tool",
"id": {
<<<<<<< HEAD
"id": "0x284c8eb915ea58dc9a7a153bcb44ab21d1ff586c"
=======
"id": "0x6fa8f8a1a22f1c2406adba18cad331fa14a6b89e"
>>>>>>> 9adcc13a6 (example + cleanup)
"id": "0x10279e7b0292d67a238aa2d38d4f485011d64131"
},
"name": "Example NFT",
"url": "ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"
}
},
"owner": {
<<<<<<< HEAD
"AddressOwner": "0x5ebdaf43899d6f0062ba8106efb84ce9feee39c3"
"AddressOwner": "0x60f522d76a62cd9d18161495ed772dde1d33b47b"
},
"previousTransaction": "4c5D8BFO7wQgOvDTn/fMWm+aO4l7YJIjbVTKXbycaa4=",
"previousTransaction": "NGxBGAdabVR3DDQOUg+rgghtvS+3B2Hh0m/ycVIb22g=",
"storageRebate": 25,
"reference": {
"objectId": "0x284c8eb915ea58dc9a7a153bcb44ab21d1ff586c",
"objectId": "0x10279e7b0292d67a238aa2d38d4f485011d64131",
"version": 1,
"digest": "ChSRu1cj9Su4HJXiIiqrLl0E8YWvwdnmCpal+i3iASM="
=======
"AddressOwner": "0x121b97aee60b0655883bc2a840b609d9abbfe8c3"
},
"previousTransaction": "MAJHGLr9znq+NPww7I3yyo/lYVCdB/ALBolUE3LM+tw=",
"storageRebate": 25,
"reference": {
"objectId": "0x6fa8f8a1a22f1c2406adba18cad331fa14a6b89e",
"version": 1,
"digest": "KXEPSjH27He0LA1PG0wpGtLSKz++T+EpeZYRZ5O9YK8="
>>>>>>> 9adcc13a6 (example + cleanup)
"digest": "FnXZE/Q9kRFcpZF4ONVYrBGfeLdJ/WKVE8gEDMCarMA="
}
}
},
Expand All @@ -52,33 +37,19 @@
"fields": {
"balance": 100000000,
"id": {
<<<<<<< HEAD
"id": "0x079ac14c4b1752bd8238a257191b27f1ed90e4a6"
=======
"id": "0x05d7f393e4c8fff94648c1c9fdeb34206f8015c3"
>>>>>>> 9adcc13a6 (example + cleanup)
"id": "0x1d8abfd088c0efcfd003eaec85d9f96ed74a123b"
}
}
},
"owner": {
<<<<<<< HEAD
"AddressOwner": "0x5ebdaf43899d6f0062ba8106efb84ce9feee39c3"
=======
"AddressOwner": "0x121b97aee60b0655883bc2a840b609d9abbfe8c3"
>>>>>>> 9adcc13a6 (example + cleanup)
"AddressOwner": "0x60f522d76a62cd9d18161495ed772dde1d33b47b"
},
"previousTransaction": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"storageRebate": 0,
"reference": {
<<<<<<< HEAD
"objectId": "0x079ac14c4b1752bd8238a257191b27f1ed90e4a6",
"version": 0,
"digest": "KW70DEursbjcXUaYkcdbRHH3Xc7PaQTVd4108QsCA58="
=======
"objectId": "0x05d7f393e4c8fff94648c1c9fdeb34206f8015c3",
"objectId": "0x1d8abfd088c0efcfd003eaec85d9f96ed74a123b",
"version": 0,
"digest": "QvSP3OP5yMpl0UFwsqYwE9A8Jx3M69ykC+Htzr7EPmE="
>>>>>>> 9adcc13a6 (example + cleanup)
"digest": "Rd9dgZ/JlWwRU1iBf+93M4EK4keCKIvriFgw1w9weZ8="
}
}
},
Expand All @@ -88,29 +59,16 @@
"data": {
"dataType": "package",
"disassembled": {
<<<<<<< HEAD
"m1": "// Move bytecode v5\nmodule 75ac865faeb1ba097a8cc89a5255d44fd2db6830.m1 {\nstruct Forge has store, key {\n\tid: UID,\n\tswords_created: u64\n}\nstruct Sword has store, key {\n\tid: UID,\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(&mut TxContext): UID)\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(&mut TxContext): UID)\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": "NeuC8MV+Zu978T9lCehhAnKCc2fP1Y9ZolvToXhf8GA=",
"storageRebate": 0,
"reference": {
"objectId": "0x75ac865faeb1ba097a8cc89a5255d44fd2db6830",
"version": 1,
"digest": "j1sxaTrbjhBuYg1i9pIjWXZnThVWFl+e1QhEKDNfTJU="
=======
"m1": "// Move bytecode v5\nmodule ce4aa3b3216f857352789ee1e11a8f7e152eeca.m1 {\nstruct Forge has store, key {\n\tid: UID,\n\tswords_created: u64\n}\nstruct Sword has store, key {\n\tid: UID,\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(&mut TxContext): UID)\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(&mut TxContext): UID)\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 82a29af7ac2baed4ea598fde4aeffb14c6617021.m1 {\nstruct Forge has store, key {\n\tid: UID,\n\tswords_created: u64\n}\nstruct Sword has store, key {\n\tid: UID,\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(&mut TxContext): UID)\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(&mut TxContext): UID)\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": "xtX/6WWMWdU1HSX8/SRaMtfUc6M+qWs27RRn+7Cw4sY=",
"previousTransaction": "ljSKDIC8B/AjOXEGlRYZxUa9ZL/j9Z1r5v1CySol54k=",
"storageRebate": 0,
"reference": {
"objectId": "0x0ce4aa3b3216f857352789ee1e11a8f7e152eeca",
"objectId": "0x82a29af7ac2baed4ea598fde4aeffb14c6617021",
"version": 1,
"digest": "M2tcLfNfndyg+Re+BFu371fUCFdIWo4os6TKh7GNGSE="
>>>>>>> 9adcc13a6 (example + cleanup)
"digest": "CFeKfWuPo058pH2aCUqu1S0imUFfpueHYzMhKyujk0w="
}
}
},
Expand All @@ -119,39 +77,21 @@
"details": {
"data": {
"dataType": "moveObject",
<<<<<<< HEAD
"type": "0x6b9fe4dd703941158b3fcd3ec82caf313df0f17f::hero::Hero",
"has_public_transfer": true,
"fields": {
"experience": 0,
"game_id": "0x9dc960669ea6db78a339e948e4a094b76d0f757f",
"hp": 100,
"id": {
"id": "0x5a2d7ed9d0bdd8587328a0abc9e760cabbdb79fc"
},
"sword": {
"type": "0x6b9fe4dd703941158b3fcd3ec82caf313df0f17f::hero::Sword",
"fields": {
"game_id": "0x9dc960669ea6db78a339e948e4a094b76d0f757f",
"id": {
"id": "0x4e015f0cfc03cf028a29fa9ba078c7980d6162a3"
=======
"type": "0xe3792312b13c834858abfbb5ba5c17d4d32800a8::hero::Hero",
"type": "0x58913af17699d5b9b97f828afd831d4cd409b0ae::hero::Hero",
"has_public_transfer": true,
"fields": {
"experience": 0,
"game_id": "0xccec7ff7b6421d746bfe37d547b60381767b8d78",
"game_id": "0xe51a4152c79ae0456491c349ad6cd5023c8d94c0",
"hp": 100,
"id": {
"id": "0x38e9bf5cfefab52afd169608b5b2c39b530e08e7"
"id": "0x56d274cef468478c1b30cd8a053b0aaae1e8d571"
},
"sword": {
"type": "0xe3792312b13c834858abfbb5ba5c17d4d32800a8::hero::Sword",
"type": "0x58913af17699d5b9b97f828afd831d4cd409b0ae::hero::Sword",
"fields": {
"game_id": "0xccec7ff7b6421d746bfe37d547b60381767b8d78",
"game_id": "0xe51a4152c79ae0456491c349ad6cd5023c8d94c0",
"id": {
"id": "0x6720945e2377451fad8cfb144159cc2f57be2216"
>>>>>>> 9adcc13a6 (example + cleanup)
"id": "0xca7edcb03c27040ef97cd0c4005ecb4058a87247"
},
"magic": 10,
"strength": 1
Expand All @@ -160,25 +100,14 @@
}
},
"owner": {
<<<<<<< HEAD
"AddressOwner": "0x5ebdaf43899d6f0062ba8106efb84ce9feee39c3"
},
"previousTransaction": "hqkAt6yhjy0NqUPz/ktsoPzVnEsNnH9PUx4MiLYENpE=",
"storageRebate": 21,
"reference": {
"objectId": "0x5a2d7ed9d0bdd8587328a0abc9e760cabbdb79fc",
"version": 1,
"digest": "/kSLV/qUW3kKwez4wTHTNCCnZcnrzOe1Llir5wz0JZE="
=======
"AddressOwner": "0x121b97aee60b0655883bc2a840b609d9abbfe8c3"
"AddressOwner": "0x60f522d76a62cd9d18161495ed772dde1d33b47b"
},
"previousTransaction": "mgaif+kz/Faag8O4V/TO6kOMDy/npnOvF31VZlXRf38=",
"previousTransaction": "uvRR/ZVQ75HhewMQmp/G2kjb7ETmMCmYxdcVI6jVG+I=",
"storageRebate": 21,
"reference": {
"objectId": "0x38e9bf5cfefab52afd169608b5b2c39b530e08e7",
"objectId": "0x56d274cef468478c1b30cd8a053b0aaae1e8d571",
"version": 1,
"digest": "z+KQz3P3aTEfGLez9PirzpRXkTzjd3sPSdVMWaaF25E="
>>>>>>> 9adcc13a6 (example + cleanup)
"digest": "AQ/zK6g681vs76niWR2728NKJzcEZIEivt+jqoKidm0="
}
}
}
Expand Down
Loading

0 comments on commit d1fb2db

Please sign in to comment.