codec

package
v0.0.0-...-21d70e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 15 Imported by: 29

Documentation

Index

Constants

View Source
const (
	UpgradeCodecHeight           = int64(30024)
	CodecChainHaltHeight         = int64(30334)
	ValidatorSplitHeight         = int64(45353)
	NonCustodial1RollbackHeight  = int64(69583)
	NonCustodial2AllowanceHeight = int64(74622)
	UpgradeCodecUpdateKey        = "CODEC"
	ValidatorSplitUpdateKey      = "SPLIT"
	NonCustodialUpdateKey        = "NCUST"
	EnforceMaxChainsUpdateKey    = "MAXCH"
	TxCacheEnhancementKey        = "REDUP"
	MaxRelayProtKey              = "MREL"
	ReplayBurnKey                = "REPBR"
	BlockSizeModifyKey           = "BLOCK"
	RSCALKey                     = "RSCAL"
	VEDITKey                     = "VEDIT"
	OutputAddressEditKey         = "OEDIT"
	ClearUnjailedValSessionKey   = "CRVAL"
	PerChainRTTM                 = "PerChainRTTM"
	AppTransferKey               = "AppTransfer"
	RewardDelegatorsKey          = "RewardDelegators"
)

Variables

View Source
var (
	UpgradeFeatureMap                      = make(map[string]int64)
	UpgradeHeight                    int64 = math.MaxInt64
	OldUpgradeHeight                 int64 = 0
	NotProtoCompatibleInterfaceError       = errors.New("the interface passed for encoding does not implement proto marshaller")
	// Used to short-circuit specific protocol upgrades in tests;
	// <= -1: replaced amino with proto
	// <= -2: after validator split
	// <= -3: after non-custodial
	// <= -4: allow smaller block sizes for testing purposes
	TestMode int64 = 0
)

Functions

func CleanUpgradeFeatureSlice

func CleanUpgradeFeatureSlice(arr []string) []string

CleanUpgradeFeatureSlice convert slice to map and back to remove duplicates

func GetCodecUpgradeHeight

func GetCodecUpgradeHeight() int64

func MapToSlice

func MapToSlice(m map[string]int64) []string

MapToSlice converts map to slice

func MarshalAny

func MarshalAny(m BinaryMarshaler, x interface{}) ([]byte, error)

MarshalAny is a convenience function for packing the provided value in an Any and then proto marshaling it to bytes

func MarshalJSONIndent

func MarshalJSONIndent(m JSONMarshaler, obj interface{}) ([]byte, error)

MarshalJSONIndent provides a utility for indented JSON encoding of an object via an Amino codec. It returns an error if it cannot serialize or indent as JSON.

func MustMarshalJSONIndent

func MustMarshalJSONIndent(m JSONMarshaler, obj interface{}) []byte

MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.

func ProtoMarshalJSON

func ProtoMarshalJSON(msg proto.Message) ([]byte, error)

ProtoMarshalJSON provides an auxiliary function to return Proto3 JSON encoded bytes of a message.

func RegisterEvidences

func RegisterEvidences(legacy *LegacyAmino, _ *ProtoCodec)

func SliceToExistingMap

func SliceToExistingMap(arr []string, m map[string]int64) map[string]int64

SliceToExistingMap merge slice to existing map

func SliceToMap

func SliceToMap(arr []string) map[string]int64

SliceToMap converts slice to map

func UnmarshalAny

func UnmarshalAny(m BinaryMarshaler, iface interface{}, bz []byte) error

UnmarshalAny is a convenience function for proto unmarshaling an Any from bz and then unpacking it to the interface pointer passed in as iface using the provided AnyUnpacker or returning an error

Ex:

var x MyInterface
err := UnmarshalAny(unpacker, &x, bz)

Types

type BinaryMarshaler

type BinaryMarshaler interface {
	MarshalBinaryBare(o ProtoMarshaler) ([]byte, error)
	MustMarshalBinaryBare(o ProtoMarshaler) []byte

	MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)
	MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte

	UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error
	MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler)

	UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error
	MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)

	types.AnyUnpacker
}

type Codec

type Codec struct {
	// contains filtered or unexported fields
}

