Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
fix the hash for decrypted tx (#49)
Browse files Browse the repository at this point in the history
closes #23
  • Loading branch information
rllola authored Oct 31, 2023
1 parent 16cdf9c commit e7bfd68
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ impl Database {
let mut code = Default::default();
let mut txid_wrapper: Vec<u8> = vec![];

let mut hash_id = tx.header_hash().to_vec();

// Decrypted transaction give access to the raw data
if let TxType::Decrypted(..) = tx.header().tx_type {
// look for wrapper tx to link to
Expand All @@ -604,6 +606,9 @@ impl Database {
txid_wrapper = txs[i].try_get("hash")?;
i += 1;

// For unknown reason the header has to be updated before hashing it for its id (https://github.com/Zondax/namadexer/issues/23)
hash_id = tx.clone().update_header(TxType::Raw).header_hash().to_vec();

code = tx
.get_section(tx.code_sechash())
.and_then(|s| s.code_sec())
Expand Down Expand Up @@ -637,7 +642,7 @@ impl Database {

let query = query_builder
.push_values(std::iter::once(0), |mut b, _| {
b.push_bind(tx.header_hash().0.as_slice().to_vec())
b.push_bind(&hash_id)
.push_bind(transfer.source.to_string())
.push_bind(transfer.target.to_string())
.push_bind(transfer.token.to_string())
Expand Down Expand Up @@ -665,7 +670,7 @@ impl Database {

let query = query_builder
.push_values(std::iter::once(0), |mut b, _| {
b.push_bind(tx.header_hash().0.as_slice().to_vec())
b.push_bind(&hash_id)
.push_bind(bond.validator.to_string())
.push_bind(bond.amount.to_string_native())
.push_bind(bond.source.as_ref().map(|s| s.to_string()))
Expand All @@ -691,7 +696,7 @@ impl Database {

let query = query_builder
.push_values(std::iter::once(0), |mut b, _| {
b.push_bind(tx.header_hash().0.as_slice().to_vec())
b.push_bind(&hash_id)
.push_bind(unbond.validator.to_string())
.push_bind(unbond.amount.to_string_native())
.push_bind(
Expand Down Expand Up @@ -726,7 +731,7 @@ impl Database {

let query = query_builder
.push_values(std::iter::once(0), |mut b, _| {
b.push_bind(tx.header_hash().0.as_slice().to_vec())
b.push_bind(&hash_id)
.push_bind(tx_bridge.transfer.asset.to_string())
.push_bind(tx_bridge.transfer.recipient.to_string())
.push_bind(tx_bridge.transfer.sender.to_string())
Expand Down Expand Up @@ -816,7 +821,7 @@ impl Database {
}

tx_values.push((
tx.header_hash().0.as_slice().to_vec(),
hash_id,
block_id.to_vec(),
utils::tx_type_name(&tx.header.tx_type),
txid_wrapper,
Expand Down

0 comments on commit e7bfd68

Please sign in to comment.