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 20, 2022
1 parent adcfac4 commit 50cb412
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 @@ -2028,13 +2028,17 @@ impl ChainRpcImpl {
fn get_transaction_verbosity1(&self, tx_hash: packed::Byte32) -> Result<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(TransactionWithStatus::with_committed(
None,
Expand Down Expand Up @@ -2062,13 +2066,17 @@ impl ChainRpcImpl {
fn get_transaction_verbosity2(&self, tx_hash: packed::Byte32) -> Result<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(TransactionWithStatus::with_committed(
Some(tx),
Expand Down

0 comments on commit 50cb412

Please sign in to comment.