Skip to content

Commit f0c3d6b

Browse files
authored
Merge pull request #884 from CosmWasm/document-ibc
Document ibc
2 parents 662d46b + 61a3749 commit f0c3d6b

File tree

13 files changed

+845
-217
lines changed

13 files changed

+845
-217
lines changed

IBC.md

Lines changed: 418 additions & 0 deletions
Large diffs are not rendered by default.

contracts/ibc-reflect-send/schema/execute_msg.json

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@
344344
"required": [
345345
"amount",
346346
"channel_id",
347+
"timeout",
347348
"to_address"
348349
],
349350
"properties": {
@@ -359,26 +360,14 @@
359360
"description": "exisiting channel to send the tokens over",
360361
"type": "string"
361362
},
362-
"timeout_block": {
363-
"description": "block after which the packet times out. at least one of timeout_block, timeout_timestamp is required",
364-
"anyOf": [
365-
{
366-
"$ref": "#/definitions/IbcTimeoutBlock"
367-
},
363+
"timeout": {
364+
"description": "when packet times out, measured on remote chain",
365+
"allOf": [
368366
{
369-
"type": "null"
367+
"$ref": "#/definitions/IbcTimeout"
370368
}
371369
]
372370
},
373-
"timeout_timestamp": {
374-
"description": "block timestamp (nanoseconds since UNIX epoch) after which the packet times out. See https://golang.org/pkg/time/#Time.UnixNano at least one of timeout_block, timeout_timestamp is required",
375-
"type": [
376-
"integer",
377-
"null"
378-
],
379-
"format": "uint64",
380-
"minimum": 0.0
381-
},
382371
"to_address": {
383372
"description": "address on the remote chain to receive these tokens",
384373
"type": "string"
@@ -399,7 +388,8 @@
399388
"type": "object",
400389
"required": [
401390
"channel_id",
402-
"data"
391+
"data",
392+
"timeout"
403393
],
404394
"properties": {
405395
"channel_id": {
@@ -408,33 +398,21 @@
408398
"data": {
409399
"$ref": "#/definitions/Binary"
410400
},
411-
"timeout_block": {
412-
"description": "block height after which the packet times out. at least one of timeout_block, timeout_timestamp is required",
413-
"anyOf": [
414-
{
415-
"$ref": "#/definitions/IbcTimeoutBlock"
416-
},
401+
"timeout": {
402+
"description": "when packet times out, measured on remote chain",
403+
"allOf": [
417404
{
418-
"type": "null"
405+
"$ref": "#/definitions/IbcTimeout"
419406
}
420407
]
421-
},
422-
"timeout_timestamp": {
423-
"description": "block timestamp (nanoseconds since UNIX epoch) after which the packet times out. See https://golang.org/pkg/time/#Time.UnixNano at least one of timeout_block, timeout_timestamp is required",
424-
"type": [
425-
"integer",
426-
"null"
427-
],
428-
"format": "uint64",
429-
"minimum": 0.0
430408
}
431409
}
432410
}
433411
},
434412
"additionalProperties": false
435413
},
436414
{
437-
"description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contracts' ibc port",
415+
"description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port",
438416
"type": "object",
439417
"required": [
440418
"close_channel"
@@ -456,6 +434,64 @@
456434
}
457435
]
458436
},
437+
"IbcTimeout": {
438+
"anyOf": [
439+
{
440+
"description": "block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain) See https://golang.org/pkg/time/#Time.UnixNano",
441+
"type": "object",
442+
"required": [
443+
"timestamp_nanos"
444+
],
445+
"properties": {
446+
"timestamp_nanos": {
447+
"type": "integer",
448+
"format": "uint64",
449+
"minimum": 0.0
450+
}
451+
},
452+
"additionalProperties": false
453+
},
454+
{
455+
"description": "block after which the packet times out (measured on remote chain)",
456+
"type": "object",
457+
"required": [
458+
"block"
459+
],
460+
"properties": {
461+
"block": {
462+
"$ref": "#/definitions/IbcTimeoutBlock"
463+
}
464+
},
465+
"additionalProperties": false
466+
},
467+
{
468+
"type": "object",
469+
"required": [
470+
"both"
471+
],
472+
"properties": {
473+
"both": {
474+
"type": "object",
475+
"required": [
476+
"block",
477+
"timestamp_nanos"
478+
],
479+
"properties": {
480+
"block": {
481+
"$ref": "#/definitions/IbcTimeoutBlock"
482+
},
483+
"timestamp_nanos": {
484+
"type": "integer",
485+
"format": "uint64",
486+
"minimum": 0.0
487+
}
488+
}
489+
}
490+
},
491+
"additionalProperties": false
492+
}
493+
]
494+
},
459495
"IbcTimeoutBlock": {
460496
"description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)",
461497
"type": "object",

contracts/ibc-reflect-send/schema/packet_msg.json

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
"required": [
298298
"amount",
299299
"channel_id",
300+
"timeout",
300301
"to_address"
301302
],
302303
"properties": {
@@ -312,26 +313,14 @@
312313
"description": "exisiting channel to send the tokens over",
313314
"type": "string"
314315
},
315-
"timeout_block": {
316-
"description": "block after which the packet times out. at least one of timeout_block, timeout_timestamp is required",
317-
"anyOf": [
318-
{
319-
"$ref": "#/definitions/IbcTimeoutBlock"
320-
},
316+
"timeout": {
317+
"description": "when packet times out, measured on remote chain",
318+
"allOf": [
321319
{
322-
"type": "null"
320+
"$ref": "#/definitions/IbcTimeout"
323321
}
324322
]
325323
},
326-
"timeout_timestamp": {
327-
"description": "block timestamp (nanoseconds since UNIX epoch) after which the packet times out. See https://golang.org/pkg/time/#Time.UnixNano at least one of timeout_block, timeout_timestamp is required",
328-
"type": [
329-
"integer",
330-
"null"
331-
],
332-
"format": "uint64",
333-
"minimum": 0.0
334-
},
335324
"to_address": {
336325
"description": "address on the remote chain to receive these tokens",
337326
"type": "string"
@@ -352,7 +341,8 @@
352341
"type": "object",
353342
"required": [
354343
"channel_id",
355-
"data"
344+
"data",
345+
"timeout"
356346
],
357347
"properties": {
358348
"channel_id": {
@@ -361,33 +351,21 @@
361351
"data": {
362352
"$ref": "#/definitions/Binary"
363353
},
364-
"timeout_block": {
365-
"description": "block height after which the packet times out. at least one of timeout_block, timeout_timestamp is required",
366-
"anyOf": [
367-
{
368-
"$ref": "#/definitions/IbcTimeoutBlock"
369-
},
354+
"timeout": {
355+
"description": "when packet times out, measured on remote chain",
356+
"allOf": [
370357
{
371-
"type": "null"
358+
"$ref": "#/definitions/IbcTimeout"
372359
}
373360
]
374-
},
375-
"timeout_timestamp": {
376-
"description": "block timestamp (nanoseconds since UNIX epoch) after which the packet times out. See https://golang.org/pkg/time/#Time.UnixNano at least one of timeout_block, timeout_timestamp is required",
377-
"type": [
378-
"integer",
379-
"null"
380-
],
381-
"format": "uint64",
382-
"minimum": 0.0
383361
}
384362
}
385363
}
386364
},
387365
"additionalProperties": false
388366
},
389367
{
390-
"description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contracts' ibc port",
368+
"description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port",
391369
"type": "object",
392370
"required": [
393371
"close_channel"
@@ -409,6 +387,64 @@
409387
}
410388
]
411389
},
390+
"IbcTimeout": {
391+
"anyOf": [
392+
{
393+
"description": "block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain) See https://golang.org/pkg/time/#Time.UnixNano",
394+
"type": "object",
395+
"required": [
396+
"timestamp_nanos"
397+
],
398+
"properties": {
399+
"timestamp_nanos": {
400+
"type": "integer",
401+
"format": "uint64",
402+
"minimum": 0.0
403+
}
404+
},
405+
"additionalProperties": false
406+
},
407+
{
408+
"description": "block after which the packet times out (measured on remote chain)",
409+
"type": "object",
410+
"required": [
411+
"block"
412+
],
413+
"properties": {
414+
"block": {
415+
"$ref": "#/definitions/IbcTimeoutBlock"
416+
}
417+
},
418+
"additionalProperties": false
419+
},
420+
{
421+
"type": "object",
422+
"required": [
423+
"both"
424+
],
425+
"properties": {
426+
"both": {
427+
"type": "object",
428+
"required": [
429+
"block",
430+
"timestamp_nanos"
431+
],
432+
"properties": {
433+
"block": {
434+
"$ref": "#/definitions/IbcTimeoutBlock"
435+
},
436+
"timestamp_nanos": {
437+
"type": "integer",
438+
"format": "uint64",
439+
"minimum": 0.0
440+
}
441+
}
442+
}
443+
},
444+
"additionalProperties": false
445+
}
446+
]
447+
},
412448
"IbcTimeoutBlock": {
413449
"description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)",
414450
"type": "object",

contracts/ibc-reflect-send/src/contract.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use cosmwasm_std::{
33
QueryResponse, Response, StdError, StdResult,
44
};
55

6-
use crate::ibc::build_timeout_timestamp;
6+
use crate::ibc::PACKET_LIFETIME;
77
use crate::ibc_msg::PacketMsg;
88
use crate::msg::{
99
AccountInfo, AccountResponse, AdminResponse, ExecuteMsg, InstantiateMsg, ListAccountsResponse,
@@ -91,8 +91,7 @@ pub fn handle_send_msgs(
9191
let msg = IbcMsg::SendPacket {
9292
channel_id,
9393
data: to_binary(&packet)?,
94-
timeout_block: None,
95-
timeout_timestamp: Some(build_timeout_timestamp(&env.block)),
94+
timeout: env.block.timestamp().plus_seconds(PACKET_LIFETIME).into(),
9695
};
9796

9897
Ok(Response {
@@ -122,8 +121,7 @@ pub fn handle_check_remote_balance(
122121
let msg = IbcMsg::SendPacket {
123122
channel_id,
124123
data: to_binary(&packet)?,
125-
timeout_block: None,
126-
timeout_timestamp: Some(build_timeout_timestamp(&env.block)),
124+
timeout: env.block.timestamp().plus_seconds(PACKET_LIFETIME).into(),
127125
};
128126

129127
Ok(Response {
@@ -173,8 +171,7 @@ pub fn handle_send_funds(
173171
channel_id: transfer_channel_id,
174172
to_address: remote_addr,
175173
amount,
176-
timeout_block: None,
177-
timeout_timestamp: Some(build_timeout_timestamp(&env.block)),
174+
timeout: env.block.timestamp().plus_seconds(PACKET_LIFETIME).into(),
178175
};
179176

180177
Ok(Response {

0 commit comments

Comments
 (0)