Skip to content

Commit

Permalink
feat(builder): add fns for getting input/output sum and input hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-da committed Aug 18, 2021
1 parent 9896064 commit 5eeae06
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::iter::FromIterator;

use curve25519_dalek_ng::scalar::Scalar;

use crate::{AmountSecrets, Dbc, DbcContent, ReissueTransaction, Result};
use crate::{AmountSecrets, Dbc, DbcContent, Hash, ReissueTransaction, Result};

///! Unblinded data for creating sn_dbc::DbcContent
pub struct Output {
Expand Down Expand Up @@ -38,6 +38,21 @@ impl TransactionBuilder {
self
}

pub fn inputs_hashes(&self) -> BTreeSet<Hash> {
self.inputs
.iter()
.map(|(dbc, _)| dbc.name())
.collect::<BTreeSet<_>>()
}

pub fn inputs_amount_sum(&self) -> u64 {
self.inputs.iter().map(|(_, s)| s.amount).sum()
}

pub fn outputs_amount_sum(&self) -> u64 {
self.outputs.iter().map(|o| o.amount).sum()
}

pub fn build(self) -> Result<(ReissueTransaction, HashMap<crate::Hash, blsttc::PublicKey>)> {
let parents = BTreeSet::from_iter(self.inputs.keys().map(Dbc::name));
let inputs_bf_sum = self
Expand Down

0 comments on commit 5eeae06

Please sign in to comment.