ibc_app_transfer/context.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
//! Defines the main context traits and IBC module callbacks
use ibc_app_transfer_types::{Memo, PrefixedCoin, PrefixedDenom};
use ibc_core::host::types::error::HostError;
use ibc_core::host::types::identifiers::{ChannelId, PortId};
use ibc_core::primitives::prelude::*;
use ibc_core::primitives::Signer;
/// Methods required in token transfer validation, to be implemented by the host
pub trait TokenTransferValidationContext {
type AccountId: TryFrom<Signer>;
/// get_port returns the portID for the transfer module.
fn get_port(&self) -> Result<PortId, HostError>;
/// Returns Ok() if the host chain supports sending coins.
fn can_send_coins(&self) -> Result<(), HostError>;
/// Returns Ok() if the host chain supports receiving coins.
fn can_receive_coins(&self) -> Result<(), HostError>;
/// Validates that the tokens can be escrowed successfully.
///
/// `memo` field allows incorporating additional contextual details in the
/// escrow validation.
fn escrow_coins_validate(
&self,
from_account: &Self::AccountId,
port_id: &PortId,
channel_id: &ChannelId,
coin: &PrefixedCoin,
memo: &Memo,
) -> Result<(), HostError>;
/// Validates that the tokens can be unescrowed successfully.
fn unescrow_coins_validate(
&self,
to_account: &Self::AccountId,
port_id: &PortId,
channel_id: &ChannelId,
coin: &PrefixedCoin,
) -> Result<(), HostError>;
/// Validates the receiver account and the coin input
fn mint_coins_validate(
&self,
account: &Self::AccountId,
coin: &PrefixedCoin,
) -> Result<(), HostError>;
/// Validates the sender account and the coin input before burning.
///
/// `memo` field allows incorporating additional contextual details in the
/// burn validation.
fn burn_coins_validate(
&self,
account: &Self::AccountId,
coin: &PrefixedCoin,
memo: &Memo,
) -> Result<(), HostError>;
/// Returns a hash of the prefixed denom.
/// Implement only if the host chain supports hashed denominations.
fn denom_hash_string(&self, _denom: &PrefixedDenom) -> Option<String> {
None
}
}
/// Methods required in token transfer execution, to be implemented by the host.
pub trait TokenTransferExecutionContext: TokenTransferValidationContext {
/// Executes the escrow of the tokens in a user account.
///
/// `memo` field allows incorporating additional contextual details in the
/// escrow execution.
fn escrow_coins_execute(
&mut self,
from_account: &Self::AccountId,
port_id: &PortId,
channel_id: &ChannelId,
coin: &PrefixedCoin,
memo: &Memo,
) -> Result<(), HostError>;
/// Executes the unescrow of the tokens in a user account.
fn unescrow_coins_execute(
&mut self,
to_account: &Self::AccountId,
port_id: &PortId,
channel_id: &ChannelId,
coin: &PrefixedCoin,
) -> Result<(), HostError>;
/// Executes minting of the tokens in a user account.
fn mint_coins_execute(
&mut self,
account: &Self::AccountId,
coin: &PrefixedCoin,
) -> Result<(), HostError>;
/// Executes burning of the tokens in a user account.
///
/// `memo` field allows incorporating additional contextual details in the
/// burn execution.
fn burn_coins_execute(
&mut self,
account: &Self::AccountId,
coin: &PrefixedCoin,
memo: &Memo,
) -> Result<(), HostError>;
}