Skip to content

Commit

Permalink
refactor(textual): Update Spec to have shorter Any header screen (cos…
Browse files Browse the repository at this point in the history
…mos#14117)

* Remove object prefix

* update test case

* Update example
  • Loading branch information
amaury1093 authored Dec 6, 2022
1 parent a1dc6d9 commit 4a7e3f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
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>
> <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}
]
},
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},
{"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

0 comments on commit 4a7e3f0

Please sign in to comment.