Bug fix: transactiond details

This commit is contained in:
Hanh 2022-03-15 16:04:37 +08:00
parent 4d3f8e8574
commit e836eb5485
4 changed files with 24 additions and 19 deletions

View File

@ -69,31 +69,31 @@ base64 = "^0.13"
[dependencies.zcash_client_backend] [dependencies.zcash_client_backend]
git = "https://github.com/hhanh00/librustzcash.git" git = "https://github.com/hhanh00/librustzcash.git"
rev = "a25bb7aaa9bf35669280a2c1b7d6fb8b52f30b2d" rev = "67689473e4edbfbd6d2ff33f6ddd5dd2a402bb20"
[dependencies.zcash_primitives] [dependencies.zcash_primitives]
git = "https://github.com/hhanh00/librustzcash.git" git = "https://github.com/hhanh00/librustzcash.git"
rev = "a25bb7aaa9bf35669280a2c1b7d6fb8b52f30b2d" rev = "67689473e4edbfbd6d2ff33f6ddd5dd2a402bb20"
features = [ "transparent-inputs" ] features = [ "transparent-inputs" ]
[dependencies.zcash_proofs] [dependencies.zcash_proofs]
git = "https://github.com/hhanh00/librustzcash.git" git = "https://github.com/hhanh00/librustzcash.git"
rev = "a25bb7aaa9bf35669280a2c1b7d6fb8b52f30b2d" rev = "67689473e4edbfbd6d2ff33f6ddd5dd2a402bb20"
[dependencies.zcash_params] [dependencies.zcash_params]
path = "../zcash-params" path = "../zcash-params"
[dependencies.zcash_address] [dependencies.zcash_address]
git = "https://github.com/hhanh00/librustzcash.git" git = "https://github.com/hhanh00/librustzcash.git"
rev = "a25bb7aaa9bf35669280a2c1b7d6fb8b52f30b2d" rev = "67689473e4edbfbd6d2ff33f6ddd5dd2a402bb20"
[dependencies.zcash_encoding] [dependencies.zcash_encoding]
git = "https://github.com/hhanh00/librustzcash.git" git = "https://github.com/hhanh00/librustzcash.git"
rev = "a25bb7aaa9bf35669280a2c1b7d6fb8b52f30b2d" rev = "67689473e4edbfbd6d2ff33f6ddd5dd2a402bb20"
[dependencies.zcash_note_encryption] [dependencies.zcash_note_encryption]
git = "https://github.com/hhanh00/librustzcash.git" git = "https://github.com/hhanh00/librustzcash.git"
rev = "a25bb7aaa9bf35669280a2c1b7d6fb8b52f30b2d" rev = "67689473e4edbfbd6d2ff33f6ddd5dd2a402bb20"
[build-dependencies] [build-dependencies]
tonic-build = "0.4.2" tonic-build = "0.4.2"

View File

