Skip to content

Refactor Timestamps #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ and this project adheres to
contract (eg. multisig) to clear the admin, to prevent future migrations
([#900])
- cosmwasm-std: Implement `Display for Coin` ([#901]).
- cosmwasm-std: Create `Uint64` analogously to `Uint128` with string
serialization allowing the use of the full uint64 range in JSON clients that
use float numbers, such as JavaScript and jq.
- cosmwasm-std: Create const functions `Uint64::new` and `Uint128::new` to
create instances in a const context.

[#692]: https://github.com/CosmWasm/cosmwasm/issues/692
[#706]: https://github.com/CosmWasm/cosmwasm/pull/706
Expand Down
17 changes: 10 additions & 7 deletions IBC.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ pub enum IbcMsg {
}
}

/// 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.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum IbcTimeout {
/// 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
TimestampNanos(u64),
/// block after which the packet times out (measured on remote chain)
/// Block timestamp (nanoseconds since UNIX epoch) after which the packet times out
/// (measured on the remote chain).
Timestamp(Timestamp),
/// Block after which the packet times out (measured on remote chain).
Block(IbcTimeoutBlock),
/// Use this to set both timestamp and block timeout. The package then times out once
/// the first of both timeouts is hit.
Both {
timestamp_nanos: u64,
timestamp: Timestamp,
block: IbcTimeoutBlock,
},
}

```

Note the `to_address` is likely not a valid `Addr`, as it uses the bech32 prefix
Expand Down
1 change: 1 addition & 0 deletions contracts/crypto-verify/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"type": "string"
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
Expand Down
1 change: 1 addition & 0 deletions contracts/hackatom/schema/balance_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
}
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
Expand Down
1 change: 1 addition & 0 deletions contracts/hackatom/schema/sudo_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
}
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
Expand Down
1 change: 1 addition & 0 deletions contracts/ibc-reflect-send/schema/account_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
}
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
Expand Down
35 changes: 23 additions & 12 deletions contracts/ibc-reflect-send/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,24 +435,23 @@
]
},
"IbcTimeout": {
"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.",
"anyOf": [
{
"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",
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).",
"type": "object",
"required": [
"timestamp_nanos"
"timestamp"
],
"properties": {
"timestamp_nanos": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"timestamp": {
"$ref": "#/definitions/Timestamp"
}
},
"additionalProperties": false
},
{
"description": "block after which the packet times out (measured on remote chain)",
"description": "Block after which the packet times out (measured on remote chain).",
"type": "object",
"required": [
"block"
Expand All @@ -465,6 +464,7 @@
"additionalProperties": false
},
{
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
"type": "object",
"required": [
"both"
Expand All @@ -474,16 +474,14 @@
"type": "object",
"required": [
"block",
"timestamp_nanos"
"timestamp"
],
"properties": {
"block": {
"$ref": "#/definitions/IbcTimeoutBlock"
},
"timestamp_nanos": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"timestamp": {
"$ref": "#/definitions/Timestamp"
}
}
}
Expand Down Expand Up @@ -598,7 +596,20 @@
}
]
},
"Timestamp": {
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.",
"allOf": [
{
"$ref": "#/definitions/Uint64"
}
]
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
},
"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"
},
"WasmMsg": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
}
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
Expand Down
35 changes: 23 additions & 12 deletions contracts/ibc-reflect-send/schema/packet_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,23 @@
]
},
"IbcTimeout": {
"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.",
"anyOf": [
{
"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",
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).",
"type": "object",
"required": [
"timestamp_nanos"
"timestamp"
],
"properties": {
"timestamp_nanos": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"timestamp": {
"$ref": "#/definitions/Timestamp"
}
},
"additionalProperties": false
},
{
"description": "block after which the packet times out (measured on remote chain)",
"description": "Block after which the packet times out (measured on remote chain).",
"type": "object",
"required": [
"block"
Expand All @@ -418,6 +417,7 @@
"additionalProperties": false
},
{
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
"type": "object",
"required": [
"both"
Expand All @@ -427,16 +427,14 @@
"type": "object",
"required": [
"block",
"timestamp_nanos"
"timestamp"
],
"properties": {
"block": {
"$ref": "#/definitions/IbcTimeoutBlock"
},
"timestamp_nanos": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"timestamp": {
"$ref": "#/definitions/Timestamp"
}
}
}
Expand Down Expand Up @@ -551,7 +549,20 @@
}
]
},
"Timestamp": {
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.",
"allOf": [
{
"$ref": "#/definitions/Uint64"
}
]
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
},
"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"
},
"WasmMsg": {
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 @@ -445,7 +445,7 @@ mod tests {
assert_eq!(transfer_channel_id, channel_id.as_str());
assert_eq!(remote_addr, to_address.as_str());
assert_eq!(&coin(12344, "utrgd"), amount);
assert!(matches!(timeout, IbcTimeout::TimestampNanos { .. }));
assert!(matches!(timeout, IbcTimeout::Timestamp { .. }));
}
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 @@ -239,7 +239,7 @@ fn send_remote_funds() {
assert_eq!(transfer_channel_id, channel_id.as_str());
assert_eq!(remote_addr, to_address.as_str());
assert_eq!(&coin(12344, "utrgd"), amount);
assert!(matches!(timeout, IbcTimeout::TimestampNanos { .. }));
assert!(matches!(timeout, IbcTimeout::Timestamp { .. }));
}
o => panic!("unexpected message: {:?}", o),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
}
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
Expand Down
35 changes: 23 additions & 12 deletions contracts/ibc-reflect/schema/packet_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,24 +387,23 @@
]
},
"IbcTimeout": {
"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.",
"anyOf": [
{
"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",
"description": "Block timestamp (nanoseconds since UNIX epoch) after which the packet times out (measured on the remote chain).",
"type": "object",
"required": [
"timestamp_nanos"
"timestamp"
],
"properties": {
"timestamp_nanos": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"timestamp": {
"$ref": "#/definitions/Timestamp"
}
},
"additionalProperties": false
},
{
"description": "block after which the packet times out (measured on remote chain)",
"description": "Block after which the packet times out (measured on remote chain).",
"type": "object",
"required": [
"block"
Expand All @@ -417,6 +416,7 @@
"additionalProperties": false
},
{
"description": "Use this to set both timestamp and block timeout. The package then times out once the first of both timeouts is hit.",
"type": "object",
"required": [
"both"
Expand All @@ -426,16 +426,14 @@
"type": "object",
"required": [
"block",
"timestamp_nanos"
"timestamp"
],
"properties": {
"block": {
"$ref": "#/definitions/IbcTimeoutBlock"
},
"timestamp_nanos": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"timestamp": {
"$ref": "#/definitions/Timestamp"
}
}
}
Expand Down Expand Up @@ -550,7 +548,20 @@
}
]
},
"Timestamp": {
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.",
"allOf": [
{
"$ref": "#/definitions/Uint64"
}
]
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
},
"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"
},
"WasmMsg": {
Expand Down
Loading