From 8105589dd7e14a7e8edbbac4a794d8eee2f30298 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Fri, 30 Apr 2021 16:44:50 -0600 Subject: [PATCH] feat: plumb through the genesis data to vpurse initialisation --- golang/cosmos/app/app.go | 38 +- .../cosmos/proto/agoric/vpurse/genesis.proto | 20 + golang/cosmos/x/vpurse/genesis.go | 61 +++ golang/cosmos/x/vpurse/keeper/keeper.go | 15 + golang/cosmos/x/vpurse/module.go | 15 +- golang/cosmos/x/vpurse/types/genesis.pb.go | 420 ++++++++++++++++++ 6 files changed, 543 insertions(+), 26 deletions(-) create mode 100644 golang/cosmos/proto/agoric/vpurse/genesis.proto create mode 100644 golang/cosmos/x/vpurse/genesis.go create mode 100644 golang/cosmos/x/vpurse/types/genesis.pb.go diff --git a/golang/cosmos/app/app.go b/golang/cosmos/app/app.go index 93a34e26bf1..5185a2e458f 100644 --- a/golang/cosmos/app/app.go +++ b/golang/cosmos/app/app.go @@ -332,6 +332,7 @@ func NewAgoricApp( // This function is tricky to get right, so we build it ourselves. callToController := func(ctx sdk.Context, str string) (string, error) { + app.MustInitController(ctx) defer swingset.SetControllerContext(ctx)() return sendToController(true, str) } @@ -423,7 +424,7 @@ func NewAgoricApp( upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, swingset.ModuleName, ) - app.mm.SetOrderEndBlockers(swingset.ModuleName, crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName) + app.mm.SetOrderEndBlockers(vpurse.ModuleName, swingset.ModuleName, crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName) // NOTE: The genutils module must occur after staking so that pools are // properly initialized with tokens from genesis accounts. @@ -433,7 +434,9 @@ func NewAgoricApp( app.mm.SetOrderInitGenesis( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, - ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, swingset.ModuleName, ibctransfertypes.ModuleName, + ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, + ibctransfertypes.ModuleName, + vpurse.ModuleName, swingset.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) @@ -527,23 +530,16 @@ func (app *GaiaApp) MustInitController(ctx sdk.Context) { } app.controllerInited = true - /* - FIXME: Get these from genesis! - - name: mallory - type: local - address: agoric1z8rldx498tf49p5ze04jhakyumkh7vyxku7e0p - pubkey: agoricpub1addwnpepqtzw4lz7yjhg7qljwf0jqaykj6q94hh9epxa6nq7u0a3hxhsn7u670cgwnz - mnemonic: "" - threshold: 0 - pubkeys: [] - */ - bootstrapAddr, err := sdk.AccAddressFromBech32("agoric1z8rldx498tf49p5ze04jhakyumkh7vyxku7e0p") - if err != nil { - fmt.Fprintln(os.Stderr, "Cannot get bootstrap addr", err) - os.Exit(1) + var bootstrapAddr sdk.AccAddress + gs := app.VpurseKeeper.GetGenesis(ctx) + if len(gs.BootstrapAddress) > 0 { + ba, err := sdk.AccAddressFromBech32(gs.BootstrapAddress) + if err != nil { + fmt.Fprintln(os.Stderr, "Cannot get bootstrap addr", err) + os.Exit(1) + } + bootstrapAddr = ba } - bootstrapValue := "50000000000" - donationValue := "5000000" // Begin initializing the controller here. action := &cosmosInitAction{ @@ -553,8 +549,8 @@ func (app *GaiaApp) MustInitController(ctx sdk.Context) { StoragePort: swingset.GetPort("storage"), ChainID: ctx.ChainID(), BootstrapAddress: bootstrapAddr.String(), - BootstrapValue: bootstrapValue, - DonationValue: donationValue, + BootstrapValue: gs.BootstrapValue.String(), + DonationValue: gs.DonationValue.String(), } bz, err := json.Marshal(action) if err == nil { @@ -568,7 +564,6 @@ func (app *GaiaApp) MustInitController(ctx sdk.Context) { // BeginBlocker application updates every begin block func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { - app.MustInitController(ctx) return app.mm.BeginBlock(ctx, req) } @@ -598,7 +593,6 @@ func updateTransferPort(gs GenesisState, reservedPort, newPort string) error { // InitChainer application update at chain initialization func (app *GaiaApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - app.MustInitController(ctx) var genesisState GenesisState if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { panic(err) diff --git a/golang/cosmos/proto/agoric/vpurse/genesis.proto b/golang/cosmos/proto/agoric/vpurse/genesis.proto new file mode 100644 index 00000000000..4dda5e0ae1c --- /dev/null +++ b/golang/cosmos/proto/agoric/vpurse/genesis.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package agoric.vpurse; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types"; + +message GenesisState { + option (gogoproto.equal) = false; + + string bootstrap_address = 1; + string bootstrap_value = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + string donation_value = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; +} diff --git a/golang/cosmos/x/vpurse/genesis.go b/golang/cosmos/x/vpurse/genesis.go new file mode 100644 index 00000000000..a0c0d279a6d --- /dev/null +++ b/golang/cosmos/x/vpurse/genesis.go @@ -0,0 +1,61 @@ +package vpurse + +import ( + // "fmt" + + "fmt" + + "github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types" + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" +) + +func NewGenesisState() *types.GenesisState { + return &types.GenesisState{ + BootstrapAddress: "", + BootstrapValue: sdk.NewInt(0), + DonationValue: sdk.NewInt(0), + } +} + +func ValidateGenesis(data *types.GenesisState) error { + if data == nil { + return fmt.Errorf("vpurse genesis data cannot be nil") + } + if len(data.BootstrapAddress) > 0 { + if _, err := sdk.AccAddressFromBech32(data.BootstrapAddress); err != nil { + return fmt.Errorf("vpurse genesis invalid bootstrapAdddress %s: %w", data.BootstrapAddress, err) + } + } + if data.BootstrapValue.IsNil() { + return fmt.Errorf("vpurse genesis bootstrapValue cannot be nil") + } + if data.BootstrapValue.IsNegative() { + return fmt.Errorf("vpurse genesis bootstrapValue %s cannot be negative", data.DonationValue.String()) + } + if data.DonationValue.IsNil() { + return fmt.Errorf("vpurse genesis donationValue cannot be nil") + } + if data.DonationValue.IsNegative() { + return fmt.Errorf("vpurse genesis donationValue %s cannot be negative", data.DonationValue.String()) + } + return nil +} + +func DefaultGenesisState() *types.GenesisState { + gs := NewGenesisState() + fmt.Println("default gen", gs) + return gs +} + +func InitGenesis(ctx sdk.Context, keeper Keeper, data *types.GenesisState) []abci.ValidatorUpdate { + keeper.SetGenesis(ctx, *data) + fmt.Println("initialising gen", *data) + return []abci.ValidatorUpdate{} +} + +func ExportGenesis(ctx sdk.Context, k Keeper) *types.GenesisState { + gs := k.GetGenesis(ctx) + fmt.Println("exporting gen", gs) + return &gs +} diff --git a/golang/cosmos/x/vpurse/keeper/keeper.go b/golang/cosmos/x/vpurse/keeper/keeper.go index 37583a790a5..0e41846bdc7 100644 --- a/golang/cosmos/x/vpurse/keeper/keeper.go +++ b/golang/cosmos/x/vpurse/keeper/keeper.go @@ -9,6 +9,8 @@ import ( "github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types" ) +const genesis string = "genesis" + // Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine type Keeper struct { storeKey sdk.StoreKey @@ -35,6 +37,19 @@ func NewKeeper( } } +func (k Keeper) GetGenesis(ctx sdk.Context) types.GenesisState { + store := ctx.KVStore(k.storeKey) + bz := store.Get([]byte(genesis)) + var gs types.GenesisState + k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &gs) + return gs +} + +func (k Keeper) SetGenesis(ctx sdk.Context, data types.GenesisState) { + store := ctx.KVStore(k.storeKey) + store.Set([]byte(genesis), k.cdc.MustMarshalBinaryLengthPrefixed(&data)) +} + func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin { return k.bankKeeper.GetBalance(ctx, addr, denom) } diff --git a/golang/cosmos/x/vpurse/module.go b/golang/cosmos/x/vpurse/module.go index 7472fb7b942..c6e0cbfebed 100644 --- a/golang/cosmos/x/vpurse/module.go +++ b/golang/cosmos/x/vpurse/module.go @@ -44,12 +44,16 @@ func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) // DefaultGenesis returns default genesis state as raw bytes for the deployment func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { - return nil + return cdc.MustMarshalJSON(DefaultGenesisState()) } // Validation check of the Genesis func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxEncodingConfig, bz json.RawMessage) error { - return nil + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return err + } + return ValidateGenesis(&data) } // Register rest routes @@ -125,11 +129,14 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the ibc-transfer module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + return InitGenesis(ctx, am.keeper, &genesisState) } // ExportGenesis returns the exported genesis state as raw bytes for the ibc-transfer // module. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { - return nil + gs := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(gs) } diff --git a/golang/cosmos/x/vpurse/types/genesis.pb.go b/golang/cosmos/x/vpurse/types/genesis.pb.go new file mode 100644 index 00000000000..2ab4be296cd --- /dev/null +++ b/golang/cosmos/x/vpurse/types/genesis.pb.go @@ -0,0 +1,420 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: agoric/vpurse/genesis.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type GenesisState struct { + BootstrapAddress string `protobuf:"bytes,1,opt,name=bootstrap_address,json=bootstrapAddress,proto3" json:"bootstrap_address,omitempty"` + BootstrapValue github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=bootstrap_value,json=bootstrapValue,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"bootstrap_value"` + DonationValue github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=donation_value,json=donationValue,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"donation_value"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_5640d8342a3d07c5, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetBootstrapAddress() string { + if m != nil { + return m.BootstrapAddress + } + return "" +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "agoric.vpurse.GenesisState") +} + +func init() { proto.RegisterFile("agoric/vpurse/genesis.proto", fileDescriptor_5640d8342a3d07c5) } + +var fileDescriptor_5640d8342a3d07c5 = []byte{ + // 272 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4e, 0x4c, 0xcf, 0x2f, + 0xca, 0x4c, 0xd6, 0x2f, 0x2b, 0x28, 0x2d, 0x2a, 0x4e, 0xd5, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, + 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x85, 0x48, 0xea, 0x41, 0x24, 0xa5, 0x44, + 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x32, 0xfa, 0x20, 0x16, 0x44, 0x91, 0xd2, 0x47, 0x46, 0x2e, 0x1e, + 0x77, 0x88, 0xb6, 0xe0, 0x92, 0xc4, 0x92, 0x54, 0x21, 0x6d, 0x2e, 0xc1, 0xa4, 0xfc, 0xfc, 0x92, + 0xe2, 0x92, 0xa2, 0xc4, 0x82, 0xf8, 0xc4, 0x94, 0x94, 0xa2, 0xd4, 0xe2, 0x62, 0x09, 0x46, 0x05, + 0x46, 0x0d, 0xce, 0x20, 0x01, 0xb8, 0x84, 0x23, 0x44, 0x5c, 0x28, 0x9c, 0x8b, 0x1f, 0xa1, 0xb8, + 0x2c, 0x31, 0xa7, 0x34, 0x55, 0x82, 0x09, 0xa4, 0xd4, 0x49, 0xef, 0xc4, 0x3d, 0x79, 0x86, 0x5b, + 0xf7, 0xe4, 0xd5, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x93, 0xf3, + 0x8b, 0x73, 0xf3, 0x8b, 0xa1, 0x94, 0x6e, 0x71, 0x4a, 0xb6, 0x7e, 0x49, 0x65, 0x41, 0x6a, 0xb1, + 0x9e, 0x67, 0x5e, 0x49, 0x10, 0x1f, 0xdc, 0x98, 0x30, 0x90, 0x29, 0x42, 0xa1, 0x5c, 0x7c, 0x29, + 0xf9, 0x79, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x50, 0x73, 0x99, 0xc9, 0x32, 0x97, 0x17, 0x66, 0x0a, + 0xd8, 0x58, 0x2b, 0x96, 0x17, 0x0b, 0xe4, 0x19, 0x9c, 0x82, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, + 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, + 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x12, 0xc9, 0x58, 0x47, 0x48, 0xd0, 0x42, 0x02, 0x11, 0x6c, 0x6c, + 0x7a, 0x7e, 0x4e, 0x62, 0x5e, 0x3a, 0xcc, 0xbe, 0x0a, 0x58, 0xa8, 0x83, 0x6d, 0x4b, 0x62, 0x03, + 0x87, 0xa7, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x41, 0xba, 0x27, 0x6a, 0x93, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.DonationValue.Size() + i -= size + if _, err := m.DonationValue.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.BootstrapValue.Size() + i -= size + if _, err := m.BootstrapValue.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.BootstrapAddress) > 0 { + i -= len(m.BootstrapAddress) + copy(dAtA[i:], m.BootstrapAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.BootstrapAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BootstrapAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.BootstrapValue.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.DonationValue.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BootstrapAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BootstrapAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BootstrapValue", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.BootstrapValue.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DonationValue", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DonationValue.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +)