Skip to content

Commit e2809fc

Browse files
Ji Young Songjoojis
authored andcommitted
Fixed #386 that adding optional block number param to getAsset() RPC method
1 parent 29b5033 commit e2809fc

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

core/src/client/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ impl AssetClient for Client {
265265
}
266266
}
267267

268-
fn get_asset(&self, transaction_hash: H256, index: usize) -> TrieResult<Option<Asset>> {
269-
if let Some(state) = Client::state_at(&self, BlockId::Latest) {
268+
fn get_asset(&self, transaction_hash: H256, index: usize, id: BlockId) -> TrieResult<Option<Asset>> {
269+
if let Some(state) = Client::state_at(&self, id) {
270270
let shard_id = 0; // FIXME
271271
let address = AssetAddress::new(transaction_hash, index, shard_id);
272272
Ok(state.asset(shard_id, &address)?)

core/src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,5 @@ pub trait DatabaseClient {
239239
pub trait AssetClient {
240240
fn get_asset_scheme(&self, transaction_hash: H256) -> TrieResult<Option<AssetScheme>>;
241241

242-
fn get_asset(&self, transaction_hash: H256, index: usize) -> TrieResult<Option<Asset>>;
242+
fn get_asset(&self, transaction_hash: H256, index: usize, id: BlockId) -> TrieResult<Option<Asset>>;
243243
}

rpc/src/v1/impls/chain.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ where
8787
self.client.get_asset_scheme(transaction_hash).map_err(errors::parcel)
8888
}
8989

90-
fn get_asset(&self, transaction_hash: H256, index: usize) -> Result<Option<Asset>> {
91-
self.client.get_asset(transaction_hash, index).map_err(errors::parcel)
90+
fn get_asset(&self, transaction_hash: H256, index: usize, block_number: Option<u64>) -> Result<Option<Asset>> {
91+
let block_id = block_number.map(BlockId::Number).unwrap_or(BlockId::Latest);
92+
self.client.get_asset(transaction_hash, index, block_id).map_err(errors::parcel)
9293
}
9394

9495
fn get_nonce(&self, address: H160, block_number: Option<u64>) -> Result<Option<U256>> {

rpc/src/v1/traits/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ build_rpc_trait! {
4646

4747
/// Gets asset with given asset type.
4848
# [rpc(name = "chain_getAsset")]
49-
fn get_asset(&self, H256, usize) -> Result<Option<Asset>>;
49+
fn get_asset(&self, H256, usize, Option<u64>) -> Result<Option<Asset>>;
5050

5151
/// Gets nonce with given account.
5252
# [rpc(name = "chain_getNonce")]

spec/JSON-RPC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ Gets an asset with the given asset type.
461461
Params:
462462
1. transaction hash - `H256`
463463
2. index - `number`
464+
3. block number: `number` | `null`
464465

465466
Return Type: `null` | `AssetObject`
466467

0 commit comments

Comments
 (0)