From 3e8f3bf8ede4d29eb902d5db8af6299a095d0423 Mon Sep 17 00:00:00 2001 From: grumbach Date: Tue, 13 Jun 2023 22:15:57 +0900 Subject: [PATCH] feat: include parent tx in spend --- src/builder.rs | 2 +- src/signed_spend.rs | 9 +++++---- src/spentbook.rs | 2 +- src/verification.rs | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index dd92ad1..41b4211 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -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 { diff --git a/src/signed_spend.rs b/src/signed_spend.rs index c489d21..5427c92 100644 --- a/src/signed_spend.rs +++ b/src/signed_spend.rs @@ -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. @@ -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 { let mut bytes: Vec = 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 } diff --git a/src/spentbook.rs b/src/spentbook.rs index 155ce47..46e4225 100644 --- a/src/spentbook.rs +++ b/src/spentbook.rs @@ -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]), } diff --git a/src/verification.rs b/src/verification.rs index 9de9b8c..5e9440f 100644 --- a/src/verification.rs +++ b/src/verification.rs @@ -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(), }); }