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

Add tx_index to TxStatus for get_transaction RPC #4583

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ Response
"block_hash": null,
"block_number": null,
"status": "pending",
"tx_index": null,
"reason": null
}
}
Expand All @@ -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
}
}
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/module/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ pub trait ChainRpc {
/// "block_hash": null,
/// "block_number": null,
/// "status": "pending",
/// "tx_index": null,
/// "reason": null
/// }
/// }
Expand All @@ -645,6 +646,7 @@ pub trait ChainRpc {
/// "block_hash": null,
/// "block_number": null,
/// "status": "pending",
/// "tx_index": null,
/// "reason": null
/// }
/// }
Expand Down Expand Up @@ -2159,6 +2161,7 @@ impl ChainRpcImpl {
None,
tx_info.block_number,
tx_info.block_hash.unpack(),
tx_info.index as u32,
cycles,
None,
));
Expand Down Expand Up @@ -2207,6 +2210,7 @@ impl ChainRpcImpl {
Some(tx),
tx_info.block_number,
tx_info.block_hash.unpack(),
tx_info.index as u32,
cycles,
None,
));
Expand Down
13 changes: 11 additions & 2 deletions util/jsonrpc-types/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ pub struct TxStatus {
pub block_number: Option<BlockNumber>,
/// The block hash of the block which has committed this transaction in the canonical chain.
pub block_hash: Option<H256>,
/// The transaction index in the block.
pub tx_index: Option<Uint32>,
/// The reason why the transaction is rejected
pub reason: Option<String>,
}
Expand All @@ -602,7 +604,9 @@ impl From<tx_pool::TxStatus> 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(),
}
Expand All @@ -616,6 +620,7 @@ impl TxStatus {
status: Status::Pending,
block_number: None,
block_hash: None,
tx_index: None,
reason: None,
}
}
Expand All @@ -626,6 +631,7 @@ impl TxStatus {
status: Status::Proposed,
block_number: None,
block_hash: None,
tx_index: None,
reason: None,
}
}
Expand All @@ -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,
}
}
Expand All @@ -654,6 +661,7 @@ impl TxStatus {
status: Status::Rejected,
block_number: None,
block_hash: None,
tx_index: None,
reason: Some(reason),
}
}
Expand All @@ -664,6 +672,7 @@ impl TxStatus {
status: Status::Unknown,
block_number: None,
block_hash: None,
tx_index: None,
reason: None,
}
}
Expand Down
5 changes: 3 additions & 2 deletions util/types/src/core/tx_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -216,11 +216,12 @@ impl TransactionWithStatus {
tx: Option<core::TransactionView>,
number: BlockNumber,
hash: H256,
tx_index: u32,
cycles: Option<core::Cycle>,
fee: Option<Capacity>,
) -> Self {
Self {
tx_status: TxStatus::Committed(number, hash),
tx_status: TxStatus::Committed(number, hash, tx_index),
transaction: tx,
cycles,
fee,
Expand Down
Loading