cosmos-sdk/tools/rosetta/codec.go
Aaron Craelius 82659a7477
refactor!: deprecate sdk.Msg.GetSigners (#15284)
Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
2023-05-25 18:35:09 +00:00

40 lines
1.1 KiB
Go

package rosetta
import (
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/types"
bankcodec "github.com/cosmos/cosmos-sdk/x/bank/types"
)
// MakeCodec generates the codec required to interact
// with the cosmos APIs used by the rosetta gateway
func MakeCodec() (*codec.ProtoCodec, codectypes.InterfaceRegistry) {
ir, err := codectypes.NewInterfaceRegistryWithOptions(
codectypes.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
},
)
if err != nil {
panic(err)
}
cdc := codec.NewProtoCodec(ir)
authcodec.RegisterInterfaces(ir)
bankcodec.RegisterInterfaces(ir)
cryptocodec.RegisterInterfaces(ir)
return cdc, ir
}