Skip to content

Commit 5e31343

Browse files
committed
CRC: add comment and add helper function is_phantom to StacksTransaction
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 33b4ee3 commit 5e31343

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

stackslib/src/chainstate/stacks/transaction.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use crate::chainstate::stacks::{TransactionPayloadID, *};
3434
use crate::codec::Error as CodecError;
3535
use crate::core::*;
3636
use crate::net::Error as net_error;
37+
use crate::util_lib::boot::boot_code_addr;
3738

3839
impl StacksMessageCodec for TransactionContractCall {
3940
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
@@ -1031,6 +1032,16 @@ impl StacksTransaction {
10311032
_ => false,
10321033
}
10331034
}
1035+
1036+
/// Is this a phantom transaction?
1037+
pub fn is_phantom(&self) -> bool {
1038+
let boot_address = boot_code_addr(self.is_mainnet()).into();
1039+
if let TransactionPayload::TokenTransfer(address, amount, _) = &self.payload {
1040+
*address == boot_address && *amount == 0
1041+
} else {
1042+
false
1043+
}
1044+
}
10341045
}
10351046

10361047
impl StacksTransactionSigner {

testnet/stacks-node/src/tests/neon_integrations.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,11 @@ pub mod test_observer {
194194
use std::sync::Mutex;
195195
use std::thread;
196196

197-
use clarity::boot_util::boot_code_addr;
198197
use stacks::chainstate::stacks::boot::RewardSet;
199198
use stacks::chainstate::stacks::events::StackerDBChunksEvent;
200-
use stacks::chainstate::stacks::{StacksTransaction, TransactionPayload};
199+
use stacks::chainstate::stacks::StacksTransaction;
201200
use stacks::codec::StacksMessageCodec;
202201
use stacks::config::{EventKeyType, EventObserverConfig};
203-
use stacks::core::CHAIN_ID_MAINNET;
204202
use stacks::net::api::postblock_proposal::BlockValidateResponse;
205203
use stacks::util::hash::hex_bytes;
206204
use stacks_common::types::chainstate::StacksBlockId;
@@ -590,21 +588,19 @@ pub mod test_observer {
590588
.unwrap()
591589
.iter()
592590
.filter_map(|tx_json| {
591+
// Filter out burn ops
593592
if let Some(burnchain_op_val) = tx_json.get("burnchain_op") {
594593
if !burnchain_op_val.is_null() {
595594
return None;
596595
}
597596
}
597+
// Filter out phantom txs
598598
let tx_hex = tx_json.get("raw_tx").unwrap().as_str().unwrap();
599599
let tx_bytes = hex_bytes(&tx_hex[2..]).unwrap();
600600
let tx =
601601
StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap();
602-
603-
let boot_address = boot_code_addr(tx.chain_id == CHAIN_ID_MAINNET).into();
604-
if let TransactionPayload::TokenTransfer(address, amount, _) = &tx.payload {
605-
if *address == boot_address && *amount == 0 {
606-
return None;
607-
}
602+
if tx.is_phantom() {
603+
return None;
608604
}
609605
Some(tx)
610606
})

0 commit comments

Comments
 (0)