Skip to content

Commit

Permalink
Merge pull request #10 from anoma/tiago/updgrade-v0.40.0
Browse files Browse the repository at this point in the history
bump namada version to `v0.40.0`
  • Loading branch information
sug0 authored Jul 22, 2024
2 parents 6f041ad + 0aeadae commit 8d4e337
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ diesel_migrations = { version = "2.1.0", default-features = false, features = [
futures = "0.3.30"
itertools = "0.13.0"
lazy_static = "1.4.0"
namada_core = { git = "https://github.com/anoma/namada", tag = "v0.39.0" }
namada_sdk = { git = "https://github.com/anoma/namada", tag = "v0.39.0" }
namada_tx = { git = "https://github.com/anoma/namada", tag = "v0.39.0" }
namada_core = { git = "https://github.com/anoma/namada", tag = "v0.40.0" }
namada_sdk = { git = "https://github.com/anoma/namada", tag = "v0.40.0" }
namada_tx = { git = "https://github.com/anoma/namada", tag = "v0.40.0" }
orm = { path = "orm" }
serde = { version = "1.0.138", features = [ "derive" ] }
serde_json = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions shared/src/block_results.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::collections::BTreeMap;

use namada_core::hash::Hash;
use namada_core::masp::TxId;
use namada_sdk::events::extend::{
MaspTxBatchRefs, MaspTxBlockIndex, ReadFromEventAttributes,
};
use tendermint_rpc::endpoint::block_results;

pub struct IndexedMaspTxs {
/// Mapping of block indexes to valid masp tx section hashes.
pub locations: BTreeMap<usize, Vec<Hash>>,
/// Mapping of block indexes to valid masp tx ids.
pub locations: BTreeMap<usize, Vec<TxId>>,
}

pub fn locate_masp_txs(
Expand Down
52 changes: 16 additions & 36 deletions shared/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ use std::fmt::Display;

use namada_core::borsh::BorshDeserialize;
use namada_core::collections::HashMap;
use namada_core::hash::Hash;
use namada_core::masp::TxId;
use namada_core::masp_primitives::transaction::Transaction as NamadaMaspTransaction;
use namada_sdk::token::{
ShieldedTransfer, ShieldingTransfer, UnshieldingTransfer,
};
use namada_sdk::token::Transfer;
use namada_tx::{Data, Section, Tx as NamadaTx, TxCommitments};

use crate::id::Id;
Expand All @@ -23,7 +21,7 @@ pub struct Transaction {
impl Transaction {
pub fn from_namada_tx(
nam_tx_bytes: &[u8],
valid_masp_tx_sechashes: &[Hash],
valid_masp_tx_ids: &[TxId],
) -> Option<Self> {
// TODO: handle IBC masp?

Expand All @@ -38,31 +36,29 @@ impl Transaction {
.iter()
.enumerate()
.filter_map(|(masp_tx_index, cmt)| {
let masp_tx_section_hash =
get_shielded_tx_sechash(&transaction, cmt)?;
Some((masp_tx_section_hash, MaspTxIndex(masp_tx_index)))
let masp_tx_id = get_shielded_tx_id(&transaction, cmt)?;
Some((masp_tx_id, MaspTxIndex(masp_tx_index)))
})
.collect();

let masp_txs = valid_masp_tx_sechashes
let masp_txs = valid_masp_tx_ids
.iter()
.filter_map(|section_hash| {
let Some(Cow::Borrowed(Section::MaspTx(masp_tx))) =
transaction.get_section(section_hash)
.filter_map(|masp_tx_id| {
let Some(masp_tx) = transaction.get_masp_section(masp_tx_id)
else {
tracing::warn!(
%transaction_id,
%section_hash,
?masp_tx_id,
"Shielded tx not found in Namada transaction"
);
return None;
};

let masp_tx_index =
all_masp_txs.get(section_hash).cloned().or_else(|| {
all_masp_txs.get(masp_tx_id).cloned().or_else(|| {
tracing::warn!(
%transaction_id,
%section_hash,
?masp_tx_id,
?masp_tx,
"Shielded tx not found in Namada transaction"
);
Expand All @@ -87,33 +83,17 @@ impl Display for Transaction {
}
}

fn get_shielded_tx_sechash(
fn get_shielded_tx_id(
transaction: &NamadaTx,
cmt: &TxCommitments,
) -> Option<Hash> {
) -> Option<TxId> {
let Some(Cow::Borrowed(Section::Data(Data { data: tx_data, .. }))) =
transaction.get_section(&cmt.data_hash)
else {
return None;
};

let shielded_transfer = || {
let data = ShieldedTransfer::try_from_slice(tx_data).ok()?;
transaction.get_section(&data.section_hash)?;
Some(data.section_hash)
};
let unshielding_transfer = || {
let data = UnshieldingTransfer::try_from_slice(tx_data).ok()?;
transaction.get_section(&data.shielded_section_hash)?;
Some(data.shielded_section_hash)
};
let shielding_transfer = || {
let data = ShieldingTransfer::try_from_slice(tx_data).ok()?;
transaction.get_section(&data.shielded_section_hash)?;
Some(data.shielded_section_hash)
};

shielded_transfer()
.or_else(unshielding_transfer)
.or_else(shielding_transfer)
Transfer::try_from_slice(tx_data)
.ok()
.and_then(|tx| tx.shielded_section_hash)
}

0 comments on commit 8d4e337

Please sign in to comment.