func NewCodec

func NewCodec(anyUnpacker types.AnyUnpacker) *Codec

func (*Codec) AminoCodec

func (cdc *Codec) AminoCodec() *LegacyAmino

func (*Codec) DisableUpgradeOverride

func (cdc *Codec) DisableUpgradeOverride()

func (*Codec) IsAfterAppTransferUpgrade

func (cdc *Codec) IsAfterAppTransferUpgrade(height int64) bool

func (*Codec) IsAfterCodecUpgrade

func (cdc *Codec) IsAfterCodecUpgrade(height int64) bool

IsAfterCodecUpgrade Note: includes the actual upgrade height

func (*Codec) IsAfterEnforceMaxChainsUpgrade

func (cdc *Codec) IsAfterEnforceMaxChainsUpgrade(height int64) bool

IsAfterEnforceMaxChainsUpgrade Note: includes the actual upgrade height

func (*Codec) IsAfterNamedFeatureActivationHeight

func (cdc *Codec) IsAfterNamedFeatureActivationHeight(height int64, key string) bool

IsAfterNamedFeatureActivationHeight Note: includes the actual upgrade height

func (*Codec) IsAfterNonCustodialUpgrade

func (cdc *Codec) IsAfterNonCustodialUpgrade(height int64) bool

IsAfterNonCustodialUpgrade Note: includes the actual upgrade height

func (*Codec) IsAfterOutputAddressEditorUpgrade

func (cdc *Codec) IsAfterOutputAddressEditorUpgrade(height int64) bool

func (*Codec) IsAfterPerChainRTTMUpgrade

func (cdc *Codec) IsAfterPerChainRTTMUpgrade(height int64) bool

func (*Codec) IsAfterRewardDelegatorUpgrade

func (cdc *Codec) IsAfterRewardDelegatorUpgrade(height int64) bool

func (*Codec) IsAfterValidatorSplitUpgrade

func (cdc *Codec) IsAfterValidatorSplitUpgrade(height int64) bool

IsAfterValidatorSplitUpgrade Note: includes the actual upgrade height

func (*Codec) IsOnNamedFeatureActivationHeight

func (cdc *Codec) IsOnNamedFeatureActivationHeight(height int64, key string) bool

IsOnNamedFeatureActivationHeight Note: includes the actual upgrade height

func (*Codec) IsOnNamedFeatureActivationHeightWithTolerance

func (cdc *Codec) IsOnNamedFeatureActivationHeightWithTolerance(
	height int64,
	featureKey string,
	tolerance int64,
) bool

IsOnNamedFeatureActivationHeightWithTolerance is used to enable certain business logic within some tolerance (i.e. only a few blocks) of feature activation to have more confidence in the feature's release and avoid non-deterministic or hard-to-predict behaviour.

func (*Codec) IsOnNonCustodialUpgrade

func (cdc *Codec) IsOnNonCustodialUpgrade(height int64) bool

IsOnNonCustodialUpgrade Note: includes the actual upgrade height

func (*Codec) LegacyMarshalBinaryBare

func (cdc *Codec) LegacyMarshalBinaryBare(o interface{}) ([]byte, error)

func (*Codec) LegacyMarshalBinaryLengthPrefixed

func (cdc *Codec) LegacyMarshalBinaryLengthPrefixed(o interface{}) ([]byte, error)

func (*Codec) LegacyUnmarshalBinaryBare

func (cdc *Codec) LegacyUnmarshalBinaryBare(bz []byte, ptr interface{}) error

func (*Codec) LegacyUnmarshalBinaryLengthPrefixed

func (cdc *Codec) LegacyUnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) error

func (*Codec) MarshalBinaryBare

func (cdc *Codec) MarshalBinaryBare(o interface{}, height int64) ([]byte, error)

func (*Codec) MarshalBinaryLengthPrefixed

func (cdc *Codec) MarshalBinaryLengthPrefixed(o interface{}, height int64) ([]byte, error)

func (*Codec) MarshalJSON

func (cdc *Codec) MarshalJSON(o interface{}) ([]byte, error)

func (*Codec) MarshalJSONIndent

