mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 22:59:58 -07:00
brk: first commit
This commit is contained in:
42
_src/structs/block_data.rs
Normal file
42
_src/structs/block_data.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user