Skip to content
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

refactor(textual): Update Spec to have shorter Any header screen #14117

Merged
merged 6 commits into from
Dec 6, 2022
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: 3 additions & 2 deletions docs/architecture/adr-050-sign-mode-textual-annex1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Dec 06, 2021: Initial Draft
* Feb 07, 2022: Draft read and concept-ACKed by the Ledger team.
* Dec 01, 2022: Remove `Object: ` prefix on Any header screen.

## Status

Expand Down Expand Up @@ -181,14 +182,14 @@ See example above with `message Vote{}`.
* Rendered as:

```
Object: <type_url>
<type_url>
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
> <value rendered underlying message>
```

#### Examples

```
Object: type.googleapis.com/cosmos.gov.v1.Vote
type.googleapis.com/cosmos.gov.v1.Vote
> Vote object
>> Proposal id: 4
>> Vote: cosmos1abc...def
Expand Down
18 changes: 9 additions & 9 deletions tx/textual/internal/testdata/any.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"@type": "/Foo"
},
"screens": [
{"text": "Object: /Foo"},
{"text": "/Foo"},
{"text": "Foo object", "indent": 1}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still say Foo object after /Foo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We touched on this in yesterday's call, but didn't come to a unanimous conclusion, so here's an issue to discuss more: #14170

]
},
Expand All @@ -14,7 +14,7 @@
"full_name": "testing"
},
"screens": [
{"text": "Object: /Foo"},
{"text": "/Foo"},
{"text": "Foo object", "indent": 1},
{"text": "Full name: testing", "indent": 2}
]
Expand All @@ -25,7 +25,7 @@
"value": "2006-01-02T15:04:05Z"
},
"screens": [
{"text": "Object: /google.protobuf.Timestamp"},
{"text": "/google.protobuf.Timestamp"},
{"text": "2006-01-02T15:04:05Z", "indent": 1}
]
},
Expand All @@ -37,8 +37,8 @@
}
},
"screens": [
{"text": "Object: /google.protobuf.Any"},
{"text": "Object: /Foo", "indent": 1},
{"text": "/google.protobuf.Any"},
{"text": "/Foo", "indent": 1},
{"text": "Foo object", "indent": 2}
]
},
Expand All @@ -51,8 +51,8 @@
}
},
"screens": [
{"text": "Object: /google.protobuf.Any"},
{"text": "Object: /Foo", "indent": 1},
{"text": "/google.protobuf.Any"},
{"text": "/Foo", "indent": 1},
Comment on lines +54 to +55
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only weird output would be this.

The first line will have, in a message context, a field name:

<Field>: /google.protobuf.Any

But the 2nd line will be a naked /Foo. I think it's fine, because nested packed Anys should be extremely rare.

{"text": "Foo object", "indent": 2},
{"text": "Full name: testing", "indent": 3}
]
Expand All @@ -66,9 +66,9 @@
}
},
"screens": [
{"text": "Object: /A"},
{"text": "/A"},
{"text": "A object", "indent": 1},
{"text": "ANY: Object: /Foo", "indent": 2},
{"text": "ANY: /Foo", "indent": 2},
{"text": "Foo object", "indent": 3},
{"text": "Full name: testing", "indent": 4}
]
Expand Down
11 changes: 2 additions & 9 deletions tx/textual/valuerenderer/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package valuerenderer
import (
"context"
"fmt"
"strings"

"github.com/cosmos/cosmos-proto/any"
"google.golang.org/protobuf/reflect/protoreflect"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (ar anyValueRenderer) Format(ctx context.Context, v protoreflect.Value) ([]
}

screens := make([]Screen, 1+len(subscreens))
screens[0].Text = "Object: " + anymsg.GetTypeUrl()
screens[0].Text = anymsg.GetTypeUrl()
for i, subscreen := range subscreens {
subscreen.Indent++
screens[i+1] = subscreen
Expand All @@ -65,13 +64,7 @@ func (ar anyValueRenderer) Parse(ctx context.Context, screens []Screen) (protore
return nilValue, fmt.Errorf("bad indentation: want 0, got %d", screens[0].Indent)
}

prefix := "Object: "
if !strings.HasPrefix(screens[0].Text, prefix) {
return nilValue, fmt.Errorf("bad Any header: %s", screens[0].Text)
}
url := strings.TrimPrefix(screens[0].Text, prefix)

msgType, err := protoregistry.GlobalTypes.FindMessageByURL(url)
msgType, err := protoregistry.GlobalTypes.FindMessageByURL(screens[0].Text)
if err != nil {
return nilValue, err
}
Expand Down