Skip to content

Commit

Permalink
feat: value renderer for timestamp protos (#12860)
Browse files Browse the repository at this point in the history
## Description

Closes: #12709



Part of Sign Mode Textual (ADR 050) implementation.

Renders Timestamp messages as RFC 3339 (simplified ISO 8601).

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
JimLarson authored Aug 23, 2022
1 parent 2e1fb48 commit ef4ad67
Show file tree
Hide file tree
Showing 8 changed files with 462 additions and 90 deletions.
15 changes: 14 additions & 1 deletion docs/architecture/adr-050-sign-mode-textual-annex1.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,20 @@ Object: /cosmos.gov.v1.Vote

### `google.protobuf.Timestamp`

Rendered as either ISO8601 (`2021-01-01T12:00:00Z`).
Rendered using [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) (a
simplification of ISO 8601), which is the current recommendation for portable
time values. The rendering always uses "Z" (UTC) as the timezone. It uses only
the necessary fractional digits of a second, omitting the fractional part
entirely if the timestamp has no fractional seconds. (The resulting timestamps
are not automatically sortable by standard lexicographic order, but we favor
the legibility of the shorter string.)

#### Examples

The timestamp with 1136214245 seconds and 700000000 nanoseconds is rendered
as `2006-01-02T15:04:05.7Z`.
The timestamp with 1136214245 seconds and zero nanoseconds is rendered
as `2006-01-02T15:04:05Z`.

### `google.protobuf.Duration` (TODO)

Expand Down
82 changes: 82 additions & 0 deletions tx/textual/internal/testdata/timestamp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[
{
"proto": {"seconds": 1136214245},
"text": "2006-01-02T15:04:05Z"
},
{
"proto": {"seconds": 1136214245, "nanos": 123456789},
"text": "2006-01-02T15:04:05.123456789Z"
},
{
"proto": {"seconds": 1136214245, "nanos": 123000000},
"text": "2006-01-02T15:04:05.123Z"
},
{ "text": "", "error": true },
{ "text": " ", "error": true },
{ "text": "garbage", "error": true },
{ "text": "11/30/2007", "error": true },
{
"proto": {"seconds": 0, "nanos": 0},
"text": "1970-01-01T00:00:00Z"
},
{
"proto": {"seconds": 0, "nanos": 1},
"text": "1970-01-01T00:00:00.000000001Z"
},
{
"proto": {"seconds": 0, "nanos": 10},
"text": "1970-01-01T00:00:00.00000001Z"
},
{
"proto": {"seconds": 0, "nanos": 100},
"text": "1970-01-01T00:00:00.0000001Z"
},
{
"proto": {"seconds": 0, "nanos": 1000},
"text": "1970-01-01T00:00:00.000001Z"
},
{
"proto": {"seconds": 0, "nanos": 10000},
"text": "1970-01-01T00:00:00.00001Z"
},
{
"proto": {"seconds": 0, "nanos": 100000},
"text": "1970-01-01T00:00:00.0001Z"
},
{
"proto": {"seconds": 0, "nanos": 1000000},
"text": "1970-01-01T00:00:00.001Z"
},
{
"proto": {"seconds": 0, "nanos": 10000000},
"text": "1970-01-01T00:00:00.01Z"
},
{
"proto": {"seconds": 0, "nanos": 100000000},
"text": "1970-01-01T00:00:00.1Z"
},
{
"proto": {"seconds": 0, "nanos": 999999999},
"text": "1970-01-01T00:00:00.999999999Z"
},
{
"proto": {"seconds": 1, "nanos": 0},
"text": "1970-01-01T00:00:01Z"
},
{
"proto": {"seconds": 2, "nanos": 0},
"text": "1970-01-01T00:00:02Z"
},
{
"proto": {"seconds": 2, "nanos": 6},
"text": "1970-01-01T00:00:02.000000006Z"
},
{
"proto": {"seconds": 1657797740, "nanos": 983000000},
"text": "2022-07-14T11:22:20.983Z"
},
{
"proto": {"seconds": -1, "nanos": 0},
"text": "1969-12-31T23:59:59Z"
}
]
2 changes: 2 additions & 0 deletions tx/textual/internal/testpb/1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
option go_package = "cosmossdk.io/tx/textual/internal/testpb";

import "google/protobuf/descriptor.proto";
import "google/protobuf/timestamp.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

Expand All @@ -22,6 +23,7 @@ message A {
cosmos.base.v1beta1.Coin COIN = 7;
repeated cosmos.base.v1beta1.Coin COINS = 8;
bytes BYTES = 9;
google.protobuf.Timestamp TIMESTAMP = 10;
}

// B contains fields that are not parseable by SIGN_MODE_TEXTUAL, some fields
Expand Down
Loading

0 comments on commit ef4ad67

Please sign in to comment.