cosmos-sdk/codec/codec.go

99 lines
3.8 KiB
Go
Raw Normal View History

package codec
2018-03-02 01:24:07 -08:00
import (
"github.com/gogo/protobuf/proto"
2018-04-09 10:32:19 -07:00
"github.com/cosmos/cosmos-sdk/codec/types"
2018-03-02 01:24:07 -08:00
)
type (
// Codec defines a functionality for serializing other objects.
// Users can defin a custom Protobuf-based serialization.
// Note, Amino can still be used without any dependency on Protobuf.
// SDK provides to Codec implementations:
//
// 1. AminoCodec: Provides full Amino serialization compatibility.
// 2. ProtoCodec: Provides full Protobuf serialization compatibility.
Codec interface {
BinaryCodec
JSONCodec
}
BinaryCodec interface {
// Marshal returns binary encoding of v.
Marshal(o ProtoMarshaler) ([]byte, error)
// MustMarshal calls Marshal and panics if error is returned.
MustMarshal(o ProtoMarshaler) []byte
// MarshalLengthPrefixed returns binary encoding of v with bytes length prefix.
MarshalLengthPrefixed(o ProtoMarshaler) ([]byte, error)
// MustMarshalLengthPrefixed calls MarshalLengthPrefixed and panics if
// error is returned.
MustMarshalLengthPrefixed(o ProtoMarshaler) []byte
// Unmarshal parses the data encoded with Marshal method and stores the result
// in the value pointed to by v.
Unmarshal(bz []byte, ptr ProtoMarshaler) error
// MustUnmarshal calls Unmarshal and panics if error is returned.
MustUnmarshal(bz []byte, ptr ProtoMarshaler)
// Unmarshal parses the data encoded with UnmarshalLengthPrefixed method and stores
// the result in the value pointed to by v.
UnmarshalLengthPrefixed(bz []byte, ptr ProtoMarshaler) error
// MustUnmarshalLengthPrefixed calls UnmarshalLengthPrefixed and panics if error
// is returned.
MustUnmarshalLengthPrefixed(bz []byte, ptr ProtoMarshaler)
// MarshalInterface is a helper method which will wrap `i` into `Any` for correct
// binary interface (de)serialization.
MarshalInterface(i proto.Message) ([]byte, error)
// UnmarshalInterface is a helper method which will parse binary enoded data
// into `Any` and unpack any into the `ptr`. It fails if the target interface type
// is not registered in codec, or is not compatible with the serialized data
UnmarshalInterface(bz []byte, ptr interface{}) error
types.AnyUnpacker
}
JSONCodec interface {
// MarshalJSON returns JSON encoding of v.
MarshalJSON(o proto.Message) ([]byte, error)
// MustMarshalJSON calls MarshalJSON and panics if error is returned.
MustMarshalJSON(o proto.Message) []byte
// MarshalInterfaceJSON is a helper method which will wrap `i` into `Any` for correct
// JSON interface (de)serialization.
MarshalInterfaceJSON(i proto.Message) ([]byte, error)
// UnmarshalInterfaceJSON is a helper method which will parse JSON enoded data
// into `Any` and unpack any into the `ptr`. It fails if the target interface type
// is not registered in codec, or is not compatible with the serialized data
UnmarshalInterfaceJSON(bz []byte, ptr interface{}) error
// UnmarshalJSON parses the data encoded with MarshalJSON method and stores the result
// in the value pointed to by v.
UnmarshalJSON(bz []byte, ptr proto.Message) error
// MustUnmarshalJSON calls Unmarshal and panics if error is returned.
MustUnmarshalJSON(bz []byte, ptr proto.Message)
2018-04-09 10:32:19 -07:00
}
// ProtoMarshaler defines an interface a type must implement to serialize itself
// as a protocol buffer defined message.
ProtoMarshaler interface {
proto.Message // for JSON serialization
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
Marshal() ([]byte, error)
MarshalTo(data []byte) (n int, err error)
MarshalToSizedBuffer(dAtA []byte) (int, error)
Size() int
Unmarshal(data []byte) error
}
PubKey proto types (#7147) * WIP on protobuf keys * Use Type() and Bytes() in sr25519 pub key Equals * Add tests * Add few more tests * Update other pub/priv key types Equals * Fix PrivKey's Sign method * Rename variables in tests * Fix infinite recursive calls * Use tm ed25519 keys * Add Sign and VerifySignature tests * Remove ed25519 and sr25519 references * proto linting * Add proto crypto file * Implement some of the new multisig proto type methods * Add tests for MultisigThresholdPubKey * Add tests for pubkey pb/amino conversion functions * Move crypto types.go and register new proto pubkeys * Add missing pointer ref * Address review comments * panic in MultisigThresholdPubKey VerifySignature * Use internal crypto.PubKey in multisig * Add tests for MultisigThresholdPubKey VerifyMultisignature * Only keep LegacyAminoMultisigThresholdPubKey and move to proto keys to v1 * Remove conversion functions and introduce internal PubKey type * Remove old secp256k1 PubKey and PrivKey * Uncomment test case * Fix linting issues * More linting * Revert tests keys values * Add Amino overrides to proto keys * Add pubkey test * Fix tests * Use threshold isntead of K * Standardize Type * Revert standardize types commit * Add comment * Simplify proto names * Add comment about multisig codec Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-09-16 04:08:55 -07:00
// AminoMarshaler defines an interface a type must implement to serialize itself
// for Amino codec.
PubKey proto types (#7147) * WIP on protobuf keys * Use Type() and Bytes() in sr25519 pub key Equals * Add tests * Add few more tests * Update other pub/priv key types Equals * Fix PrivKey's Sign method * Rename variables in tests * Fix infinite recursive calls * Use tm ed25519 keys * Add Sign and VerifySignature tests * Remove ed25519 and sr25519 references * proto linting * Add proto crypto file * Implement some of the new multisig proto type methods * Add tests for MultisigThresholdPubKey * Add tests for pubkey pb/amino conversion functions * Move crypto types.go and register new proto pubkeys * Add missing pointer ref * Address review comments * panic in MultisigThresholdPubKey VerifySignature * Use internal crypto.PubKey in multisig * Add tests for MultisigThresholdPubKey VerifyMultisignature * Only keep LegacyAminoMultisigThresholdPubKey and move to proto keys to v1 * Remove conversion functions and introduce internal PubKey type * Remove old secp256k1 PubKey and PrivKey * Uncomment test case * Fix linting issues * More linting * Revert tests keys values * Add Amino overrides to proto keys * Add pubkey test * Fix tests * Use threshold isntead of K * Standardize Type * Revert standardize types commit * Add comment * Simplify proto names * Add comment about multisig codec Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-09-16 04:08:55 -07:00
AminoMarshaler interface {
MarshalAmino() ([]byte, error)
UnmarshalAmino([]byte) error
MarshalAminoJSON() ([]byte, error)
UnmarshalAminoJSON([]byte) error
}
)