func (cdc *Codec) MarshalJSONIndent(o interface{}, prefix string, indent string) ([]byte, error)

func (*Codec) MustMarshalJSON

func (cdc *Codec) MustMarshalJSON(o interface{}) []byte

func (*Codec) MustUnmarshalJSON

func (cdc *Codec) MustUnmarshalJSON(bz []byte, ptr interface{})

func (*Codec) ProtoCodec

func (cdc *Codec) ProtoCodec() *ProtoCodec

func (*Codec) ProtoMarshalBinaryBare

func (cdc *Codec) ProtoMarshalBinaryBare(o ProtoMarshaler) ([]byte, error)

func (*Codec) ProtoMarshalBinaryLengthPrefixed

func (cdc *Codec) ProtoMarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)

func (*Codec) ProtoUnmarshalBinaryBare

func (cdc *Codec) ProtoUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error

func (*Codec) ProtoUnmarshalBinaryLengthPrefixed

func (cdc *Codec) ProtoUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error

func (*Codec) RegisterImplementation

func (cdc *Codec) RegisterImplementation(iface interface{}, impls ...proto.Message)

func (*Codec) RegisterInterface

func (cdc *Codec) RegisterInterface(name string, iface interface{}, impls ...proto.Message)

func (*Codec) RegisterStructure

func (cdc *Codec) RegisterStructure(o interface{}, name string)

func (*Codec) SetUpgradeOverride

func (cdc *Codec) SetUpgradeOverride(b bool)

func (*Codec) UnmarshalBinaryBare

func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}, height int64) error

func (*Codec) UnmarshalBinaryLengthPrefixed

func (cdc *Codec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}, height int64) error

func (*Codec) UnmarshalJSON

func (cdc *Codec) UnmarshalJSON(bz []byte, o interface{}) error

type JSONMarshaler

type JSONMarshaler interface {
	MarshalJSON(o interface{}) ([]byte, error)
	MustMarshalJSON(o interface{}) []byte

	UnmarshalJSON(bz []byte, ptr interface{}) error
	MustUnmarshalJSON(bz []byte, ptr interface{})
}

type LegacyAmino

type LegacyAmino struct {
	Amino *amino.Codec
}

deprecated: Codec defines a wrapper for an Amino codec that properly handles protobuf types with Any's

func NewLegacyAminoCodec

func NewLegacyAminoCodec() *LegacyAmino

func (*LegacyAmino) MarshalBinaryBare

func (cdc *LegacyAmino) MarshalBinaryBare(o interface{}) ([]byte, error)

func (*LegacyAmino) MarshalBinaryLengthPrefixed

func (cdc *LegacyAmino) MarshalBinaryLengthPrefixed(o interface{}) ([]byte, error)

func (*LegacyAmino) MarshalJSON

func (cdc *LegacyAmino) MarshalJSON(o interface{}) ([]byte, error)

func (*LegacyAmino) MarshalJSONIndent

func (cdc *LegacyAmino) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byte, error)

func (*LegacyAmino) MustMarshalBinaryBare

func (cdc *LegacyAmino) MustMarshalBinaryBare(o interface{}) []byte

func (*LegacyAmino) MustMarshalBinaryLengthPrefixed

func (cdc *LegacyAmino) MustMarshalBinaryLengthPrefixed(o interface{}) []byte

func (*LegacyAmino) MustMarshalJSON

func (cdc *LegacyAmino) MustMarshalJSON(o interface{}) []byte

func (*LegacyAmino) MustUnmarshalBinaryBare

func (cdc *LegacyAmino) MustUnmarshalBinaryBare(bz []byte, ptr interface{})

func (*LegacyAmino) MustUnmarshalBinaryLengthPrefixed

func (cdc *LegacyAmino) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{})

func (*LegacyAmino) MustUnmarshalJSON

func (cdc *LegacyAmino) MustUnmarshalJSON(bz []byte, ptr interface{})

func (*LegacyAmino) PrintTypes

func (cdc *LegacyAmino) PrintTypes(out io.Writer) error

func (*LegacyAmino) RegisterConcrete

func (cdc *LegacyAmino) RegisterConcrete(o interface{}, name string, copts *amino.ConcreteOptions)

