Skip to content

Commit

Permalink
Add MemoSource trait
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Jun 4, 2024
1 parent d4e629e commit eb4d6a2
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions packages/std/src/ibc/transfer_msg_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,54 @@ pub struct WithCallbacks {
dst_callback: IbcDstCallback,
}

impl From<EmptyMemo> for Option<String> {
fn from(_: EmptyMemo) -> Self {
pub trait MemoSource {
fn into_memo(self) -> Option<String>;
}

impl MemoSource for EmptyMemo {
fn into_memo(self) -> Option<String> {
None
}
}

impl From<WithMemo> for Option<String> {
fn from(m: WithMemo) -> Self {
Some(m.memo)
impl MemoSource for WithMemo {
fn into_memo(self) -> Option<String> {
Some(self.memo)
}
}

impl From<WithSrcCallback> for Option<String> {
fn from(s: WithSrcCallback) -> Self {
Some(to_json_string(&IbcCallbackRequest::source(s.src_callback)).unwrap())
impl MemoSource for WithSrcCallback {
fn into_memo(self) -> Option<String> {
Some(to_json_string(&IbcCallbackRequest::source(self.src_callback)).unwrap())
}
}

impl From<WithDstCallback> for Option<String> {
fn from(d: WithDstCallback) -> Self {
Some(to_json_string(&IbcCallbackRequest::destination(d.dst_callback)).unwrap())
impl MemoSource for WithDstCallback {
fn into_memo(self) -> Option<String> {
Some(to_json_string(&IbcCallbackRequest::destination(self.dst_callback)).unwrap())
}
}

impl From<WithCallbacks> for Option<String> {
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<String> {
Some(
to_json_string(&IbcCallbackRequest::both(
self.src_callback,
self.dst_callback,
))
.unwrap(),
)
}
}

impl<T: Into<Option<String>>> TransferMsgBuilder<T> {
impl<M: MemoSource> TransferMsgBuilder<M> {
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(),
}
}
}
Expand Down

0 comments on commit eb4d6a2

Please sign in to comment.