Skip to content

Commit

Permalink
Rename tx_version and tx_locktime
Browse files Browse the repository at this point in the history
  • Loading branch information
gcarq committed Jul 21, 2020
1 parent dadaa4c commit 30604f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
22 changes: 8 additions & 14 deletions src/blockchain/parser/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub trait BlockchainRead: io::Read {
let mut txs: Vec<Tx> = Vec::with_capacity(tx_count as usize);
for _ in 0..tx_count {
let mut flags = 0u8;
let tx_version = self.read_u32::<LittleEndian>()?;
let version = self.read_u32::<LittleEndian>()?;

// Parse transaction inputs and check if this transaction contains segwit data
let mut in_count = VarUint::read_from(self)?;
Expand All @@ -74,15 +74,9 @@ pub trait BlockchainRead: io::Read {
}
}
}
let tx_locktime = self.read_u32::<LittleEndian>()?;
let locktime = self.read_u32::<LittleEndian>()?;
let tx = Tx::new(
tx_version,
in_count,
&inputs,
out_count,
&outputs,
tx_locktime,
version_id,
version, in_count, &inputs, out_count, &outputs, locktime, version_id,
);
txs.push(tx);
}
Expand Down Expand Up @@ -154,7 +148,7 @@ mod tests {
bits 0x1d00ffff
nonce 0x1dac2b7c
tx_count 0x01
tx_version 0x01000000 big endian??
tx.version 0x01000000 big endian??
tx.in_count 0x01
tx.in.prev_hash 0x0000000000000000000000000000000000000000000000000000000000000000
tx.in.out_id 0xffffffff
Expand Down Expand Up @@ -242,7 +236,7 @@ mod tests {

// Tx
assert_eq!(0x01, block.tx_count.value);
assert_eq!(0x00000001, block.txs[0].value.tx_version);
assert_eq!(0x00000001, block.txs[0].value.version);

// Tx Inputs
assert_eq!(0x01, block.txs[0].value.in_count.value);
Expand All @@ -267,7 +261,7 @@ mod tests {
let script_pubkey = &block.txs[0].value.outputs[0].out.script_pubkey;
assert_eq!("4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac",
utils::arr_to_hex(&script_pubkey));
assert_eq!(0x00000000, block.txs[0].value.tx_locktime);
assert_eq!(0x00000000, block.txs[0].value.locktime);

assert_eq!(
Some(String::from("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa")),
Expand Down Expand Up @@ -323,7 +317,7 @@ mod tests {
assert_eq!(txs.len(), 1);

let tx = txs.first().unwrap();
assert_eq!(tx.tx_version, 1);
assert_eq!(tx.version, 1);

// Assert inputs
assert_eq!(tx.in_count.value, 1);
Expand Down Expand Up @@ -352,6 +346,6 @@ mod tests {
Some(String::from("13gv9XbKJPxxRF8Zm1LsVKeeiMCFguQPqm"))
);

assert_eq!(tx.tx_locktime, 0);
assert_eq!(tx.locktime, 0);
}
}
20 changes: 10 additions & 10 deletions src/blockchain/proto/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ use crate::common::utils;
/// Please note: The txid is not stored here. See Hashed.
#[derive(Clone)]
pub struct Tx {
pub tx_version: u32,
pub version: u32,
pub in_count: VarUint,
pub inputs: Vec<TxInput>,
pub out_count: VarUint,
pub outputs: Vec<EvaluatedTxOut>,
pub tx_locktime: u32,
pub locktime: u32,
}

impl Tx {
pub fn new(
tx_version: u32,
version: u32,
in_count: VarUint,
inputs: &[TxInput],
out_count: VarUint,
outputs: &[TxOutput],
tx_locktime: u32,
locktime: u32,
version_id: u8,
) -> Self {
// Evaluate and wrap all outputs to process them later
Expand All @@ -34,12 +34,12 @@ impl Tx {
.map(|o| EvaluatedTxOut::eval_script(o, version_id))
.collect();
Tx {
tx_version,
version,
in_count,
inputs: Vec::from(inputs),
out_count,
outputs: evaluated_out,
tx_locktime,
locktime,
}
}

Expand All @@ -56,10 +56,10 @@ impl Tx {
impl fmt::Debug for Tx {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("Tx")
.field("tx_version", &self.tx_version)
.field("version", &self.version)
.field("in_count", &self.in_count)
.field("out_count", &self.out_count)
.field("tx_locktime", &self.tx_locktime)
.field("locktime", &self.locktime)
.finish()
}
}
Expand All @@ -70,7 +70,7 @@ impl ToRaw for Tx {
Vec::with_capacity((4 + self.in_count.value + self.out_count.value + 4) as usize);

// Serialize version
bytes.extend_from_slice(&self.tx_version.to_le_bytes());
bytes.extend_from_slice(&self.version.to_le_bytes());
// Serialize all TxInputs
bytes.extend_from_slice(&self.in_count.to_bytes());
for i in &self.inputs {
Expand All @@ -82,7 +82,7 @@ impl ToRaw for Tx {
bytes.extend_from_slice(&o.out.to_bytes());
}
// Serialize locktime
bytes.extend_from_slice(&self.tx_locktime.to_le_bytes());
bytes.extend_from_slice(&self.locktime.to_le_bytes());
bytes
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/callbacks/csvdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ impl Hashed<Tx> {
"{};{};{};{}\n",
&utils::arr_to_hex_swapped(&self.hash),
&block_hash,
&self.value.tx_version,
&self.value.tx_locktime
&self.value.version,
&self.value.locktime
)
}
}
Expand Down

0 comments on commit 30604f1

Please sign in to comment.