Skip to content

Commit

Permalink
node-data: added field in spent transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed May 22, 2024
1 parent 677a39d commit d619323
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions node-data/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::message::payload::{
};
use crate::message::{ConsensusHeader, SignInfo};
use crate::Serializable;
use rusk_abi::{EconomicMode, ECO_MODE_LEN};
use std::io::{self, Read, Write};

impl Serializable for Block {
Expand Down Expand Up @@ -87,6 +88,11 @@ impl Serializable for SpentTransaction {
self.inner.write(w)?;
w.write_all(&self.block_height.to_le_bytes())?;
w.write_all(&self.gas_spent.to_le_bytes())?;
{
let mut buf = [0u8; ECO_MODE_LEN];
self.economic_mode.write(&mut buf);
w.write_all(&buf)?;
}

match &self.err {
Some(e) => {
Expand All @@ -110,6 +116,9 @@ impl Serializable for SpentTransaction {

let block_height = Self::read_u64_le(r)?;
let gas_spent = Self::read_u64_le(r)?;
let mut buf = [0u8; ECO_MODE_LEN];
r.read_exact(&mut buf)?;
let economic_mode = EconomicMode::read(&buf);
let error_len = Self::read_u32_le(r)?;

let err = if error_len > 0 {
Expand All @@ -125,6 +134,7 @@ impl Serializable for SpentTransaction {
inner,
block_height,
gas_spent,
economic_mode,
err,
})
}
Expand Down
3 changes: 3 additions & 0 deletions node-data/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::io::{self, Read, Write};

#[cfg(any(feature = "faker", test))]
use fake::{Dummy, Fake, Faker};
use rusk_abi::EconomicMode;

pub type Seed = Signature;
pub type Hash = [u8; 32];
Expand Down Expand Up @@ -94,6 +95,7 @@ pub struct SpentTransaction {
pub inner: Transaction,
pub block_height: u64,
pub gas_spent: u64,
pub economic_mode: EconomicMode,
pub err: Option<String>,
}

Expand Down Expand Up @@ -443,6 +445,7 @@ pub mod faker {
inner: tx,
block_height: 0,
gas_spent: 3,
economic_mode: EconomicMode::None,
err: Some("error".to_string()),
}
}
Expand Down

0 comments on commit d619323

Please sign in to comment.