Skip to content

Commit

Permalink
fix(rpc): return the cycles of the first non-cellbase transaction as …
Browse files Browse the repository at this point in the history
…cellbase's cycles
  • Loading branch information
yangby-cryptape committed Dec 22, 2022
1 parent e2276b3 commit 78fc4bd
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions rpc/src/module/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,13 +1890,17 @@ impl ChainRpcImpl {
) -> Result<Option<TransactionWithStatus>> {
let snapshot = self.shared.snapshot();
if let Some(tx_info) = snapshot.get_transaction_info(&tx_hash) {
let cycles = snapshot
.get_block_ext(&tx_info.block_hash)
.and_then(|block_ext| {
block_ext
.cycles
.and_then(|v| v.get(tx_info.index.saturating_sub(1)).copied())
});
let cycles = if tx_info.is_cellbase() {
None
} else {
snapshot
.get_block_ext(&tx_info.block_hash)
.and_then(|block_ext| {
block_ext
.cycles
.and_then(|v| v.get(tx_info.index.saturating_sub(1)).copied())
})
};

return Ok(Some(TransactionWithStatus::with_committed(
None,
Expand Down Expand Up @@ -1929,13 +1933,17 @@ impl ChainRpcImpl {
) -> Result<Option<TransactionWithStatus>> {
let snapshot = self.shared.snapshot();
if let Some((tx, tx_info)) = snapshot.get_transaction_with_info(&tx_hash) {
let cycles = snapshot
.get_block_ext(&tx_info.block_hash)
.and_then(|block_ext| {
block_ext
.cycles
.and_then(|v| v.get(tx_info.index.saturating_sub(1)).copied())
});
let cycles = if tx_info.is_cellbase() {
None
} else {
snapshot
.get_block_ext(&tx_info.block_hash)
.and_then(|block_ext| {
block_ext
.cycles
.and_then(|v| v.get(tx_info.index.saturating_sub(1)).copied())
})
};

return Ok(Some(TransactionWithStatus::with_committed(
Some(tx),
Expand Down

0 comments on commit 78fc4bd

Please sign in to comment.