diff --git a/CHANGELOG.md b/CHANGELOG.md index bc2933a1eb..592a170a6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Features - [cronos#110](https://github.com/crypto-org-chain/cronos/pull/110) embed swagger doc ui +- [cronos#113](https://github.com/crypto-org-chain/cronos/pull/113) export token mapping state to genesis *September 22, 2021* ## v0.5.4 diff --git a/docs/api/proto-docs.md b/docs/api/proto-docs.md index cb5732c566..6c92d8e72c 100644 --- a/docs/api/proto-docs.md +++ b/docs/api/proto-docs.md @@ -6,6 +6,7 @@ - [cronos/cronos.proto](#cronos/cronos.proto) - [Params](#cronos.Params) + - [TokenMapping](#cronos.TokenMapping) - [TokenMappingChangeProposal](#cronos.TokenMappingChangeProposal) - [cronos/genesis.proto](#cronos/genesis.proto) @@ -47,6 +48,23 @@ Params defines the parameters for the cronos module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `ibc_cro_denom` | [string](#string) | | | +| `ibc_timeout` | [uint64](#uint64) | | | + + + + + + + + +### TokenMapping +TokenMapping defines a mapping between native denom and contract + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `denom` | [string](#string) | | | +| `contract` | [string](#string) | | | @@ -95,9 +113,9 @@ GenesisState defines the cronos module's genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#cronos.Params) | | params defines all the paramaters of the module. - -this line is used by starport scaffolding # genesis/proto/state this line is used by starport scaffolding # ibc/genesis/proto | +| `params` | [Params](#cronos.Params) | | params defines all the paramaters of the module. | +| `external_contracts` | [TokenMapping](#cronos.TokenMapping) | repeated | | +| `auto_contracts` | [TokenMapping](#cronos.TokenMapping) | repeated | this line is used by starport scaffolding # genesis/proto/state this line is used by starport scaffolding # ibc/genesis/proto | diff --git a/integration_tests/configs/genesis_token_mapping.yaml b/integration_tests/configs/genesis_token_mapping.yaml index 956a53799f..d311f6369f 100644 --- a/integration_tests/configs/genesis_token_mapping.yaml +++ b/integration_tests/configs/genesis_token_mapping.yaml @@ -18,6 +18,13 @@ cronos_777-1: mnemonic: "notable error gospel wave pair ugly measure elite toddler cost various fly make eye ketchup despair slab throw tribe swarm word fruit into inmate" genesis: app_state: + cronos: + external_contracts: + - denom: gravity0x0000000000000000000000000000000000000000 + contract: "0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503" + auto_contracts: + - denom: gravity0x0000000000000000000000000000000000000000 + contract: "0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503" auth: accounts: - "@type": "/ethermint.types.v1.EthAccount" diff --git a/integration_tests/test_exported_genesis.py b/integration_tests/test_exported_genesis.py index fad5ea26cc..4dc6c0bf93 100644 --- a/integration_tests/test_exported_genesis.py +++ b/integration_tests/test_exported_genesis.py @@ -28,3 +28,12 @@ def test_exported_contract(custom_cronos): address="0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503", abi=abi ) assert erc20.caller.balanceOf(ADDRS["validator"]) == 100000000000000000000000000 + + +def test_exported_token_mapping(custom_cronos): + cli = custom_cronos.cosmos_cli(0) + rsp = cli.query_contract_by_denom( + "gravity0x0000000000000000000000000000000000000000" + ) + assert rsp["contract"] == "0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503" + assert rsp["auto_contract"] == "0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503" diff --git a/proto/cronos/cronos.proto b/proto/cronos/cronos.proto index 9673ea35b7..df1f30854a 100644 --- a/proto/cronos/cronos.proto +++ b/proto/cronos/cronos.proto @@ -23,3 +23,9 @@ message TokenMappingChangeProposal { string denom = 3; string contract = 4; } + +// TokenMapping defines a mapping between native denom and contract +message TokenMapping { + string denom = 1; + string contract = 2; +} diff --git a/proto/cronos/genesis.proto b/proto/cronos/genesis.proto index d129139e83..b09cd9e05b 100644 --- a/proto/cronos/genesis.proto +++ b/proto/cronos/genesis.proto @@ -12,6 +12,8 @@ option go_package = "github.com/crypto-org-chain/cronos/x/cronos/types"; message GenesisState { // params defines all the paramaters of the module. Params params = 1 [(gogoproto.nullable) = false]; + repeated TokenMapping external_contracts = 2 [(gogoproto.nullable) = false]; + repeated TokenMapping auto_contracts = 3 [(gogoproto.nullable) = false]; // this line is used by starport scaffolding # genesis/proto/state // this line is used by starport scaffolding # ibc/genesis/proto } diff --git a/x/cronos/genesis.go b/x/cronos/genesis.go index 8173144d65..818d6f9cbc 100644 --- a/x/cronos/genesis.go +++ b/x/cronos/genesis.go @@ -1,15 +1,39 @@ package cronos import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/crypto-org-chain/cronos/x/cronos/keeper" "github.com/crypto-org-chain/cronos/x/cronos/types" + "github.com/ethereum/go-ethereum/common" ) // InitGenesis initializes the capability module's state from a provided genesis // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { k.SetParams(ctx, genState.Params) + + for _, m := range genState.ExternalContracts { + if !types.IsValidDenomToWrap(m.Denom) { + panic(fmt.Sprintf("Invalid denom to map to contract: %s", m.Denom)) + } + if !common.IsHexAddress(m.Contract) { + panic(fmt.Sprintf("Invalid contract address: %s", m.Contract)) + } + k.SetExternalContractForDenom(ctx, m.Denom, common.HexToAddress(m.Contract)) + } + + for _, m := range genState.AutoContracts { + if !types.IsValidDenomToWrap(m.Denom) { + panic(fmt.Sprintf("Invalid denom to map to contract: %s", m.Denom)) + } + if !common.IsHexAddress(m.Contract) { + panic(fmt.Sprintf("Invalid contract address: %s", m.Contract)) + } + k.SetAutoContractForDenom(ctx, m.Denom, common.HexToAddress(m.Contract)) + } + // this line is used by starport scaffolding # genesis/module/init // this line is used by starport scaffolding # ibc/genesis/init @@ -22,6 +46,8 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { // this line is used by starport scaffolding # ibc/genesis/export return &types.GenesisState{ - Params: k.GetParams(ctx), + Params: k.GetParams(ctx), + ExternalContracts: k.GetExternalContracts(ctx), + AutoContracts: k.GetAutoContracts(ctx), } } diff --git a/x/cronos/genesis_test.go b/x/cronos/genesis_test.go index 7082dcdc25..f9e34af005 100644 --- a/x/cronos/genesis_test.go +++ b/x/cronos/genesis_test.go @@ -36,6 +36,78 @@ func (suite *CronosTestSuite) TestInitGenesis() { }}, true, }, + { + "Wrong denom in external token mapping", + func() {}, + &types.GenesisState{ + ExternalContracts: []types.TokenMapping{ + { + Denom: "aaa/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865", + Contract: "0x0000000000000000000000000000000000000000", + }, + }, + }, + true, + }, + { + "Wrong denom in auto token mapping", + func() {}, + &types.GenesisState{ + AutoContracts: []types.TokenMapping{ + { + Denom: "aaa/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865", + Contract: "0x0000000000000000000000000000000000000000", + }, + }, + }, + true, + }, + { + "Wrong contract in external token mapping", + func() {}, + &types.GenesisState{ + ExternalContracts: []types.TokenMapping{ + { + Denom: "ibc/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865", + Contract: "0x00000000000000000000000000000000000000", + }, + }, + }, + true, + }, + { + "Wrong contract in auto token mapping", + func() {}, + &types.GenesisState{ + AutoContracts: []types.TokenMapping{ + { + Denom: "ibc/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865", + Contract: "0x00000000000000000000000000000000000000", + }, + }, + }, + true, + }, + { + "Correct token mapping", + func() {}, + &types.GenesisState{ + Params: types.DefaultParams(), + ExternalContracts: []types.TokenMapping{ + { + Denom: "ibc/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865", + Contract: "0x0000000000000000000000000000000000000000", + }, + }, + AutoContracts: []types.TokenMapping{ + { + Denom: "gravity0x0000000000000000000000000000000000000000", + Contract: "0x0000000000000000000000000000000000000000", + }, + }, + }, + false, + }, } for _, tc := range testCases { diff --git a/x/cronos/keeper/keeper.go b/x/cronos/keeper/keeper.go index 908483d194..ab07798b94 100644 --- a/x/cronos/keeper/keeper.go +++ b/x/cronos/keeper/keeper.go @@ -8,6 +8,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/crypto-org-chain/cronos/x/cronos/types" "github.com/ethereum/go-ethereum/common" @@ -125,6 +126,32 @@ func (k Keeper) SetExternalContractForDenom(ctx sdk.Context, denom string, addre store.Set(types.ContractToDenomKey(address.Bytes()), []byte(denom)) } +// GetExternalContracts returns all external contract mappings +func (k Keeper) GetExternalContracts(ctx sdk.Context) (out []types.TokenMapping) { + store := ctx.KVStore(k.storeKey) + iter := prefix.NewStore(store, types.KeyPrefixDenomToExternalContract).Iterator(nil, nil) + for ; iter.Valid(); iter.Next() { + out = append(out, types.TokenMapping{ + Denom: string(iter.Key()), + Contract: common.BytesToAddress(iter.Value()).Hex(), + }) + } + return +} + +// GetAutoContracts returns all auto-deployed contract mappings +func (k Keeper) GetAutoContracts(ctx sdk.Context) (out []types.TokenMapping) { + store := ctx.KVStore(k.storeKey) + iter := prefix.NewStore(store, types.KeyPrefixDenomToAutoContract).Iterator(nil, nil) + for ; iter.Valid(); iter.Next() { + out = append(out, types.TokenMapping{ + Denom: string(iter.Key()), + Contract: common.BytesToAddress(iter.Value()).Hex(), + }) + } + return +} + // DeleteExternalContractForDenom delete the external contract mapping for native denom, // returns false if mapping not exists. func (k Keeper) DeleteExternalContractForDenom(ctx sdk.Context, denom string) bool { diff --git a/x/cronos/types/cronos.pb.go b/x/cronos/types/cronos.pb.go index a4db81e64a..22b8983a4c 100644 --- a/x/cronos/types/cronos.pb.go +++ b/x/cronos/types/cronos.pb.go @@ -115,36 +115,91 @@ func (m *TokenMappingChangeProposal) XXX_DiscardUnknown() { var xxx_messageInfo_TokenMappingChangeProposal proto.InternalMessageInfo +// TokenMapping defines a mapping between native denom and contract +type TokenMapping struct { + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` + Contract string `protobuf:"bytes,2,opt,name=contract,proto3" json:"contract,omitempty"` +} + +func (m *TokenMapping) Reset() { *m = TokenMapping{} } +func (m *TokenMapping) String() string { return proto.CompactTextString(m) } +func (*TokenMapping) ProtoMessage() {} +func (*TokenMapping) Descriptor() ([]byte, []int) { + return fileDescriptor_8bc54992a93db2d2, []int{2} +} +func (m *TokenMapping) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TokenMapping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TokenMapping.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TokenMapping) XXX_Merge(src proto.Message) { + xxx_messageInfo_TokenMapping.Merge(m, src) +} +func (m *TokenMapping) XXX_Size() int { + return m.Size() +} +func (m *TokenMapping) XXX_DiscardUnknown() { + xxx_messageInfo_TokenMapping.DiscardUnknown(m) +} + +var xxx_messageInfo_TokenMapping proto.InternalMessageInfo + +func (m *TokenMapping) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *TokenMapping) GetContract() string { + if m != nil { + return m.Contract + } + return "" +} + func init() { proto.RegisterType((*Params)(nil), "cronos.Params") proto.RegisterType((*TokenMappingChangeProposal)(nil), "cronos.TokenMappingChangeProposal") + proto.RegisterType((*TokenMapping)(nil), "cronos.TokenMapping") } func init() { proto.RegisterFile("cronos/cronos.proto", fileDescriptor_8bc54992a93db2d2) } var fileDescriptor_8bc54992a93db2d2 = []byte{ - // 323 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0xb1, 0x6e, 0xea, 0x30, - 0x14, 0x86, 0xe3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bb, 0xf4, 0x0f, 0x2a, 0xdc, 0x48, - 0xdf, 0x22, 0xf5, 0x10, 0x0e, 0x68, 0x67, 0x25, 0x0b, 0xe1, 0x94, 0x45, 0x05, 0xa6, 0xfe, 0xbb, - 0x9d, 0x7e, 0x57, 0xd5, 0x9e, 0x6f, 0xff, 0xdb, 0xef, 0xd5, 0x10, 0xf6, 0x69, 0x4b, 0x80, 0x41, - 0xc7, 0x05, 0xf6, 0x1a, 0x75, 0xf0, 0xc5, 0x93, 0xd6, 0xc3, 0x3e, 0x0a, 0xaa, 0x4a, 0xd3, 0xab, - 0xa7, 0x23, 0x23, 0x87, 0x23, 0x23, 0xaf, 0x47, 0x46, 0x76, 0x27, 0x16, 0x1c, 0x4e, 0x2c, 0x78, - 0x3e, 0xb1, 0xe0, 0xe6, 0x2c, 0x57, 0xb8, 0xde, 0x66, 0x63, 0x01, 0x3a, 0x11, 0xae, 0xb4, 0x08, - 0x23, 0x70, 0xf9, 0x48, 0xac, 0xb9, 0x32, 0x1f, 0xd7, 0x4e, 0xee, 0x3f, 0x07, 0x2c, 0xad, 0x2c, - 0xb2, 0x66, 0x7d, 0xdf, 0xf3, 0xf7, 0x00, 0x00, 0x00, 0xff, 0xff, 0x82, 0x9d, 0xe5, 0x71, 0x94, - 0x01, 0x00, 0x00, + // 338 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xbf, 0x6e, 0xea, 0x30, + 0x14, 0xc6, 0x63, 0x2e, 0x17, 0x81, 0xb9, 0x77, 0x49, 0x19, 0x10, 0x83, 0x83, 0x32, 0x31, 0x14, + 0xa2, 0xaa, 0x1b, 0x53, 0x05, 0x55, 0x97, 0xaa, 0x12, 0x8a, 0x98, 0xba, 0x20, 0xc7, 0x58, 0xc1, + 0x2a, 0xf6, 0xb1, 0x1c, 0xa3, 0x36, 0x6f, 0xd0, 0x91, 0xb1, 0x23, 0x8f, 0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 0x6c, 0xbb, 0x5a, 0x1a, 0xdf, 0x3c, 0xac, 0x3f, 0x6e, 0x02, 0xaf, 0xac, + 0x74, 0x81, 0xff, 0x1d, 0x36, 0xfa, 0xc9, 0x42, 0xbf, 0x65, 0x55, 0x8e, 0xb3, 0x46, 0xd7, 0xcf, + 0x3b, 0x82, 0xb6, 0x3b, 0x82, 0xde, 0x76, 0x04, 0xad, 0xf7, 0xc4, 0xdb, 0xee, 0x89, 0xf7, 0xb2, + 0x27, 0xde, 0xed, 0x59, 0x2a, 0xec, 0x62, 0x95, 0x0c, 0x18, 0xc8, 0x88, 0x99, 0x5c, 0x5b, 0xe8, + 0x83, 0x49, 0xfb, 0x6c, 0x41, 0x85, 0xfa, 0xfc, 0x57, 0xf4, 0xf0, 0xb5, 0xd8, 0x5c, 0xf3, 0x2c, + 0xa9, 0x95, 0x1f, 0x3a, 0xff, 0x08, 0x00, 0x00, 0xff, 0xff, 0x18, 0x65, 0x3a, 0xeb, 0xd6, 0x01, + 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -233,6 +288,43 @@ func (m *TokenMappingChangeProposal) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *TokenMapping) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TokenMapping) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TokenMapping) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintCronos(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0x12 + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintCronos(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintCronos(dAtA []byte, offset int, v uint64) int { offset -= sovCronos(v) base := offset @@ -285,6 +377,23 @@ func (m *TokenMappingChangeProposal) Size() (n int) { return n } +func (m *TokenMapping) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovCronos(uint64(l)) + } + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovCronos(uint64(l)) + } + return n +} + func sovCronos(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -570,6 +679,120 @@ func (m *TokenMappingChangeProposal) Unmarshal(dAtA []byte) error { } return nil } +func (m *TokenMapping) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCronos + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TokenMapping: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TokenMapping: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCronos + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCronos + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCronos + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCronos + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCronos + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCronos + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCronos(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCronos + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipCronos(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/cronos/types/genesis.pb.go b/x/cronos/types/genesis.pb.go index 5e79f92552..b4eb85d4c8 100644 --- a/x/cronos/types/genesis.pb.go +++ b/x/cronos/types/genesis.pb.go @@ -26,7 +26,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the cronos module's genesis state. type GenesisState struct { // params defines all the paramaters of the module. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + ExternalContracts []TokenMapping `protobuf:"bytes,2,rep,name=external_contracts,json=externalContracts,proto3" json:"external_contracts"` + AutoContracts []TokenMapping `protobuf:"bytes,3,rep,name=auto_contracts,json=autoContracts,proto3" json:"auto_contracts"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -69,6 +71,20 @@ func (m *GenesisState) GetParams() Params { return Params{} } +func (m *GenesisState) GetExternalContracts() []TokenMapping { + if m != nil { + return m.ExternalContracts + } + return nil +} + +func (m *GenesisState) GetAutoContracts() []TokenMapping { + if m != nil { + return m.AutoContracts + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "cronos.GenesisState") } @@ -76,19 +92,24 @@ func init() { func init() { proto.RegisterFile("cronos/genesis.proto", fileDescriptor_997c9bf6ad78cc99) } var fileDescriptor_997c9bf6ad78cc99 = []byte{ - // 188 bytes of a gzipped FileDescriptorProto + // 260 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x49, 0x2e, 0xca, 0xcf, 0xcb, 0x2f, 0xd6, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0x88, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x85, 0xf4, 0x41, 0x2c, 0x88, - 0xac, 0x94, 0x30, 0x54, 0x0f, 0x84, 0x82, 0x08, 0x2a, 0xd9, 0x70, 0xf1, 0xb8, 0x43, 0xcc, 0x08, - 0x2e, 0x49, 0x2c, 0x49, 0x15, 0xd2, 0xe1, 0x62, 0x2b, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0x96, 0x60, - 0x54, 0x60, 0xd4, 0xe0, 0x36, 0xe2, 0xd3, 0x83, 0x2a, 0x0f, 0x00, 0x8b, 0x3a, 0xb1, 0x9c, 0xb8, - 0x27, 0xcf, 0x10, 0x04, 0x55, 0xe3, 0xe4, 0x7d, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, - 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, - 0x0c, 0x51, 0x86, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc9, 0x45, - 0x95, 0x05, 0x25, 0xf9, 0xba, 0xf9, 0x45, 0xe9, 0xba, 0xc9, 0x19, 0x89, 0x99, 0x79, 0x50, 0x17, - 0xe8, 0x57, 0xc0, 0x18, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x17, 0x19, 0x03, 0x02, - 0x00, 0x00, 0xff, 0xff, 0x6b, 0x46, 0x4a, 0x10, 0xdc, 0x00, 0x00, 0x00, + 0xac, 0x94, 0x30, 0x54, 0x0f, 0x84, 0x82, 0x08, 0x2a, 0x9d, 0x62, 0xe4, 0xe2, 0x71, 0x87, 0x18, + 0x12, 0x5c, 0x92, 0x58, 0x92, 0x2a, 0xa4, 0xc3, 0xc5, 0x56, 0x90, 0x58, 0x94, 0x98, 0x5b, 0x2c, + 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0xc4, 0xa7, 0x07, 0x55, 0x1f, 0x00, 0x16, 0x75, 0x62, 0x39, + 0x71, 0x4f, 0x9e, 0x21, 0x08, 0xaa, 0x46, 0xc8, 0x93, 0x4b, 0x28, 0xb5, 0xa2, 0x24, 0xb5, 0x28, + 0x2f, 0x31, 0x27, 0x3e, 0x39, 0x3f, 0xaf, 0xa4, 0x28, 0x31, 0xb9, 0xa4, 0x58, 0x82, 0x49, 0x81, + 0x59, 0x83, 0xdb, 0x48, 0x04, 0xa6, 0x33, 0x24, 0x3f, 0x3b, 0x35, 0xcf, 0x37, 0xb1, 0xa0, 0x20, + 0x33, 0x2f, 0x1d, 0xaa, 0x5f, 0x10, 0xa6, 0xcb, 0x19, 0xa6, 0x49, 0xc8, 0x91, 0x8b, 0x2f, 0xb1, + 0xb4, 0x24, 0x1f, 0xc9, 0x18, 0x66, 0x82, 0xc6, 0xf0, 0x82, 0x74, 0xc0, 0x8d, 0x70, 0xf2, 0x3e, + 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, + 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xc3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, + 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe4, 0xa2, 0xca, 0x82, 0x92, 0x7c, 0xdd, 0xfc, 0xa2, 0x74, + 0xdd, 0xe4, 0x8c, 0xc4, 0xcc, 0x3c, 0x68, 0x80, 0xe8, 0x57, 0xc0, 0x18, 0x25, 0x95, 0x05, 0xa9, + 0xc5, 0x49, 0x6c, 0xe0, 0x00, 0x32, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xd9, 0xac, 0xa2, 0x1e, + 0x6b, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -111,6 +132,34 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.AutoContracts) > 0 { + for iNdEx := len(m.AutoContracts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AutoContracts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.ExternalContracts) > 0 { + for iNdEx := len(m.ExternalContracts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ExternalContracts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -143,6 +192,18 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) + if len(m.ExternalContracts) > 0 { + for _, e := range m.ExternalContracts { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.AutoContracts) > 0 { + for _, e := range m.AutoContracts { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -214,6 +275,74 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExternalContracts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExternalContracts = append(m.ExternalContracts, TokenMapping{}) + if err := m.ExternalContracts[len(m.ExternalContracts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AutoContracts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AutoContracts = append(m.AutoContracts, TokenMapping{}) + if err := m.AutoContracts[len(m.AutoContracts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:])