func (*LegacyAmino) RegisterInterface

func (cdc *LegacyAmino) RegisterInterface(ptr interface{}, iopts *amino.InterfaceOptions)

func (*LegacyAmino) Seal

func (cdc *LegacyAmino) Seal()

func (*LegacyAmino) UnmarshalBinaryBare

func (cdc *LegacyAmino) UnmarshalBinaryBare(bz []byte, ptr interface{}) error

func (*LegacyAmino) UnmarshalBinaryLengthPrefixed

func (cdc *LegacyAmino) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) error

func (*LegacyAmino) UnmarshalJSON

func (cdc *LegacyAmino) UnmarshalJSON(bz []byte, ptr interface{}) error

func (*LegacyAmino) UnpackAny

func (*LegacyAmino) UnpackAny(*types.Any, interface{}) error

type Marshaler

type Marshaler interface {
	BinaryMarshaler
	JSONMarshaler
}

Marshaler defines the interface module codecs must implement in order to support backwards compatibility with Amino while allowing custom Protobuf-based serialization. Note, Amino can still be used without any dependency on Protobuf. There are three typical implementations that fulfill this contract:

1. AminoCodec: Provides full Amino serialization compatibility. 2. ProtoCodec: Provides full Protobuf serialization compatibility.

type ProtoCodec

type ProtoCodec struct {
	// contains filtered or unexported fields
}

ProtoCodec defines a codec that utilizes Protobuf for both binary and JSON encoding.

func NewProtoCodec

func NewProtoCodec(anyUnpacker types.AnyUnpacker) *ProtoCodec

func (*ProtoCodec) MarshalBinaryBare

func (pc *ProtoCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error)

func (*ProtoCodec) MarshalBinaryLengthPrefixed

func (pc *ProtoCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error)

func (*ProtoCodec) MarshalJSON

func (pc *ProtoCodec) MarshalJSON(o interface{}) ([]byte, error)

func (*ProtoCodec) MustMarshalBinaryBare

func (pc *ProtoCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte

func (*ProtoCodec) MustMarshalBinaryLengthPrefixed

func (pc *ProtoCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte

func (*ProtoCodec) MustMarshalJSON

func (pc *ProtoCodec) MustMarshalJSON(o interface{}) []byte

func (*ProtoCodec) MustUnmarshalBinaryBare

func (pc *ProtoCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler)

func (*ProtoCodec) MustUnmarshalBinaryLengthPrefixed

func (pc *ProtoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)

func (*ProtoCodec) MustUnmarshalJSON

func (pc *ProtoCodec) MustUnmarshalJSON(bz []byte, ptr interface{})

func (*ProtoCodec) Register

func (pc *ProtoCodec) Register(protoName string, iface interface{}, impls ...proto.Message)

func (*ProtoCodec) RegisterImplementation

func (pc *ProtoCodec) RegisterImplementation(iface interface{}, impls ...proto.Message)

func (*ProtoCodec) UnmarshalBinaryBare

func (pc *ProtoCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error

func (*ProtoCodec) UnmarshalBinaryLengthPrefixed

func (pc *ProtoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error

func (*ProtoCodec) UnmarshalJSON

func (pc *ProtoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error

func (*ProtoCodec) UnpackAny

func (pc *ProtoCodec) UnpackAny(any *types.Any, iface interface{}) error

type ProtoMarshaler

type ProtoMarshaler interface {
	proto.Message // for JSON serialization

	Marshal() ([]byte, error)
	MarshalTo(data []byte) (n int, err error)
	MarshalToSizedBuffer(dAtA []byte) (int, error)
	Size() int
	Unmarshal(data []byte) error
}

ProtoMarshaler defines an interface a type must implement as protocol buffer defined message.

Directories

Path Synopsis
Package legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
Package legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
Package types defines a custom wrapper for google.protobuf.Any which supports cached values as well as InterfaceRegistry which keeps track of types which can be used with Any for both security and introspection
Package types defines a custom wrapper for google.protobuf.Any which supports cached values as well as InterfaceRegistry which keeps track of types which can be used with Any for both security and introspection
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report:
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL