Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 7371fd2

Browse files
Fix compilation
1 parent b2d5ddc commit 7371fd2

File tree

8 files changed

+489
-56
lines changed

8 files changed

+489
-56
lines changed

Cargo.lock

Lines changed: 423 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bee-ledger/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//! A crate that contains all types and features required to compute and maintain the ledger state.
55
6-
//#![warn(missing_docs)]
6+
// #![warn(missing_docs)]
77

88
pub mod types;
99
#[cfg(feature = "workers")]

bee-ledger/src/types/balance_diff.rs

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
use crate::types::Error;
55

6-
use bee_message::{address::Address, constants::IOTA_SUPPLY};
6+
use bee_message::{
7+
address::Address,
8+
constants::IOTA_SUPPLY,
9+
output::{Output, DUST_THRESHOLD},
10+
};
711

812
use std::collections::{
913
hash_map::{IntoIter, Iter, IterMut},
@@ -100,6 +104,49 @@ impl BalanceDiffs {
100104
self.0.get(address)
101105
}
102106

107+
/// Negates a `BalanceDiffs`.
108+
pub fn negate(&mut self) {
109+
for (_, diff) in self.iter_mut() {
110+
diff.negate();
111+
}
112+
}
113+
114+
pub fn output_add(&mut self, output: &Output) -> Result<(), Error> {
115+
match output {
116+
Output::SignatureLockedSingle(output) => {
117+
self.amount_add(*output.address(), output.amount())?;
118+
if output.amount() < DUST_THRESHOLD {
119+
self.dust_outputs_inc(*output.address())?;
120+
}
121+
}
122+
Output::SignatureLockedDustAllowance(output) => {
123+
self.amount_add(*output.address(), output.amount())?;
124+
self.dust_allowance_add(*output.address(), output.amount())?;
125+
}
126+
output => return Err(Error::UnsupportedOutputKind(output.kind())),
127+
}
128+
129+
Ok(())
130+
}
131+
132+
pub fn output_sub(&mut self, output: &Output) -> Result<(), Error> {
133+
match output {
134+
Output::SignatureLockedSingle(output) => {
135+
self.amount_sub(*output.address(), output.amount())?;
136+
if output.amount() < DUST_THRESHOLD {
137+
self.dust_outputs_dec(*output.address())?;
138+
}
139+
}
140+
Output::SignatureLockedDustAllowance(output) => {
141+
self.amount_sub(*output.address(), output.amount())?;
142+
self.dust_allowance_sub(*output.address(), output.amount())?;
143+
}
144+
output => return Err(Error::UnsupportedOutputKind(output.kind())),
145+
}
146+
147+
Ok(())
148+
}
149+
103150
/// Adds a given amount to a given address.
104151
pub fn amount_add(&mut self, address: Address, amount: u64) -> Result<(), Error> {
105152
let entry = self.0.entry(address).or_default();
@@ -169,13 +216,6 @@ impl BalanceDiffs {
169216
pub fn iter_mut(&mut self) -> IterMut<'_, Address, BalanceDiff> {
170217
self.0.iter_mut()
171218
}
172-
173-
/// Negates a `BalanceDiffs`.
174-
pub fn negate(&mut self) {
175-
for (_, diff) in self.iter_mut() {
176-
diff.negate();
177-
}
178-
}
179219
}
180220

181221
impl IntoIterator for BalanceDiffs {

bee-ledger/src/types/unspent.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use bee_message::output::OutputId;
99
use std::ops::Deref;
1010

1111
/// Represents an output id as unspent.
12-
#[derive(Debug, Eq, PartialEq)]
12+
#[derive(Eq, PartialEq)]
1313
pub struct Unspent(OutputId);
1414

1515
impl From<OutputId> for Unspent {
@@ -38,6 +38,18 @@ impl Unspent {
3838
}
3939
}
4040

41+
impl core::fmt::Display for Unspent {
42+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
43+
write!(f, "{}", *self)
44+
}
45+
}
46+
47+
impl core::fmt::Debug for Unspent {
48+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
49+
write!(f, "Unspent({})", self)
50+
}
51+
}
52+
4153
impl Packable for Unspent {
4254
type Error = Error;
4355

bee-ledger/src/workers/consensus/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use crate::types::{BalanceDiffs, ConsumedOutput, CreatedOutput};
55

6-
use bee_ledger_types::types::ConflictReason;
76
use bee_message::{milestone::MilestoneIndex, output::OutputId, MessageId};
7+
use bee_tangle::ConflictReason;
88

99
use std::collections::HashMap;
1010

bee-ledger/src/workers/consensus/white_flag.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::{
1010
},
1111
};
1212

13-
use bee_ledger_types::types::ConflictReason;
1413
use bee_message::{
1514
address::Address,
1615
input::Input,
@@ -22,7 +21,7 @@ use bee_message::{
2221
unlock::{UnlockBlock, UnlockBlocks},
2322
Message, MessageId,
2423
};
25-
use bee_tangle::MsTangle;
24+
use bee_tangle::{ConflictReason, MsTangle};
2625

2726
use crypto::hashes::blake2b::Blake2b256;
2827

bee-ledger/src/workers/consensus/worker.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ use crate::{
1717
},
1818
};
1919

20-
use bee_ledger_types::types::ConflictReason;
2120
use bee_message::{
2221
milestone::MilestoneIndex,
2322
output::{Output, OutputId},
2423
payload::{milestone::MilestoneId, receipt::ReceiptPayload, transaction::TransactionId, Payload},
2524
MessageId,
2625
};
2726
use bee_runtime::{event::Bus, node::Node, shutdown_stream::ShutdownStream, worker::Worker};
28-
use bee_tangle::{MsTangle, TangleWorker};
27+
use bee_tangle::{ConflictReason, MsTangle, TangleWorker};
2928

3029
use async_trait::async_trait;
3130

bee-ledger/src/workers/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use crate::types::{ConsumedOutput, CreatedOutput};
55

6-
use bee_ledger_types::types::ConflictReason;
76
use bee_message::{milestone::MilestoneIndex, MessageId};
7+
use bee_tangle::ConflictReason;
88

99
/// An event that indicates that a milestone was confirmed.
1010
#[derive(Clone)]

0 commit comments

Comments
 (0)