From eb4d6a2acaac79fe3440ae6fc2b260e49d1820c7 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Tue, 4 Jun 2024 12:04:22 +0200 Subject: [PATCH] Add MemoSource trait --- packages/std/src/ibc/transfer_msg_builder.rs | 42 ++++++++++++-------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/packages/std/src/ibc/transfer_msg_builder.rs b/packages/std/src/ibc/transfer_msg_builder.rs index 8e04f34ed5..484ef4038b 100644 --- a/packages/std/src/ibc/transfer_msg_builder.rs +++ b/packages/std/src/ibc/transfer_msg_builder.rs @@ -24,44 +24,54 @@ pub struct WithCallbacks { dst_callback: IbcDstCallback, } -impl From for Option { - fn from(_: EmptyMemo) -> Self { +pub trait MemoSource { + fn into_memo(self) -> Option; +} + +impl MemoSource for EmptyMemo { + fn into_memo(self) -> Option { None } } -impl From for Option { - fn from(m: WithMemo) -> Self { - Some(m.memo) +impl MemoSource for WithMemo { + fn into_memo(self) -> Option { + Some(self.memo) } } -impl From for Option { - fn from(s: WithSrcCallback) -> Self { - Some(to_json_string(&IbcCallbackRequest::source(s.src_callback)).unwrap()) +impl MemoSource for WithSrcCallback { + fn into_memo(self) -> Option { + Some(to_json_string(&IbcCallbackRequest::source(self.src_callback)).unwrap()) } } -impl From for Option { - fn from(d: WithDstCallback) -> Self { - Some(to_json_string(&IbcCallbackRequest::destination(d.dst_callback)).unwrap()) +impl MemoSource for WithDstCallback { + fn into_memo(self) -> Option { + Some(to_json_string(&IbcCallbackRequest::destination(self.dst_callback)).unwrap()) } } -impl From for Option { - fn from(c: WithCallbacks) -> Self { - Some(to_json_string(&IbcCallbackRequest::both(c.src_callback, c.dst_callback)).unwrap()) +impl MemoSource for WithCallbacks { + fn into_memo(self) -> Option { + Some( + to_json_string(&IbcCallbackRequest::both( + self.src_callback, + self.dst_callback, + )) + .unwrap(), + ) } } -impl>> TransferMsgBuilder { +impl TransferMsgBuilder { pub fn build(self) -> IbcMsg { IbcMsg::Transfer { channel_id: self.channel_id, to_address: self.to_address, amount: self.amount, timeout: self.timeout, - memo: self.memo.into(), + memo: self.memo.into_memo(), } } }