From 7f1228b6f155b6a65a595908154486b49b6e2d43 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Tue, 13 Aug 2024 13:07:50 +0800 Subject: [PATCH 1/2] Rpc::get_transaction add tx_index to TxStatus Signed-off-by: Eval EXEC --- rpc/src/module/chain.rs | 4 ++++ util/jsonrpc-types/src/blockchain.rs | 13 +++++++++++-- util/types/src/core/tx_pool.rs | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/rpc/src/module/chain.rs b/rpc/src/module/chain.rs index a7d2c861fb..a82aabb77b 100644 --- a/rpc/src/module/chain.rs +++ b/rpc/src/module/chain.rs @@ -625,6 +625,7 @@ pub trait ChainRpc { /// "block_hash": null, /// "block_number": null, /// "status": "pending", + /// "tx_index": null, /// "reason": null /// } /// } @@ -645,6 +646,7 @@ pub trait ChainRpc { /// "block_hash": null, /// "block_number": null, /// "status": "pending", + /// "tx_index": null, /// "reason": null /// } /// } @@ -2159,6 +2161,7 @@ impl ChainRpcImpl { None, tx_info.block_number, tx_info.block_hash.unpack(), + tx_info.index as u32, cycles, None, )); @@ -2207,6 +2210,7 @@ impl ChainRpcImpl { Some(tx), tx_info.block_number, tx_info.block_hash.unpack(), + tx_info.index as u32, cycles, None, )); diff --git a/util/jsonrpc-types/src/blockchain.rs b/util/jsonrpc-types/src/blockchain.rs index 247b394c1c..e5812d1d9e 100644 --- a/util/jsonrpc-types/src/blockchain.rs +++ b/util/jsonrpc-types/src/blockchain.rs @@ -593,6 +593,8 @@ pub struct TxStatus { pub block_number: Option, /// The block hash of the block which has committed this transaction in the canonical chain. pub block_hash: Option, + /// The transaction index in the block. + pub tx_index: Option, /// The reason why the transaction is rejected pub reason: Option, } @@ -602,7 +604,9 @@ impl From for TxStatus { match tx_pool_status { tx_pool::TxStatus::Pending => TxStatus::pending(), tx_pool::TxStatus::Proposed => TxStatus::proposed(), - tx_pool::TxStatus::Committed(number, hash) => TxStatus::committed(number.into(), hash), + tx_pool::TxStatus::Committed(number, hash, tx_index) => { + TxStatus::committed(number.into(), hash, tx_index.into()) + } tx_pool::TxStatus::Rejected(reason) => TxStatus::rejected(reason), tx_pool::TxStatus::Unknown => TxStatus::unknown(), } @@ -616,6 +620,7 @@ impl TxStatus { status: Status::Pending, block_number: None, block_hash: None, + tx_index: None, reason: None, } } @@ -626,6 +631,7 @@ impl TxStatus { status: Status::Proposed, block_number: None, block_hash: None, + tx_index: None, reason: None, } } @@ -635,11 +641,12 @@ impl TxStatus { /// ## Params /// /// * `hash` - the block hash in which the transaction is committed. - pub fn committed(number: BlockNumber, hash: H256) -> Self { + pub fn committed(number: BlockNumber, hash: H256, tx_index: Uint32) -> Self { Self { status: Status::Committed, block_number: Some(number), block_hash: Some(hash), + tx_index: Some(tx_index), reason: None, } } @@ -654,6 +661,7 @@ impl TxStatus { status: Status::Rejected, block_number: None, block_hash: None, + tx_index: None, reason: Some(reason), } } @@ -664,6 +672,7 @@ impl TxStatus { status: Status::Unknown, block_number: None, block_hash: None, + tx_index: None, reason: None, } } diff --git a/util/types/src/core/tx_pool.rs b/util/types/src/core/tx_pool.rs index 5cb15443f7..bed1fb1a68 100644 --- a/util/types/src/core/tx_pool.rs +++ b/util/types/src/core/tx_pool.rs @@ -122,7 +122,7 @@ pub enum TxStatus { /// Status "proposed". The transaction is in the pool and has been proposed. Proposed, /// Status "committed". The transaction has been committed to the canonical chain. - Committed(BlockNumber, H256), + Committed(BlockNumber, H256, u32), /// Status "unknown". The node has not seen the transaction, /// or it should be rejected but was cleared due to storage limitations. Unknown, @@ -216,11 +216,12 @@ impl TransactionWithStatus { tx: Option, number: BlockNumber, hash: H256, + tx_index: u32, cycles: Option, fee: Option, ) -> Self { Self { - tx_status: TxStatus::Committed(number, hash), + tx_status: TxStatus::Committed(number, hash, tx_index), transaction: tx, cycles, fee, From 0d18f5b9906be43cd7a3efc7e97f58756022141b Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Tue, 13 Aug 2024 13:40:15 +0800 Subject: [PATCH 2/2] Execute `make gen-rpc-doc` --- rpc/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rpc/README.md b/rpc/README.md index e85719ae50..b769033c7d 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -926,6 +926,7 @@ Response "block_hash": null, "block_number": null, "status": "pending", + "tx_index": null, "reason": null } } @@ -946,6 +947,7 @@ The response looks like below when `verbosity` is 0. "block_hash": null, "block_number": null, "status": "pending", + "tx_index": null, "reason": null } }