From e746f7b6f9b7f9e01104b58f24fc43c1f4a622e3 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 24 Jan 2019 23:26:14 +0000 Subject: [PATCH] Add tx index within block to WalletTx struct --- zcash_client_backend/src/wallet.rs | 1 + zcash_client_backend/src/welding_rig.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/zcash_client_backend/src/wallet.rs b/zcash_client_backend/src/wallet.rs index 22df1cb..dd5229b 100644 --- a/zcash_client_backend/src/wallet.rs +++ b/zcash_client_backend/src/wallet.rs @@ -13,6 +13,7 @@ use zcash_primitives::{ /// [`Transaction`]: zcash_primitives::transaction::Transaction pub struct WalletTx { pub txid: TxId, + pub index: usize, pub num_spends: usize, pub num_outputs: usize, pub shielded_spends: Vec, diff --git a/zcash_client_backend/src/welding_rig.rs b/zcash_client_backend/src/welding_rig.rs index b8310e3..27d29bb 100644 --- a/zcash_client_backend/src/welding_rig.rs +++ b/zcash_client_backend/src/welding_rig.rs @@ -162,6 +162,7 @@ pub fn scan_block( wtxs.push(( WalletTx { txid, + index: tx.index as usize, num_spends, num_outputs, shielded_spends, @@ -269,7 +270,11 @@ mod tests { cb.set_height(height as u64); // Add a random Sapling tx before ours - cb.vtx.push(random_compact_tx(&mut rng)); + { + let mut tx = random_compact_tx(&mut rng); + tx.index = cb.vtx.len() as u64; + cb.vtx.push(tx); + } let mut cspend = CompactSpend::new(); cspend.set_nf(nf.to_vec()); @@ -283,6 +288,7 @@ mod tests { ctx.set_hash(txid); ctx.spends.push(cspend); ctx.outputs.push(cout); + ctx.index = cb.vtx.len() as u64; cb.vtx.push(ctx); cb @@ -301,6 +307,7 @@ mod tests { assert_eq!(txs.len(), 1); let (tx, new_witnesses) = &txs[0]; + assert_eq!(tx.index, 1); assert_eq!(tx.num_spends, 1); assert_eq!(tx.num_outputs, 1); assert_eq!(tx.shielded_spends.len(), 0); @@ -329,6 +336,7 @@ mod tests { assert_eq!(txs.len(), 1); let (tx, new_witnesses) = &txs[0]; + assert_eq!(tx.index, 1); assert_eq!(tx.num_spends, 1); assert_eq!(tx.num_outputs, 1); assert_eq!(tx.shielded_spends.len(), 1);