Skip to content

Commit

Permalink
Parameterize accounts ids and amounts in ORM
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Dec 10, 2024
1 parent 5abf47b commit 019e12e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions crates/overflow-receive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ pub trait OverflowRecvContext {
/// Mint coins.
fn mint_coins_execute(
&mut self,
receiver: &Signer,
receiver: &<Self::PacketMetadata as PacketMetadata>::AccountId,
coin: &Coin<PrefixedDenom>,
) -> Result<(), Self::Error>;

/// Unescrow coins.
fn unescrow_coins_execute(
&mut self,
receiver: &Signer,
receiver: &<Self::PacketMetadata as PacketMetadata>::AccountId,
port: &PortId,
channel: &ChannelId,
coin: &Coin<PrefixedDenom>,
Expand Down Expand Up @@ -163,9 +163,9 @@ where
let (override_amount, remainder_amount) = match transfer_pkt
.token
.amount
.checked_sub(*orm_metadata.target_amount())
.checked_sub((*orm_metadata.target_amount()).into())
{
Some(amt) if *amt != [0u64, 0, 0, 0] => (*orm_metadata.target_amount(), amt),
Some(amt) if *amt != [0u64, 0, 0, 0] => ((*orm_metadata.target_amount()).into(), amt),
Some(_ /* = 0 */) => return Err(MiddlewareError::ForwardToNextMiddleware),
None => {
return Err(MiddlewareError::Message(format!(
Expand Down
11 changes: 9 additions & 2 deletions crates/overflow-receive/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use alloc::string::String;
use core::fmt::Display;

use ibc_app_transfer_types::Amount;
use ibc_primitives::Signer;

/// Metadata included in ICS-20 packet memos,
/// related with the overflow receive middleware.
pub trait PacketMetadata {
/// Account identifier.
type AccountId: Display + Into<Signer>;

/// Amount type.
type Amount: Copy + Display + Into<Amount>;

/// Determine if the value `msg` is a valid `PacketMetadata`.
fn is_overflow_receive_msg(msg: &serde_json::Map<String, serde_json::Value>) -> bool;

Expand All @@ -16,9 +23,9 @@ pub trait PacketMetadata {

/// Account that shall receive the funds in case of an
/// overflow.
fn overflow_receiver(&self) -> &Signer;
fn overflow_receiver(&self) -> &Self::AccountId;

/// The target amount that the original receiver will
/// receive.
fn target_amount(&self) -> &Amount;
fn target_amount(&self) -> &Self::Amount;
}
3 changes: 3 additions & 0 deletions crates/overflow-receive/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub struct OverflowReceiveMetadata {
}

impl msg::PacketMetadata for OrmPacketMetadata {
type AccountId = Signer;
type Amount = Amount;

fn is_overflow_receive_msg(msg: &serde_json::Map<String, serde_json::Value>) -> bool {
msg.contains_key("overflow_receive")
}
Expand Down

0 comments on commit 019e12e

Please sign in to comment.