Skip to content

Commit e125999

Browse files
scale encoding for transfer (#745)
1 parent 98594ae commit e125999

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Scale encoding for ICS-20 transfer message
2+
([#745](https://github.com/cosmos/ibc-rs/issues/745))

crates/ibc/src/applications/transfer/amount.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Contains the `Amount` type, which represents amounts of tokens transferred.
22
3-
use core::str::FromStr;
3+
use core::{ops::Deref, str::FromStr};
44
use derive_more::{Display, From, Into};
55

66
use super::error::TokenTransferError;
@@ -11,6 +11,28 @@ use primitive_types::U256;
1111
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Display, From, Into)]
1212
pub struct Amount(U256);
1313

14+
#[cfg(feature = "parity-scale-codec")]
15+
impl parity_scale_codec::WrapperTypeDecode for Amount {
16+
type Wrapped = [u64; 4];
17+
}
18+
19+
#[cfg(feature = "parity-scale-codec")]
20+
impl parity_scale_codec::WrapperTypeEncode for Amount {}
21+
22+
impl Deref for Amount {
23+
type Target = [u64; 4];
24+
25+
fn deref(&self) -> &Self::Target {
26+
&self.0 .0
27+
}
28+
}
29+
30+
impl From<[u64; 4]> for Amount {
31+
fn from(value: [u64; 4]) -> Self {
32+
Self(U256(value))
33+
}
34+
}
35+
1436
impl Amount {
1537
pub fn checked_add(self, rhs: Self) -> Option<Self> {
1638
self.0.checked_add(rhs.0).map(Self)

crates/ibc/src/applications/transfer/coin.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ pub type RawCoin = Coin<String>;
2323

2424
/// Coin defines a token with a denomination and an amount.
2525
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
26+
#[cfg_attr(
27+
feature = "parity-scale-codec",
28+
derive(parity_scale_codec::Encode, parity_scale_codec::Decode,)
29+
)]
2630
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
2731
pub struct Coin<D> {
2832
/// Denomination

crates/ibc/src/applications/transfer/msgs/transfer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ pub(crate) const TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";
2424
/// have to specify the information related to the transfer of the token, and
2525
/// let the library figure out how to build the packet properly.
2626
#[derive(Clone, Debug, PartialEq, Eq)]
27+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
28+
#[cfg_attr(
29+
feature = "parity-scale-codec",
30+
derive(parity_scale_codec::Encode, parity_scale_codec::Decode,)
31+
)]
2732
pub struct MsgTransfer {
2833
/// the port on which the packet will be sent
2934
pub port_id_on_a: PortId,

crates/ibc/src/applications/transfer/packet.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ use crate::signer::Signer;
1616
feature = "serde",
1717
serde(try_from = "RawPacketData", into = "RawPacketData")
1818
)]
19+
#[cfg_attr(
20+
feature = "parity-scale-codec",
21+
derive(parity_scale_codec::Encode, parity_scale_codec::Decode,)
22+
)]
1923
#[derive(Clone, Debug, PartialEq, Eq)]
2024
pub struct PacketData {
2125
pub token: PrefixedCoin,

0 commit comments

Comments
 (0)