Skip to content

Commit ad3e86f

Browse files
committed
Rename TimestampNanos to Timestamp and improve IbcTimeout docs
1 parent c54fe43 commit ad3e86f

File tree

9 files changed

+61
-39
lines changed

9 files changed

+61
-39
lines changed

IBC.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,26 @@ pub enum IbcMsg {
3737
}
3838
}
3939

40+
/// In IBC each package must set at least one type of timeout:
41+
/// the timestamp or the block height. Using this rather complex enum instead of
42+
/// two timeout fields we ensure that at least one timeout is set.
4043
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
4144
#[serde(rename_all = "snake_case")]
4245
pub enum IbcTimeout {
43-
/// block timestamp (nanoseconds since UNIX epoch) after which the packet times out
44-
/// (measured on the remote chain)
46+
/// Block timestamp (nanoseconds since UNIX epoch) after which the packet times out
47+
/// (measured on the remote chain).
48+
///
4549
/// See https://golang.org/pkg/time/#Time.UnixNano
46-
TimestampNanos(u64),
50+
Timestamp(u64),
4751
/// block after which the packet times out (measured on remote chain)
4852
Block(IbcTimeoutBlock),
53+
/// Use this to set both timestamp and block timeout. The package then times out once
54+
/// the first of both timeouts is hit.
4955
Both {
50-
timestamp_nanos: u64,
56+
timestamp: u64,
5157
block: IbcTimeoutBlock,
5258
},
5359
}
54-
5560
```
5661

5762
Note the `to_address` is likely not a valid `Addr`, as it uses the bech32 prefix

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,16 @@
435435
]
436436
},
437437
"IbcTimeout": {
438+
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
438439
"anyOf": [
439440
{
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+
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).\n\nSee https://golang.org/pkg/time/#Time.UnixNano",
441442
"type": "object",
442443
"required": [
443-
"timestamp_nanos"
444+
"timestamp"
444445
],
445446
"properties": {
446-
"timestamp_nanos": {
447+
"timestamp": {
447448
"type": "integer",
448449
"format": "uint64",
449450
"minimum": 0.0
@@ -465,6 +466,7 @@
465466
"additionalProperties": false
466467
},
467468
{
469+
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
468470
"type": "object",
469471
"required": [
470472
"both"
@@ -474,13 +476,13 @@
474476
"type": "object",
475477
"required": [
476478
"block",
477-
"timestamp_nanos"
479+
"timestamp"
478480
],
479481
"properties": {
480482
"block": {
481483
"$ref": "#/definitions/IbcTimeoutBlock"
482484
},
483-
"timestamp_nanos": {
485+
"timestamp": {
484486
"type": "integer",
485487
"format": "uint64",
486488
"minimum": 0.0

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,16 @@
388388
]
389389
},
390390
"IbcTimeout": {
391+
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
391392
"anyOf": [
392393
{
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+
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).\n\nSee https://golang.org/pkg/time/#Time.UnixNano",
394395
"type": "object",
395396
"required": [
396-
"timestamp_nanos"
397+
"timestamp"
397398
],
398399
"properties": {
399-
"timestamp_nanos": {
400+
"timestamp": {
400401
"type": "integer",
401402
"format": "uint64",
402403
"minimum": 0.0
@@ -418,6 +419,7 @@
418419
"additionalProperties": false
419420
},
420421
{
422+
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
421423
"type": "object",
422424
"required": [
423425
"both"
@@ -427,13 +429,13 @@
427429
"type": "object",
428430
"required": [
429431
"block",
430-
"timestamp_nanos"
432+
"timestamp"
431433
],
432434
"properties": {
433435
"block": {
434436
"$ref": "#/definitions/IbcTimeoutBlock"
435437
},
436-
"timestamp_nanos": {
438+
"timestamp": {
437439
"type": "integer",
438440
"format": "uint64",
439441
"minimum": 0.0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ mod tests {
445445
assert_eq!(transfer_channel_id, channel_id.as_str());
446446
assert_eq!(remote_addr, to_address.as_str());
447447
assert_eq!(&coin(12344, "utrgd"), amount);
448-
assert!(matches!(timeout, IbcTimeout::TimestampNanos { .. }));
448+
assert!(matches!(timeout, IbcTimeout::Timestamp { .. }));
449449
}
450450
o => panic!("unexpected message: {:?}", o),
451451
}

contracts/ibc-reflect-send/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ fn send_remote_funds() {
239239
assert_eq!(transfer_channel_id, channel_id.as_str());
240240
assert_eq!(remote_addr, to_address.as_str());
241241
assert_eq!(&coin(12344, "utrgd"), amount);
242-
assert!(matches!(timeout, IbcTimeout::TimestampNanos { .. }));
242+
assert!(matches!(timeout, IbcTimeout::Timestamp { .. }));
243243
}
244244
o => panic!("unexpected message: {:?}", o),
245245
}

contracts/ibc-reflect/schema/packet_msg.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,16 @@
387387
]
388388
},
389389
"IbcTimeout": {
390+
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
390391
"anyOf": [
391392
{
392-
"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",
393+
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).\n\nSee https://golang.org/pkg/time/#Time.UnixNano",
393394
"type": "object",
394395
"required": [
395-
"timestamp_nanos"
396+
"timestamp"
396397
],
397398
"properties": {
398-
"timestamp_nanos": {
399+
"timestamp": {
399400
"type": "integer",
400401
"format": "uint64",
401402
"minimum": 0.0
@@ -417,6 +418,7 @@
417418
"additionalProperties": false
418419
},
419420
{
421+
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
420422
"type": "object",
421423
"required": [
422424
"both"
@@ -426,13 +428,13 @@
426428
"type": "object",
427429
"required": [
428430
"block",
429-
"timestamp_nanos"
431+
"timestamp"
430432
],
431433
"properties": {
432434
"block": {
433435
"$ref": "#/definitions/IbcTimeoutBlock"
434436
},
435-
"timestamp_nanos": {
437+
"timestamp": {
436438
"type": "integer",
437439
"format": "uint64",
438440
"minimum": 0.0

contracts/reflect/schema/execute_msg.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,16 @@
431431
]
432432
},
433433
"IbcTimeout": {
434+
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
434435
"anyOf": [
435436
{
436-
"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",
437+
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).\n\nSee https://golang.org/pkg/time/#Time.UnixNano",
437438
"type": "object",
438439
"required": [
439-
"timestamp_nanos"
440+
"timestamp"
440441
],
441442
"properties": {
442-
"timestamp_nanos": {
443+
"timestamp": {
443444
"type": "integer",
444445
"format": "uint64",
445446
"minimum": 0.0
@@ -461,6 +462,7 @@
461462
"additionalProperties": false
462463
},
463464
{
465+
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
464466
"type": "object",
465467
"required": [
466468
"both"
@@ -470,13 +472,13 @@
470472
"type": "object",
471473
"required": [
472474
"block",
473-
"timestamp_nanos"
475+
"timestamp"
474476
],
475477
"properties": {
476478
"block": {
477479
"$ref": "#/definitions/IbcTimeoutBlock"
478480
},
479-
"timestamp_nanos": {
481+
"timestamp": {
480482
"type": "integer",
481483
"format": "uint64",
482484
"minimum": 0.0

contracts/reflect/schema/response_for__custom_msg.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,16 @@
419419
]
420420
},
421421
"IbcTimeout": {
422+
"description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.",
422423
"anyOf": [
423424
{
424-
"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",
425+
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).\n\nSee https://golang.org/pkg/time/#Time.UnixNano",
425426
"type": "object",
426427
"required": [
427-
"timestamp_nanos"
428+
"timestamp"
428429
],
429430
"properties": {
430-
"timestamp_nanos": {
431+
"timestamp": {
431432
"type": "integer",
432433
"format": "uint64",
433434
"minimum": 0.0
@@ -449,6 +450,7 @@
449450
"additionalProperties": false
450451
},
451452
{
453+
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
452454
"type": "object",
453455
"required": [
454456
"both"
@@ -458,13 +460,13 @@
458460
"type": "object",
459461
"required": [
460462
"block",
461-
"timestamp_nanos"
463+
"timestamp"
462464
],
463465
"properties": {
464466
"block": {
465467
"$ref": "#/definitions/IbcTimeoutBlock"
466468
},
467-
"timestamp_nanos": {
469+
"timestamp": {
468470
"type": "integer",
469471
"format": "uint64",
470472
"minimum": 0.0

packages/std/src/ibc.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,31 @@ pub struct IbcEndpoint {
5454
pub channel_id: String,
5555
}
5656

57+
/// In IBC each package must set at least one type of timeout:
58+
/// the timestamp or the block height. Using this rather complex enum instead of
59+
/// two timeout fields we ensure that at least one timeout is set.
5760
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
5861
#[serde(rename_all = "snake_case")]
5962
pub enum IbcTimeout {
60-
/// block timestamp (nanoseconds since UNIX epoch) after which the packet times out
61-
/// (measured on the remote chain)
63+
/// Block timestamp (nanoseconds since UNIX epoch) after which the packet times out
64+
/// (measured on the remote chain).
65+
///
6266
/// See https://golang.org/pkg/time/#Time.UnixNano
63-
TimestampNanos(u64),
67+
Timestamp(u64),
6468
/// block after which the packet times out (measured on remote chain)
6569
Block(IbcTimeoutBlock),
70+
/// Use this to set both timestamp and block timeout. The package then times out once
71+
/// the first of both timeouts is hit.
6672
Both {
67-
timestamp_nanos: u64,
73+
timestamp: u64,
6874
block: IbcTimeoutBlock,
6975
},
7076
}
7177

7278
impl From<Timestamp> for IbcTimeout {
7379
fn from(time: Timestamp) -> IbcTimeout {
74-
IbcTimeout::TimestampNanos(time.seconds * 1_000_000_000 + time.nanos)
80+
let nanos = time.seconds * 1_000_000_000 + time.nanos;
81+
IbcTimeout::Timestamp(nanos)
7582
}
7683
}
7784

@@ -253,10 +260,10 @@ mod tests {
253260
channel_id: "channel-123".to_string(),
254261
to_address: "my-special-addr".into(),
255262
amount: Coin::new(12345678, "uatom"),
256-
timeout: IbcTimeout::TimestampNanos(1234567890),
263+
timeout: IbcTimeout::Timestamp(1234567890),
257264
};
258265
let encoded = to_string(&msg).unwrap();
259-
let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"timestamp_nanos":1234567890}}}"#;
266+
let expected = r#"{"transfer":{"channel_id":"channel-123","to_address":"my-special-addr","amount":{"denom":"uatom","amount":"12345678"},"timeout":{"timestamp":1234567890}}}"#;
260267
assert_eq!(encoded.as_str(), expected);
261268
}
262269

0 commit comments

Comments
 (0)