Skip to content

Commit eb4d6a2

Browse files
committed
Add MemoSource trait
1 parent d4e629e commit eb4d6a2

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

packages/std/src/ibc/transfer_msg_builder.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,54 @@ pub struct WithCallbacks {
2424
dst_callback: IbcDstCallback,
2525
}
2626

27-
impl From<EmptyMemo> for Option<String> {
28-
fn from(_: EmptyMemo) -> Self {
27+
pub trait MemoSource {
28+
fn into_memo(self) -> Option<String>;
29+
}
30+
31+
impl MemoSource for EmptyMemo {
32+
fn into_memo(self) -> Option<String> {
2933
None
3034
}
3135
}
3236

33-
impl From<WithMemo> for Option<String> {
34-
fn from(m: WithMemo) -> Self {
35-
Some(m.memo)
37+
impl MemoSource for WithMemo {
38+
fn into_memo(self) -> Option<String> {
39+
Some(self.memo)
3640
}
3741
}
3842

39-
impl From<WithSrcCallback> for Option<String> {
40-
fn from(s: WithSrcCallback) -> Self {
41-
Some(to_json_string(&IbcCallbackRequest::source(s.src_callback)).unwrap())
43+
impl MemoSource for WithSrcCallback {
44+
fn into_memo(self) -> Option<String> {
45+
Some(to_json_string(&IbcCallbackRequest::source(self.src_callback)).unwrap())
4246
}
4347
}
4448

45-
impl From<WithDstCallback> for Option<String> {
46-
fn from(d: WithDstCallback) -> Self {
47-
Some(to_json_string(&IbcCallbackRequest::destination(d.dst_callback)).unwrap())
49+
impl MemoSource for WithDstCallback {
50+
fn into_memo(self) -> Option<String> {
51+
Some(to_json_string(&IbcCallbackRequest::destination(self.dst_callback)).unwrap())
4852
}
4953
}
5054

51-
impl From<WithCallbacks> for Option<String> {
52-
fn from(c: WithCallbacks) -> Self {
53-
Some(to_json_string(&IbcCallbackRequest::both(c.src_callback, c.dst_callback)).unwrap())
55+
impl MemoSource for WithCallbacks {
56+
fn into_memo(self) -> Option<String> {
57+
Some(
58+
to_json_string(&IbcCallbackRequest::both(
59+
self.src_callback,
60+
self.dst_callback,
61+
))
62+
.unwrap(),
63+
)
5464
}
5565
}
5666

57-
impl<T: Into<Option<String>>> TransferMsgBuilder<T> {
67+
impl<M: MemoSource> TransferMsgBuilder<M> {
5868
pub fn build(self) -> IbcMsg {
5969
IbcMsg::Transfer {
6070
channel_id: self.channel_id,
6171
to_address: self.to_address,
6272
amount: self.amount,
6373
timeout: self.timeout,
64-
memo: self.memo.into(),
74+
memo: self.memo.into_memo(),
6575
}
6676
}
6777
}

0 commit comments

Comments
 (0)