Rename clientCtx.JSONMarshaler to JSONCodec (#9251)
* Rename clientCtx.JSONMarshaler to JSONCodec * change md files * Fix lint
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
- 2020 September 25: Remove `PublicKey` type in favor of `secp256k1.PubKey`, `ed25519.PubKey` and `multisig.LegacyAminoPubKey`.
|
||||
- 2020 October 15: Add `GetAccount` and `GetAccountWithHeight` methods to the `AccountRetriever` interface.
|
||||
- 2021 Feb 24: The SDK does not use Tendermint's `PubKey` interface anymore, but its own `cryptotypes.PubKey`. Updates to reflect this.
|
||||
- 2021 May 3: Rename `clientCtx.JSONMarshaler` to `clientCtx.JSONCodec`
|
||||
|
||||
## Status
|
||||
|
||||
@@ -343,7 +344,7 @@ type TxBuilder interface {
|
||||
}
|
||||
```
|
||||
|
||||
We then update `Context` to have new fields: `JSONMarshaler`, `TxGenerator`,
|
||||
We then update `Context` to have new fields: `JSONCodec`, `TxGenerator`,
|
||||
and `AccountRetriever`, and we update `AppModuleBasic.GetTxCmd` to take
|
||||
a `Context` which should have all of these fields pre-populated.
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ Here are descriptions of what each of the four fields means:
|
||||
- `InterfaceRegistry`: The `InterfaceRegistry` is used by the Protobuf codec to handle interfaces that are encoded and decoded (we also say "unpacked") using [`google.protobuf.Any`](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). `Any` could be thought as a struct that contains a `type_url` (name of a concrete type implementing the interface) and a `value` (its encoded bytes). `InterfaceRegistry` provides a mechanism for registering interfaces and implementations that can be safely unpacked from `Any`. Each of the application's modules implements the `RegisterInterfaces` method that can be used to register the module's own interfaces and implementations.
|
||||
- You can read more about Any in [ADR-19](../architecture/adr-019-protobuf-state-encoding.md#usage-of-any-to-encode-interfaces).
|
||||
- To go more into details, the SDK uses an implementation of the Protobuf specification called [`gogoprotobuf`](https://github.com/gogo/protobuf). By default, the [gogo protobuf implementation of `Any`](https://godoc.org/github.com/gogo/protobuf/types) uses [global type registration](https://github.com/gogo/protobuf/blob/master/proto/properties.go#L540) to decode values packed in `Any` into concrete Go types. This introduces a vulnerability where any malicious module in the dependency tree could registry a type with the global protobuf registry and cause it to be loaded and unmarshaled by a transaction that referenced it in the `type_url` field. For more information, please refer to [ADR-019](../architecture/adr-019-protobuf-state-encoding.md).
|
||||
- `Marshaler`: the default codec used throughout the SDK. It is composed of a `BinaryMarshaler` used to encode and decode state, and a `JSONMarshaler` used to output data to the users (for example in the [CLI](#cli)). By default, the SDK uses Protobuf as `Marshaler`.
|
||||
- `Marshaler`: the default codec used throughout the SDK. It is composed of a `BinaryCodec` used to encode and decode state, and a `JSONCodec` used to output data to the users (for example in the [CLI](#cli)). By default, the SDK uses Protobuf as `Marshaler`.
|
||||
- `TxConfig`: `TxConfig` defines an interface a client can utilize to generate an application-defined concrete transaction type. Currently, the SDK handles two transaction types: `SIGN_MODE_DIRECT` (which uses Protobuf binary as over-the-wire encoding) and `SIGN_MODE_LEGACY_AMINO_JSON` (which depends on Amino). Read more about transactions [here](../core/transactions.md).
|
||||
- `Amino`: Some legacy parts of the SDK still use Amino for backwards-compatibility. Each module exposes a `RegisterLegacyAmino` method to register the module's specific types within Amino. This `Amino` codec should not be used by app developers anymore, and will be removed in future releases.
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ clientCtx, err := client.GetClientTxContext(cmd)
|
||||
|
||||
Some other flags helper functions are transformed: `flags.PostCommands(cmds ...*cobra.Command) []*cobra.Command` and `flags.GetCommands(...)` usage is now replaced by `flags.AddTxFlagsToCmd(cmd *cobra.Command)` and `flags.AddQueryFlagsToCmd(cmd *cobra.Command)` respectively.
|
||||
|
||||
Moreover, new CLI commands don't take any codec as input anymore. Instead, the `clientCtx` can be retrieved from the `cmd` itself using the `GetClient{Query,Tx}Context` function above, and the codec as `clientCtx.JSONMarshaler`.
|
||||
Moreover, new CLI commands don't take any codec as input anymore. Instead, the `clientCtx` can be retrieved from the `cmd` itself using the `GetClient{Query,Tx}Context` function above, and the codec as `clientCtx.JSONCodec`.
|
||||
|
||||
```diff
|
||||
// v0.39
|
||||
@@ -157,7 +157,7 @@ Moreover, new CLI commands don't take any codec as input anymore. Instead, the `
|
||||
// v0.40
|
||||
+ func NewSendTxCmd() *cobra.Command {
|
||||
+ clientCtx, err := client.GetClientTxContext(cmd)
|
||||
+ clientCtx.JSONMarshaler.MarshalJSON(...)
|
||||
+ clientCtx.JSONCodec.MarshalJSON(...)
|
||||
+}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user