diff --git a/golang/cosmos/app/app.go b/golang/cosmos/app/app.go index c803ee16313..9177fafbf10 100644 --- a/golang/cosmos/app/app.go +++ b/golang/cosmos/app/app.go @@ -132,6 +132,7 @@ var ( swingset.AppModuleBasic{}, vibc.AppModuleBasic{}, vbank.AppModuleBasic{}, + lien.AppModuleBasic{}, feegrantmodule.AppModuleBasic{}, upgrade.AppModuleBasic{}, evidence.AppModuleBasic{}, @@ -262,7 +263,7 @@ func NewAgoricApp( minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, evidencetypes.StoreKey, feegrant.StoreKey, ibctransfertypes.StoreKey, - swingset.StoreKey, vibc.StoreKey, vbank.StoreKey, + swingset.StoreKey, vibc.StoreKey, vbank.StoreKey, lien.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, ) @@ -409,9 +410,10 @@ func NewAgoricApp( app.vbankPort = vm.RegisterPortHandler("bank", vbank.NewPortHandler(vbankModule, app.VbankKeeper)) // Lien keeper, and circular reference back to wrappedAccountKeeper - app.LienKeeper = lien.NewKeeper(wrappedAccountKeeper, app.BankKeeper, app.StakingKeeper, callToController) + app.LienKeeper = lien.NewKeeper(keys[lien.StoreKey], appCodec, wrappedAccountKeeper, app.BankKeeper, app.StakingKeeper, callToController) wrappedAccountKeeper.SetWrapper(app.LienKeeper.GetAccountWrapper()) - app.lienPort = vm.RegisterPortHandler("lien", app.LienKeeper) + lienModule := lien.NewAppModule(app.LienKeeper) + app.lienPort = vm.RegisterPortHandler("lien", lien.NewPortHandler(app.LienKeeper)) // create evidence keeper with router evidenceKeeper := evidencekeeper.NewKeeper( @@ -456,6 +458,7 @@ func NewAgoricApp( swingset.NewAppModule(app.SwingSetKeeper), vibcModule, vbankModule, + lienModule, transferModule, authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ) @@ -480,7 +483,7 @@ func NewAgoricApp( slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, ibctransfertypes.ModuleName, - vbank.ModuleName, swingset.ModuleName, + vbank.ModuleName, swingset.ModuleName, lien.ModuleName, authz.ModuleName, feegrant.ModuleName, ) diff --git a/golang/cosmos/proto/agoric/lien/genesis.proto b/golang/cosmos/proto/agoric/lien/genesis.proto new file mode 100644 index 00000000000..54df8445555 --- /dev/null +++ b/golang/cosmos/proto/agoric/lien/genesis.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; +package agoric.lien; + +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; + +option go_package = "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"; + +message GenesisState { + option (gogoproto.equal) = false; + + repeated AccountLien liens = 1 [ + (gogoproto.nullable) = false + ]; +} + +message AccountLien { + string address = 1; + repeated cosmos.base.v1beta1.Coin lien = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} \ No newline at end of file diff --git a/golang/cosmos/x/lien/alias.go b/golang/cosmos/x/lien/alias.go index d3bd2b6d405..8349550f12b 100644 --- a/golang/cosmos/x/lien/alias.go +++ b/golang/cosmos/x/lien/alias.go @@ -6,8 +6,10 @@ import ( ) var ( + ModuleName = types.ModuleName NewKeeper = keeper.NewKeeper NewWrappedAccountKeeper = types.NewWrappedAccountKeeper + StoreKey = types.StoreKey ) type ( diff --git a/golang/cosmos/x/lien/genesis.go b/golang/cosmos/x/lien/genesis.go new file mode 100644 index 00000000000..e830330eb90 --- /dev/null +++ b/golang/cosmos/x/lien/genesis.go @@ -0,0 +1,35 @@ +package lien + +import ( + "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func DefaultGenesisState() types.GenesisState { + return types.GenesisState{} +} + +func ValidateGenesisState(genesisState types.GenesisState) error { + for _, lien := range genesisState.Liens { + _, err := sdk.AccAddressFromBech32(lien.Address) + if err != nil { + return err + } + } + return nil +} + +func InitGenesis(ctx sdk.Context, keeper Keeper, genesisState types.GenesisState) { + for _, lien := range genesisState.Liens { + keeper.SetAccountLien(ctx, lien) + } +} + +func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState { + genesisState := types.GenesisState{} + keeper.IterateAccountLiens(ctx, func(lien types.AccountLien) bool { + genesisState.Liens = append(genesisState.Liens, lien) + return false + }) + return genesisState +} diff --git a/golang/cosmos/x/lien/keeper/account.go b/golang/cosmos/x/lien/keeper/account.go index 96616166015..665e36a1b0e 100644 --- a/golang/cosmos/x/lien/keeper/account.go +++ b/golang/cosmos/x/lien/keeper/account.go @@ -54,7 +54,18 @@ func (la *LienAccount) LockedCoins(ctx sdk.Context) sdk.Coins { } func (la *LienAccount) LienedLockedCoins(ctx sdk.Context) sdk.Coins { - return la.lienKeeper.GetLien(ctx, la.GetAddress()) + state := la.lienKeeper.GetAccountState(ctx, la.GetAddress()) + lien := la.lienKeeper.GetAccountLien(ctx, la.GetAddress()) + return computeLienLocked(lien.GetLien(), state.Bonded, state.Unbonding) +} + +func computeLienLocked(liened, bonded, unbonding sdk.Coins) sdk.Coins { + // We're only interested in the lien-encumbered unbonded coins. + // The bonded and unbonding coins are encumbered first, so we + // compute the remainder. + locked, _ := liened.SafeSub(bonded) + locked, _ = locked.SafeSub(unbonding) + return maxCoins(sdk.NewCoins(), locked) } func NewAccountWrapper(lk Keeper) types.AccountWrapper { diff --git a/golang/cosmos/x/lien/keeper/keeper.go b/golang/cosmos/x/lien/keeper/keeper.go index 31ca8d811ce..5b2bf303329 100644 --- a/golang/cosmos/x/lien/keeper/keeper.go +++ b/golang/cosmos/x/lien/keeper/keeper.go @@ -1,13 +1,11 @@ package keeper import ( - "encoding/json" - "fmt" "math" - "github.com/Agoric/agoric-sdk/golang/cosmos/vm" "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" ) @@ -18,15 +16,21 @@ import ( const stakingToken = "ubld" type Keeper struct { - accountKeeper *types.WrappedAccountKeeper - bankKeeper types.BankKeeper - stakingKeeper types.StakingKeeper + key sdk.StoreKey + cdc codec.Codec + + accountKeeper *types.WrappedAccountKeeper + bankKeeper types.BankKeeper + stakingKeeper types.StakingKeeper + callToController func(ctx sdk.Context, str string) (string, error) } -func NewKeeper(ak *types.WrappedAccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, +func NewKeeper(key sdk.StoreKey, cdc codec.Codec, ak *types.WrappedAccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, callToController func(ctx sdk.Context, str string) (string, error)) Keeper { return Keeper{ + key: key, + cdc: cdc, accountKeeper: ak, bankKeeper: bk, stakingKeeper: sk, @@ -41,38 +45,49 @@ func (lk Keeper) GetAccountWrapper() types.AccountWrapper { type AccountState struct { Total sdk.Coins `json:"total"` Bonded sdk.Coins `json:"bonded"` - Unbonding sdk.Coins - Locked sdk.Coins + Unbonding sdk.Coins `json:"unbonding"` + Locked sdk.Coins `json:"locked"` } -type getLiened struct { - Type string `json:"type"` // LIEN_GET_LIENED_AMOUNT - Address string `json:"address"` - CurrentTime string `json:"currentTime"` - Denom string `json:"denom"` +func (lk Keeper) GetAccountLien(ctx sdk.Context, addr sdk.AccAddress) types.AccountLien { + store := ctx.KVStore(lk.key) + bz := store.Get(types.LienByAddressKey(addr)) + if bz == nil { + return types.AccountLien{Address: addr.String()} // XXX bech32 convert? + } + return lk.DecodeLien(bz) } -func (lk Keeper) GetLien(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins { - req := getLiened{ - Type: "LIEN_GET_LIENED_AMOUNT", - Address: addr.String(), - CurrentTime: ctx.BlockTime().String(), // XXX use right format - Denom: stakingToken, - } - bz, err := json.Marshal(&req) +func (lk Keeper) SetAccountLien(ctx sdk.Context, lien types.AccountLien) { + store := ctx.KVStore(lk.key) + bz := lk.MarshalAccount(lien) + addr, err := sdk.AccAddressFromBech32(lien.Address) if err != nil { panic(err) } - reply, err := lk.callToController(ctx, string(bz)) - if err != nil { - panic(err) - } - amt := sdk.NewInt(0) - err = amt.UnmarshalJSON([]byte(reply)) - if err != nil { - panic(fmt.Sprintf(`Can't decode "%s": %v`, reply, err)) + store.Set(types.LienByAddressKey(addr), bz) +} + +func (lk Keeper) MarshalAccount(lien types.AccountLien) []byte { + return lk.cdc.MustMarshal(&lien) +} + +func (lk Keeper) DecodeLien(bz []byte) types.AccountLien { + var lien types.AccountLien + lk.cdc.MustUnmarshal(bz, &lien) + return lien +} + +func (lk Keeper) IterateAccountLiens(ctx sdk.Context, cb func(types.AccountLien) bool) { + store := ctx.KVStore(lk.key) + iterator := store.Iterator(nil, nil) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + lien := lk.DecodeLien(iterator.Value()) + if cb(lien) { + break + } } - return sdk.NewCoins(sdk.NewCoin(stakingToken, amt)) } func (lk Keeper) GetAccountState(ctx sdk.Context, addr sdk.AccAddress) AccountState { @@ -139,54 +154,3 @@ func (lk Keeper) getLocked(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins { } return vestingAccount.GetVestingCoins(ctx.BlockTime()) } - -var _ vm.PortHandler = &Keeper{} - -type portMessage struct { - Type string `json:"type"` - Address string `json:"address"` - Denom string `json:"denom"` -} - -type msgAccountState struct { - CurrentTime string `json:"currentTime"` - Total string `json:"total"` - Bonded string `json:"bonded"` - Unbonding string `json:"unbonding"` - Locked string `json:"locked"` -} - -func (lk Keeper) Receive(ctx *vm.ControllerContext, str string) (string, error) { - var msg portMessage - err := json.Unmarshal([]byte(str), &msg) - if err != nil { - return "", err - } - switch msg.Type { - case "LIEN_GET_ACCOUNT_STATE": - addr, err := sdk.AccAddressFromBech32(msg.Address) - if err != nil { - return "", fmt.Errorf("cannot converts %s to address: %w", msg.Address, err) - } - if msg.Denom != stakingToken { - return "", fmt.Errorf("bad staking token %s", msg.Denom) - } - now := ctx.Context.BlockTime() - as := lk.GetAccountState(ctx.Context, addr) - reply := msgAccountState{ - CurrentTime: now.String(), - Total: as.Total.AmountOf(msg.Denom).String(), - Bonded: as.Bonded.AmountOf(msg.Denom).String(), - Unbonding: as.Unbonding.AmountOf(msg.Denom).String(), - Locked: as.Locked.AmountOf(msg.Denom).String(), - } - bz, err := json.Marshal(&reply) - if err != nil { - return "", fmt.Errorf("cannot marshal %v: %s", reply, err) - } - return string(bz), nil - - default: - return "", fmt.Errorf("unrecognized type %s", msg.Type) - } -} diff --git a/golang/cosmos/x/lien/lien.go b/golang/cosmos/x/lien/lien.go new file mode 100644 index 00000000000..a5b637f708f --- /dev/null +++ b/golang/cosmos/x/lien/lien.go @@ -0,0 +1,122 @@ +package lien + +import ( + "encoding/json" + "fmt" + + "github.com/Agoric/agoric-sdk/golang/cosmos/vm" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type portHandler struct { + keeper Keeper +} + +type portMessage struct { + Type string `json:"type"` + Address string `json:"address"` + Denom string `json:"denom"` + Amount string `json:"amount"` +} + +type msgAccountState struct { + CurrentTime string `json:"currentTime"` + Total string `json:"total"` + Bonded string `json:"bonded"` + Unbonding string `json:"unbonding"` + Locked string `json:"locked"` +} + +func NewPortHandler(k Keeper) vm.PortHandler { + return portHandler{keeper: k} +} + +const ( + LIEN_GET_ACCOUNT_STATE = "LIEN_GET_ACCOUNT_STATE" + LIEN_SET_TOTAL = "LIEN_SET_TOTAL" +) + +func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (string, error) { + var msg portMessage + err := json.Unmarshal([]byte(str), &msg) + if err != nil { + return "", err + } + switch msg.Type { + case LIEN_GET_ACCOUNT_STATE: + return ch.handleGetAccountState(ctx.Context, msg) + + case LIEN_SET_TOTAL: + return ch.handleSetTotal(ctx.Context, msg) + } + return "", fmt.Errorf("unrecognized type %s", msg.Type) +} + +func (ch portHandler) handleGetAccountState(ctx sdk.Context, msg portMessage) (string, error) { + addr, err := sdk.AccAddressFromBech32(msg.Address) + if err != nil { + return "", fmt.Errorf("cannot convert %s to address: %w", msg.Address, err) + } + denom := msg.Denom + if err = sdk.ValidateDenom(denom); err != nil { + return "", fmt.Errorf("invalid denom %s: %w", denom, err) + } + state := ch.keeper.GetAccountState(ctx, addr) + reply := msgAccountState{ + CurrentTime: ctx.BlockTime().String(), // XXX check format + Total: state.Total.AmountOf(denom).String(), // XXX conversion + Bonded: state.Bonded.AmountOf(denom).String(), + Unbonding: state.Unbonding.AmountOf(denom).String(), + Locked: state.Locked.AmountOf(denom).String(), + } + bz, err := json.Marshal(&reply) + if err != nil { + return "", fmt.Errorf("cannot marshal %v: %w", reply, err) + } + return string(bz), nil +} + +func (ch portHandler) handleSetTotal(ctx sdk.Context, msg portMessage) (string, error) { + addr, err := sdk.AccAddressFromBech32(msg.Address) + if err != nil { + return "", fmt.Errorf("cannot convert %s to address: %w", msg.Address, err) + } + denom := msg.Denom + if err = sdk.ValidateDenom(denom); err != nil { + return "", fmt.Errorf("invalid denom %s: %w", denom, err) + } + var amount sdk.Int + err = amount.UnmarshalJSON([]byte(msg.Amount)) + if err != nil { + return "", fmt.Errorf("cannot decode lien amount %s: %w", msg.Amount, err) + } + lien := ch.keeper.GetAccountLien(ctx, addr) + oldAmount := lien.Lien.AmountOf(denom) + if amount.Equal(oldAmount) { + // no-op, no need to do anything + return "true", nil + } else if amount.LT(oldAmount) { + // always okay to reduce liened amount + diff := sdk.NewCoin(denom, oldAmount.Sub(amount)) + lien.Lien = lien.Lien.Sub(sdk.NewCoins(diff)) + ch.keeper.SetAccountLien(ctx, lien) + return "true", nil + } else { + // check if it's okay to increase lein + state := ch.keeper.GetAccountState(ctx, addr) + total := state.Total.AmountOf(denom) + bonded := state.Bonded.AmountOf(denom) + unbonding := state.Unbonding.AmountOf(denom) + locked := state.Locked.AmountOf(denom) + unbonded := total.Sub(bonded).Sub(unbonding) + unlocked := total.Sub(locked) + if amount.GT(unbonded) || amount.GT(unlocked) { + return "false", nil + } + diff := sdk.NewCoin(denom, amount.Sub(oldAmount)) + lien.Lien = lien.Lien.Add(diff) + ch.keeper.SetAccountLien(ctx, lien) + return "true", nil + } +} diff --git a/golang/cosmos/x/lien/module.go b/golang/cosmos/x/lien/module.go new file mode 100644 index 00000000000..df44e40b047 --- /dev/null +++ b/golang/cosmos/x/lien/module.go @@ -0,0 +1,115 @@ +package lien + +import ( + "encoding/json" + "fmt" + + "github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" +) + +var ( + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} +) + +// AppModuleBasic is the concrete type implementing module.AppModuleBasic. +type AppModuleBasic struct { +} + +// Name implements the module.AppModuleBasic interface. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { +} + +func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) { +} + +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + genesisState := DefaultGenesisState() + return cdc.MustMarshalJSON(&genesisState) +} + +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, data json.RawMessage) error { + var genesisState types.GenesisState + if err := cdc.UnmarshalJSON(data, &genesisState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return ValidateGenesisState(genesisState) +} + +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { +} + +func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) { +} + +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil +} + +type AppModule struct { + AppModuleBasic + keeper Keeper +} + +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + InitGenesis(ctx, am.keeper, genesisState) + return []abci.ValidatorUpdate{} +} + +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genesisState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(&genesisState) +} + +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) { +} + +func (am AppModule) Route() sdk.Route { + return sdk.Route{} +} + +func (am AppModule) QuerierRoute() string { + return "" +} + +func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { + return nil +} + +func (am AppModule) RegisterServices(module.Configurator) { +} + +func (am AppModule) ConsensusVersion() uint64 { + return 1 +} + +func (am AppModule) BeginBlock(sdk.Context, abci.RequestBeginBlock) { +} + +func (am AppModule) EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +func NewAppModule(k Keeper) module.AppModule { + return AppModule{keeper: k} +} diff --git a/golang/cosmos/x/lien/types/genesis.pb.go b/golang/cosmos/x/lien/types/genesis.pb.go new file mode 100644 index 00000000000..7d6be5eb9bf --- /dev/null +++ b/golang/cosmos/x/lien/types/genesis.pb.go @@ -0,0 +1,570 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: agoric/lien/genesis.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + 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 { + Liens []AccountLien `protobuf:"bytes,1,rep,name=liens,proto3" json:"liens"` +} + +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_4aa701dea5f962c9, []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) GetLiens() []AccountLien { + if m != nil { + return m.Liens + } + return nil +} + +type AccountLien struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Lien github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=lien,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"lien"` +} + +func (m *AccountLien) Reset() { *m = AccountLien{} } +func (m *AccountLien) String() string { return proto.CompactTextString(m) } +func (*AccountLien) ProtoMessage() {} +func (*AccountLien) Descriptor() ([]byte, []int) { + return fileDescriptor_4aa701dea5f962c9, []int{1} +} +func (m *AccountLien) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AccountLien) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AccountLien.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 *AccountLien) XXX_Merge(src proto.Message) { + xxx_messageInfo_AccountLien.Merge(m, src) +} +func (m *AccountLien) XXX_Size() int { + return m.Size() +} +func (m *AccountLien) XXX_DiscardUnknown() { + xxx_messageInfo_AccountLien.DiscardUnknown(m) +} + +var xxx_messageInfo_AccountLien proto.InternalMessageInfo + +func (m *AccountLien) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *AccountLien) GetLien() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Lien + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "agoric.lien.GenesisState") + proto.RegisterType((*AccountLien)(nil), "agoric.lien.AccountLien") +} + +func init() { proto.RegisterFile("agoric/lien/genesis.proto", fileDescriptor_4aa701dea5f962c9) } + +var fileDescriptor_4aa701dea5f962c9 = []byte{ + // 305 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xbf, 0x4e, 0xf3, 0x30, + 0x14, 0xc5, 0xe3, 0xef, 0x2b, 0x20, 0x5c, 0xa6, 0x88, 0x21, 0xed, 0xe0, 0xa2, 0x4e, 0x5d, 0xb0, + 0x29, 0x20, 0x21, 0xb1, 0xb5, 0x0c, 0x48, 0x88, 0x85, 0xb2, 0xb1, 0x20, 0xc7, 0xb1, 0x8c, 0x45, + 0xeb, 0x5b, 0xc5, 0x2e, 0x82, 0x37, 0x60, 0xe4, 0x11, 0x98, 0x79, 0x92, 0x8e, 0x1d, 0x99, 0x00, + 0x25, 0x0b, 0x8f, 0x81, 0x6c, 0xb7, 0x52, 0x26, 0xff, 0xb9, 0xf7, 0xfe, 0xce, 0xb9, 0x07, 0x77, + 0xb8, 0x82, 0x52, 0x0b, 0x36, 0xd5, 0xd2, 0x30, 0x25, 0x8d, 0xb4, 0xda, 0xd2, 0x79, 0x09, 0x0e, + 0xd2, 0x76, 0x2c, 0x51, 0x5f, 0xea, 0xee, 0x2b, 0x50, 0x10, 0xfe, 0x99, 0xbf, 0xc5, 0x96, 0x2e, + 0x11, 0x60, 0x67, 0x60, 0x59, 0xce, 0xad, 0x64, 0x4f, 0xc3, 0x5c, 0x3a, 0x3e, 0x64, 0x02, 0xb4, + 0x89, 0xf5, 0xfe, 0x15, 0xde, 0xbb, 0x8c, 0xcc, 0x5b, 0xc7, 0x9d, 0x4c, 0x4f, 0xf1, 0x96, 0xa7, + 0xd9, 0x0c, 0x1d, 0xfc, 0x1f, 0xb4, 0x8f, 0x33, 0xda, 0x90, 0xa0, 0x23, 0x21, 0x60, 0x61, 0xdc, + 0xb5, 0x96, 0x66, 0xdc, 0x5a, 0x7e, 0xf5, 0x92, 0x49, 0x6c, 0x3e, 0x6f, 0xfd, 0xbe, 0xf7, 0x92, + 0xfe, 0x2b, 0xc2, 0xed, 0x46, 0x4b, 0x9a, 0xe1, 0x1d, 0x5e, 0x14, 0xa5, 0xb4, 0x9e, 0x86, 0x06, + 0xbb, 0x93, 0xcd, 0x33, 0xbd, 0xc7, 0x2d, 0x3f, 0x98, 0xfd, 0x0b, 0x22, 0x1d, 0x1a, 0x4d, 0x52, + 0x6f, 0x92, 0xae, 0x4d, 0xd2, 0x0b, 0xd0, 0x66, 0x7c, 0xe4, 0x55, 0x3e, 0xbe, 0x7b, 0x03, 0xa5, + 0xdd, 0xc3, 0x22, 0xa7, 0x02, 0x66, 0x6c, 0xbd, 0x51, 0x3c, 0x0e, 0x6d, 0xf1, 0xc8, 0xdc, 0xcb, + 0x5c, 0xda, 0x30, 0x60, 0x27, 0x01, 0x3c, 0xbe, 0x59, 0x56, 0x04, 0xad, 0x2a, 0x82, 0x7e, 0x2a, + 0x82, 0xde, 0x6a, 0x92, 0xac, 0x6a, 0x92, 0x7c, 0xd6, 0x24, 0xb9, 0x3b, 0x6b, 0x90, 0x46, 0x31, + 0xd9, 0xb8, 0x62, 0x20, 0x29, 0x98, 0x72, 0xa3, 0x36, 0x12, 0xcf, 0x31, 0xf4, 0x80, 0xcf, 0xb7, + 0x43, 0x60, 0x27, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf9, 0x1c, 0x03, 0x50, 0x90, 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 + if len(m.Liens) > 0 { + for iNdEx := len(m.Liens) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Liens[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *AccountLien) 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 *AccountLien) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AccountLien) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Lien) > 0 { + for iNdEx := len(m.Lien) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Lien[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address))) + 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 + if len(m.Liens) > 0 { + for _, e := range m.Liens { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *AccountLien) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.Lien) > 0 { + for _, e := range m.Lien { + l = e.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 Liens", 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.Liens = append(m.Liens, AccountLien{}) + if err := m.Liens[len(m.Liens)-1].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) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AccountLien) 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: AccountLien: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AccountLien: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", 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.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Lien", 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.Lien = append(m.Lien, types.Coin{}) + if err := m.Lien[len(m.Lien)-1].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) || (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") +) diff --git a/golang/cosmos/x/lien/types/key.go b/golang/cosmos/x/lien/types/key.go new file mode 100644 index 00000000000..922b97203de --- /dev/null +++ b/golang/cosmos/x/lien/types/key.go @@ -0,0 +1,19 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + ModuleName = "lien" + + StoreKey = ModuleName +) + +var ( + LienByAddressPrefix = []byte{0x01} +) + +func LienByAddressKey(addr sdk.AccAddress) []byte { + return append(LienByAddressPrefix, addr.Bytes()...) +}