Skip to content

Commit

Permalink
Use Option<String> for memo field
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Oct 17, 2023
1 parent bf5b492 commit 9e21260
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 18 deletions.
6 changes: 4 additions & 2 deletions contracts/ibc-reflect-send/schema/ibc-reflect-send.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@
"required": [
"amount",
"channel_id",
"memo",
"timeout",
"to_address"
],
Expand All @@ -427,7 +426,10 @@
},
"memo": {
"description": "optional memo",
"type": "string"
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
Expand Down
6 changes: 4 additions & 2 deletions contracts/ibc-reflect-send/schema/ibc/packet_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@
"required": [
"amount",
"channel_id",
"memo",
"timeout",
"to_address"
],
Expand All @@ -365,7 +364,10 @@
},
"memo": {
"description": "optional memo",
"type": "string"
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
Expand Down
6 changes: 4 additions & 2 deletions contracts/ibc-reflect-send/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@
"required": [
"amount",
"channel_id",
"memo",
"timeout",
"to_address"
],
Expand All @@ -416,7 +415,10 @@
},
"memo": {
"description": "optional memo",
"type": "string"
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
Expand Down
2 changes: 1 addition & 1 deletion contracts/ibc-reflect-send/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn handle_send_funds(
to_address: remote_addr,
amount,
timeout: env.block.time.plus_seconds(PACKET_LIFETIME).into(),
memo: String::new(),
memo: None,
};

let res = Response::new()
Expand Down
2 changes: 1 addition & 1 deletion contracts/ibc-reflect-send/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ mod tests {
assert_eq!(&coin(12344, "utrgd"), amount);
assert!(timeout.block().is_none());
assert!(timeout.timestamp().is_some());
assert_eq!(memo, "");
assert!(memo.is_none());
}
o => panic!("unexpected message: {o:?}"),
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/ibc-reflect-send/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn send_remote_funds() {
assert_eq!(&coin(12344, "utrgd"), amount);
assert!(timeout.block().is_none());
assert!(timeout.timestamp().is_some());
assert_eq!(memo, "");
assert!(memo.is_none());
}
o => panic!("unexpected message: {o:?}"),
}
Expand Down
6 changes: 4 additions & 2 deletions contracts/ibc-reflect/schema/ibc/packet_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@
"required": [
"amount",
"channel_id",
"memo",
"timeout",
"to_address"
],
Expand All @@ -352,7 +351,10 @@
},
"memo": {
"description": "optional memo",
"type": "string"
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
Expand Down
6 changes: 4 additions & 2 deletions contracts/reflect/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@
"required": [
"amount",
"channel_id",
"memo",
"timeout",
"to_address"
],
Expand All @@ -470,7 +469,10 @@
},
"memo": {
"description": "optional memo",
"type": "string"
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
Expand Down
6 changes: 4 additions & 2 deletions contracts/reflect/schema/reflect.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@
"required": [
"amount",
"channel_id",
"memo",
"timeout",
"to_address"
],
Expand All @@ -480,7 +479,10 @@
},
"memo": {
"description": "optional memo",
"type": "string"
"type": [
"string",
"null"
]
},
"timeout": {
"description": "when packet times out, measured on remote chain",
Expand Down
7 changes: 4 additions & 3 deletions packages/std/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ pub enum IbcMsg {
/// when packet times out, measured on remote chain
timeout: IbcTimeout,
/// optional memo
memo: String,
#[serde(skip_serializing_if = "Option::is_none")]
memo: Option<String>,
},
/// Sends an IBC packet with given data over the existing channel.
/// Data should be encoded in a format defined by the channel version,
Expand Down Expand Up @@ -795,10 +796,10 @@ mod tests {
to_address: "my-special-addr".into(),
amount: Coin::new(12345678, "uatom"),
timeout: IbcTimeout::with_timestamp(Timestamp::from_nanos(1234567890)),
memo: String::new(),
memo: None,
};
let encoded = to_string(&msg).unwrap();
let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"},"memo":""}}"#;
let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"block":null,"timestamp":"1234567890"}}}"#;
assert_eq!(encoded.as_str(), expected);
}

Expand Down

0 comments on commit 9e21260

Please sign in to comment.