mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 23:29:58 -07:00
git: reset
This commit is contained in:
46
parser/src/structs/address_realized_data.rs
Normal file
46
parser/src/structs/address_realized_data.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use super::{AddressData, Price, ProfitOrLoss, WAmount};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AddressRealizedData {
|
||||
pub initial_address_data: AddressData,
|
||||
pub received: WAmount,
|
||||
pub sent: WAmount,
|
||||
pub profit: Price,
|
||||
pub loss: Price,
|
||||
pub utxos_created: u32,
|
||||
pub utxos_destroyed: u32,
|
||||
}
|
||||
|
||||
impl AddressRealizedData {
|
||||
pub fn default(initial_address_data: &AddressData) -> Self {
|
||||
Self {
|
||||
received: WAmount::ZERO,
|
||||
sent: WAmount::ZERO,
|
||||
profit: Price::ZERO,
|
||||
loss: Price::ZERO,
|
||||
utxos_created: 0,
|
||||
utxos_destroyed: 0,
|
||||
initial_address_data: *initial_address_data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn receive(&mut self, amount: WAmount) {
|
||||
self.received += amount;
|
||||
self.utxos_created += 1;
|
||||
}
|
||||
|
||||
pub fn send(&mut self, amount: WAmount, realized_profit_or_loss: ProfitOrLoss) {
|
||||
self.sent += amount;
|
||||
|
||||
self.utxos_destroyed += 1;
|
||||
|
||||
match realized_profit_or_loss {
|
||||
ProfitOrLoss::Profit(price) => {
|
||||
self.profit += price;
|
||||
}
|
||||
ProfitOrLoss::Loss(price) => {
|
||||
self.loss += price;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user