Skip to content

Commit

Permalink
feat: split account ids into sender/receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Jan 15, 2025
1 parent ce458cc commit d9027bb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions ibc-apps/ics20-transfer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ pub trait TokenTransferValidationContext {
/// Native chain account id.
type AccountId;

/// Attempt to convert a [`Signer`] to a native chain account id.
fn account_id_from_signer(&self, signer: &Signer) -> Option<Self::AccountId>;
/// Attempt to convert a [`Signer`] to a native chain sender account.
fn sender_account_from_signer(&self, signer: &Signer) -> Option<Self::AccountId>;

/// Attempt to convert a [`Signer`] to a native chain receiver account.
fn receiver_account_from_signer(&self, signer: &Signer) -> Option<Self::AccountId>;

/// get_port returns the portID for the transfer module.
fn get_port(&self) -> Result<PortId, HostError>;
Expand Down
4 changes: 2 additions & 2 deletions ibc-apps/ics20-transfer/src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn refund_packet_token_execute(
data: &PacketData,
) -> Result<(), TokenTransferError> {
let sender = ctx_a
.account_id_from_signer(&data.sender)
.sender_account_from_signer(&data.sender)
.ok_or(TokenTransferError::FailedToParseAccount)?;

if is_sender_chain_source(
Expand Down Expand Up @@ -47,7 +47,7 @@ pub fn refund_packet_token_validate(
data: &PacketData,
) -> Result<(), TokenTransferError> {
let sender = ctx_a
.account_id_from_signer(&data.sender)
.sender_account_from_signer(&data.sender)
.ok_or(TokenTransferError::FailedToParseAccount)?;

if is_sender_chain_source(
Expand Down
2 changes: 1 addition & 1 deletion ibc-apps/ics20-transfer/src/handler/on_recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn process_recv_packet_execute<Ctx: TokenTransferExecutionContext>(
.map_err(|err| (ModuleExtras::empty(), err.into()))?;

let receiver_account = ctx_b
.account_id_from_signer(&data.receiver)
.receiver_account_from_signer(&data.receiver)
.ok_or_else(|| {
(
ModuleExtras::empty(),
Expand Down
4 changes: 2 additions & 2 deletions ibc-apps/ics20-transfer/src/handler/send_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ where
let token = &msg.packet_data.token;

let sender = token_ctx_a
.account_id_from_signer(&msg.packet_data.sender)
.sender_account_from_signer(&msg.packet_data.sender)
.ok_or(TokenTransferError::FailedToParseAccount)?;

if is_sender_chain_source(
Expand Down Expand Up @@ -127,7 +127,7 @@ where
let token = &msg.packet_data.token;

let sender = token_ctx_a
.account_id_from_signer(&msg.packet_data.sender)
.sender_account_from_signer(&msg.packet_data.sender)
.ok_or(TokenTransferError::FailedToParseAccount)?;

if is_sender_chain_source(
Expand Down
6 changes: 5 additions & 1 deletion ibc-testkit/src/testapp/ibc/applications/transfer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use super::types::DummyTransferModule;
impl TokenTransferValidationContext for DummyTransferModule {
type AccountId = Signer;

fn account_id_from_signer(&self, signer: &Signer) -> Option<Self::AccountId> {
fn sender_account_from_signer(&self, signer: &Signer) -> Option<Self::AccountId> {
Some(signer.clone())
}

fn receiver_account_from_signer(&self, signer: &Signer) -> Option<Self::AccountId> {
Some(signer.clone())
}

Expand Down

0 comments on commit d9027bb

Please sign in to comment.