github.com/Finschia/finschia-sdk@v0.49.1/x/feegrant/codec.go (about)

     1  package feegrant
     2  
     3  import (
     4  	"github.com/Finschia/finschia-sdk/codec"
     5  	"github.com/Finschia/finschia-sdk/codec/legacy"
     6  	"github.com/Finschia/finschia-sdk/codec/types"
     7  	cryptocodec "github.com/Finschia/finschia-sdk/crypto/codec"
     8  	sdk "github.com/Finschia/finschia-sdk/types"
     9  	"github.com/Finschia/finschia-sdk/types/msgservice"
    10  	authzcodec "github.com/Finschia/finschia-sdk/x/authz/codec"
    11  	fdncodec "github.com/Finschia/finschia-sdk/x/foundation/codec"
    12  	govcodec "github.com/Finschia/finschia-sdk/x/gov/codec"
    13  )
    14  
    15  // RegisterLegacyAminoCodec registers the necessary x/feegrant interfaces and concrete types
    16  // on the provided LegacyAmino codec. These types are used for Amino JSON serialization.
    17  func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
    18  	legacy.RegisterAminoMsg(cdc, &MsgGrantAllowance{}, "cosmos-sdk/MsgGrantAllowance")
    19  	legacy.RegisterAminoMsg(cdc, &MsgRevokeAllowance{}, "cosmos-sdk/MsgRevokeAllowance")
    20  
    21  	cdc.RegisterInterface((*FeeAllowanceI)(nil), nil)
    22  	cdc.RegisterConcrete(&BasicAllowance{}, "cosmos-sdk/BasicAllowance", nil)
    23  	cdc.RegisterConcrete(&PeriodicAllowance{}, "cosmos-sdk/PeriodicAllowance", nil)
    24  	cdc.RegisterConcrete(&AllowedMsgAllowance{}, "cosmos-sdk/AllowedMsgAllowance", nil)
    25  }
    26  
    27  // RegisterInterfaces registers the interfaces types with the interface registry
    28  func RegisterInterfaces(registry types.InterfaceRegistry) {
    29  	registry.RegisterImplementations((*sdk.Msg)(nil),
    30  		&MsgGrantAllowance{},
    31  		&MsgRevokeAllowance{},
    32  	)
    33  
    34  	registry.RegisterInterface(
    35  		"cosmos.feegrant.v1beta1.FeeAllowanceI",
    36  		(*FeeAllowanceI)(nil),
    37  		&BasicAllowance{},
    38  		&PeriodicAllowance{},
    39  		&AllowedMsgAllowance{},
    40  	)
    41  
    42  	msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
    43  }
    44  
    45  var (
    46  	amino = codec.NewLegacyAmino()
    47  
    48  	// ModuleCdc references the global x/feegrant module codec. Note, the codec should
    49  	// ONLY be used in certain instances of tests and for JSON encoding as Amino is
    50  	// still used for that purpose.
    51  	//
    52  	// The actual codec used for serialization should be provided to x/feegrant and
    53  	// defined at the application level.
    54  	ModuleCdc = codec.NewAminoCodec(amino)
    55  )
    56  
    57  func init() {
    58  	RegisterLegacyAminoCodec(amino)
    59  	cryptocodec.RegisterCrypto(amino)
    60  	sdk.RegisterLegacyAminoCodec(amino)
    61  
    62  	// Register all Amino interfaces and concrete types on the authz  and gov Amino codec so that this can later be
    63  	// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
    64  	RegisterLegacyAminoCodec(authzcodec.Amino)
    65  	RegisterLegacyAminoCodec(govcodec.Amino)
    66  	RegisterLegacyAminoCodec(fdncodec.Amino)
    67  }