Skip to content

Commit

Permalink
feat: include parent tx in spend
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed Jun 20, 2023
1 parent 207c852 commit 3e8f3bf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl TransactionBuilder {
spent_tx: spent_tx.clone(),
reason,
blinded_amount: input.blinded_amount,
dbc_creation_tx_hash: i.input_src_tx.hash(),
dbc_creation_tx: i.input_src_tx.clone(),
};
let derived_key_sig = i.input.derived_key.sign(&spend.to_bytes());
SignedSpend {
Expand Down
9 changes: 5 additions & 4 deletions src/signed_spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl SignedSpend {

/// Get the hash of the transaction this DBC was created in
pub fn dbc_creation_tx_hash(&self) -> Hash {
self.spend.dbc_creation_tx_hash
self.spend.dbc_creation_tx.hash()
}

/// Get blinded amount.
Expand Down Expand Up @@ -119,20 +119,21 @@ pub struct Spend {
/// The amount of the input Dbc.
#[debug(skip)]
pub blinded_amount: BlindedAmount,
/// The hash of the transaction that the input Dbc was created in.
/// The transaction that the input Dbc was created in.
#[debug(skip)]
pub dbc_creation_tx_hash: Hash,
pub dbc_creation_tx: DbcTransaction,
}

impl Spend {
/// Represent this Spend as bytes.
/// There is no from_bytes, because this function is not symetric as it uses hashes
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes: Vec<u8> = Default::default();
bytes.extend(self.dbc_id.to_bytes());
bytes.extend(self.spent_tx.hash().as_ref());
bytes.extend(self.reason.as_ref());
bytes.extend(self.blinded_amount.compress().to_bytes());
bytes.extend(self.dbc_creation_tx_hash.as_ref());
bytes.extend(self.dbc_creation_tx.hash().as_ref());
bytes
}

Expand Down
2 changes: 1 addition & 1 deletion src/spentbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ mod tests {
spent_tx: signed_spend.spend.spent_tx.clone(),
reason: Hash::default(),
blinded_amount: *signed_spend.blinded_amount(),
dbc_creation_tx_hash: tx1.hash(),
dbc_creation_tx: tx1.clone(),
},
derived_key_sig: SecretKey::random().sign([0u8; 32]),
}
Expand Down
6 changes: 3 additions & 3 deletions src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ pub fn get_blinded_amounts_from_transaction(
// Get txs that are referenced by the signed spends.
let mut referenced_spent_txs: Vec<_> = vec![];
for input in input_signed_spends {
if let Some(src_tx) = spent_src_transactions.get(&input.spend.dbc_creation_tx_hash) {
if src_tx.hash() == input.spend.dbc_creation_tx_hash {
if let Some(src_tx) = spent_src_transactions.get(&input.spend.dbc_creation_tx.hash()) {
if src_tx.hash() == input.spend.dbc_creation_tx.hash() {
referenced_spent_txs.push(src_tx);
continue;
}
}
return Err(Error::MissingSpentSrcTransaction {
dbc_id: *input.dbc_id(),
dbc_creation_tx_hash: input.spend.dbc_creation_tx_hash,
dbc_creation_tx_hash: input.spend.dbc_creation_tx.hash(),
});
}

Expand Down

0 comments on commit 3e8f3bf

Please sign in to comment.