@ -15,7 +15,7 @@ use tonic::Request;
use zcash_note_encryption::batch::try_compact_note_decryption; use zcash_note_encryption::batch::try_compact_note_decryption;
use zcash_primitives::consensus::{BlockHeight, Network, NetworkUpgrade, Parameters}; use zcash_primitives::consensus::{BlockHeight, Network, NetworkUpgrade, Parameters};
use zcash_primitives::merkle_tree::{CommitmentTree, IncrementalWitness}; use zcash_primitives::merkle_tree::{CommitmentTree, IncrementalWitness};
use zcash_primitives::sapling::note_encryption::{SaplingDomain, try_sapling_compact_note_decryption}; use zcash_primitives::sapling::note_encryption::SaplingDomain;
use zcash_primitives::sapling::{Node, Note, PaymentAddress}; use zcash_primitives::sapling::{Node, Note, PaymentAddress};
use zcash_primitives::transaction::components::sapling::CompactOutputDescription; use zcash_primitives::transaction::components::sapling::CompactOutputDescription;
use zcash_primitives::zip32::ExtendedFullViewingKey; use zcash_primitives::zip32::ExtendedFullViewingKey;
@ -137,6 +137,7 @@ struct AccountOutput<'a, N: Parameters> {
epk: EphemeralKeyBytes, epk: EphemeralKeyBytes,
cmu: <SaplingDomain<N> as Domain>::ExtractedCommitmentBytes, cmu: <SaplingDomain<N> as Domain>::ExtractedCommitmentBytes,
ciphertext: [u8; COMPACT_NOTE_SIZE], ciphertext: [u8; COMPACT_NOTE_SIZE],
tx_index: usize,
output_index: usize, output_index: usize,
block_output_index: usize, block_output_index: usize,
vtx: &'a CompactTx, vtx: &'a CompactTx,
@ -144,7 +145,7 @@ struct AccountOutput<'a, N: Parameters> {
} }
impl <'a, N: Parameters> AccountOutput<'a, N> { impl <'a, N: Parameters> AccountOutput<'a, N> {
fn new(output_index: usize, block_output_index: usize, vtx: &'a CompactTx, co: &CompactOutput) -> Self { fn new(tx_index: usize, output_index: usize, block_output_index: usize, vtx: &'a CompactTx, co: &CompactOutput) -> Self {
let mut epk_bytes = [0u8; 32]; let mut epk_bytes = [0u8; 32];
epk_bytes.copy_from_slice(&co.epk); epk_bytes.copy_from_slice(&co.epk);
let epk = EphemeralKeyBytes::from(epk_bytes); let epk = EphemeralKeyBytes::from(epk_bytes);
@ -155,6 +156,7 @@ impl <'a, N: Parameters> AccountOutput<'a, N> {
ciphertext_bytes.copy_from_slice(&co.ciphertext); ciphertext_bytes.copy_from_slice(&co.ciphertext);
AccountOutput { AccountOutput {
tx_index,
output_index, output_index,
block_output_index, block_output_index,
vtx, vtx,
@ -200,7 +202,7 @@ fn decrypt_notes<'a, N: Parameters>(
for (output_index, co) in vtx.outputs.iter().enumerate() { for (output_index, co) in vtx.outputs.iter().enumerate() {
let domain = SaplingDomain::<N>::for_height(network.clone(), height); let domain = SaplingDomain::<N>::for_height(network.clone(), height);
let output = AccountOutput::<N>::new(output_index, count_outputs as usize, vtx, co); let output = AccountOutput::<N>::new(tx_index, output_index, count_outputs as usize, vtx, co);
outputs.push((domain, output)); outputs.push((domain, output));
// let od = to_output_description(co); // let od = to_output_description(co);
@ -245,7 +247,7 @@ fn decrypt_notes<'a, N: Parameters>(
viewonly: vk.1.viewonly, viewonly: vk.1.viewonly,
position_in_block: output.1.block_output_index, position_in_block: output.1.block_output_index,
height: block.height as u32, height: block.height as u32,
tx_index: output.1.vtx.index as usize, tx_index: output.1.tx_index,
txid: output.1.vtx.hash.clone(), txid: output.1.vtx.hash.clone(),
output_index: output.1.output_index, output_index: output.1.output_index,
}); });

View File

@ -311,7 +311,7 @@ pub async fn sync_async(
return c; return c;
}); });
let ids: Vec<_> = ids.into_iter().map(|e| e.id_tx).collect(); let ids: Vec<_> = ids.into_iter().map(|e| e.id_tx).collect();
retrieve_tx_info(coin_type, &mut client, &db_path2, &ids).await?; retrieve_tx_info(coin_type, &mut client, &db_path2, &ids).await.unwrap();
} }
log::info!("Transaction Details : {}", start.elapsed().as_millis()); log::info!("Transaction Details : {}", start.elapsed().as_millis());

View File

@ -72,6 +72,7 @@ pub async fn decode_transaction(
let mut zaddress = String::new(); let mut zaddress = String::new();
let tx = tx.into_data(); let tx = tx.into_data();
// log::info!("{:?}", tx);
let sapling_bundle = tx.sapling_bundle().ok_or(anyhow!("No sapling bundle"))?; let sapling_bundle = tx.sapling_bundle().ok_or(anyhow!("No sapling bundle"))?;
for spend in sapling_bundle.shielded_spends.iter() { for spend in sapling_bundle.shielded_spends.iter() {
let nf = spend.nullifier.to_vec(); let nf = spend.nullifier.to_vec();
@ -80,17 +81,19 @@ pub async fn decode_transaction(
} }
} }
let mut contact_decoder = ContactDecoder::new(tx.sapling_bundle().unwrap().shielded_outputs.len()); let mut contact_decoder = ContactDecoder::new(sapling_bundle.shielded_outputs.len());
let mut tx_memo: Memo = Memo::Empty; let mut tx_memo: Memo = Memo::Empty;
for output in tx.transparent_bundle().ok_or(anyhow!("No transparent bundle"))?.vout.iter() { if let Some(transparent_bundle) = tx.transparent_bundle() {
if let Some(taddr) = output.script_pubkey.address() { for output in transparent_bundle.vout.iter() {
taddress = encode_transparent_address( if let Some(taddr) = output.script_pubkey.address() {
&network.b58_pubkey_address_prefix(), taddress = encode_transparent_address(
&network.b58_script_address_prefix(), &network.b58_pubkey_address_prefix(),
&taddr, &network.b58_script_address_prefix(),
); &taddr,
);
}
} }
} }