Skip to content

Commit

Permalink
Fix IbcCallbackData destination field name
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Apr 8, 2024
1 parent 173b410 commit 5a7f6b6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
34 changes: 34 additions & 0 deletions contracts/ibc-callbacks/schema/ibc-callbacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
"to_address"
],
"properties": {
"callback_type": {
"description": "Who should receive callbacks for the message",
"default": "both",
"allOf": [
{
"$ref": "#/definitions/CallbackType"
}
]
},
"channel_id": {
"description": "The channel to send the packet through",
"type": "string"
Expand All @@ -38,6 +47,31 @@
},
"additionalProperties": false,
"definitions": {
"CallbackType": {
"oneOf": [
{
"description": "Only this contract on the source chain should receive callbacks",
"type": "string",
"enum": [
"src"
]
},
{
"description": "Only the destination address should receive callbacks",
"type": "string",
"enum": [
"dst"
]
},
{
"description": "Both the source contract and the destination address should receive callbacks",
"type": "string",
"enum": [
"both"
]
}
]
},
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
Expand Down
34 changes: 34 additions & 0 deletions contracts/ibc-callbacks/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
"to_address"
],
"properties": {
"callback_type": {
"description": "Who should receive callbacks for the message",
"default": "both",
"allOf": [
{
"$ref": "#/definitions/CallbackType"
}
]
},
"channel_id": {
"description": "The channel to send the packet through",
"type": "string"
Expand All @@ -27,6 +36,31 @@
},
"additionalProperties": false,
"definitions": {
"CallbackType": {
"oneOf": [
{
"description": "Only this contract on the source chain should receive callbacks",
"type": "string",
"enum": [
"src"
]
},
{
"description": "Only the destination address should receive callbacks",
"type": "string",
"enum": [
"dst"
]
},
{
"description": "Both the source contract and the destination address should receive callbacks",
"type": "string",
"enum": [
"both"
]
}
]
},
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
Expand Down
20 changes: 10 additions & 10 deletions packages/std/src/ibc/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ pub struct IbcCallbackData {
#[serde(skip_serializing_if = "Option::is_none")]
src_callback: Option<IbcSrcCallback>,
#[serde(skip_serializing_if = "Option::is_none")]
dst_callback: Option<IbcDstCallback>,
dest_callback: Option<IbcDstCallback>,
}

impl IbcCallbackData {
/// Use this if you want to execute callbacks on both the source and destination chain.
pub fn both(src_callback: IbcSrcCallback, dst_callback: IbcDstCallback) -> Self {
pub fn both(src_callback: IbcSrcCallback, dest_callback: IbcDstCallback) -> Self {
IbcCallbackData {
src_callback: Some(src_callback),
dst_callback: Some(dst_callback),
dest_callback: Some(dest_callback),
}
}

/// Use this if you want to execute callbacks on the source chain, but not the destination chain.
pub fn source(src_callback: IbcSrcCallback) -> Self {
IbcCallbackData {
src_callback: Some(src_callback),
dst_callback: None,
dest_callback: None,
}
}

Check warning on line 62 in packages/std/src/ibc/callbacks.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/ibc/callbacks.rs#L57-L62

Added lines #L57 - L62 were not covered by tests

/// Use this if you want to execute callbacks on the destination chain, but not the source chain.
pub fn destination(dst_callback: IbcDstCallback) -> Self {
pub fn destination(dest_callback: IbcDstCallback) -> Self {
IbcCallbackData {
src_callback: None,
dst_callback: Some(dst_callback),
dest_callback: Some(dest_callback),
}
}

Check warning on line 70 in packages/std/src/ibc/callbacks.rs

View check run for this annotation

Codecov / codecov/patch

packages/std/src/ibc/callbacks.rs#L65-L70

Added lines #L65 - L70 were not covered by tests
}
Expand Down Expand Up @@ -154,19 +154,19 @@ mod tests {
let json = to_json_string(&data).unwrap();
assert_eq!(
json,
r#"{"src_callback":{"address":"src_address","gas_limit":"123"},"dst_callback":{"address":"dst_address","gas_limit":"1234"}}"#
r#"{"src_callback":{"address":"src_address","gas_limit":"123"},"dest_callback":{"address":"dst_address","gas_limit":"1234"}}"#
);

// dst only, without gas limit
let mut src = data.src_callback.take().unwrap();
data.dst_callback.as_mut().unwrap().gas_limit = None;
data.dest_callback.as_mut().unwrap().gas_limit = None;
let json = to_json_string(&data).unwrap();
assert_eq!(json, r#"{"dst_callback":{"address":"dst_address"}}"#);
assert_eq!(json, r#"{"dest_callback":{"address":"dst_address"}}"#);

// source only, without gas limit
src.gas_limit = None;
data.src_callback = Some(src);
data.dst_callback = None;
data.dest_callback = None;
let json = to_json_string(&data).unwrap();
assert_eq!(json, r#"{"src_callback":{"address":"src_address"}}"#);
}
Expand Down

0 comments on commit 5a7f6b6

Please sign in to comment.