Skip to content

Commit 3a608aa

Browse files
committed
feat: rename spends with better names
BREAKING CHANGE: renames fields and methods in Spend
1 parent 0d65b1c commit 3a608aa

File tree

9 files changed

+80
-75
lines changed

9 files changed

+80
-75
lines changed

benches/reissue.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ fn bench_reissue_1_to_100(c: &mut Criterion) {
3939
.build(Hash::default(), &mut rng)
4040
.unwrap();
4141

42-
let dst_tx = &dbc_builder.dst_tx;
42+
let spent_tx = &dbc_builder.spent_tx;
4343
for signed_spend in dbc_builder.signed_spends() {
44-
spentbook_node.log_spent(dst_tx, signed_spend).unwrap();
44+
spentbook_node.log_spent(spent_tx, signed_spend).unwrap();
4545
}
4646

4747
let signed_spends: BTreeSet<_> = dbc_builder.signed_spends().into_iter().cloned().collect();
@@ -51,7 +51,7 @@ fn bench_reissue_1_to_100(c: &mut Criterion) {
5151
let guard = pprof::ProfilerGuard::new(100).unwrap();
5252

5353
b.iter(|| {
54-
TransactionVerifier::verify(black_box(dst_tx), &signed_spends).unwrap();
54+
TransactionVerifier::verify(black_box(spent_tx), &signed_spends).unwrap();
5555
});
5656

5757
#[cfg(unix)]
@@ -98,9 +98,9 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
9898
.build(Hash::default(), &mut rng)
9999
.unwrap();
100100

101-
let dst_tx = dbc_builder.dst_tx.clone();
101+
let spent_tx = dbc_builder.spent_tx.clone();
102102
for signed_spend in dbc_builder.signed_spends() {
103-
spentbook_node.log_spent(&dst_tx, signed_spend).unwrap();
103+
spentbook_node.log_spent(&spent_tx, signed_spend).unwrap();
104104
}
105105
let dbcs = dbc_builder.build().unwrap();
106106

@@ -126,10 +126,10 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
126126
.build(Hash::default(), &mut rng)
127127
.unwrap();
128128

129-
let merge_dst_tx = merge_dbc_builder.dst_tx.clone();
129+
let merge_spent_tx = merge_dbc_builder.spent_tx.clone();
130130
for signed_spend in merge_dbc_builder.signed_spends() {
131131
spentbook_node
132-
.log_spent(&merge_dst_tx, signed_spend)
132+
.log_spent(&merge_spent_tx, signed_spend)
133133
.unwrap();
134134
}
135135

@@ -144,7 +144,7 @@ fn bench_reissue_100_to_1(c: &mut Criterion) {
144144
let guard = pprof::ProfilerGuard::new(100).unwrap();
145145

146146
b.iter(|| {
147-
TransactionVerifier::verify(black_box(&merge_dst_tx), &signed_spends).unwrap();
147+
TransactionVerifier::verify(black_box(&merge_spent_tx), &signed_spends).unwrap();
148148
});
149149

150150
#[cfg(unix)]
@@ -186,7 +186,7 @@ fn generate_dbc_of_value(
186186
}))
187187
.build(Hash::default(), rng)?;
188188

189-
let tx = dbc_builder.dst_tx.clone();
189+
let tx = dbc_builder.spent_tx.clone();
190190
for signed_spend in dbc_builder.signed_spends() {
191191
spentbook_node.log_spent(&tx, signed_spend)?;
192192
}

src/builder.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ impl TransactionBuilder {
122122
/// Build the DbcTransaction by signing the inputs,
123123
/// and generating the blinded outputs. Return a DbcBuilder.
124124
pub fn build(self, reason: Hash, rng: impl RngCore + CryptoRng) -> Result<DbcBuilder> {
125-
let (dst_tx, revealed_outputs) = self.revealed_tx.sign(rng)?;
125+
let (spent_tx, revealed_outputs) = self.revealed_tx.sign(rng)?;
126126

127-
let signed_spends: BTreeSet<_> = dst_tx
127+
let signed_spends: BTreeSet<_> = spent_tx
128128
.inputs
129129
.iter()
130130
.flat_map(|input| {
@@ -135,10 +135,10 @@ impl TransactionBuilder {
135135
.map(|i| {
136136
let spend = crate::Spend {
137137
dbc_id: input.dbc_id(),
138-
dst_tx: dst_tx.clone(),
138+
spent_tx: spent_tx.clone(),
139139
reason,
140140
blinded_amount: input.blinded_amount,
141-
src_tx_hash: i.input_src_tx.hash(),
141+
dbc_creation_tx_hash: i.input_src_tx.hash(),
142142
};
143143
let derived_key_sig = i.input.derived_key.sign(&spend.to_bytes());
144144
SignedSpend {
@@ -150,7 +150,7 @@ impl TransactionBuilder {
150150
.collect();
151151

152152
Ok(DbcBuilder::new(
153-
dst_tx,
153+
spent_tx,
154154
revealed_outputs,
155155
self.output_id_sources,
156156
self.revealed_tx,
@@ -163,7 +163,7 @@ impl TransactionBuilder {
163163
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
164164
#[derive(Debug, Clone)]
165165
pub struct DbcBuilder {
166-
pub dst_tx: DbcTransaction,
166+
pub spent_tx: DbcTransaction,
167167
pub revealed_outputs: Vec<RevealedOutput>,
168168
pub output_id_sources: OutputIdSources,
169169
pub revealed_tx: RevealedTx,
@@ -173,14 +173,14 @@ pub struct DbcBuilder {
173173
impl DbcBuilder {
174174
/// Create a new DbcBuilder.
175175
pub fn new(
176-
dst_tx: DbcTransaction,
176+
spent_tx: DbcTransaction,
177177
revealed_outputs: Vec<RevealedOutput>,
178178
output_id_sources: OutputIdSources,
179179
revealed_tx: RevealedTx,
180180
signed_spends: BTreeSet<SignedSpend>,
181181
) -> Self {
182182
Self {
183-
dst_tx,
183+
spent_tx,
184184
revealed_outputs,
185185
output_id_sources,
186186
revealed_tx,
@@ -189,7 +189,7 @@ impl DbcBuilder {
189189
}
190190

191191
/// Return the signed spends. They each already contain the
192-
/// dst_tx, so the inclusion of it in the result is just for convenience.
192+
/// spent_tx, so the inclusion of it in the result is just for convenience.
193193
pub fn signed_spends(&self) -> Vec<&SignedSpend> {
194194
self.signed_spends.iter().collect()
195195
}
@@ -201,7 +201,7 @@ impl DbcBuilder {
201201
pub fn build(self) -> Result<Vec<(Dbc, RevealedAmount)>> {
202202
// Verify the tx, along with signed spends.
203203
// Note that we do this just once for entire tx, not once per output Dbc.
204-
TransactionVerifier::verify(&self.dst_tx, &self.signed_spends)?;
204+
TransactionVerifier::verify(&self.spent_tx, &self.signed_spends)?;
205205

206206
// Build output Dbcs.
207207
self.build_output_dbcs()
@@ -223,7 +223,7 @@ impl DbcBuilder {
223223
.collect();
224224

225225
let dbc_id_list: Vec<&DbcIdSource> = self
226-
.dst_tx
226+
.spent_tx
227227
.outputs
228228
.iter()
229229
.map(|output| {
@@ -235,7 +235,7 @@ impl DbcBuilder {
235235

236236
// Form the final output DBCs
237237
let output_dbcs: Vec<(Dbc, RevealedAmount)> = self
238-
.dst_tx
238+
.spent_tx
239239
.outputs
240240
.iter()
241241
.zip(dbc_id_list)
@@ -254,7 +254,7 @@ impl DbcBuilder {
254254
));
255255
let dbc = Dbc {
256256
id: dbc_id_src.dbc_id(),
257-
src_tx: self.dst_tx.clone(),
257+
src_tx: self.spent_tx.clone(),
258258
ciphers,
259259
signed_spends: self.signed_spends.clone(),
260260
};

src/dbc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ pub(crate) mod tests {
453453
}))
454454
.build(Hash::default(), rng)?;
455455

456-
let tx = &dbc_builder.dst_tx;
456+
let tx = &dbc_builder.spent_tx;
457457
for signed_spend in dbc_builder.signed_spends() {
458458
spentbook_node.log_spent(tx, signed_spend)?
459459
}

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pub enum Error {
3838
#[error("Transaction hash does not match the transaction signed by spentbook.")]
3939
InvalidTransactionHash,
4040

41-
#[error("Missing a src transaction {src_tx_hash:?} of a signed spend {dbc_id:?}.")]
41+
#[error("Missing a src transaction {dbc_creation_tx_hash:?} of a signed spend {dbc_id:?}.")]
4242
MissingSpentSrcTransaction {
4343
dbc_id: DbcId,
44-
src_tx_hash: crate::Hash,
44+
dbc_creation_tx_hash: crate::Hash,
4545
},
4646

4747
#[error("Dbc ciphers are not present in transaction outputs.")]

src/mock/genesis_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl GenesisBuilder {
5858
)
5959
.build(Hash::default(), rng)?;
6060

61-
let tx = &dbc_builder.dst_tx;
61+
let tx = &dbc_builder.spent_tx;
6262
for signed_spend in dbc_builder.signed_spends() {
6363
for spentbook_node in self.spentbook_nodes.iter_mut() {
6464
spentbook_node.log_spent(tx, signed_spend)?;

src/mock/mock_spentbook.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,23 @@ impl SpentbookNode {
9494
#[cfg(test)]
9595
pub fn log_spent_and_skip_tx_verification(
9696
&mut self,
97-
dst_tx: &DbcTransaction,
97+
spent_tx: &DbcTransaction,
9898
signed_spend: &SignedSpend,
9999
) -> Result<()> {
100-
self.log_spent_worker(dst_tx, signed_spend, false)
100+
self.log_spent_worker(spent_tx, signed_spend, false)
101101
}
102102

103103
fn log_spent_worker(
104104
&mut self,
105-
dst_tx: &DbcTransaction,
105+
spent_tx: &DbcTransaction,
106106
signed_spend: &SignedSpend,
107107
verify_tx: bool,
108108
) -> Result<()> {
109109
let input_id = signed_spend.dbc_id();
110-
let dst_tx_hash = signed_spend.dst_tx_hash();
111-
let tx_hash = dst_tx.hash();
110+
let spent_tx_hash = signed_spend.spent_tx_hash();
111+
let tx_hash = spent_tx.hash();
112112

113-
if tx_hash != dst_tx_hash {
113+
if tx_hash != spent_tx_hash {
114114
return Err(Error::InvalidTransactionHash);
115115
}
116116

@@ -123,7 +123,7 @@ impl SpentbookNode {
123123
if input_id == genesis_dbc_id {
124124
vec![(*input_id, *genesis_blinded_amount)]
125125
} else {
126-
dst_tx
126+
spent_tx
127127
.inputs
128128
.iter()
129129
.map(|input| {
@@ -147,7 +147,7 @@ impl SpentbookNode {
147147

148148
if verify_tx {
149149
// Do not permit invalid tx to be logged.
150-
dst_tx.verify(&tx_blinded_amounts)?;
150+
spent_tx.verify(&tx_blinded_amounts)?;
151151
}
152152

153153
// Add dbc_id:tx_hash to dbc_id index.
@@ -158,7 +158,7 @@ impl SpentbookNode {
158158
let existing_tx = self
159159
.transactions
160160
.entry(tx_hash)
161-
.or_insert_with(|| dst_tx.clone());
161+
.or_insert_with(|| spent_tx.clone());
162162

163163
// Add dbc_id:blinded_output to dbc_id index.
164164
for output in existing_tx.outputs.iter() {

src/signed_spend.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ impl SignedSpend {
2929
&self.spend.dbc_id
3030
}
3131

32-
/// Get dst transaction hash.
33-
pub fn dst_tx_hash(&self) -> Hash {
34-
self.spend.dst_tx.hash()
32+
/// Get the hash of the transaction this DBC is spent in
33+
pub fn spent_tx_hash(&self) -> Hash {
34+
self.spend.spent_tx.hash()
3535
}
3636

37-
/// Get src transaction hash.
38-
pub fn src_tx_hash(&self) -> Hash {
39-
self.spend.src_tx_hash
37+
/// Get the transaction this DBC is spent in
38+
pub fn spent_tx(&self) -> DbcTransaction {
39+
self.spend.spent_tx.clone()
40+
}
41+
42+
/// Get the hash of the transaction this DBC was created in
43+
pub fn dbc_creation_tx_hash(&self) -> Hash {
44+
self.spend.dbc_creation_tx_hash
4045
}
4146

4247
/// Get blinded amount.
@@ -59,12 +64,12 @@ impl SignedSpend {
5964

6065
/// Verify this SignedSpend
6166
///
62-
/// Checks that the provided dst_tx_hash equals the input dst tx hash that was
67+
/// Checks that the provided spent_tx_hash equals the input dst tx hash that was
6368
/// signed by the DerivedKey. Also verifies that that signature is
6469
/// valid for this SignedSpend.
65-
pub fn verify(&self, dst_tx_hash: Hash) -> Result<()> {
66-
// Verify that input dst_tx_hash matches self.dst_tx_hash which was signed by the DerivedKey of the input.
67-
if dst_tx_hash != self.dst_tx_hash() {
70+
pub fn verify(&self, spent_tx_hash: Hash) -> Result<()> {
71+
// Verify that input spent_tx_hash matches self.spent_tx_hash which was signed by the DerivedKey of the input.
72+
if spent_tx_hash != self.spent_tx_hash() {
6873
return Err(Error::InvalidTransactionHash);
6974
}
7075

@@ -106,25 +111,25 @@ pub struct Spend {
106111
pub dbc_id: DbcId,
107112
/// The transaction that the input Dbc is being spent in.
108113
#[debug(skip)]
109-
pub dst_tx: DbcTransaction,
114+
pub spent_tx: DbcTransaction,
110115
/// Reason why this Dbc was spent.
111116
pub reason: Hash,
112117
/// The amount of the input Dbc.
113118
#[debug(skip)]
114119
pub blinded_amount: BlindedAmount,
115120
/// The hash of the transaction that the input Dbc was created in.
116-
pub src_tx_hash: Hash,
121+
pub dbc_creation_tx_hash: Hash,
117122
}
118123

119124
impl Spend {
120125
/// Represent this Spend as bytes.
121126
pub fn to_bytes(&self) -> Vec<u8> {
122127
let mut bytes: Vec<u8> = Default::default();
123128
bytes.extend(self.dbc_id.to_bytes());
124-
bytes.extend(self.dst_tx.hash().as_ref());
129+
bytes.extend(self.spent_tx.hash().as_ref());
125130
bytes.extend(self.reason.as_ref());
126131
bytes.extend(self.blinded_amount.compress().to_bytes());
127-
bytes.extend(self.src_tx_hash.as_ref());
132+
bytes.extend(self.dbc_creation_tx_hash.as_ref());
128133
bytes
129134
}
130135

0 commit comments

Comments
 (0)