Skip to content

Commit

Permalink
shielded_token/vp: replace IBC dep with DI
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jul 9, 2024
1 parent 177879e commit 835061e
Show file tree
Hide file tree
Showing 5 changed files with 539 additions and 440 deletions.
37 changes: 37 additions & 0 deletions crates/core/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
//! IBC-related data types

use std::collections::{BTreeMap, BTreeSet};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use data_encoding::{DecodePartial, HEXLOWER, HEXLOWER_PERMISSIVE};
use ibc::core::host::types::identifiers::{ChannelId, PortId, Sequence};
pub use ibc::*;
use masp_primitives::transaction::components::ValueSum;
use masp_primitives::transaction::TransparentAddress;
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
use namada_migrations::*;
use serde::{Deserialize, Serialize};

use super::address::HASH_LEN;
use crate::address::Address;
use crate::masp::TAddrData;
use crate::{storage, token};

/// Abstract IBC storage read interface
pub trait Read<S> {
/// Storage error
type Err;

/// Extract MASP transaction from IBC envelope
fn try_extract_masp_tx_from_envelope(
tx_data: &[u8],
) -> Result<Option<masp_primitives::transaction::Transaction>, Self::Err>;

/// Apply relevant IBC packets to the changed balances structure
fn apply_ibc_packet(
storage: &S,
tx_data: &[u8],
acc: ChangedBalances,
keys_changed: &BTreeSet<storage::Key>,
) -> Result<ChangedBalances, Self::Err>;
}

/// Balances changed by a transaction
#[derive(Default, Debug, Clone)]
pub struct ChangedBalances {
/// Map between MASP transparent address and namada types
pub decoder: BTreeMap<TransparentAddress, TAddrData>,
/// Balances before the tx
pub pre: BTreeMap<TransparentAddress, ValueSum<Address, token::Amount>>,
/// Balances after the tx
pub post: BTreeMap<TransparentAddress, ValueSum<Address, token::Amount>>,
}

/// IBC token hash derived from a denomination.
#[derive(
Expand Down
Loading

0 comments on commit 835061e

Please sign in to comment.