refactor(textual): Update Spec to have shorter Any header screen (#14117)
* Remove object prefix * update test case * Update example
This commit is contained in:
parent
a1dc6d9998
commit
4a7e3f0522
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
18
tx/textual/internal/testdata/any.json
vendored
18
tx/textual/internal/testdata/any.json
vendored
@ -4,7 +4,7 @@
|
||||
"@type": "/Foo"
|
||||
},
|
||||
"screens": [
|
||||
{"text": "Object: /Foo"},
|
||||
{"text": "/Foo"},
|
||||
{"text": "Foo object", "indent": 1}
|
||||
]
|
||||
},
|
||||
@ -14,7 +14,7 @@
|
||||
"full_name": "testing"
|
||||
},
|
||||
"screens": [
|
||||
{"text": "Object: /Foo"},
|
||||
{"text": "/Foo"},
|
||||
{"text": "Foo object", "indent": 1},
|
||||
{"text": "Full name: testing", "indent": 2}
|
||||
]
|
||||
@ -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}
|
||||
]
|
||||
},
|
||||
@ -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}
|
||||
]
|
||||
},
|
||||
@ -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}
|
||||
]
|
||||
@ -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}
|
||||
]
|
||||
|
||||
@ -3,7 +3,6 @@ package valuerenderer
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-proto/any"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user