mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 22:59:58 -07:00
43 lines
899 B
Rust
43 lines
899 B
Rust
use allocative::Allocative;
|
|
use bincode::{Decode, Encode};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use super::{Amount, Height, Price, Timestamp};
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Encode, Decode, Allocative)]
|
|
pub struct BlockData {
|
|
pub height: Height,
|
|
pub price: Price,
|
|
pub timestamp: Timestamp,
|
|
pub amount: Amount,
|
|
pub utxos: u32,
|
|
}
|
|
|
|
impl BlockData {
|
|
pub fn new(height: Height, price: Price, timestamp: Timestamp) -> Self {
|
|
Self {
|
|
height,
|
|
price,
|
|
timestamp,
|
|
amount: Amount::ZERO,
|
|
utxos: 0,
|
|
}
|
|
}
|
|
|
|
pub fn send(&mut self, amount: Amount) {
|
|
self.utxos -= 1;
|
|
|
|
if self.amount < amount {
|
|
unreachable!();
|
|
}
|
|
|
|
self.amount -= amount;
|
|
}
|
|
|
|
pub fn receive(&mut self, amount: Amount) {
|
|
self.utxos += 1;
|
|
|
|
self.amount += amount;
|
|
}
|
|
}
|