primitives/
transaction_index.rs1use cfx_types::H256;
6use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
7use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream};
8
9#[derive(Debug, PartialEq, Eq, Hash, Clone, Default)]
11pub struct TransactionIndex {
12 pub block_hash: H256,
14 pub real_index: usize,
16 pub is_phantom: bool,
18 pub rpc_index: Option<usize>,
20}
21
22impl MallocSizeOf for TransactionIndex {
23 fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { 0 }
24}
25
26impl Encodable for TransactionIndex {
27 fn rlp_append(&self, s: &mut RlpStream) {
28 s.begin_list(4);
29 s.append(&self.block_hash);
30 s.append(&self.real_index);
31 s.append(&self.is_phantom);
32 s.append(&self.rpc_index);
33 }
34}
35
36impl Decodable for TransactionIndex {
37 fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
38 match rlp.item_count()? {
39 2 => Ok(TransactionIndex {
40 block_hash: rlp.val_at(0)?,
41 real_index: rlp.val_at(1)?,
42 is_phantom: false,
43 rpc_index: None,
44 }),
45 3 => Ok(TransactionIndex {
46 block_hash: rlp.val_at(0)?,
47 real_index: rlp.val_at(1)?,
48 is_phantom: rlp.val_at(2)?,
49 rpc_index: None,
50 }),
51 4 => Ok(TransactionIndex {
52 block_hash: rlp.val_at(0)?,
53 real_index: rlp.val_at(1)?,
54 is_phantom: rlp.val_at(2)?,
55 rpc_index: rlp.val_at(3)?,
56 }),
57 _ => Err(DecoderError::RlpInvalidLength),
58 }
59 }
60}