Skip to content

Commit

Permalink
Merge pull request #4283 from eval-exec/exec/add-hash-and-number-for-rpc
Browse files Browse the repository at this point in the history
[RPC CHANGE] : Add `block_number` to `TxStatus` for `get_transaction` RPC
  • Loading branch information
quake authored Jan 8, 2024
2 parents 7570a27 + 21c2afb commit c6929d0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ Response
"min_replace_fee": "0x16923f7f6a",
"tx_status": {
"block_hash": null,
"block_number": null,
"status": "pending",
"reason": null
}
Expand All @@ -909,6 +910,7 @@ The response looks like below when `verbosity` is 0.
"cycles": "0x219",
"tx_status": {
"block_hash": null,
"block_number": null,
"status": "pending",
"reason": null
}
Expand Down Expand Up @@ -7210,6 +7212,8 @@ Transaction status and the block hash if it is committed.

* `status`: [`Status`](#type-status) - The transaction status, allowed values: “pending”, “proposed” “committed” “unknown” and “rejected”.

* `block_number`: [`BlockNumber`](#type-blocknumber) `|` `null` - The block number of the block which has committed this transaction in the canonical chain.

* `block_hash`: [`H256`](#type-h256) `|` `null` - The block hash of the block which has committed this transaction in the canonical chain.

* `reason`: `string` `|` `null` - The reason why the transaction is rejected
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 @@ -623,6 +623,7 @@ pub trait ChainRpc {
/// "min_replace_fee": "0x16923f7f6a",
/// "tx_status": {
/// "block_hash": null,
/// "block_number": null,
/// "status": "pending",
/// "reason": null
/// }
Expand All @@ -642,6 +643,7 @@ pub trait ChainRpc {
/// "cycles": "0x219",
/// "tx_status": {
/// "block_hash": null,
/// "block_number": null,
/// "status": "pending",
/// "reason": null
/// }
Expand Down Expand Up @@ -2138,6 +2140,7 @@ impl ChainRpcImpl {
};
return Ok(TransactionWithStatus::with_committed(
None,
tx_info.block_number,
tx_info.block_hash.unpack(),
cycles,
None,
Expand Down Expand Up @@ -2185,6 +2188,7 @@ impl ChainRpcImpl {

return Ok(TransactionWithStatus::with_committed(
Some(tx),
tx_info.block_number,
tx_info.block_hash.unpack(),
cycles,
None,
Expand Down
11 changes: 9 additions & 2 deletions util/jsonrpc-types/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ pub enum Status {
pub struct TxStatus {
/// The transaction status, allowed values: "pending", "proposed" "committed" "unknown" and "rejected".
pub status: Status,
/// The block number of the block which has committed this transaction in the canonical chain.
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 reason why the transaction is rejected
Expand All @@ -599,7 +601,7 @@ 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(hash) => TxStatus::committed(hash),
tx_pool::TxStatus::Committed(number, hash) => TxStatus::committed(number.into(), hash),
tx_pool::TxStatus::Rejected(reason) => TxStatus::rejected(reason),
tx_pool::TxStatus::Unknown => TxStatus::unknown(),
}
Expand All @@ -611,6 +613,7 @@ impl TxStatus {
pub fn pending() -> Self {
Self {
status: Status::Pending,
block_number: None,
block_hash: None,
reason: None,
}
Expand All @@ -620,6 +623,7 @@ impl TxStatus {
pub fn proposed() -> Self {
Self {
status: Status::Proposed,
block_number: None,
block_hash: None,
reason: None,
}
Expand All @@ -630,9 +634,10 @@ impl TxStatus {
/// ## Params
///
/// * `hash` - the block hash in which the transaction is committed.
pub fn committed(hash: H256) -> Self {
pub fn committed(number: BlockNumber, hash: H256) -> Self {
Self {
status: Status::Committed,
block_number: Some(number),
block_hash: Some(hash),
reason: None,
}
Expand All @@ -646,6 +651,7 @@ impl TxStatus {
pub fn rejected(reason: String) -> Self {
Self {
status: Status::Rejected,
block_number: None,
block_hash: None,
reason: Some(reason),
}
Expand All @@ -655,6 +661,7 @@ impl TxStatus {
pub fn unknown() -> Self {
Self {
status: Status::Unknown,
block_number: None,
block_hash: 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 @@ -113,7 +113,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(H256),
Committed(BlockNumber, H256),
/// 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 @@ -203,12 +203,13 @@ impl TransactionWithStatus {
/// Build with committed status
pub fn with_committed(
tx: Option<core::TransactionView>,
number: BlockNumber,
hash: H256,
cycles: Option<core::Cycle>,
fee: Option<Capacity>,
) -> Self {
Self {
tx_status: TxStatus::Committed(hash),
tx_status: TxStatus::Committed(number, hash),
transaction: tx,
cycles,
fee,
Expand Down

0 comments on commit c6929d0

Please sign in to comment.