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

[RPC CHANGE] : Add block_number to TxStatus for get_transaction RPC #4283

Merged
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
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
Loading