diff --git a/.gitignore b/.gitignore index 50eb1164..8c806e68 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ *.test *gentxs *node* +*__debug__* # Output of the go coverage tool, specifically when used with LiteIDE diff --git a/app/app.go b/app/app.go index c1ca54fd..c487bf3d 100644 --- a/app/app.go +++ b/app/app.go @@ -7,6 +7,10 @@ import ( "os" "path/filepath" + "github.com/gorilla/mux" + "github.com/rakyll/statik/fs" + "github.com/spf13/cast" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" @@ -30,20 +34,20 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - ibcclientHandler "github.com/cosmos/ibc-go/v5/modules/core/02-client/client" - "github.com/gorilla/mux" - "github.com/rakyll/statik/fs" - "github.com/sge-network/sge/app/keepers" - sgeappparams "github.com/sge-network/sge/app/params" - "github.com/sge-network/sge/app/upgrades" - v1 "github.com/sge-network/sge/app/upgrades/v1" - "github.com/spf13/cast" + abci "github.com/tendermint/tendermint/abci/types" tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" + ibcclientHandler "github.com/cosmos/ibc-go/v5/modules/core/02-client/client" + + "github.com/sge-network/sge/app/keepers" + sgeappparams "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/app/upgrades" + v1 "github.com/sge-network/sge/app/upgrades/v1" + // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) diff --git a/app/app_test.go b/app/app_test.go index 941f665d..7ebed7a7 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -3,11 +3,14 @@ package app_test import ( "testing" - sdksimapp "github.com/cosmos/cosmos-sdk/simapp" - "github.com/sge-network/sge/app" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/libs/log" tmdb "github.com/tendermint/tm-db" + + sdksimapp "github.com/cosmos/cosmos-sdk/simapp" + + "github.com/sge-network/sge/app" ) func TestApp(t *testing.T) { diff --git a/app/encoding.go b/app/encoding.go index b36193d5..c5d83b59 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -2,6 +2,7 @@ package app import ( "github.com/cosmos/cosmos-sdk/std" + "github.com/sge-network/sge/app/params" ) diff --git a/app/export.go b/app/export.go index 49414402..c2d99b4d 100644 --- a/app/export.go +++ b/app/export.go @@ -5,12 +5,13 @@ import ( "fmt" "log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // ExportAppStateAndValidators exports the state of the application for a genesis diff --git a/app/export_test.go b/app/export_test.go index 41d5756e..768cfc91 100644 --- a/app/export_test.go +++ b/app/export_test.go @@ -3,8 +3,9 @@ package app_test import ( "testing" - simappUtil "github.com/sge-network/sge/testutil/simapp" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/simapp" ) func TestExport(t *testing.T) { @@ -23,8 +24,8 @@ func TestExport(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tApp, _, err := simappUtil.GetTestObjectsWithOptions( - simappUtil.Options{ + tApp, _, err := simapp.GetTestObjectsWithOptions( + simapp.Options{ CreateGenesisValidators: true, }, ) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 173e9124..d446e49c 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -86,6 +86,14 @@ import ( orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" orderbookmoduletypes "github.com/sge-network/sge/x/orderbook/types" + subaccountmodule "github.com/sge-network/sge/x/subaccount" + subaccountmodulekeeper "github.com/sge-network/sge/x/subaccount/keeper" + subaccountmoduletypes "github.com/sge-network/sge/x/subaccount/types" + + rewardmodule "github.com/sge-network/sge/x/reward" + rewardmodulekeeper "github.com/sge-network/sge/x/reward/keeper" + rewardmoduletypes "github.com/sge-network/sge/x/reward/types" + // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) @@ -114,19 +122,23 @@ type AppKeepers struct { GroupKeeper groupkeeper.Keeper //// SGE keepers \\\\ - BetKeeper *betmodulekeeper.Keeper - MarketKeeper *marketmodulekeeper.Keeper - MintKeeper mintkeeper.Keeper - HouseKeeper *housemodulekeeper.Keeper - OrderbookKeeper *orderbookmodulekeeper.Keeper - OVMKeeper *ovmmodulekeeper.Keeper + BetKeeper *betmodulekeeper.Keeper + MarketKeeper *marketmodulekeeper.Keeper + MintKeeper mintkeeper.Keeper + HouseKeeper *housemodulekeeper.Keeper + OrderbookKeeper *orderbookmodulekeeper.Keeper + OVMKeeper *ovmmodulekeeper.Keeper + RewardKeeper *rewardmodulekeeper.Keeper + SubaccountKeeper *subaccountmodulekeeper.Keeper //// SGE modules \\\\ - BetModule betmodule.AppModule - MarketModule marketmodule.AppModule - HouseModule housemodule.AppModule - OrderbookModule orderbookmodule.AppModule - OVMModule ovmmodule.AppModule + BetModule betmodule.AppModule + MarketModule marketmodule.AppModule + HouseModule housemodule.AppModule + OrderbookModule orderbookmodule.AppModule + OVMModule ovmmodule.AppModule + RewardModule rewardmodule.AppModule + SubaccountModule subaccountmodule.AppModule // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -381,7 +393,7 @@ func NewAppKeeper( appKeepers.SlashingKeeper, ) - //// SGE keepers \\\\ + // // SGE keepers \\\\ appKeepers.OrderbookKeeper = orderbookmodulekeeper.NewKeeper( appCodec, @@ -436,7 +448,42 @@ func NewAppKeeper( ) appKeepers.OrderbookKeeper.SetHouseKeeper(appKeepers.HouseKeeper) - //// SGE modules \\\\ + appKeepers.SubaccountKeeper = subaccountmodulekeeper.NewKeeper( + appCodec, + appKeepers.keys[subaccountmoduletypes.StoreKey], + appKeepers.GetSubspace(subaccountmoduletypes.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.OVMKeeper, + appKeepers.BetKeeper, + appKeepers.OrderbookKeeper, + appKeepers.HouseKeeper, + ) + + appKeepers.RewardKeeper = rewardmodulekeeper.NewKeeper( + appCodec, + appKeepers.keys[rewardmoduletypes.StoreKey], + appKeepers.keys[rewardmoduletypes.MemStoreKey], + appKeepers.GetSubspace(rewardmoduletypes.ModuleName), + appKeepers.BetKeeper, + appKeepers.OVMKeeper, + appKeepers.SubaccountKeeper, + rewardmodulekeeper.SdkExpectedKeepers{ + AuthzKeeper: appKeepers.AuthzKeeper, + BankKeeper: appKeepers.BankKeeper, + AccountKeeper: appKeepers.AccountKeeper, + }, + ) + + // ** Hooks ** \\ + + appKeepers.OrderbookKeeper.SetHooks( + orderbookmoduletypes.NewMultiOrderBookHooks( + appKeepers.SubaccountKeeper.Hooks(), + ), + ) + + // // SGE modules \\\\ appKeepers.BetModule = betmodule.NewAppModule( appCodec, @@ -468,6 +515,14 @@ func NewAppKeeper( appKeepers.AccountKeeper, appKeepers.BankKeeper, ) + appKeepers.RewardModule = rewardmodule.NewAppModule( + appCodec, + *appKeepers.RewardKeeper, + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + ) + + appKeepers.SubaccountModule = subaccountmodule.NewAppModule(*appKeepers.SubaccountKeeper) //// IBC modules \\\\ appKeepers.IBCModule = ibc.NewAppModule(appKeepers.IBCKeeper) @@ -530,6 +585,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, paramsKeeper.Subspace(orderbookmoduletypes.ModuleName) paramsKeeper.Subspace(ovmmoduletypes.ModuleName) paramsKeeper.Subspace(housemoduletypes.ModuleName) + paramsKeeper.Subspace(rewardmoduletypes.ModuleName) + paramsKeeper.Subspace(subaccountmoduletypes.ModuleName) return paramsKeeper } diff --git a/app/keepers/keys.go b/app/keepers/keys.go index aa207d4e..4d9c427d 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -16,6 +16,7 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types" ibcfeetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types" @@ -23,12 +24,13 @@ import ( ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host" betmoduletypes "github.com/sge-network/sge/x/bet/types" - ovmmoduletypes "github.com/sge-network/sge/x/ovm/types" - housemoduletypes "github.com/sge-network/sge/x/house/types" marketmoduletypes "github.com/sge-network/sge/x/market/types" minttypes "github.com/sge-network/sge/x/mint/types" orderbookmoduletypes "github.com/sge-network/sge/x/orderbook/types" + ovmmoduletypes "github.com/sge-network/sge/x/ovm/types" + rewardmoduletypes "github.com/sge-network/sge/x/reward/types" + subaccounttypes "github.com/sge-network/sge/x/subaccount/types" // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -49,6 +51,8 @@ func (appKeepers *AppKeepers) GenerateKeys() { marketmoduletypes.StoreKey, ovmmoduletypes.StoreKey, housemoduletypes.StoreKey, + rewardmoduletypes.StoreKey, + subaccounttypes.StoreKey, ) // Define transient store keys diff --git a/app/modules.go b/app/modules.go index 29d285fc..fd2ded30 100644 --- a/app/modules.go +++ b/app/modules.go @@ -35,6 +35,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" ibcfee "github.com/cosmos/ibc-go/v5/modules/apps/29-fee" @@ -43,24 +44,25 @@ import ( ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v5/modules/core" ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host" - sgeappparams "github.com/sge-network/sge/app/params" - "github.com/sge-network/sge/x/mint" - minttypes "github.com/sge-network/sge/x/mint/types" + sgeappparams "github.com/sge-network/sge/app/params" betmodule "github.com/sge-network/sge/x/bet" betmoduletypes "github.com/sge-network/sge/x/bet/types" - + housemodule "github.com/sge-network/sge/x/house" + housemoduletypes "github.com/sge-network/sge/x/house/types" marketmodule "github.com/sge-network/sge/x/market" marketmoduletypes "github.com/sge-network/sge/x/market/types" - + mintmodule "github.com/sge-network/sge/x/mint" + minttypes "github.com/sge-network/sge/x/mint/types" orderbookmodule "github.com/sge-network/sge/x/orderbook" orderbookmoduletypes "github.com/sge-network/sge/x/orderbook/types" - ovmmodule "github.com/sge-network/sge/x/ovm" ovmmoduletypes "github.com/sge-network/sge/x/ovm/types" + subaccountmodule "github.com/sge-network/sge/x/subaccount" + subaccounttypes "github.com/sge-network/sge/x/subaccount/types" - housemodule "github.com/sge-network/sge/x/house" - housemoduletypes "github.com/sge-network/sge/x/house/types" + rewardmodule "github.com/sge-network/sge/x/reward" + rewardmoduletypes "github.com/sge-network/sge/x/reward/types" // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -84,6 +86,7 @@ var mAccPerms = map[string][]string{ betmoduletypes.BetFeeCollectorFunder{}.GetModuleAcc(): nil, housemoduletypes.HouseFeeCollectorFunder{}.GetModuleAcc(): nil, orderbookmoduletypes.OrderBookLiquidityFunder{}.GetModuleAcc(): nil, + rewardmoduletypes.RewardPoolFunder{}.GetModuleAcc(): nil, } // ModuleBasics defines the module BasicManager is in charge of setting up basic, @@ -95,7 +98,7 @@ var ModuleBasics = module.NewBasicManager( bank.AppModuleBasic{}, capability.AppModuleBasic{}, staking.AppModuleBasic{}, - mint.AppModuleBasic{}, + mintmodule.AppModuleBasic{}, distr.AppModuleBasic{}, gov.NewAppModuleBasic(getGovProposalHandlers()), params.AppModuleBasic{}, @@ -118,6 +121,8 @@ var ModuleBasics = module.NewBasicManager( orderbookmodule.AppModuleBasic{}, ovmmodule.AppModuleBasic{}, housemodule.AppModuleBasic{}, + rewardmodule.AppModuleBasic{}, + subaccountmodule.AppModuleBasic{}, ) func appModules( @@ -140,7 +145,7 @@ func appModules( capability.NewAppModule(appCodec, *app.CapabilityKeeper), crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, app.BankKeeper), + mintmodule.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, app.BankKeeper), slashing.NewAppModule( appCodec, app.SlashingKeeper, @@ -189,6 +194,8 @@ func appModules( app.OrderbookModule, app.OVMModule, app.HouseModule, + app.RewardModule, + app.SubaccountModule, // this line is u } } @@ -214,7 +221,7 @@ func simulationModules( app.interfaceRegistry, ), gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), + mintmodule.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), distr.NewAppModule( appCodec, @@ -251,6 +258,7 @@ func simulationModules( app.BetModule, app.MarketModule, app.OVMModule, + app.RewardModule, } } @@ -285,6 +293,8 @@ func orderBeginBlockers() []string { orderbookmoduletypes.ModuleName, ovmmoduletypes.ModuleName, housemoduletypes.ModuleName, + rewardmoduletypes.ModuleName, + subaccounttypes.ModuleName, } } @@ -316,6 +326,8 @@ func orderEndBlockers() []string { orderbookmoduletypes.ModuleName, ovmmoduletypes.ModuleName, housemoduletypes.ModuleName, + rewardmoduletypes.ModuleName, + subaccounttypes.ModuleName, } } @@ -347,5 +359,7 @@ func orderInitBlockers() []string { orderbookmoduletypes.ModuleName, ovmmoduletypes.ModuleName, housemoduletypes.ModuleName, + rewardmoduletypes.ModuleName, + subaccounttypes.ModuleName, } } diff --git a/app/prefix.go b/app/prefix.go index 8e896ff9..ec0a97e7 100644 --- a/app/prefix.go +++ b/app/prefix.go @@ -2,6 +2,7 @@ package app import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/app/params" ) diff --git a/app/sim_test.go b/app/sim_test.go index fb26dcd8..65918d7b 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -6,17 +6,20 @@ import ( "os" "testing" + "github.com/stretchr/testify/require" + + "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/libs/rand" + dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/baseapp" sdksimapp "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/helpers" "github.com/cosmos/cosmos-sdk/store" simulation2 "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/sge-network/sge/app" - "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/libs/rand" - dbm "github.com/tendermint/tm-db" ) // SimAppChainID hardcoded chainID for simulation diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 40399296..b6f579fc 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -3,6 +3,7 @@ package upgrades import ( store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/sge-network/sge/app/keepers" ) diff --git a/cmd/sged/cmd/genaccounts.go b/cmd/sged/cmd/genaccounts.go index 5a8a46a8..3a06e359 100644 --- a/cmd/sged/cmd/genaccounts.go +++ b/cmd/sged/cmd/genaccounts.go @@ -6,6 +6,8 @@ import ( "errors" "fmt" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -17,7 +19,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - "github.com/spf13/cobra" ) const ( @@ -105,7 +106,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa return cmd } -func getAccountAddress(cmd *cobra.Command, address string, homeDir string, clientCtx client.Context) (sdk.AccAddress, error) { +func getAccountAddress(cmd *cobra.Command, address, homeDir string, clientCtx client.Context) (sdk.AccAddress, error) { addr, err := sdk.AccAddressFromBech32(address) if err != nil { inBuf := bufio.NewReader(cmd.InOrStdin()) diff --git a/cmd/sged/cmd/genaccounts_test.go b/cmd/sged/cmd/genaccounts_test.go index 7a10793c..3464a1ac 100644 --- a/cmd/sged/cmd/genaccounts_test.go +++ b/cmd/sged/cmd/genaccounts_test.go @@ -5,13 +5,15 @@ import ( "path/filepath" "testing" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/cmd/sged/cmd" "github.com/sge-network/sge/testutil/network" - "github.com/stretchr/testify/require" ) func TestAddGenesisAccountCmdPanic(t *testing.T) { diff --git a/cmd/sged/cmd/root.go b/cmd/sged/cmd/root.go index 3767e21c..3903f904 100644 --- a/cmd/sged/cmd/root.go +++ b/cmd/sged/cmd/root.go @@ -5,6 +5,14 @@ import ( "os" "path/filepath" + "github.com/spf13/cast" + "github.com/spf13/cobra" + + tmcfg "github.com/tendermint/tendermint/config" + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -24,14 +32,9 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/app/params" - "github.com/spf13/cast" - "github.com/spf13/cobra" - tmcfg "github.com/tendermint/tendermint/config" - tmcli "github.com/tendermint/tendermint/libs/cli" - "github.com/tendermint/tendermint/libs/log" - dbm "github.com/tendermint/tm-db" ) // NewRootCmd creates a new root command for simd. It is called once in the diff --git a/cmd/sged/main.go b/cmd/sged/main.go index 3160c6e1..c3351621 100644 --- a/cmd/sged/main.go +++ b/cmd/sged/main.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/cmd/sged/cmd" ) diff --git a/go.mod b/go.mod index c0b06a12..d89f45e6 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/sge-network/sge go 1.19 require ( + cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.1.2 github.com/cosmos/cosmos-sdk v0.46.14 github.com/cosmos/gogoproto v1.4.11 @@ -61,7 +62,6 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.1 // indirect cloud.google.com/go/storage v1.30.1 // indirect - cosmossdk.io/errors v1.0.0-beta.7 // indirect filippo.io/edwards25519 v1.0.0-rc.1 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/proto/sge/bet/bet.proto b/proto/sge/bet/bet.proto index a5036f32..d581ad26 100644 --- a/proto/sge/bet/bet.proto +++ b/proto/sge/bet/bet.proto @@ -40,13 +40,13 @@ message Bet { // amount is the wager amount. string amount = 6 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; // fee is the betting fee user needs to pay for placing a bet string fee = 7 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; @@ -163,13 +163,13 @@ message BetFulfillment { [ (gogoproto.moretags) = "yaml:\"participation_index\"" ]; // bet amount fulfilled by the participation string bet_amount = 3 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"bet_amount\"" ]; // payout_profit is the fulfilled profit by the participation. string payout_profit = 4 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"payout_profit\"" ]; diff --git a/proto/sge/bet/constraints.proto b/proto/sge/bet/constraints.proto index 6e3f4d61..9de48fef 100644 --- a/proto/sge/bet/constraints.proto +++ b/proto/sge/bet/constraints.proto @@ -9,13 +9,13 @@ option go_package = "github.com/sge-network/sge/x/bet/types"; message Constraints { // min_amount is the minimum allowed bet amount. string min_amount = 1 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; // fee is the fee that the bettor needs to pay to bet. string fee = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; } \ No newline at end of file diff --git a/proto/sge/bet/wager.proto b/proto/sge/bet/wager.proto index 7b536162..b44c2900 100644 --- a/proto/sge/bet/wager.proto +++ b/proto/sge/bet/wager.proto @@ -16,7 +16,7 @@ message WagerProps { // amount is the wager amount. string amount = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; diff --git a/proto/sge/house/authz.proto b/proto/sge/house/authz.proto index a26f9470..a2fe4d37 100644 --- a/proto/sge/house/authz.proto +++ b/proto/sge/house/authz.proto @@ -10,7 +10,7 @@ option go_package = "github.com/sge-network/sge/x/house/types"; message DepositAuthorization { string spend_limit = 1 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; } @@ -20,7 +20,7 @@ message DepositAuthorization { message WithdrawAuthorization { string withdraw_limit = 1 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; } \ No newline at end of file diff --git a/proto/sge/house/deposit.proto b/proto/sge/house/deposit.proto index 8016f94c..c77e5e18 100644 --- a/proto/sge/house/deposit.proto +++ b/proto/sge/house/deposit.proto @@ -33,7 +33,7 @@ message Deposit { // amount is the amount being deposited on an order book to be a house string amount = 5 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"amount\"" ]; @@ -44,7 +44,7 @@ message Deposit { // total_withdrawal_amount is the total amount withdrawn from the liquidity // provided string total_withdrawal_amount = 7 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"total_withdrawal_amount\"" ]; diff --git a/proto/sge/house/params.proto b/proto/sge/house/params.proto index d5e4f6ca..70bcc815 100644 --- a/proto/sge/house/params.proto +++ b/proto/sge/house/params.proto @@ -12,7 +12,7 @@ message Params { // min_deposit is the minimum acceptable deposit amount. string min_deposit = 1 [ (gogoproto.moretags) = "yaml:\"min_deposit\"", - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; diff --git a/proto/sge/house/tx.proto b/proto/sge/house/tx.proto index 9f5cb9d7..47147b36 100644 --- a/proto/sge/house/tx.proto +++ b/proto/sge/house/tx.proto @@ -35,7 +35,7 @@ message MsgDeposit { ]; // amount is the amount being deposited on an order book to be a house string amount = 3 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; // ticket is the jwt ticket data. @@ -77,7 +77,7 @@ message MsgWithdraw { WithdrawalMode mode = 4 [ (gogoproto.moretags) = "yaml:\"mode\"" ]; // amount is the requested withdrawal amount string amount = 5 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; // ticket is the jwt ticket data. diff --git a/proto/sge/house/withdraw.proto b/proto/sge/house/withdraw.proto index 27b5cc29..7601132c 100644 --- a/proto/sge/house/withdraw.proto +++ b/proto/sge/house/withdraw.proto @@ -42,7 +42,7 @@ message Withdrawal { // amount is the amount being withdrawn. string amount = 7 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"amount\"" ]; diff --git a/proto/sge/mint/params.proto b/proto/sge/mint/params.proto index d19a4d9d..9966d8ec 100644 --- a/proto/sge/mint/params.proto +++ b/proto/sge/mint/params.proto @@ -25,7 +25,7 @@ message Params { // exclude_amount is the excluded amount form being calculated in inflation. string exclude_amount = 4 [ (gogoproto.moretags) = "yaml:\"exclude_amount\"", - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; } diff --git a/proto/sge/orderbook/exposure.proto b/proto/sge/orderbook/exposure.proto index 0234b2b8..48401ca8 100644 --- a/proto/sge/orderbook/exposure.proto +++ b/proto/sge/orderbook/exposure.proto @@ -61,14 +61,14 @@ message ParticipationExposure { // exposure is the total exposure taken on given odds. string exposure = 4 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"exposure\"" ]; // bet_amount is the total bet amount corresponding to the exposure. string bet_amount = 5 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"bet_amount\"" ]; diff --git a/proto/sge/orderbook/participation.proto b/proto/sge/orderbook/participation.proto index 41d9d0eb..2961fc3b 100644 --- a/proto/sge/orderbook/participation.proto +++ b/proto/sge/orderbook/participation.proto @@ -27,21 +27,21 @@ message OrderBookParticipation { // liquidity is the total initial liquidity provided. string liquidity = 4 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"liquidity\"" ]; // fee is the amount of fee to be paid if participation happens. string fee = 5 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"fee\"" ]; // current_round_liquidity is the liquidity provided for the current round. string current_round_liquidity = 6 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"current_round_liquidity\"" ]; @@ -53,7 +53,7 @@ message OrderBookParticipation { // total_bet_amount is the total bet amount corresponding to all exposures. string total_bet_amount = 8 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"total_bet_amount\"" ]; @@ -61,21 +61,21 @@ message OrderBookParticipation { // current_round_total_bet_amount is the total bet amount corresponding to all // exposures in the current round. string current_round_total_bet_amount = 9 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"current_round_total_bet_amount\"" ]; // max_loss is the total bet amount corresponding to all exposure. string max_loss = 10 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"max_loss\"" ]; // current_round_max_loss is the current round max loss. string current_round_max_loss = 11 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"current_round_max_loss\"" ]; @@ -91,7 +91,7 @@ message OrderBookParticipation { // actual_profit is the actual profit of the participation fulfillment. string actual_profit = 13 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"actual_profit\"" ]; diff --git a/proto/sge/reward/campaign.proto b/proto/sge/reward/campaign.proto new file mode 100644 index 00000000..57839865 --- /dev/null +++ b/proto/sge/reward/campaign.proto @@ -0,0 +1,51 @@ +syntax = "proto3"; +package sgenetwork.sge.reward; + +import "gogoproto/gogo.proto"; +import "sge/reward/reward.proto"; + +option go_package = "github.com/sge-network/sge/x/reward/types"; + +// Campaign is type for defining the campaign properties. +message Campaign { + // creator is the address of campaign creator. + string creator = 1; + string uid = 2 [ + (gogoproto.customname) = "UID", + (gogoproto.jsontag) = "uid", + json_name = "uid" + ]; + string funder_address = 3; + // start_ts is the start timestamp of a campaign. + uint64 start_ts = 4 [ + (gogoproto.customname) = "StartTS", + (gogoproto.jsontag) = "start_ts", + json_name = "start_ts" + ]; + // end_ts is the end timestamp of a campaign. + uint64 end_ts = 5 [ + (gogoproto.customname) = "EndTS", + (gogoproto.jsontag) = "end_ts", + json_name = "end_ts" + ]; + // reward_type is the type of defined reward. + RewardType reward_type = 6; + // reward_defs is the list of definitions of the campaign rewards. + repeated Definition reward_defs = 7 [ (gogoproto.nullable) = false ]; + // pool is the tracker of pool funds of the campaign. + Pool pool = 8 [ (gogoproto.nullable) = false ]; +} + +// Pool is the type for the campaign funding pool. +message Pool { + string total = 1 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"total\"" + ]; + string spent = 2 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"spent\"" + ]; +} \ No newline at end of file diff --git a/proto/sge/reward/genesis.proto b/proto/sge/reward/genesis.proto new file mode 100644 index 00000000..2282b22f --- /dev/null +++ b/proto/sge/reward/genesis.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package sgenetwork.sge.reward; + +import "gogoproto/gogo.proto"; +import "sge/reward/params.proto"; +import "sge/reward/campaign.proto"; + +option go_package = "github.com/sge-network/sge/x/reward/types"; + +// GenesisState defines the reward module's genesis state. +message GenesisState { + Params params = 1 [ (gogoproto.nullable) = false ]; + repeated Campaign campaign_list = 2 [ (gogoproto.nullable) = false ]; +} diff --git a/proto/sge/reward/params.proto b/proto/sge/reward/params.proto new file mode 100644 index 00000000..c82a1059 --- /dev/null +++ b/proto/sge/reward/params.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package sgenetwork.sge.reward; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/sge-network/sge/x/reward/types"; + +// Params defines the parameters for the module. +message Params { option (gogoproto.goproto_stringer) = false; } diff --git a/proto/sge/reward/query.proto b/proto/sge/reward/query.proto new file mode 100644 index 00000000..5e005b85 --- /dev/null +++ b/proto/sge/reward/query.proto @@ -0,0 +1,59 @@ +syntax = "proto3"; + +package sgenetwork.sge.reward; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "sge/reward/params.proto"; +import "sge/reward/campaign.proto"; + +option go_package = "github.com/sge-network/sge/x/reward/types"; + +// Query defines the gRPC querier service. +service Query { + + // Parameters queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/sge-network/sge/reward/params"; + } + + // Queries an specific Campaign item. + rpc Campaign(QueryCampaignRequest) returns (QueryCampaignResponse) { + option (google.api.http).get = "/sge-network/sge/reward/campaign/{uid}"; + } + + // Queries list of all Campaign items. + rpc CampaignAll(QueryCampaignAllRequest) returns (QueryCampaignAllResponse) { + option (google.api.http).get = "/sge-network/sge/reward/campaign"; + } +} +// QueryParamsRequest is request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + + // params holds all the parameters of this module. + Params params = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryCampaignRequest is request body of the query campaign endpoint. +message QueryCampaignRequest { string uid = 1; } + +// QueryCampaignRequest is response body of the query campaign endpoint. +message QueryCampaignResponse { + Campaign campaign = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryCampaignAllRequest is request body of the query all campaigns endpoint. +message QueryCampaignAllRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// QueryCampaignAllResponse is response body of the query all campaigns +// endpoint. +message QueryCampaignAllResponse { + repeated Campaign campaign = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} diff --git a/proto/sge/reward/reward.proto b/proto/sge/reward/reward.proto new file mode 100644 index 00000000..a19d92e9 --- /dev/null +++ b/proto/sge/reward/reward.proto @@ -0,0 +1,101 @@ +syntax = "proto3"; +package sgenetwork.sge.reward; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/sge-network/sge/x/reward/types"; + +// RewardCommon is the type for common data of a reward. +message RewardCommon { + string creator = 1; + string campaign_uid = 2 [ + (gogoproto.customname) = "CampaignUID", + (gogoproto.jsontag) = "campaign_uid", + json_name = "campaign_uid" + ]; + uint64 ts = 3 [ + (gogoproto.customname) = "TS", + (gogoproto.jsontag) = "ts", + json_name = "ts" + ]; +} + +// Definition is the type for reward declaration for a campaign. +message Definition { + ReceiverType rec_type = 1; + ReceiverAccType rec_acc_type = 2; + string amount = 3 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"amount\"" + ]; + uint64 unlock_ts = 4 [ + (gogoproto.customname) = "UnlockTS", + (gogoproto.jsontag) = "unlock_ts", + json_name = "unlock_ts" + ]; +} + +// Distribution is the type for the distribution of a reward. +message Distribution { + string acc_addr = 1; + Allocation allocation = 2 [ (gogoproto.nullable) = false ]; +} + +// Allocation is the distribution allocation of the rewards. +message Allocation { + string amount = 1 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"amount\"" + ]; + ReceiverAccType rec_acc_type = 2; + uint64 unlock_ts = 3 [ + (gogoproto.customname) = "UnlockTS", + (gogoproto.jsontag) = "unlock_ts", + json_name = "unlock_ts" + ]; +} + +// Receiver is the type for reward receiver properties. +message Receiver { + ReceiverType rec_type = 1; + string addr = 2; +} + +// RewardType defines supported types of rewards of reward module. +enum RewardType { + // the invalid or unknown + REWARD_TYPE_UNSPECIFIED = 0; + // signup reward + REWARD_TYPE_SIGNUP = 1; + // referral reward + REWARD_TYPE_REFERRAL = 2; + // affiliation reward + REWARD_TYPE_AFFILIATION = 3; + // noloss bets reward + REWARD_TYPE_NOLOSS_BETS = 4; +} + +// ReceiverAccType defines supported types account types for reward +// distribution. +enum ReceiverAccType { + // the invalid or unknown + RECEIVER_ACC_TYPE_UNSPECIFIED = 0; + // main account + RECEIVER_ACC_TYPE_MAIN = 1; + // sub account + RECEIVER_ACC_TYPE_SUB = 2; +} + +// ReceiverType defines all of reward receiver types in the system. +enum ReceiverType { + // the invalid or unknown + RECEIVER_TYPE_UNSPECIFIED = 0; + // single receiver account + RECEIVER_TYPE_SINGLE = 1; + // referrer + RECEIVER_TYPE_REFERRER = 2; + // referee + RECEIVER_TYPE_REFEREE = 3; +} diff --git a/proto/sge/reward/ticket.proto b/proto/sge/reward/ticket.proto new file mode 100644 index 00000000..f6c7f4ed --- /dev/null +++ b/proto/sge/reward/ticket.proto @@ -0,0 +1,45 @@ +syntax = "proto3"; +package sgenetwork.sge.reward; + +import "gogoproto/gogo.proto"; +import "sge/reward/reward.proto"; + +option go_package = "github.com/sge-network/sge/x/reward/types"; + +// CreateCampaignPayload is the type for campaign creation payload. +message CreateCampaignPayload { + string funder_address = 1; + uint64 start_ts = 2; + uint64 end_ts = 3; + RewardType type = 4; + repeated Definition reward_defs = 6 [ (gogoproto.nullable) = false ]; + string pool_amount = 7 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"pool_amount\"" + ]; +} + +// UpdateCampaignPayload is the type for campaign update payload. +message UpdateCampaignPayload { uint64 end_ts = 1; } + +// ApplySignupRewardPayload is the signup reward ticket payload type. +message ApplySignupRewardPayload { + Receiver receiver = 1 [ (gogoproto.nullable) = false ]; +} + +// ApplyRerferralRewardPayload is the referral reward ticket payload type. +message ApplyRerferralRewardPayload { + repeated Receiver receivers = 1 [ (gogoproto.nullable) = false ]; +} + +// ApplyAffiliationRewardPayload is the affiliation reward ticket payload type. +message ApplyAffiliationRewardPayload { + Receiver receiver = 1 [ (gogoproto.nullable) = false ]; +} + +// ApplyNoLossBetsRewardPayload is the noloss bets reward ticket payload type. +message ApplyNoLossBetsRewardPayload { + Receiver receiver = 1 [ (gogoproto.nullable) = false ]; + repeated string bet_uids = 3; +} \ No newline at end of file diff --git a/proto/sge/reward/tx.proto b/proto/sge/reward/tx.proto new file mode 100644 index 00000000..60867762 --- /dev/null +++ b/proto/sge/reward/tx.proto @@ -0,0 +1,54 @@ +syntax = "proto3"; + +package sgenetwork.sge.reward; + +option go_package = "github.com/sge-network/sge/x/reward/types"; + +// Msg defines the Msg service. +service Msg { + // CreateCampaign is campaign create message endpoint. + rpc CreateCampaign(MsgCreateCampaign) returns (MsgCreateCampaignResponse); + // UpdateCampaign is campaign update message endpoint. + rpc UpdateCampaign(MsgUpdateCampaign) returns (MsgUpdateCampaignResponse); + // ApplyReward is reward application message endpoint. + rpc ApplyReward(MsgApplyReward) returns (MsgApplyRewardResponse); +} + +// MsgCreateCampaign is campaign create message type. +message MsgCreateCampaign { + // creator is the address of creator account. + string creator = 1; + // uid is the uinque identifier of the campaign. + string uid = 2; + // ticket is the payload data. + string ticket = 3; +} + +// MsgCreateCampaignResponse campaign create message response type. +message MsgCreateCampaignResponse {} + +// MsgUpdateCampaign is campaign update message type. +message MsgUpdateCampaign { + // creator is the address of creator account. + string creator = 1; + // uid is the uinque identifier of the campaign. + string uid = 2; + // ticket is the payload data. + string ticket = 3; +} + +// MsgUpdateCampaignResponse campaign update message response type. +message MsgUpdateCampaignResponse {} + +// MsgApplyReward is apply reward message type. +message MsgApplyReward { + // creator is the address of creator account. + string creator = 1; + // campaign_uid is the uinque identifier of the campaign. + string campaign_uid = 2; + // ticket is the payload data. + string ticket = 3; +} + +// MsgApplyRewardResponse apply reward message response type. +message MsgApplyRewardResponse {} diff --git a/proto/sge/subaccount/balance.proto b/proto/sge/subaccount/balance.proto new file mode 100644 index 00000000..603c8bf2 --- /dev/null +++ b/proto/sge/subaccount/balance.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; +package sgenetwork.sge.subaccount; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/sge-network/sge/x/subaccount/types"; + +// Balance defines the balance of a subaccount. +message Balance { + // deposited_amount keeps track of how much was deposited so far in the + // subaccount. + string deposited_amount = 1 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + + // spent_amount keeps track of how much was spent in the account in betting, + // house, staking, etc. + string spent_amount = 2 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + + // withdrawn_amount keeps track of how much was withdrawn in the account after + // locked coins become free. + string withdrawm_amount = 3 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + + // lost_amount keeps track of the amounts that were lost due to betting + // losses, slashing etc. + string lost_amount = 4 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; +} + +// LockedBalance defines a balance which is locked. +message LockedBalance { + uint64 unlock_ts = 1 [ + (gogoproto.customname) = "UnlockTS", + (gogoproto.jsontag) = "unlock_ts", + json_name = "unlock_ts" + ]; + string amount = 2 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; +} diff --git a/proto/sge/subaccount/genesis.proto b/proto/sge/subaccount/genesis.proto new file mode 100644 index 00000000..efd00716 --- /dev/null +++ b/proto/sge/subaccount/genesis.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; +package sgenetwork.sge.subaccount; + +import "gogoproto/gogo.proto"; +import "sge/subaccount/params.proto"; +import "sge/subaccount/balance.proto"; + +option go_package = "github.com/sge-network/sge/x/subaccount/types"; + +// GenesisState defines the subaccount module's genesis state. +message GenesisState { + // params contains the subaccount parameters. + Params params = 1 [ (gogoproto.nullable) = false ]; + + uint64 subaccount_id = 2; + + // subaccounts contains all the subaccounts. + repeated GenesisSubaccount subaccounts = 3 [ (gogoproto.nullable) = false ]; +} + +// GenesisSubaccount defines the genesis subaccount containing owner, address +// and balance information. +message GenesisSubaccount { + // address is the address of the subaccount. + string address = 1; + + // owner is the owner of the subaccount. + string owner = 2; + + // balance defines the balance status of a subaccount + Balance balance = 3 [ (gogoproto.nullable) = false ]; + + // locked_balances defines the lockup of balances history of a subaccount + repeated LockedBalance locked_balances = 4 [ (gogoproto.nullable) = false ]; +} \ No newline at end of file diff --git a/proto/sge/subaccount/params.proto b/proto/sge/subaccount/params.proto new file mode 100644 index 00000000..8f87618e --- /dev/null +++ b/proto/sge/subaccount/params.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package sgenetwork.sge.subaccount; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/sge-network/sge/x/subaccount/types"; + +// Params defines the parameters for the module. +message Params { option (gogoproto.goproto_stringer) = false; } diff --git a/proto/sge/subaccount/query.proto b/proto/sge/subaccount/query.proto new file mode 100644 index 00000000..c922eb2e --- /dev/null +++ b/proto/sge/subaccount/query.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; +package sgenetwork.sge.subaccount; + +option go_package = "github.com/sge-network/sge/x/subaccount/types"; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "sge/subaccount/balance.proto"; +import "sge/subaccount/params.proto"; + +// Query defines the gRPC querier service. +service Query { + // Subaccount fetches a subaccount given the owner. + rpc Subaccount(QuerySubaccountRequest) returns (QuerySubaccountResponse) { + option (google.api.http).get = "/sge/subaccount/subaccount"; + }; + // Params returns the subaccount module parameters. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/sge/subaccount/params"; + }; +} + +// QueryParamsRequest is the request type for the Query/Params RPC method +message QueryParamsRequest {} +// QueryParamsResponse is the response type for the Query/Params RPC method +message QueryParamsResponse { sge.subaccount.Params params = 1; } + +// QuerySubaccountRequest is the request type for the Query/Subaccount RPC +message QuerySubaccountRequest { string subaccount_owner = 1; } + +// QuerySubaccountResponse is the response type for the Query/Subaccount RPC +message QuerySubaccountResponse { + string subaccount_address = 1; + sge.subaccount.Balance balance = 2 [ (gogoproto.nullable) = false ]; + repeated sge.subaccount.LockedBalance locked_balance = 3 + [ (gogoproto.nullable) = false ]; +} diff --git a/proto/sge/subaccount/tx.proto b/proto/sge/subaccount/tx.proto new file mode 100644 index 00000000..5f94257c --- /dev/null +++ b/proto/sge/subaccount/tx.proto @@ -0,0 +1,98 @@ +syntax = "proto3"; +package sgenetwork.sge.subaccount; + +import "sge/subaccount/balance.proto"; +import "sge/bet/tx.proto"; +import "sge/house/tx.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/sge-network/sge/x/subaccount/types"; + +// Msg defines the Msg service. +service Msg { + // Create defines a method for creating a subaccount. + rpc Create(MsgCreate) returns (MsgCreateResponse); + + // TopUp defines a method for topping up a subaccount. + rpc TopUp(MsgTopUp) returns (MsgTopUpResponse); + + // WithdrawUnlockedBalances defines a method for withdrawing unlocked + // balances. + rpc WithdrawUnlockedBalances(MsgWithdrawUnlockedBalances) + returns (MsgWithdrawUnlockedBalancesResponse); + + // PlaceBet defines a method for placing a bet using a subaccount. + rpc Wager(MsgWager) returns (MsgWagerResponse); + + // HouseDeposit defines a method for depositing funds to provide liquidity to + // a market. + rpc HouseDeposit(MsgHouseDeposit) returns (MsgHouseDepositResponse); + + // HouseWithdraw defines a method for withdrawing funds from a market. + rpc HouseWithdraw(MsgHouseWithdraw) returns (MsgHouseWithdrawResponse); +} + +// MsgCreate defines the Msg/Create request type. +message MsgCreate { + // creator is the msg signer. + string creator = 1; + + // sub_account_owner is the owner of the subaccount. + string sub_account_owner = 2; + + // locked_balances is the list of balance locks. + repeated LockedBalance locked_balances = 3 [ (gogoproto.nullable) = false ]; +} + +// MsgCreateAccountResponse defines the Msg/CreateAccount response type. +message MsgCreateResponse {} + +// MsgTopUp defines the Msg/TopUp request type. +message MsgTopUp { + // creator is the msg signer. + string creator = 1; + + // sub_account is the subaccount address. + string sub_account = 2; + + // locked_balances is the list of balance locks. + repeated LockedBalance locked_balances = 3 [ (gogoproto.nullable) = false ]; +} + +// MsgTopUpResponse defines the Msg/TopUp response type. +message MsgTopUpResponse {} + +// MsgWithdrawUnlockedBalances defines the Msg/WithdrawUnlockedBalances request +// type. +message MsgWithdrawUnlockedBalances { + // creator is the subaccount owner. + string creator = 1; +} + +// MsgWithdrawUnlockedBalancesResponse defines the Msg/WithdrawUnlockedBalances +// response type. +message MsgWithdrawUnlockedBalancesResponse {} + +// MsgPlaceBet wraps the MsgPlaceBet message. We need it in order not to have +// double interface registration conflicts. +message MsgWager { sgenetwork.sge.bet.MsgWager msg = 1; } + +// MsgBetResponse wraps the MsgPlaceBetResponse message. We need it in order not +// to have double interface registration conflicts. +message MsgWagerResponse { sgenetwork.sge.bet.MsgWagerResponse response = 1; } + +// MsgHouseDeposit wraps the MsgHouseDeposit message. We need it in order not to +// have double interface registration conflicts. +message MsgHouseDeposit { sge.house.MsgDeposit msg = 1; } + +// MsgHouseDepositResponse wraps the MsgHouseDepositResponse message. We need it +// in order not to have double interface registration conflicts. +message MsgHouseDepositResponse { sge.house.MsgDepositResponse response = 1; } + +// MsgHouseWithdraw wraps the MsgHouseWithdraw message. We need it in order not +// to have double interface registration conflicts. +message MsgHouseWithdraw { sge.house.MsgWithdraw msg = 1; } + +// MsgHouseWithdrawResponse wraps the MsgHouseWithdrawResponse message. We need +// it in order not to have double interface registration conflicts. +message MsgHouseWithdrawResponse { sge.house.MsgWithdrawResponse response = 1; } \ No newline at end of file diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 20cf6de7..4bb1d5d4 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -3,7 +3,7 @@ set -eo pipefail # get protoc executions -go get github.com/cosmos/gogoproto@v1.4.10 2>/dev/null +go get github.com/cosmos/gogoproto@v1.4.11 2>/dev/null # get cosmos sdk from github go get github.com/cosmos/cosmos-sdk@v0.46.14 2>/dev/null diff --git a/testutil/network/network.go b/testutil/network/network.go index 5785c66a..0f7a117a 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -8,15 +8,18 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" + + tmrand "github.com/tendermint/tendermint/libs/rand" + tmdb "github.com/tendermint/tm-db" + pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdksimapp "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/network" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/sge-network/sge/app" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmdb "github.com/tendermint/tm-db" ) type ( diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go index 1ae31ba3..aa98dd16 100644 --- a/testutil/sample/sample.go +++ b/testutil/sample/sample.go @@ -5,11 +5,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// AccAddress returns a sample account address +// AccAddress returns a sample account address as string func AccAddress() string { + return NativeAccAddress().String() +} + +func NativeAccAddress() sdk.AccAddress { pk := ed25519.GenPrivKey().PubKey() addr := pk.Address() - return sdk.AccAddress(addr).String() + return sdk.AccAddress(addr) } // ValAddress returns a sample validator address diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index ce77ab75..55341a96 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -8,6 +8,9 @@ import ( "testing" "time" + "github.com/spf13/cast" + + sdkmath "cosmossdk.io/math" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdksimapp "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -17,18 +20,19 @@ import ( stakingKeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/sge-network/sge/app" - "github.com/sge-network/sge/app/params" - "github.com/sge-network/sge/utils" - mintmoduletypes "github.com/sge-network/sge/x/mint/types" - ovmtypes "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cast" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" tmdb "github.com/tendermint/tm-db" + + "github.com/sge-network/sge/app" + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/utils" + mintmoduletypes "github.com/sge-network/sge/x/mint/types" + ovmtypes "github.com/sge-network/sge/x/ovm/types" ) // TestApp is used as a container of the sge app @@ -184,7 +188,7 @@ func generateSimappUsers() { func generateSimappUserBalances() (balances []banktypes.Balance) { genTokens := sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction) genCoin := sdk.NewCoin(params.DefaultBondDenom, genTokens) - sdkgenCoin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000000000)) + sdkgenCoin := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1000000000)) for _, v := range TestParamUsers { balances = append(balances, banktypes.Balance{ Address: v.Address.String(), @@ -212,7 +216,7 @@ func generateSimappAccountCoins(ctx *sdk.Context, tApp *TestApp) error { // SetAccountCoins sets the balance of accounts for testing func SetAccountCoins(ctx *sdk.Context, k bankkeeper.Keeper, addr sdk.AccAddress, amount int64) error { - coin := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(amount))) + coin := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdkmath.NewInt(amount))) err := k.MintCoins(*ctx, mintmoduletypes.ModuleName, coin) if err != nil { return err @@ -231,7 +235,7 @@ func SetModuleAccountCoins( moduleName string, amount int64, ) error { - coin := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(amount))) + coin := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdkmath.NewInt(amount))) err := k.MintCoins(*ctx, mintmoduletypes.ModuleName, coin) if err != nil { return err diff --git a/testutil/simapp/simapp_test.go b/testutil/simapp/simapp_test.go index 3a915594..16889217 100644 --- a/testutil/simapp/simapp_test.go +++ b/testutil/simapp/simapp_test.go @@ -3,11 +3,11 @@ package simapp_test import ( "testing" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/stretchr/testify/require" ) func TestGetTestObjects(t *testing.T) { - _, _, err := simappUtil.GetTestObjects() + _, _, err := simapp.GetTestObjects() require.NoError(t, err) } diff --git a/testutil/simapp/test_helpers.go b/testutil/simapp/test_helpers.go index 399af0f6..d1460cea 100644 --- a/testutil/simapp/test_helpers.go +++ b/testutil/simapp/test_helpers.go @@ -8,12 +8,13 @@ import ( "fmt" "math" + "github.com/golang-jwt/jwt" + "github.com/spf13/cast" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/golang-jwt/jwt" - "github.com/spf13/cast" ) // PKs is a slice of public keys for test @@ -47,7 +48,7 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress { } // testAddr returns sample account address -func testAddr(addr string, bech string) (sdk.AccAddress, error) { +func testAddr(addr, bech string) (sdk.AccAddress, error) { res, err := sdk.AccAddressFromHexUnsafe(addr) if err != nil { return nil, err diff --git a/utils/authorization.go b/utils/authorization.go new file mode 100644 index 00000000..724ce0f7 --- /dev/null +++ b/utils/authorization.go @@ -0,0 +1,79 @@ +package utils + +import ( + "time" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/cosmos/cosmos-sdk/x/authz" +) + +// AuthzKeeper defines the expected authz keeper. +type AuthzKeeper interface { + GetAuthorization( + ctx sdk.Context, + grantee sdk.AccAddress, + granter sdk.AccAddress, + msgType string, + ) (authz.Authorization, *time.Time) + SaveGrant( + ctx sdk.Context, + grantee, granter sdk.AccAddress, + authorization authz.Authorization, + expiration *time.Time, + ) error + DeleteGrant( + ctx sdk.Context, + grantee, granter sdk.AccAddress, + msgType string, + ) error +} + +func ValidateMsgAuthorization( + authzKeeper AuthzKeeper, + ctx sdk.Context, + creator, depositor string, + msg sdk.Msg, + errAuthorizationNotFound, errAuthorizationNotAccepted error, +) error { + granteeAddr := sdk.MustAccAddressFromBech32(creator) + granterAddr, err := sdk.AccAddressFromBech32(depositor) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid granter address (%s)", err) + } + authorization, expiration := authzKeeper.GetAuthorization( + ctx, + granteeAddr, + granterAddr, + sdk.MsgTypeURL(msg), + ) + if authorization == nil { + return sdkerrors.Wrapf( + errAuthorizationNotFound, + "grantee: %s, granter: %s", + creator, + depositor, + ) + } + authRes, err := authorization.Accept(ctx, msg) + if err != nil { + return sdkerrors.Wrapf(errAuthorizationNotAccepted, "%s", err) + } + + if authRes.Delete { + err = authzKeeper.DeleteGrant(ctx, granteeAddr, granterAddr, sdk.MsgTypeURL(msg)) + } else if authRes.Updated != nil { + err = authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, authRes.Updated, expiration) + } + if err != nil { + return err + } + + if !authRes.Accept { + return errAuthorizationNotAccepted + } + + return nil +} diff --git a/utils/fund.go b/utils/fund.go new file mode 100644 index 00000000..c2255b1f --- /dev/null +++ b/utils/fund.go @@ -0,0 +1,74 @@ +package utils + +import ( + sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/app/params" +) + +type IModuleFunder interface { + GetModuleAcc() string +} + +type ModuleAccFunder struct { + bk BankKeeper + ak AccountKeeper + + bankError error +} + +func NewModuleAccFunder(bk BankKeeper, ak AccountKeeper, bankError error) *ModuleAccFunder { + return &ModuleAccFunder{bk, ak, bankError} +} + +// AccountKeeper defines the expected account keeper methods. +type AccountKeeper interface { + GetModuleAddress(moduleName string) sdk.AccAddress +} + +// BankKeeper defines the expected bank keeper methods. +type BankKeeper interface { + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, ecipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error +} + +// Fund transfers the input amount from sender to the module account. +func (f *ModuleAccFunder) Fund( + mf IModuleFunder, + ctx sdk.Context, + senderAcc sdk.AccAddress, + amount sdkmath.Int, +) error { + amt := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, amount)) + + // Transfer funds + err := f.bk.SendCoinsFromAccountToModule(ctx, senderAcc, mf.GetModuleAcc(), amt) + if err != nil { + return sdkerrors.Wrapf(f.bankError, ": %s", err) + } + + return nil +} + +// Refund transfers the input amount from the module account to the receiver account. +func (f *ModuleAccFunder) Refund( + mf IModuleFunder, + ctx sdk.Context, + receiverAcc sdk.AccAddress, + amount sdkmath.Int, +) error { + mAcc := mf.GetModuleAcc() + + amt := sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, amount)) + + // Transfer funds + err := f.bk.SendCoinsFromModuleToAccount(ctx, mAcc, receiverAcc, amt) + if err != nil { + return sdkerrors.Wrapf(f.bankError, err.Error()) + } + + return nil +} diff --git a/x/bet/abci.go b/x/bet/abci.go index 9c6c69e8..be9304f9 100644 --- a/x/bet/abci.go +++ b/x/bet/abci.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/bet/keeper" ) diff --git a/x/bet/client/cli/query_bet.go b/x/bet/client/cli/query_bet.go index 84155918..d3231f84 100644 --- a/x/bet/client/cli/query_bet.go +++ b/x/bet/client/cli/query_bet.go @@ -4,10 +4,12 @@ import ( "context" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/bet/types" - "github.com/spf13/cobra" ) // CmdListBet implements a command to return all bets diff --git a/x/bet/client/cli/query_bet_test.go b/x/bet/client/cli/query_bet_test.go index dce6997f..cda533ac 100644 --- a/x/bet/client/cli/query_bet_test.go +++ b/x/bet/client/cli/query_bet_test.go @@ -6,19 +6,22 @@ import ( "testing" "time" - "github.com/cosmos/cosmos-sdk/client/flags" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" "github.com/spf13/cast" "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + tmcli "github.com/tendermint/tendermint/libs/cli" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/client/flags" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/bet/client/cli" "github.com/sge-network/sge/x/bet/types" markettypes "github.com/sge-network/sge/x/market/types" @@ -36,7 +39,7 @@ func networkWithBetObjects(t *testing.T, n int) (*network.Network, []types.Bet) market := markettypes.Market{ UID: testMarketUID, - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), StartTS: 1111111111, EndTS: uint64(time.Now().Unix()) + 5000, Odds: []*markettypes.Odds{ @@ -63,8 +66,8 @@ func networkWithBetObjects(t *testing.T, n int) (*network.Network, []types.Bet) UID: uuid.NewString(), MarketUID: market.UID, OddsValue: "10", - Amount: sdk.NewInt(10), - Fee: sdk.NewInt(1), + Amount: sdkmath.NewInt(10), + Fee: sdkmath.NewInt(1), MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"), } nullify.Fill(&bet) diff --git a/x/bet/client/cli/query_params.go b/x/bet/client/cli/query_params.go index 747f19c9..0f315630 100644 --- a/x/bet/client/cli/query_params.go +++ b/x/bet/client/cli/query_params.go @@ -3,10 +3,12 @@ package cli import ( "context" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/bet/types" - "github.com/spf13/cobra" ) // CmdQueryParams returns a command object instance for module params diff --git a/x/bet/client/cli/query_test.go b/x/bet/client/cli/query_test.go index c64089b6..1dcb3571 100644 --- a/x/bet/client/cli/query_test.go +++ b/x/bet/client/cli/query_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/bet/client/cli" - "github.com/stretchr/testify/require" ) const testAddress = "cosmos1s4ycalgh3gjemd4hmqcvcgmnf647rnd0tpg2w9" diff --git a/x/bet/client/cli/tx.go b/x/bet/client/cli/tx.go index 577740a6..7c276c0a 100644 --- a/x/bet/client/cli/tx.go +++ b/x/bet/client/cli/tx.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/bet/types" ) diff --git a/x/bet/client/cli/tx_bet.go b/x/bet/client/cli/tx_bet.go index 75fbf9a4..c73717ed 100644 --- a/x/bet/client/cli/tx_bet.go +++ b/x/bet/client/cli/tx_bet.go @@ -1,12 +1,14 @@ package cli import ( + "github.com/spf13/cobra" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/bet/types" - "github.com/spf13/cobra" ) // CmdWager implements a command to place and store a single bet @@ -22,7 +24,7 @@ func CmdWager() *cobra.Command { argAmount := args[1] argTicket := args[2] - argAmountCosmosInt, ok := sdk.NewIntFromString(argAmount) + argAmountCosmosInt, ok := sdkmath.NewIntFromString(argAmount) if !ok { return types.ErrInvalidAmount } diff --git a/x/bet/client/cli/tx_bet_test.go b/x/bet/client/cli/tx_bet_test.go index e5cf85f0..0aa75f19 100644 --- a/x/bet/client/cli/tx_bet_test.go +++ b/x/bet/client/cli/tx_bet_test.go @@ -4,10 +4,12 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/bet/client/cli" @@ -25,7 +27,7 @@ func TestTXBetCLI(t *testing.T) { fmt.Sprintf( "--%s=%s", flags.FlagFees, - sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String(), + sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String(), ), } diff --git a/x/bet/client/cli/tx_test.go b/x/bet/client/cli/tx_test.go index 06fba660..2fab7773 100644 --- a/x/bet/client/cli/tx_test.go +++ b/x/bet/client/cli/tx_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/bet/client/cli" - "github.com/stretchr/testify/require" ) func TestGetTxCmd(t *testing.T) { diff --git a/x/bet/genesis.go b/x/bet/genesis.go index ea9282ab..6892f61f 100644 --- a/x/bet/genesis.go +++ b/x/bet/genesis.go @@ -2,6 +2,7 @@ package bet import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/bet/keeper" "github.com/sge-network/sge/x/bet/types" ) diff --git a/x/bet/genesis_test.go b/x/bet/genesis_test.go index d41d4394..cd49dd64 100644 --- a/x/bet/genesis_test.go +++ b/x/bet/genesis_test.go @@ -3,15 +3,17 @@ package bet_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/bet" "github.com/sge-network/sge/x/bet/types" - "github.com/stretchr/testify/require" ) func TestGenesis(t *testing.T) { - tApp, ctx, err := simappUtil.GetTestObjects() + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) genesisState := types.GenesisState{ @@ -20,11 +22,11 @@ func TestGenesis(t *testing.T) { BetList: []types.Bet{ { UID: "0", - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), }, { UID: "1", - Creator: simappUtil.TestParamUsers["user2"].Address.String(), + Creator: simapp.TestParamUsers["user2"].Address.String(), }, }, Uid2IdList: []types.UID2ID{ @@ -40,13 +42,13 @@ func TestGenesis(t *testing.T) { PendingBetList: []types.PendingBet{ { UID: "1", - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), }, }, SettledBetList: []types.SettledBet{ { UID: "1", - BettorAddress: simappUtil.TestParamUsers["user1"].Address.String(), + BettorAddress: simapp.TestParamUsers["user1"].Address.String(), }, }, Stats: types.BetStats{ diff --git a/x/bet/handler.go b/x/bet/handler.go index b5004f5f..d340d1af 100644 --- a/x/bet/handler.go +++ b/x/bet/handler.go @@ -3,8 +3,10 @@ package bet import ( "fmt" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/bet/keeper" "github.com/sge-network/sge/x/bet/types" ) @@ -22,7 +24,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) } } } diff --git a/x/bet/keeper/bet.go b/x/bet/keeper/bet.go index f7c182e4..b417d741 100644 --- a/x/bet/keeper/bet.go +++ b/x/bet/keeper/bet.go @@ -1,8 +1,10 @@ package keeper import ( + sdkerrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/bet/types" ) @@ -168,3 +170,24 @@ func (k Keeper) GetSettledBets(ctx sdk.Context) (list []types.SettledBet, err er return } + +func (k Keeper) PrepareBetObject(ctx sdk.Context, creator string, props *types.WagerProps) (*types.Bet, error) { + // Check if the value already exists + _, isFound := k.GetBetID(ctx, props.UID) + if isFound { + return nil, sdkerrors.Wrapf(types.ErrDuplicateUID, "%s", props.UID) + } + + payload := &types.WagerTicketPayload{} + err := k.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), props.Ticket, &payload) + if err != nil { + return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + } + + if err = payload.Validate(creator); err != nil { + return nil, sdkerrors.Wrapf(types.ErrInTicketValidation, "%s", err) + } + + bet := types.NewBet(creator, props, payload.OddsType, payload.SelectedOdds) + return bet, nil +} diff --git a/x/bet/keeper/bet_test.go b/x/bet/keeper/bet_test.go index 6246bc63..ff3a2cde 100644 --- a/x/bet/keeper/bet_test.go +++ b/x/bet/keeper/bet_test.go @@ -3,24 +3,26 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/bet/keeper" "github.com/sge-network/sge/x/bet/types" - "github.com/stretchr/testify/require" ) func createNBet( - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, keeper *keeper.KeeperTest, ctx sdk.Context, n int, ) []types.Bet { items := make([]types.Bet, n) - testCreator = simappUtil.TestParamUsers["user1"].Address.String() + testCreator = simapp.TestParamUsers["user1"].Address.String() tApp.MarketKeeper.SetMarket(ctx, testMarket) for i := range items { @@ -28,8 +30,8 @@ func createNBet( items[i].Creator = testCreator items[i].OddsValue = "10" items[i].OddsType = types.OddsType_ODDS_TYPE_DECIMAL - items[i].Amount = sdk.NewInt(10) - items[i].Fee = sdk.NewInt(1) + items[i].Amount = sdkmath.NewInt(10) + items[i].Fee = sdkmath.NewInt(1) items[i].MarketUID = testMarketUID items[i].MaxLossMultiplier = sdk.NewDec(10) @@ -46,7 +48,7 @@ func createNBet( func TestBetGet(t *testing.T) { tApp, k, ctx := setupKeeperAndApp(t) items := createNBet(tApp, k, ctx, 10) - testCreator = simappUtil.TestParamUsers["user1"].Address.String() + testCreator = simapp.TestParamUsers["user1"].Address.String() rst, found := k.GetBet(ctx, testCreator, diff --git a/x/bet/keeper/grpc_query_bet.go b/x/bet/keeper/grpc_query_bet.go index 36811068..e13d09de 100644 --- a/x/bet/keeper/grpc_query_bet.go +++ b/x/bet/keeper/grpc_query_bet.go @@ -5,14 +5,16 @@ import ( "fmt" "strings" + "github.com/spf13/cast" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/bet/types" - "github.com/spf13/cast" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) const ( @@ -30,7 +32,7 @@ func (k Keeper) Bets(c context.Context, req *types.QueryBetsRequest) (*types.Que betStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.BetListPrefix) - pageRes, err := query.Paginate(betStore, req.Pagination, func(key []byte, value []byte) error { + pageRes, err := query.Paginate(betStore, req.Pagination, func(key, value []byte) error { var bet types.Bet if err := k.cdc.Unmarshal(value, &bet); err != nil { return err @@ -60,7 +62,7 @@ func (k Keeper) BetsByCreator( betStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.BetListByCreatorPrefix(req.Creator)) - pageRes, err := query.Paginate(betStore, req.Pagination, func(key []byte, value []byte) error { + pageRes, err := query.Paginate(betStore, req.Pagination, func(key, value []byte) error { var bet types.Bet if err := k.cdc.Unmarshal(value, &bet); err != nil { return err @@ -151,7 +153,7 @@ func (k Keeper) PendingBets( pageRes, err := query.Paginate( pendingBetStore, req.Pagination, - func(key []byte, value []byte) error { + func(key, value []byte) error { var pendingBet types.PendingBet if err := k.cdc.Unmarshal(value, &pendingBet); err != nil { return err @@ -195,7 +197,7 @@ func (k Keeper) SettledBetsOfHeight( pageRes, err := query.Paginate( settledBetStore, req.Pagination, - func(key []byte, value []byte) error { + func(key, value []byte) error { var settledBet types.SettledBet if err := k.cdc.Unmarshal(value, &settledBet); err != nil { return err diff --git a/x/bet/keeper/grpc_query_bet_test.go b/x/bet/keeper/grpc_query_bet_test.go index f90ac259..12526df8 100644 --- a/x/bet/keeper/grpc_query_bet_test.go +++ b/x/bet/keeper/grpc_query_bet_test.go @@ -3,16 +3,17 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/query" "github.com/spf13/cast" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/bet/types" ) @@ -168,7 +169,7 @@ func TestBetsByCreatorQueryPaginated(t *testing.T) { request := func(next []byte, offset, limit uint64, total bool) *types.QueryBetsByCreatorRequest { return &types.QueryBetsByCreatorRequest{ - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), Pagination: &query.PageRequest{ Key: next, Offset: offset, @@ -267,7 +268,7 @@ func TestBetByUIDsQuery(t *testing.T) { desc: "First", request: &types.QueryBetsByUIDsRequest{ Items: []string{ - simappUtil.TestParamUsers["user1"].Address.String() + ":" + msgs[0].UID, + simapp.TestParamUsers["user1"].Address.String() + ":" + msgs[0].UID, }, }, response: &types.QueryBetsByUIDsResponse{Bets: []types.Bet{msgs[0]}}, @@ -276,7 +277,7 @@ func TestBetByUIDsQuery(t *testing.T) { desc: "Second", request: &types.QueryBetsByUIDsRequest{ Items: []string{ - simappUtil.TestParamUsers["user1"].Address.String() + ":" + msgs[1].UID, + simapp.TestParamUsers["user1"].Address.String() + ":" + msgs[1].UID, }, }, response: &types.QueryBetsByUIDsResponse{Bets: []types.Bet{msgs[1]}}, @@ -285,7 +286,7 @@ func TestBetByUIDsQuery(t *testing.T) { desc: "NotFound", request: &types.QueryBetsByUIDsRequest{ Items: []string{ - simappUtil.TestParamUsers["user1"].Address.String() + ":" + "100000", + simapp.TestParamUsers["user1"].Address.String() + ":" + "100000", }, }, response: &types.QueryBetsByUIDsResponse{Bets: []types.Bet{}, NotFoundBetUids: []string{"100000"}}, diff --git a/x/bet/keeper/grpc_query_params.go b/x/bet/keeper/grpc_query_params.go index e3bf4609..57ecd7be 100644 --- a/x/bet/keeper/grpc_query_params.go +++ b/x/bet/keeper/grpc_query_params.go @@ -3,10 +3,12 @@ package keeper import ( "context" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sge-network/sge/x/bet/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/bet/types" ) // Params returns the params of the module diff --git a/x/bet/keeper/keeper.go b/x/bet/keeper/keeper.go index d0981b16..b319ba0e 100644 --- a/x/bet/keeper/keeper.go +++ b/x/bet/keeper/keeper.go @@ -3,12 +3,14 @@ package keeper import ( "fmt" + "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/sge-network/sge/x/bet/types" - "github.com/tendermint/tendermint/libs/log" ) // Keeper is the type for module properties diff --git a/x/bet/keeper/keeper_test.go b/x/bet/keeper/keeper_test.go index 26cde5a9..54f38fce 100644 --- a/x/bet/keeper/keeper_test.go +++ b/x/bet/keeper/keeper_test.go @@ -7,15 +7,17 @@ import ( "github.com/golang-jwt/jwt" "github.com/google/uuid" "github.com/spf13/cast" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" + sgetypes "github.com/sge-network/sge/types" "github.com/sge-network/sge/x/bet/keeper" "github.com/sge-network/sge/x/bet/types" marketkeeper "github.com/sge-network/sge/x/market/keeper" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) var ( @@ -40,7 +42,7 @@ var ( testMarket = markettypes.Market{ UID: testMarketUID, - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), StartTS: 1111111111, EndTS: uint64(time.Now().Unix()) + 5000, Odds: testMarketOdds, @@ -48,8 +50,8 @@ var ( } ) -func setupKeeperAndApp(t testing.TB) (*simappUtil.TestApp, *keeper.KeeperTest, sdk.Context) { - tApp, ctx, err := simappUtil.GetTestObjects() +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.KeeperTest, sdk.Context) { + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) return tApp, tApp.BetKeeper, ctx @@ -61,8 +63,8 @@ func setupKeeper(t testing.TB) (*keeper.KeeperTest, sdk.Context) { return k, ctx } -func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) { - testCreator = simappUtil.TestParamUsers["user1"].Address.String() +func addTestMarket(t testing.TB, tApp *simapp.TestApp, ctx sdk.Context) { + testCreator = simapp.TestParamUsers["user1"].Address.String() testAddMarketClaim := jwt.MapClaims{ "uid": testMarketUID, "start_ts": 1111111111, @@ -89,12 +91,12 @@ func addTestMarket(t testing.TB, tApp *simappUtil.TestApp, ctx sdk.Context) { func addTestMarketBatch( t testing.TB, - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, ctx sdk.Context, count int, ) (uids []string) { for i := 0; i < count; i++ { - testCreator = simappUtil.TestParamUsers["user"+cast.ToString(i)].Address.String() + testCreator = simapp.TestParamUsers["user"+cast.ToString(i)].Address.String() uid := uuid.NewString() uids = append(uids, uid) testAddMarketClaim := jwt.MapClaims{ @@ -127,11 +129,11 @@ func addTestMarketBatch( func placeTestBet( ctx sdk.Context, t testing.TB, - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, betUID string, selectedOdds *types.BetOdds, ) { - testCreator = simappUtil.TestParamUsers["user1"].Address.String() + testCreator = simapp.TestParamUsers["user1"].Address.String() wctx := sdk.WrapSDKContext(ctx) betSrv := keeper.NewMsgServerImpl(*tApp.BetKeeper) testKyc := &sgetypes.KycDataPayload{ @@ -157,7 +159,7 @@ func placeTestBet( Creator: testCreator, Props: &types.WagerProps{ UID: betUID, - Amount: sdk.NewInt(1000000), + Amount: sdkmath.NewInt(1000000), Ticket: testWagerTicket, }, } @@ -168,7 +170,7 @@ func placeTestBet( func createJwtTicket(claim jwt.MapClaims) (string, error) { token := jwt.NewWithClaims(jwt.SigningMethodEdDSA, claim) - return token.SignedString(simappUtil.TestOVMPrivateKeys[0]) + return token.SignedString(simapp.TestOVMPrivateKeys[0]) } func TestLogger(t *testing.T) { diff --git a/x/bet/keeper/msg_server_bet.go b/x/bet/keeper/msg_server_bet.go index f6d18c9e..ad3d6187 100644 --- a/x/bet/keeper/msg_server_bet.go +++ b/x/bet/keeper/msg_server_bet.go @@ -3,8 +3,9 @@ package keeper import ( "context" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/bet/types" ) @@ -14,24 +15,11 @@ func (k msgServer) Wager( ) (*types.MsgWagerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // Check if the value already exists - _, isFound := k.GetBetID(ctx, msg.Props.UID) - if isFound { - return nil, sdkerrors.Wrapf(types.ErrDuplicateUID, "%s", msg.Props.UID) - } - - payload := &types.WagerTicketPayload{} - err := k.ovmKeeper.VerifyTicketUnmarshal(sdk.WrapSDKContext(ctx), msg.Props.Ticket, &payload) + bet, err := k.PrepareBetObject(ctx, msg.Creator, msg.Props) if err != nil { - return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + return nil, err } - if err = payload.Validate(msg.Creator); err != nil { - return nil, sdkerrors.Wrapf(types.ErrInTicketValidation, "%s", err) - } - - bet := types.NewBet(msg.Creator, msg.Props, payload.OddsType, payload.SelectedOdds) - if err := k.Keeper.Wager(ctx, bet); err != nil { return nil, sdkerrors.Wrapf(types.ErrInWager, "%s", err) } diff --git a/x/bet/keeper/msg_server_bet_test.go b/x/bet/keeper/msg_server_bet_test.go index 86a46a79..3c3d0f5c 100644 --- a/x/bet/keeper/msg_server_bet_test.go +++ b/x/bet/keeper/msg_server_bet_test.go @@ -3,20 +3,20 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/golang-jwt/jwt" "github.com/stretchr/testify/require" - simappUtil "github.com/sge-network/sge/testutil/simapp" + sdkmath "cosmossdk.io/math" + "github.com/golang-jwt/jwt" + + "github.com/sge-network/sge/testutil/simapp" sgetypes "github.com/sge-network/sge/types" "github.com/sge-network/sge/x/bet/types" - markettypes "github.com/sge-network/sge/x/market/types" ) func TestBetMsgServerWager(t *testing.T) { tApp, k, msgk, ctx, wctx := setupMsgServerAndApp(t) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] var err error t.Run("Redundant UID", func(t *testing.T) { @@ -38,7 +38,7 @@ func TestBetMsgServerWager(t *testing.T) { Creator: creator.Address.String(), Props: &types.WagerProps{ UID: "betUID_1", - Amount: sdk.NewInt(500), + Amount: sdkmath.NewInt(500), Ticket: "wrongTicket", }, } @@ -69,7 +69,7 @@ func TestBetMsgServerWager(t *testing.T) { Props: &types.WagerProps{ UID: "betUID_1", - Amount: sdk.NewInt(500), + Amount: sdkmath.NewInt(500), Ticket: wagerTicket, }, } @@ -98,7 +98,7 @@ func TestBetMsgServerWager(t *testing.T) { Props: &types.WagerProps{ UID: "betUID_1", - Amount: sdk.NewInt(500), + Amount: sdkmath.NewInt(500), Ticket: wagerTicket, }, } @@ -126,7 +126,7 @@ func TestBetMsgServerWager(t *testing.T) { Creator: creator.Address.String(), Props: &types.WagerProps{ UID: "BetUID_2", - Amount: sdk.NewInt(1000000), + Amount: sdkmath.NewInt(1000000), Ticket: wagerTicket, }, } @@ -151,10 +151,10 @@ func TestBetMsgServerWager(t *testing.T) { _, err = tApp.OrderbookKeeper.InitiateOrderBookParticipation( ctx, - simappUtil.TestParamUsers["user1"].Address, + simapp.TestParamUsers["user1"].Address, marketItem.UID, - sdk.NewInt(100000000), - sdk.NewInt(1), + sdkmath.NewInt(100000000), + sdkmath.NewInt(1), ) require.NoError(t, err) diff --git a/x/bet/keeper/msg_server_test.go b/x/bet/keeper/msg_server_test.go index 0990f293..c9dd94c6 100644 --- a/x/bet/keeper/msg_server_test.go +++ b/x/bet/keeper/msg_server_test.go @@ -6,14 +6,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/bet/keeper" "github.com/sge-network/sge/x/bet/types" ) func setupMsgServerAndApp( t testing.TB, -) (*simappUtil.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { +) (*simapp.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { tApp, k, ctx := setupKeeperAndApp(t) return tApp, k, keeper.NewMsgServerImpl(*k), ctx, sdk.WrapSDKContext(ctx) } diff --git a/x/bet/keeper/params.go b/x/bet/keeper/params.go index 29e1d916..67abf3a4 100644 --- a/x/bet/keeper/params.go +++ b/x/bet/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/bet/types" ) diff --git a/x/bet/keeper/params_test.go b/x/bet/keeper/params_test.go index 054ae9bb..58a809d9 100644 --- a/x/bet/keeper/params_test.go +++ b/x/bet/keeper/params_test.go @@ -3,8 +3,9 @@ package keeper_test import ( "testing" - "github.com/sge-network/sge/x/bet/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/bet/types" ) func TestGetParams(t *testing.T) { diff --git a/x/bet/keeper/settle.go b/x/bet/keeper/settle.go index d674f180..8bbc16e8 100644 --- a/x/bet/keeper/settle.go +++ b/x/bet/keeper/settle.go @@ -3,8 +3,10 @@ package keeper import ( "fmt" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/bet/types" markettypes "github.com/sge-network/sge/x/market/types" @@ -31,7 +33,7 @@ func (k Keeper) Settle(ctx sdk.Context, bettorAddressStr, betUID string) error { bettorAddress, err := sdk.AccAddressFromBech32(bet.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } if bet.Creator != bettorAddressStr { @@ -106,7 +108,7 @@ func (k Keeper) updateSettlementState(ctx sdk.Context, bet types.Bet, betID uint func (k Keeper) settleResolved(ctx sdk.Context, bet *types.Bet) error { bettorAddress, err := sdk.AccAddressFromBech32(bet.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } payout, err := types.CalculatePayoutProfit(bet.OddsType, bet.OddsValue, bet.Amount) diff --git a/x/bet/keeper/settle_test.go b/x/bet/keeper/settle_test.go index 67bf0b9a..b7d33e1b 100644 --- a/x/bet/keeper/settle_test.go +++ b/x/bet/keeper/settle_test.go @@ -3,19 +3,22 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/google/uuid" - simappUtil "github.com/sge-network/sge/testutil/simapp" - "github.com/sge-network/sge/x/bet/types" - markettypes "github.com/sge-network/sge/x/market/types" "github.com/spf13/cast" "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/bet/types" + markettypes "github.com/sge-network/sge/x/market/types" ) func TestSettleBet(t *testing.T) { tApp, k, ctx := setupKeeperAndApp(t) - testCreator = simappUtil.TestParamUsers["user1"].Address.String() + testCreator = simapp.TestParamUsers["user1"].Address.String() addTestMarket(t, tApp, ctx) tcs := []struct { @@ -42,7 +45,7 @@ func TestSettleBet(t *testing.T) { MarketUID: "nonExistMarket", Creator: "invalid creator", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { desc: "failed in checking status", @@ -50,7 +53,7 @@ func TestSettleBet(t *testing.T) { MarketUID: testMarketUID, OddsValue: "10", OddsType: types.OddsType_ODDS_TYPE_DECIMAL, - Amount: sdk.NewInt(1000000), + Amount: sdkmath.NewInt(1000000), Creator: testCreator, OddsUID: testOddsUID1, Status: types.Bet_STATUS_SETTLED, @@ -72,7 +75,7 @@ func TestSettleBet(t *testing.T) { MarketUID: testMarketUID, OddsValue: "10", OddsType: types.OddsType_ODDS_TYPE_DECIMAL, - Amount: sdk.NewInt(1000000), + Amount: sdkmath.NewInt(1000000), Creator: testCreator, OddsUID: testOddsUID1, }, @@ -92,7 +95,7 @@ func TestSettleBet(t *testing.T) { MarketUID: testMarketUID, OddsValue: "10", OddsType: types.OddsType_ODDS_TYPE_DECIMAL, - Amount: sdk.NewInt(1000000), + Amount: sdkmath.NewInt(1000000), Creator: testCreator, OddsUID: testOddsUID1, }, @@ -112,7 +115,7 @@ func TestSettleBet(t *testing.T) { MarketUID: testMarketUID, OddsValue: "10", OddsType: types.OddsType_ODDS_TYPE_DECIMAL, - Amount: sdk.NewInt(1000000), + Amount: sdkmath.NewInt(1000000), Creator: testCreator, OddsUID: testOddsUID1, }, @@ -133,7 +136,7 @@ func TestSettleBet(t *testing.T) { MarketUID: testMarketUID, OddsValue: "10", OddsType: types.OddsType_ODDS_TYPE_DECIMAL, - Amount: sdk.NewInt(1000000), + Amount: sdkmath.NewInt(1000000), Creator: testCreator, OddsUID: testOddsUID1, @@ -169,10 +172,10 @@ func TestSettleBet(t *testing.T) { if resetMarket.Status == markettypes.MarketStatus_MARKET_STATUS_ACTIVE { _, err := tApp.OrderbookKeeper.InitiateOrderBookParticipation( ctx, - simappUtil.TestParamUsers["user1"].Address, + simapp.TestParamUsers["user1"].Address, resetMarket.UID, - sdk.NewInt(100000000), - sdk.NewInt(1), + sdkmath.NewInt(100000000), + sdkmath.NewInt(1), ) require.NoError(t, err) } @@ -232,10 +235,10 @@ func TestBatchSettleBet(t *testing.T) { for i := depositorUser; i <= depositorUser+participationCount; i++ { _, err := tApp.OrderbookKeeper.InitiateOrderBookParticipation( ctx, - simappUtil.TestParamUsers["user"+cast.ToString(i)].Address, + simapp.TestParamUsers["user"+cast.ToString(i)].Address, market.UID, - sdk.NewInt(100000000), - sdk.NewInt(1), + sdkmath.NewInt(100000000), + sdkmath.NewInt(1), ) require.NoError(t, err) } diff --git a/x/bet/keeper/stats.go b/x/bet/keeper/stats.go index e9698a54..9bbad830 100644 --- a/x/bet/keeper/stats.go +++ b/x/bet/keeper/stats.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/bet/types" ) diff --git a/x/bet/keeper/view.go b/x/bet/keeper/view.go index bf3cdca8..97fbd6df 100644 --- a/x/bet/keeper/view.go +++ b/x/bet/keeper/view.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/bet/types" ) diff --git a/x/bet/keeper/wager.go b/x/bet/keeper/wager.go index a59a6825..27029975 100644 --- a/x/bet/keeper/wager.go +++ b/x/bet/keeper/wager.go @@ -1,18 +1,21 @@ package keeper import ( + "github.com/spf13/cast" + + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/bet/types" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cast" ) // Wager stores a new bet in KVStore func (k Keeper) Wager(ctx sdk.Context, bet *types.Bet) error { bettorAddress, err := sdk.AccAddressFromBech32(bet.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } market, err := k.getMarket(ctx, bet.MarketUID) diff --git a/x/bet/keeper/wager_test.go b/x/bet/keeper/wager_test.go index 08c7e671..74a6dfcd 100644 --- a/x/bet/keeper/wager_test.go +++ b/x/bet/keeper/wager_test.go @@ -4,12 +4,15 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - simappUtil "github.com/sge-network/sge/testutil/simapp" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/bet/types" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) func TestWager(t *testing.T) { @@ -28,14 +31,14 @@ func TestWager(t *testing.T) { UID: "betUID", MarketUID: "notExistMarketUID", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { desc: "not found market", bet: &types.Bet{ UID: "betUID", MarketUID: "notExistMarketUID", - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), }, err: types.ErrNoMatchingMarket, }, @@ -48,7 +51,7 @@ func TestWager(t *testing.T) { bet: &types.Bet{ UID: "betUID", MarketUID: "uid_inactive", - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), }, err: types.ErrInactiveMarket, }, @@ -61,7 +64,7 @@ func TestWager(t *testing.T) { bet: &types.Bet{ UID: "betUID", MarketUID: "uid_declared", - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), }, err: types.ErrInactiveMarket, }, @@ -75,7 +78,7 @@ func TestWager(t *testing.T) { bet: &types.Bet{ UID: "betUID", MarketUID: "uid_expired", - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), }, err: types.ErrEndTSIsPassed, }, @@ -98,10 +101,10 @@ func TestWager(t *testing.T) { UID: "betUID", MarketUID: "uid_oddsNotexist", OddsUID: "notExistOdds", - Amount: sdk.NewInt(1000), + Amount: sdkmath.NewInt(1000), OddsValue: "5", OddsType: types.OddsType_ODDS_TYPE_DECIMAL, - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), }, err: types.ErrOddsUIDNotExist, }, @@ -124,10 +127,10 @@ func TestWager(t *testing.T) { UID: "betUID", MarketUID: "uid_lowBetAmount", OddsUID: "odds1", - Amount: sdk.NewInt(100), + Amount: sdkmath.NewInt(100), OddsValue: "5", OddsType: types.OddsType_ODDS_TYPE_DECIMAL, - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), }, err: types.ErrBetAmountIsLow, }, @@ -160,10 +163,10 @@ func TestWager(t *testing.T) { UID: "betUID", MarketUID: "uid_success", OddsUID: "odds1", - Amount: sdk.NewInt(1000000), + Amount: sdkmath.NewInt(1000000), OddsValue: "5", OddsType: types.OddsType_ODDS_TYPE_DECIMAL, - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"), }, }, @@ -184,10 +187,10 @@ func TestWager(t *testing.T) { if tc.market.Status == markettypes.MarketStatus_MARKET_STATUS_ACTIVE { _, err = tApp.OrderbookKeeper.InitiateOrderBookParticipation( ctx, - simappUtil.TestParamUsers["user1"].Address, + simapp.TestParamUsers["user1"].Address, tc.market.UID, - sdk.NewInt(100000000), - sdk.NewInt(1), + sdkmath.NewInt(100000000), + sdkmath.NewInt(1), ) require.NoError(t, err) } diff --git a/x/bet/module.go b/x/bet/module.go index caf98dbc..51627c10 100644 --- a/x/bet/module.go +++ b/x/bet/module.go @@ -16,6 +16,7 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/bet/client/cli" "github.com/sge-network/sge/x/bet/keeper" "github.com/sge-network/sge/x/bet/types" diff --git a/x/bet/module_simulation.go b/x/bet/module_simulation.go index 80ead42a..c4fc5c56 100644 --- a/x/bet/module_simulation.go +++ b/x/bet/module_simulation.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/sge-network/sge/testutil/sample" betsimulation "github.com/sge-network/sge/x/bet/simulation" "github.com/sge-network/sge/x/bet/types" diff --git a/x/bet/simulation/bet.go b/x/bet/simulation/bet.go index 13c04fc0..f0324eae 100644 --- a/x/bet/simulation/bet.go +++ b/x/bet/simulation/bet.go @@ -4,14 +4,16 @@ import ( //#nosec "math/rand" + "github.com/spf13/cast" + "github.com/cosmos/cosmos-sdk/baseapp" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/sge-network/sge/x/bet/keeper" "github.com/sge-network/sge/x/bet/types" - "github.com/spf13/cast" ) // SimulateMsgWager returns an Operation function to run a state machine transition diff --git a/x/bet/simulation/decoder.go b/x/bet/simulation/decoder.go index 46222fe0..5104dfba 100644 --- a/x/bet/simulation/decoder.go +++ b/x/bet/simulation/decoder.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/x/bet/types" ) diff --git a/x/bet/simulation/decoder_test.go b/x/bet/simulation/decoder_test.go index d77694a9..c4323e58 100644 --- a/x/bet/simulation/decoder_test.go +++ b/x/bet/simulation/decoder_test.go @@ -7,8 +7,10 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/bet/simulation" @@ -23,7 +25,7 @@ func TestDecodeStore(t *testing.T) { sample.AccAddress(), &types.WagerProps{ UID: uuid.NewString(), - Amount: sdk.NewInt(10), + Amount: sdkmath.NewInt(10), Ticket: "", }, types.OddsType_ODDS_TYPE_DECIMAL, diff --git a/x/bet/simulation/genesis.go b/x/bet/simulation/genesis.go index 15d744b9..045ce93f 100644 --- a/x/bet/simulation/genesis.go +++ b/x/bet/simulation/genesis.go @@ -7,11 +7,12 @@ import ( //#nosec "math/rand" + "github.com/spf13/cast" + sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/bet/types" - "github.com/spf13/cast" ) // Simulation parameter constants @@ -34,12 +35,12 @@ func GenMaxBetByUIDQueryCount(r *rand.Rand) uint32 { // GenMinAmount randomized min bet amount func GenMinAmount(r *rand.Rand) sdkmath.Int { - return sdk.NewInt(int64(r.Intn(99))) + return sdkmath.NewInt(int64(r.Intn(99))) } // GenFee randomized min bet fee func GenFee(r *rand.Rand) sdkmath.Int { - return sdk.NewInt(int64(r.Intn(99))) + return sdkmath.NewInt(int64(r.Intn(99))) } // RandomizedGenState generates a random GenesisState for bet diff --git a/x/bet/simulation/genesis_test.go b/x/bet/simulation/genesis_test.go index e71553bc..ee9c35e5 100644 --- a/x/bet/simulation/genesis_test.go +++ b/x/bet/simulation/genesis_test.go @@ -6,12 +6,13 @@ import ( "math/rand" "testing" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/stretchr/testify/require" "github.com/sge-network/sge/x/bet/simulation" "github.com/sge-network/sge/x/bet/types" diff --git a/x/bet/simulation/params.go b/x/bet/simulation/params.go index 0112bde1..8c0357ce 100644 --- a/x/bet/simulation/params.go +++ b/x/bet/simulation/params.go @@ -7,9 +7,9 @@ import ( //#nosec "math/rand" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/sge-network/sge/x/bet/types" ) diff --git a/x/bet/types/bet.go b/x/bet/types/bet.go index b0a2fb1b..c3d965dc 100644 --- a/x/bet/types/bet.go +++ b/x/bet/types/bet.go @@ -2,6 +2,7 @@ package types import ( sdkmath "cosmossdk.io/math" + markettypes "github.com/sge-network/sge/x/market/types" ) diff --git a/x/bet/types/bet.pb.go b/x/bet/types/bet.pb.go index 32f77381..c783b631 100644 --- a/x/bet/types/bet.pb.go +++ b/x/bet/types/bet.pb.go @@ -4,6 +4,7 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" @@ -128,9 +129,9 @@ type Bet struct { // odds_value is the odds on which the bet is placed. OddsValue string `protobuf:"bytes,5,opt,name=odds_value,json=oddsValue,proto3" json:"odds_value,omitempty"` // amount is the wager amount. - Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,6,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` // fee is the betting fee user needs to pay for placing a bet - Fee github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,7,opt,name=fee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"fee"` + Fee cosmossdk_io_math.Int `protobuf:"bytes,7,opt,name=fee,proto3,customtype=cosmossdk.io/math.Int" json:"fee"` // status is the status of the bet, such as `unspecified` or `settled`. Status Bet_Status `protobuf:"varint,8,opt,name=status,proto3,enum=sgenetwork.sge.bet.Bet_Status" json:"status,omitempty"` // result is the result of the bet, such as `won` or `lost`. @@ -434,9 +435,9 @@ type BetFulfillment struct { // participation_index is the index in initial participation queue index ParticipationIndex uint64 `protobuf:"varint,2,opt,name=participation_index,json=participationIndex,proto3" json:"participation_index,omitempty" yaml:"participation_index"` // bet amount fulfilled by the participation - BetAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=bet_amount,json=betAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"bet_amount" yaml:"bet_amount"` + BetAmount cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=bet_amount,json=betAmount,proto3,customtype=cosmossdk.io/math.Int" json:"bet_amount" yaml:"bet_amount"` // payout_profit is the fulfilled profit by the participation. - PayoutProfit github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=payout_profit,json=payoutProfit,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"payout_profit" yaml:"payout_profit"` + PayoutProfit cosmossdk_io_math.Int `protobuf:"bytes,4,opt,name=payout_profit,json=payoutProfit,proto3,customtype=cosmossdk.io/math.Int" json:"payout_profit" yaml:"payout_profit"` } func (m *BetFulfillment) Reset() { *m = BetFulfillment{} } @@ -499,62 +500,63 @@ func init() { func init() { proto.RegisterFile("sge/bet/bet.proto", fileDescriptor_9bc076bb1a4d9f6e) } var fileDescriptor_9bc076bb1a4d9f6e = []byte{ - // 879 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x4f, 0x6f, 0xe2, 0x46, - 0x14, 0x8f, 0x71, 0x96, 0x84, 0x97, 0x84, 0x98, 0xc9, 0x6a, 0xd7, 0x4a, 0xb7, 0x80, 0x2c, 0xb5, - 0x8a, 0x54, 0x2d, 0x48, 0x59, 0xa9, 0x52, 0xdb, 0xcb, 0x02, 0x36, 0x0d, 0x2a, 0x0b, 0x68, 0x80, - 0x56, 0xea, 0xa1, 0x96, 0xc1, 0x13, 0xe2, 0xc6, 0x7f, 0x90, 0x67, 0xdc, 0x26, 0xe7, 0x7e, 0x80, - 0xf6, 0x23, 0xf4, 0xe3, 0xec, 0x71, 0x8f, 0x55, 0x0f, 0x56, 0x45, 0x6e, 0x3d, 0xee, 0x27, 0xa8, - 0x66, 0x3c, 0x21, 0x46, 0x4d, 0xab, 0x64, 0x0f, 0xc0, 0x9b, 0xdf, 0xfc, 0x7e, 0xbf, 0x37, 0xf3, - 0xfc, 0x78, 0x86, 0x0a, 0x5d, 0x90, 0xe6, 0x8c, 0x30, 0xfe, 0x69, 0x2c, 0xe3, 0x88, 0x45, 0x08, - 0xd1, 0x05, 0x09, 0x09, 0xfb, 0x39, 0x8a, 0x2f, 0x1b, 0x74, 0x41, 0x1a, 0x33, 0xc2, 0x8e, 0x9f, - 0x2e, 0xa2, 0x45, 0x24, 0xb6, 0x9b, 0x3c, 0xca, 0x98, 0xc7, 0xcf, 0x6f, 0xc5, 0x91, 0xeb, 0x52, - 0x9b, 0x5d, 0x2f, 0x49, 0xb6, 0x61, 0xfc, 0xba, 0x0b, 0x6a, 0x9b, 0x30, 0x54, 0x07, 0x35, 0xf1, - 0x5c, 0x5d, 0xa9, 0x2b, 0x27, 0xa5, 0x76, 0x79, 0x95, 0xd6, 0xd4, 0x69, 0xcf, 0xfc, 0x3b, 0xad, - 0x71, 0x14, 0xf3, 0x2f, 0xf4, 0x15, 0x40, 0xe0, 0xc4, 0x97, 0x84, 0xd9, 0x9c, 0x58, 0x10, 0xc4, - 0x8f, 0x56, 0x69, 0xad, 0xf4, 0x46, 0xa0, 0x19, 0x3d, 0x47, 0xc1, 0xb9, 0x18, 0xbd, 0x82, 0x5d, - 0x91, 0x99, 0x4b, 0x55, 0x21, 0x7d, 0xbe, 0x4a, 0x6b, 0x3b, 0x43, 0xd7, 0xa5, 0x99, 0x70, 0xbd, - 0x8d, 0xd7, 0x11, 0xfa, 0x02, 0x4a, 0xeb, 0xe3, 0xea, 0xdb, 0x75, 0xe5, 0xa4, 0x7c, 0xfa, 0xa2, - 0xf1, 0xef, 0x2b, 0x37, 0xb8, 0xcb, 0xe4, 0x7a, 0x49, 0x32, 0x29, 0x8f, 0xd0, 0xc7, 0x00, 0x42, - 0xfa, 0x93, 0xe3, 0x27, 0x44, 0x7f, 0xc2, 0x33, 0x62, 0x61, 0xf6, 0x2d, 0x07, 0x50, 0x17, 0x8a, - 0x4e, 0x10, 0x25, 0x21, 0xd3, 0x8b, 0xe2, 0x30, 0x8d, 0xb7, 0x69, 0x6d, 0xeb, 0xcf, 0xb4, 0xf6, - 0xe9, 0xc2, 0x63, 0x17, 0xc9, 0xac, 0x31, 0x8f, 0x82, 0xe6, 0x3c, 0xa2, 0x41, 0x44, 0xe5, 0xcf, - 0x4b, 0xea, 0x5e, 0x36, 0xf9, 0x39, 0x68, 0xa3, 0x17, 0x32, 0x2c, 0xd5, 0xe8, 0x35, 0xa8, 0xe7, - 0x84, 0xe8, 0x3b, 0x1f, 0x64, 0xc2, 0xa5, 0xe8, 0x73, 0x28, 0x52, 0xe6, 0xb0, 0x84, 0xea, 0xbb, - 0xe2, 0x82, 0xd5, 0xfb, 0x2e, 0xd8, 0x26, 0xac, 0x31, 0x16, 0x2c, 0x2c, 0xd9, 0x5c, 0x17, 0x13, - 0x9a, 0xf8, 0x4c, 0x2f, 0xfd, 0xbf, 0x0e, 0x0b, 0x16, 0x96, 0x6c, 0xa4, 0xc3, 0xce, 0x3c, 0x26, - 0x0e, 0x8b, 0x62, 0x1d, 0x44, 0x55, 0x6e, 0x97, 0xbc, 0x64, 0x22, 0x24, 0xae, 0xed, 0x30, 0x7d, - 0xaf, 0xae, 0x9c, 0xa8, 0xb8, 0x24, 0x91, 0x16, 0x43, 0x9f, 0x41, 0x85, 0x12, 0xc6, 0x7c, 0x12, - 0x90, 0x90, 0xd9, 0x17, 0xc4, 0x5b, 0x5c, 0x30, 0x7d, 0x5f, 0xb0, 0xb4, 0xbb, 0x8d, 0x33, 0x81, - 0xa3, 0x1f, 0xe0, 0x28, 0x70, 0xae, 0x6c, 0x3f, 0xa2, 0xd4, 0x0e, 0x12, 0x9f, 0x79, 0x4b, 0xdf, - 0x23, 0xb1, 0x7e, 0xf0, 0xe8, 0x3a, 0x99, 0x64, 0x8e, 0x2b, 0x81, 0x73, 0xd5, 0x8f, 0x28, 0x7d, - 0xb3, 0x36, 0x42, 0xdf, 0xc0, 0xe1, 0x8c, 0x30, 0xfb, 0x3c, 0xf1, 0xcf, 0x3d, 0xdf, 0xe7, 0x89, - 0xf5, 0x72, 0x5d, 0x3d, 0xd9, 0x3b, 0x35, 0xfe, 0xa3, 0x0c, 0xdd, 0x3b, 0x26, 0x2e, 0xcf, 0x36, - 0xd6, 0xc6, 0xef, 0x0a, 0x14, 0xb3, 0xea, 0xa2, 0x67, 0x80, 0xc6, 0x93, 0xd6, 0x64, 0x3a, 0xb6, - 0xa7, 0x83, 0xf1, 0xc8, 0xea, 0xf4, 0xba, 0x3d, 0xcb, 0xd4, 0xb6, 0x50, 0x05, 0x0e, 0x24, 0x3e, - 0xea, 0xb7, 0x3a, 0x96, 0xa9, 0x29, 0xe8, 0x08, 0x0e, 0x25, 0xd4, 0x69, 0x0d, 0x3a, 0x56, 0xdf, - 0x32, 0xb5, 0x02, 0x42, 0x50, 0x96, 0x60, 0xab, 0x3d, 0xc4, 0x13, 0xcb, 0xd4, 0xd4, 0x1c, 0x36, - 0xb2, 0x06, 0x66, 0x6f, 0xf0, 0xb5, 0xb6, 0x8d, 0x8e, 0xe1, 0x99, 0xc4, 0xb0, 0x35, 0x9e, 0xf6, - 0x27, 0xb6, 0x69, 0x75, 0xfa, 0x2d, 0x6c, 0x99, 0xda, 0x93, 0x1c, 0x7f, 0x6c, 0x4d, 0x26, 0xdc, - 0xb7, 0x68, 0xfc, 0x08, 0xc5, 0xec, 0x39, 0xf2, 0x13, 0x4a, 0xc9, 0xe6, 0x09, 0x11, 0x94, 0x25, - 0x7e, 0x9b, 0x45, 0x41, 0x65, 0x00, 0x89, 0x7d, 0x37, 0x1c, 0x68, 0x05, 0x74, 0x08, 0x7b, 0x72, - 0xdd, 0x1f, 0x8e, 0x27, 0x9a, 0xca, 0xef, 0x20, 0x01, 0x6c, 0x75, 0xa7, 0x03, 0xd3, 0x32, 0xb5, - 0x6d, 0xe3, 0x0c, 0x8a, 0xd3, 0x9e, 0x79, 0xda, 0x33, 0x1f, 0x30, 0x13, 0x5e, 0x40, 0x41, 0xce, - 0x82, 0xed, 0xf6, 0xfe, 0x2a, 0xad, 0x15, 0xc4, 0x7e, 0xc1, 0x73, 0x71, 0xc1, 0x73, 0x8d, 0x33, - 0x80, 0x11, 0x09, 0x5d, 0x2f, 0x5c, 0x3c, 0x6c, 0xc2, 0xe4, 0x7a, 0xb3, 0xb0, 0xd1, 0x9b, 0xc6, - 0x14, 0x60, 0x2c, 0x7a, 0xcc, 0x7d, 0x98, 0xd3, 0x27, 0xc0, 0x1f, 0x32, 0x8b, 0x62, 0xdb, 0x71, - 0xdd, 0x98, 0x50, 0x2a, 0x0d, 0x0f, 0x32, 0xb4, 0x95, 0x81, 0xc6, 0x2f, 0x2a, 0x94, 0x37, 0x9b, - 0x03, 0x0d, 0xe1, 0x68, 0xe9, 0xc4, 0xcc, 0x9b, 0x7b, 0x4b, 0x27, 0x64, 0x6b, 0x79, 0x96, 0xab, - 0xfa, 0x3e, 0xad, 0x1d, 0x5f, 0x3b, 0x81, 0xff, 0xa5, 0x71, 0x0f, 0xc9, 0xc0, 0x28, 0x87, 0xca, - 0x1c, 0x1b, 0x86, 0xcc, 0x8b, 0x42, 0xdb, 0x0b, 0x5d, 0x72, 0x25, 0x6b, 0x76, 0x9f, 0xe1, 0x1d, - 0x29, 0x6f, 0xc8, 0xd1, 0x1e, 0x07, 0xd1, 0x0c, 0x80, 0xf7, 0xbe, 0x9c, 0x5f, 0xd9, 0x30, 0xed, - 0x3c, 0x6e, 0xf4, 0xbc, 0x4f, 0x6b, 0x95, 0x2c, 0xeb, 0x9d, 0x93, 0x81, 0x4b, 0x33, 0xc2, 0x5a, - 0xd9, 0x5c, 0xbb, 0x84, 0x83, 0xa5, 0x73, 0x1d, 0x25, 0xcc, 0x5e, 0xc6, 0xd1, 0xb9, 0xc7, 0xc4, - 0xf4, 0x2d, 0xb5, 0xbb, 0x8f, 0x4e, 0xf3, 0xf4, 0xf6, 0x72, 0x39, 0x33, 0x03, 0xef, 0x67, 0xeb, - 0x91, 0x58, 0xb6, 0x5f, 0xbf, 0x5d, 0x55, 0x95, 0x77, 0xab, 0xaa, 0xf2, 0xd7, 0xaa, 0xaa, 0xfc, - 0x76, 0x53, 0xdd, 0x7a, 0x77, 0x53, 0xdd, 0xfa, 0xe3, 0xa6, 0xba, 0xf5, 0x7d, 0x3e, 0x0f, 0x5d, - 0x90, 0x97, 0xf2, 0x8f, 0xcd, 0xe3, 0xe6, 0x95, 0x78, 0x9d, 0x89, 0x5c, 0xb3, 0xa2, 0x78, 0x97, - 0xbd, 0xfa, 0x27, 0x00, 0x00, 0xff, 0xff, 0xfa, 0xa0, 0x08, 0x67, 0x23, 0x07, 0x00, 0x00, + // 895 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x41, 0x6f, 0xe2, 0x46, + 0x14, 0xc6, 0x90, 0x25, 0xcb, 0x4b, 0x42, 0xcc, 0x64, 0xbb, 0x6b, 0xa5, 0xbb, 0x80, 0x2c, 0xb5, + 0x8a, 0x54, 0xad, 0x91, 0xb2, 0xda, 0x4a, 0x6d, 0x2f, 0x05, 0xec, 0x34, 0xa8, 0x2c, 0xd0, 0x01, + 0x5a, 0x69, 0x0f, 0xb5, 0x0c, 0x9e, 0x10, 0x37, 0x36, 0x83, 0x3c, 0x43, 0x9b, 0xfc, 0x8b, 0xfe, + 0x84, 0xfe, 0x9c, 0x3d, 0xee, 0xb1, 0xea, 0xc1, 0x6a, 0xc9, 0xad, 0x52, 0x2f, 0xfb, 0x0b, 0xaa, + 0x19, 0x4f, 0x88, 0x51, 0xd3, 0xdd, 0x1c, 0x12, 0xde, 0x7c, 0xf3, 0x7d, 0xef, 0xbd, 0x79, 0xf3, + 0xe6, 0x19, 0x2a, 0x6c, 0x46, 0x1a, 0x13, 0xc2, 0xc5, 0x9f, 0xb5, 0x88, 0x29, 0xa7, 0x08, 0xb1, + 0x19, 0x99, 0x13, 0xfe, 0x0b, 0x8d, 0x2f, 0x2c, 0x36, 0x23, 0xd6, 0x84, 0xf0, 0xc3, 0x47, 0x33, + 0x3a, 0xa3, 0x72, 0xbb, 0x21, 0xac, 0x94, 0x79, 0xf8, 0xe4, 0x46, 0x4c, 0x7d, 0x9f, 0xb9, 0xfc, + 0x6a, 0x41, 0xd2, 0x0d, 0xf3, 0x9f, 0x6d, 0x28, 0xb4, 0x08, 0x47, 0x75, 0x28, 0x2c, 0x03, 0xdf, + 0xd0, 0xea, 0xda, 0x51, 0xa9, 0x55, 0x5e, 0x25, 0xb5, 0xc2, 0xb8, 0x63, 0xff, 0x9d, 0xd4, 0x04, + 0x8a, 0xc5, 0x3f, 0xf4, 0x15, 0x40, 0xe4, 0xc5, 0x17, 0x84, 0xbb, 0x82, 0x98, 0x97, 0xc4, 0x8f, + 0x57, 0x49, 0xad, 0xf4, 0x4a, 0xa2, 0x29, 0x3d, 0x43, 0xc1, 0x19, 0x1b, 0xbd, 0x80, 0x87, 0x32, + 0xb2, 0x90, 0x16, 0xa4, 0xf4, 0xc9, 0x2a, 0xa9, 0x6d, 0xf7, 0x7d, 0x9f, 0xa5, 0xc2, 0xf5, 0x36, + 0x5e, 0x5b, 0xe8, 0x0b, 0x28, 0xad, 0xd3, 0x35, 0xb6, 0xea, 0xda, 0x51, 0xf9, 0xf8, 0xa9, 0xf5, + 0xdf, 0x23, 0x5b, 0xc2, 0xcb, 0xe8, 0x6a, 0x41, 0x52, 0xa9, 0xb0, 0xd0, 0x33, 0x00, 0x29, 0xfd, + 0xd9, 0x0b, 0x97, 0xc4, 0x78, 0x20, 0x22, 0x62, 0xe9, 0xec, 0x7b, 0x01, 0xa0, 0x97, 0x50, 0xf4, + 0x22, 0xba, 0x9c, 0x73, 0xa3, 0x28, 0x93, 0x79, 0xf6, 0x26, 0xa9, 0xe5, 0xfe, 0x48, 0x6a, 0x1f, + 0x4d, 0x29, 0x8b, 0x28, 0x63, 0xfe, 0x85, 0x15, 0xd0, 0x46, 0xe4, 0xf1, 0x73, 0xab, 0x33, 0xe7, + 0x58, 0x91, 0x51, 0x03, 0x0a, 0x67, 0x84, 0x18, 0xdb, 0xf7, 0xd1, 0x08, 0x26, 0xfa, 0x1c, 0x8a, + 0x8c, 0x7b, 0x7c, 0xc9, 0x8c, 0x87, 0x32, 0xfd, 0xea, 0x5d, 0xe9, 0xb7, 0x08, 0xb7, 0x86, 0x92, + 0x85, 0x15, 0x5b, 0xe8, 0x62, 0xc2, 0x96, 0x21, 0x37, 0x4a, 0xef, 0xd7, 0x61, 0xc9, 0xc2, 0x8a, + 0x8d, 0x0c, 0xd8, 0x9e, 0xc6, 0xc4, 0xe3, 0x34, 0x36, 0x40, 0x9e, 0xf9, 0x66, 0x29, 0x0a, 0x22, + 0x4d, 0xe2, 0xbb, 0x1e, 0x37, 0x76, 0xea, 0xda, 0x51, 0x01, 0x97, 0x14, 0xd2, 0xe4, 0xe8, 0x33, + 0xa8, 0x30, 0xc2, 0x79, 0x48, 0x22, 0x32, 0xe7, 0xee, 0x39, 0x09, 0x66, 0xe7, 0xdc, 0xd8, 0x95, + 0x2c, 0xfd, 0x76, 0xe3, 0x54, 0xe2, 0xe8, 0x47, 0x38, 0x88, 0xbc, 0x4b, 0x37, 0xa4, 0x8c, 0xb9, + 0xd1, 0x32, 0xe4, 0xc1, 0x22, 0x0c, 0x48, 0x6c, 0xec, 0xc9, 0xb2, 0x58, 0xaa, 0x2c, 0x9f, 0xce, + 0x02, 0x7e, 0xbe, 0x9c, 0x58, 0x53, 0x1a, 0x35, 0xd2, 0x0a, 0xa9, 0x9f, 0xe7, 0xcc, 0xbf, 0x68, + 0x88, 0x2b, 0x65, 0x96, 0x4d, 0xa6, 0xb8, 0x12, 0x79, 0x97, 0x5d, 0xca, 0xd8, 0xab, 0xb5, 0x23, + 0xf4, 0x2d, 0xec, 0x4f, 0x08, 0x77, 0xcf, 0x96, 0xe1, 0x59, 0x10, 0x86, 0x22, 0xb0, 0x51, 0xae, + 0x17, 0x8e, 0x76, 0x8e, 0xcd, 0xff, 0x29, 0xc3, 0xc9, 0x2d, 0x13, 0x97, 0x27, 0x1b, 0x6b, 0xf3, + 0x37, 0x0d, 0x8a, 0x69, 0x75, 0xd1, 0x63, 0x40, 0xc3, 0x51, 0x73, 0x34, 0x1e, 0xba, 0xe3, 0xde, + 0x70, 0xe0, 0xb4, 0x3b, 0x27, 0x1d, 0xc7, 0xd6, 0x73, 0xa8, 0x02, 0x7b, 0x0a, 0x1f, 0x74, 0x9b, + 0x6d, 0xc7, 0xd6, 0x35, 0x74, 0x00, 0xfb, 0x0a, 0x6a, 0x37, 0x7b, 0x6d, 0xa7, 0xeb, 0xd8, 0x7a, + 0x1e, 0x21, 0x28, 0x2b, 0xb0, 0xd9, 0xea, 0xe3, 0x91, 0x63, 0xeb, 0x85, 0x0c, 0x36, 0x70, 0x7a, + 0x76, 0xa7, 0xf7, 0x8d, 0xbe, 0x85, 0x0e, 0xe1, 0xb1, 0xc2, 0xb0, 0x33, 0x1c, 0x77, 0x47, 0xae, + 0xed, 0xb4, 0xbb, 0x4d, 0xec, 0xd8, 0xfa, 0x83, 0x0c, 0x7f, 0xe8, 0x8c, 0x46, 0xc2, 0x6f, 0xd1, + 0xfc, 0x09, 0x8a, 0xe9, 0x3d, 0x8a, 0x0c, 0x95, 0x64, 0x33, 0x43, 0x04, 0x65, 0x85, 0xdf, 0x44, + 0xd1, 0x50, 0x19, 0x40, 0x61, 0x3f, 0xf4, 0x7b, 0x7a, 0x1e, 0xed, 0xc3, 0x8e, 0x5a, 0x77, 0xfb, + 0xc3, 0x91, 0x5e, 0x10, 0x67, 0x50, 0x00, 0x76, 0x4e, 0xc6, 0x3d, 0xdb, 0xb1, 0xf5, 0x2d, 0xf3, + 0x14, 0x8a, 0xe3, 0x8e, 0x7d, 0xdc, 0xb1, 0xef, 0xf1, 0xe2, 0x9f, 0x42, 0x5e, 0xbd, 0xf4, 0xad, + 0xd6, 0xee, 0x2a, 0xa9, 0xe5, 0xe5, 0x7e, 0x3e, 0xf0, 0x71, 0x3e, 0xf0, 0xcd, 0x53, 0x80, 0x01, + 0x99, 0xfb, 0xc1, 0x7c, 0x76, 0xbf, 0xf9, 0x91, 0xe9, 0xcd, 0xfc, 0x46, 0x6f, 0x9a, 0x63, 0x80, + 0xa1, 0xec, 0x31, 0xff, 0x7e, 0x9e, 0x3e, 0x01, 0x71, 0xc9, 0x9c, 0xc6, 0xae, 0xe7, 0xfb, 0x31, + 0x61, 0x4c, 0x39, 0xdc, 0x4b, 0xd1, 0x66, 0x0a, 0x9a, 0x7f, 0xe5, 0xa1, 0xbc, 0xd9, 0x1c, 0xa8, + 0x0f, 0x07, 0x0b, 0x2f, 0xe6, 0xc1, 0x34, 0x58, 0x78, 0x73, 0xbe, 0x96, 0xa7, 0xb1, 0xaa, 0xef, + 0x92, 0xda, 0xe1, 0x95, 0x17, 0x85, 0x5f, 0x9a, 0x77, 0x90, 0x4c, 0x8c, 0x32, 0xa8, 0x8a, 0xb1, + 0xe1, 0x90, 0x07, 0x74, 0xee, 0x06, 0x73, 0x9f, 0x5c, 0xaa, 0x9a, 0xdd, 0xe5, 0xf0, 0x96, 0x94, + 0x75, 0x28, 0xd0, 0x8e, 0x00, 0xd1, 0x77, 0x00, 0xa2, 0xf7, 0xd5, 0x74, 0x4a, 0x47, 0xe5, 0xf1, + 0x7b, 0x27, 0xcd, 0xbb, 0xa4, 0x56, 0x49, 0x83, 0xdc, 0x0a, 0x4d, 0x5c, 0x9a, 0x10, 0xde, 0x4c, + 0xa7, 0xd6, 0x6b, 0xd8, 0x5b, 0x78, 0x57, 0x74, 0xc9, 0xdd, 0x45, 0x4c, 0xcf, 0x02, 0x2e, 0x47, + 0x69, 0xa9, 0xf5, 0xf2, 0x43, 0x5e, 0x1f, 0xdd, 0xa4, 0x9e, 0xd1, 0x9a, 0x78, 0x37, 0x5d, 0x0f, + 0xe4, 0xb2, 0xf5, 0xf5, 0x9b, 0x55, 0x55, 0x7b, 0xbb, 0xaa, 0x6a, 0x7f, 0xae, 0xaa, 0xda, 0xaf, + 0xd7, 0xd5, 0xdc, 0xdb, 0xeb, 0x6a, 0xee, 0xf7, 0xeb, 0x6a, 0xee, 0x75, 0xf6, 0xfd, 0xb3, 0x19, + 0x79, 0xae, 0x9e, 0xad, 0xb0, 0x1b, 0x97, 0xf2, 0x53, 0x24, 0x67, 0xc0, 0xa4, 0x28, 0xbf, 0x43, + 0x2f, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x87, 0x67, 0xbe, 0xdf, 0x06, 0x00, 0x00, } func (m *Bet) Marshal() (dAtA []byte, err error) { diff --git a/x/bet/types/bet_test.go b/x/bet/types/bet_test.go index e4e7a8f0..f42db502 100644 --- a/x/bet/types/bet_test.go +++ b/x/bet/types/bet_test.go @@ -3,9 +3,10 @@ package types_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/sge-network/sge/x/bet/types" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) func TestCheckSettlementEligiblity(t *testing.T) { diff --git a/x/bet/types/codec.go b/x/bet/types/codec.go index b09f7fac..488a4623 100644 --- a/x/bet/types/codec.go +++ b/x/bet/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/msgservice" ) diff --git a/x/bet/types/constraints.pb.go b/x/bet/types/constraints.pb.go index 553b6b33..c598502a 100644 --- a/x/bet/types/constraints.pb.go +++ b/x/bet/types/constraints.pb.go @@ -4,8 +4,8 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -27,9 +27,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Constraints is the bet constrains type for the bets type Constraints struct { // min_amount is the minimum allowed bet amount. - MinAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=min_amount,json=minAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_amount"` + MinAmount cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=min_amount,json=minAmount,proto3,customtype=cosmossdk.io/math.Int" json:"min_amount"` // fee is the fee that the bettor needs to pay to bet. - Fee github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=fee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"fee"` + Fee cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=fee,proto3,customtype=cosmossdk.io/math.Int" json:"fee"` } func (m *Constraints) Reset() { *m = Constraints{} } @@ -77,16 +77,16 @@ var fileDescriptor_902ec3e683a9aac6 = []byte{ 0x4f, 0x4a, 0x2d, 0xd1, 0x4f, 0xce, 0xcf, 0x2b, 0x2e, 0x29, 0x4a, 0xcc, 0xcc, 0x2b, 0x29, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x2a, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x2b, 0x4e, 0x4f, 0xd5, 0x4b, 0x4a, 0x2d, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, - 0x4b, 0xeb, 0x83, 0x58, 0x10, 0x95, 0x4a, 0xf3, 0x18, 0xb9, 0xb8, 0x9d, 0x11, 0xfa, 0x85, 0x7c, - 0xb9, 0xb8, 0x72, 0x33, 0xf3, 0xe2, 0x13, 0x73, 0xf3, 0x4b, 0xf3, 0x4a, 0x24, 0x18, 0x15, 0x18, - 0x35, 0x38, 0x9d, 0xf4, 0x4e, 0xdc, 0x93, 0x67, 0xb8, 0x75, 0x4f, 0x5e, 0x2d, 0x3d, 0xb3, 0x24, - 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x18, 0x4a, 0xe9, - 0x16, 0xa7, 0x64, 0xeb, 0x97, 0x54, 0x16, 0xa4, 0x16, 0xeb, 0x79, 0xe6, 0x95, 0x04, 0x71, 0xe6, - 0x66, 0xe6, 0x39, 0x82, 0x0d, 0x10, 0x72, 0xe0, 0x62, 0x4e, 0x4b, 0x4d, 0x95, 0x60, 0x22, 0xcb, - 0x1c, 0x90, 0x56, 0x27, 0x87, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, - 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x42, - 0x36, 0xa6, 0x38, 0x3d, 0x55, 0x17, 0xea, 0x61, 0x10, 0x5b, 0xbf, 0x02, 0x1c, 0x30, 0x60, 0xa3, - 0x92, 0xd8, 0xc0, 0x3e, 0x35, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x30, 0xdb, 0xa2, 0x4c, 0x30, + 0x4b, 0xeb, 0x83, 0x58, 0x10, 0x95, 0x4a, 0x35, 0x5c, 0xdc, 0xce, 0x08, 0xed, 0x42, 0x36, 0x5c, + 0x5c, 0xb9, 0x99, 0x79, 0xf1, 0x89, 0xb9, 0xf9, 0xa5, 0x79, 0x25, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, + 0x9c, 0x4e, 0xb2, 0x27, 0xee, 0xc9, 0x33, 0xdc, 0xba, 0x27, 0x2f, 0x9a, 0x9c, 0x5f, 0x9c, 0x9b, + 0x5f, 0x5c, 0x9c, 0x92, 0xad, 0x97, 0x99, 0xaf, 0x9f, 0x9b, 0x58, 0x92, 0xa1, 0xe7, 0x99, 0x57, + 0x12, 0xc4, 0x99, 0x9b, 0x99, 0xe7, 0x08, 0x56, 0x2f, 0xa4, 0xcf, 0xc5, 0x9c, 0x96, 0x9a, 0x2a, + 0xc1, 0x44, 0x8c, 0x36, 0x90, 0x4a, 0x27, 0x87, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, + 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, + 0x63, 0x88, 0x52, 0x4b, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x2f, 0x4e, + 0x4f, 0xd5, 0x85, 0xfa, 0x06, 0xc4, 0xd6, 0xaf, 0x00, 0xfb, 0xba, 0xa4, 0xb2, 0x20, 0xb5, 0x38, + 0x89, 0x0d, 0xec, 0x0d, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x09, 0xd4, 0x97, 0xc8, 0x0d, 0x01, 0x00, 0x00, } diff --git a/x/bet/types/errors.go b/x/bet/types/errors.go index bc76fce1..3e1a04c3 100644 --- a/x/bet/types/errors.go +++ b/x/bet/types/errors.go @@ -3,7 +3,7 @@ package types // DONTCOVER import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "cosmossdk.io/errors" ) // x/bet module sentinel errors diff --git a/x/bet/types/expected_keepers.go b/x/bet/types/expected_keepers.go index a2c5045b..5025d9fd 100644 --- a/x/bet/types/expected_keepers.go +++ b/x/bet/types/expected_keepers.go @@ -6,6 +6,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" + markettypes "github.com/sge-network/sge/x/market/types" ) diff --git a/x/bet/types/genesis_test.go b/x/bet/types/genesis_test.go index 3d39854d..7934c9ea 100644 --- a/x/bet/types/genesis_test.go +++ b/x/bet/types/genesis_test.go @@ -4,8 +4,9 @@ import ( "testing" "github.com/google/uuid" - "github.com/sge-network/sge/x/bet/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/bet/types" ) const ( diff --git a/x/bet/types/messages_bet.go b/x/bet/types/messages_bet.go index 9a684e1d..bdb77067 100644 --- a/x/bet/types/messages_bet.go +++ b/x/bet/types/messages_bet.go @@ -3,8 +3,10 @@ package types import ( "strings" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" ) @@ -51,7 +53,7 @@ func (msg *MsgWager) GetSignBytes() []byte { func (msg *MsgWager) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil || msg.Creator == "" || strings.Contains(msg.Creator, " ") { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } return WagerValidation(msg.Props) diff --git a/x/bet/types/messages_bet_test.go b/x/bet/types/messages_bet_test.go index 8d9e45dd..2b301186 100644 --- a/x/bet/types/messages_bet_test.go +++ b/x/bet/types/messages_bet_test.go @@ -3,11 +3,12 @@ package types_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkmath "cosmossdk.io/math" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/bet/types" - "github.com/stretchr/testify/require" ) func TestMsgWagerValidateBasic(t *testing.T) { @@ -21,7 +22,7 @@ func TestMsgWagerValidateBasic(t *testing.T) { msg: types.MsgWager{ Creator: "invalid_address", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "valid bet message", @@ -29,7 +30,7 @@ func TestMsgWagerValidateBasic(t *testing.T) { Creator: sample.AccAddress(), Props: &types.WagerProps{ UID: "6e31c60f-2025-48ce-ae79-1dc110f16355", - Amount: sdk.NewInt(int64(10)), + Amount: sdkmath.NewInt(int64(10)), Ticket: "Ticket", }, }, @@ -62,7 +63,7 @@ func TestNewBet(t *testing.T) { inputBet := &types.WagerProps{ UID: "betUid", Ticket: "ticket", - Amount: sdk.NewInt(int64(10)), + Amount: sdkmath.NewInt(int64(10)), } creator := "creator" inputBetOdds := &types.BetOdds{ diff --git a/x/bet/types/odds_type.go b/x/bet/types/odds_type.go index 054bb016..3933a4d0 100644 --- a/x/bet/types/odds_type.go +++ b/x/bet/types/odds_type.go @@ -3,9 +3,9 @@ package types import ( "strings" + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) type OddsTypeI interface { @@ -91,14 +91,14 @@ func (*fractionalOdds) CalculatePayout(oddsVal string, amount sdkmath.Int) (sdk. } // the fraction part should be an integer, values such as 1.5/2 is not accepted - firstPart, ok := sdk.NewIntFromString(fraction[0]) + firstPart, ok := sdkmath.NewIntFromString(fraction[0]) if !ok { return sdk.ZeroDec(), sdkerrors.Wrapf(ErrFractionalOddsIncorrectFormat, "%s, invalid integer %s", oddsVal, fraction[0]) } // the fraction part should be an integer, values such as 1/2.5 is not accepted - secondPart, ok := sdk.NewIntFromString(fraction[1]) + secondPart, ok := sdkmath.NewIntFromString(fraction[1]) if !ok { return sdk.ZeroDec(), sdkerrors.Wrapf(ErrFractionalOddsIncorrectFormat, "%s, invalid integer %s", oddsVal, fraction[1]) @@ -134,14 +134,14 @@ func (*fractionalOdds) CalculateBetAmount(oddsVal string, payoutProfit sdk.Dec) } // the fraction part should be an integer, values such as 1.5/2 is not accepted - firstPart, ok := sdk.NewIntFromString(fraction[0]) + firstPart, ok := sdkmath.NewIntFromString(fraction[0]) if !ok { return sdk.ZeroDec(), sdkerrors.Wrapf(ErrFractionalOddsIncorrectFormat, "%s, invalid integer %s", oddsVal, fraction[0]) } // the fraction part should be an integer, values such as 1/2.5 is not accepted - secondPart, ok := sdk.NewIntFromString(fraction[1]) + secondPart, ok := sdkmath.NewIntFromString(fraction[1]) if !ok { return sdk.ZeroDec(), sdkerrors.Wrapf(ErrFractionalOddsIncorrectFormat, "%s, invalid integer %s", oddsVal, fraction[1]) @@ -170,7 +170,7 @@ type moneylineOdds struct{} // CalculatePayout calculates total payout of a certain bet amount by moneyline odds calculations func (*moneylineOdds) CalculatePayout(oddsVal string, amount sdkmath.Int) (sdk.Dec, error) { // moneyline odds value could be integer - oddsValue, ok := sdk.NewIntFromString(oddsVal) + oddsValue, ok := sdkmath.NewIntFromString(oddsVal) if !ok { return sdk.ZeroDec(), sdkerrors.Wrapf(ErrMoneylineOddsIncorrectFormat, "%s", oddsVal) @@ -205,7 +205,7 @@ func (*moneylineOdds) CalculatePayout(oddsVal string, amount sdkmath.Int) (sdk.D // CalculateBetAmount calculates bet amount func (*moneylineOdds) CalculateBetAmount(oddsVal string, payoutProfit sdk.Dec) (sdk.Dec, error) { // moneyline odds value could be integer - oddsValue, ok := sdk.NewIntFromString(oddsVal) + oddsValue, ok := sdkmath.NewIntFromString(oddsVal) if !ok { return sdk.ZeroDec(), sdkerrors.Wrapf(ErrMoneylineOddsIncorrectFormat, "%s", oddsVal) diff --git a/x/bet/types/params.go b/x/bet/types/params.go index d738d567..c85b69d6 100644 --- a/x/bet/types/params.go +++ b/x/bet/types/params.go @@ -3,9 +3,11 @@ package types import ( fmt "fmt" + "gopkg.in/yaml.v2" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "gopkg.in/yaml.v2" ) const ( @@ -14,8 +16,8 @@ const ( ) var ( - defaultMinAmount = sdk.NewInt(1000000) - defaultFee = sdk.NewInt(100) + defaultMinAmount = sdkmath.NewInt(1000000) + defaultFee = sdkmath.NewInt(100) ) // parameter store keys diff --git a/x/bet/types/payout_test.go b/x/bet/types/payout_test.go index 29e85cd2..6b131b34 100644 --- a/x/bet/types/payout_test.go +++ b/x/bet/types/payout_test.go @@ -3,12 +3,15 @@ package types_test import ( "testing" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/bet/types" - "github.com/stretchr/testify/require" ) -var ecceptedTruncatedValue = sdk.NewInt(1) +var ecceptedTruncatedValue = sdkmath.NewInt(1) var defaultBetAmount = int64(35625789) @@ -56,13 +59,13 @@ func TestCalculateDecimalPayout(t *testing.T) { payoutProfit, err := types.CalculatePayoutProfit( types.OddsType_ODDS_TYPE_DECIMAL, tc.oddsValue, - sdk.NewInt(tc.betAmount), + sdkmath.NewInt(tc.betAmount), ) if tc.err != nil { require.ErrorIs(t, tc.err, err) } else { require.NoError(t, err) - require.True(t, sdk.NewInt(tc.expVal).Equal(payoutProfit.TruncateInt()), "expected: %d, actual: %d", tc.expVal, payoutProfit) + require.True(t, sdkmath.NewInt(tc.expVal).Equal(payoutProfit.TruncateInt()), "expected: %d, actual: %d", tc.expVal, payoutProfit) } calcBetAmount, err := types.CalculateBetAmount( @@ -74,7 +77,7 @@ func TestCalculateDecimalPayout(t *testing.T) { require.ErrorIs(t, tc.err, err) } else { require.NoError(t, err) - require.True(t, sdk.NewInt(tc.betAmount).Sub(calcBetAmount.Ceil().TruncateInt()).LT(ecceptedTruncatedValue), "expected: %d, actual: %d", tc.betAmount, calcBetAmount) + require.True(t, sdkmath.NewInt(tc.betAmount).Sub(calcBetAmount.Ceil().TruncateInt()).LT(ecceptedTruncatedValue), "expected: %d, actual: %d", tc.betAmount, calcBetAmount) } }) } @@ -187,13 +190,13 @@ func TestCalculateFractionalPayout(t *testing.T) { payoutProfit, err := types.CalculatePayoutProfit( types.OddsType_ODDS_TYPE_FRACTIONAL, tc.oddsValue, - sdk.NewInt(tc.betAmount), + sdkmath.NewInt(tc.betAmount), ) if tc.err != nil { require.ErrorIs(t, tc.err, err) } else { require.NoError(t, err) - require.True(t, sdk.NewInt(tc.expVal).Equal(payoutProfit.TruncateInt()), "expected: %d, actual: %d", tc.expVal, payoutProfit) + require.True(t, sdkmath.NewInt(tc.expVal).Equal(payoutProfit.TruncateInt()), "expected: %d, actual: %d", tc.expVal, payoutProfit) } calcBetAmount, err := types.CalculateBetAmount( @@ -205,7 +208,7 @@ func TestCalculateFractionalPayout(t *testing.T) { require.ErrorIs(t, tc.err, err) } else { require.NoError(t, err) - require.True(t, sdk.NewInt(tc.betAmount).Sub(calcBetAmount.Ceil().RoundInt()).Abs().LTE(ecceptedTruncatedValue), "expected: %d, actual: %d", tc.betAmount, calcBetAmount) + require.True(t, sdkmath.NewInt(tc.betAmount).Sub(calcBetAmount.Ceil().RoundInt()).Abs().LTE(ecceptedTruncatedValue), "expected: %d, actual: %d", tc.betAmount, calcBetAmount) } }) } @@ -311,13 +314,13 @@ func TestCalculateMoneylinePayout(t *testing.T) { payoutProfit, err := types.CalculatePayoutProfit( types.OddsType_ODDS_TYPE_MONEYLINE, tc.oddsValue, - sdk.NewInt(tc.betAmount), + sdkmath.NewInt(tc.betAmount), ) if tc.err != nil { require.ErrorIs(t, tc.err, err) } else { require.NoError(t, err) - require.True(t, sdk.NewInt(tc.expVal).Equal(payoutProfit.TruncateInt()), "expected: %d, actual: %d", tc.expVal, payoutProfit) + require.True(t, sdkmath.NewInt(tc.expVal).Equal(payoutProfit.TruncateInt()), "expected: %d, actual: %d", tc.expVal, payoutProfit) } calcBetAmount, err := types.CalculateBetAmount( @@ -329,7 +332,7 @@ func TestCalculateMoneylinePayout(t *testing.T) { require.ErrorIs(t, tc.err, err) } else { require.NoError(t, err) - require.True(t, sdk.NewInt(tc.betAmount).Sub(calcBetAmount.Ceil().TruncateInt()).Abs().LTE(ecceptedTruncatedValue), "expected: %d, actual: %d", tc.betAmount, calcBetAmount) + require.True(t, sdkmath.NewInt(tc.betAmount).Sub(calcBetAmount.Ceil().TruncateInt()).Abs().LTE(ecceptedTruncatedValue), "expected: %d, actual: %d", tc.betAmount, calcBetAmount) } }) } diff --git a/x/bet/types/ticket.go b/x/bet/types/ticket.go index 19b43bfc..b3c0909e 100644 --- a/x/bet/types/ticket.go +++ b/x/bet/types/ticket.go @@ -3,8 +3,9 @@ package types import ( "strings" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" ) diff --git a/x/bet/types/ticket_test.go b/x/bet/types/ticket_test.go index 4ca2618a..59348f94 100644 --- a/x/bet/types/ticket_test.go +++ b/x/bet/types/ticket_test.go @@ -3,10 +3,12 @@ package types_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + sgetypes "github.com/sge-network/sge/types" "github.com/sge-network/sge/x/bet/types" - "github.com/stretchr/testify/require" ) func TestTicketFieldsValidation(t *testing.T) { diff --git a/x/bet/types/wager.pb.go b/x/bet/types/wager.pb.go index 2123470c..730d4090 100644 --- a/x/bet/types/wager.pb.go +++ b/x/bet/types/wager.pb.go @@ -4,8 +4,8 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -29,7 +29,7 @@ type WagerProps struct { // uid is the universal unique identifier assigned to bet. UID string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"` // amount is the wager amount. - Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` // ticket is a signed string containing important info such as `oddsValue`. Ticket string `protobuf:"bytes,3,opt,name=ticket,proto3" json:"ticket,omitempty"` } @@ -93,18 +93,18 @@ var fileDescriptor_b14a4fe747361920 = []byte{ 0x4f, 0x4a, 0x2d, 0xd1, 0x2f, 0x4f, 0x4c, 0x4f, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x2a, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x2b, 0x4e, 0x4f, 0xd5, 0x4b, 0x4a, 0x2d, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x4b, 0xeb, 0x83, 0x58, 0x10, 0x95, - 0x4a, 0x7d, 0x8c, 0x5c, 0x5c, 0xe1, 0x20, 0x9d, 0x01, 0x45, 0xf9, 0x05, 0xc5, 0x42, 0x0a, 0x5c, - 0xcc, 0xa5, 0x99, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x4e, 0x7c, 0x8f, 0xee, 0xc9, 0x33, - 0x87, 0x7a, 0xba, 0xbc, 0xba, 0x27, 0x0f, 0x12, 0x0d, 0x02, 0x11, 0x42, 0x6e, 0x5c, 0x6c, 0x89, - 0xb9, 0xf9, 0xa5, 0x79, 0x25, 0x12, 0x4c, 0x60, 0x45, 0x7a, 0x27, 0xee, 0xc9, 0x33, 0xdc, 0xba, - 0x27, 0xaf, 0x96, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x9c, 0x5f, - 0x9c, 0x9b, 0x5f, 0x0c, 0xa5, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0xf5, - 0x3c, 0xf3, 0x4a, 0x82, 0xa0, 0xba, 0x85, 0xc4, 0xb8, 0xd8, 0x4a, 0x32, 0x93, 0xb3, 0x53, 0x4b, - 0x24, 0x98, 0x41, 0xe6, 0x04, 0x41, 0x79, 0x4e, 0x0e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, - 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, - 0x2c, 0xc7, 0x10, 0x85, 0x6c, 0x43, 0x71, 0x7a, 0xaa, 0x2e, 0xd4, 0x83, 0x20, 0xb6, 0x7e, 0x05, - 0x38, 0x08, 0xc0, 0xb6, 0x24, 0xb1, 0x81, 0x7d, 0x66, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x5d, - 0x87, 0x3f, 0x36, 0x1a, 0x01, 0x00, 0x00, + 0x4a, 0xb5, 0x5c, 0x5c, 0xe1, 0x20, 0x8d, 0x01, 0x45, 0xf9, 0x05, 0xc5, 0x42, 0x0a, 0x5c, 0xcc, + 0xa5, 0x99, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x4e, 0x7c, 0x8f, 0xee, 0xc9, 0x33, 0x87, + 0x7a, 0xba, 0xbc, 0xba, 0x27, 0x0f, 0x12, 0x0d, 0x02, 0x11, 0x42, 0xa6, 0x5c, 0x6c, 0x89, 0xb9, + 0xf9, 0xa5, 0x79, 0x25, 0x12, 0x4c, 0x60, 0x45, 0xb2, 0x27, 0xee, 0xc9, 0x33, 0xdc, 0xba, 0x27, + 0x2f, 0x9a, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0x5c, 0x9c, 0x92, 0xad, 0x97, 0x99, 0xaf, 0x9f, 0x9b, + 0x58, 0x92, 0xa1, 0xe7, 0x99, 0x57, 0x12, 0x04, 0x55, 0x2c, 0x24, 0xc6, 0xc5, 0x56, 0x92, 0x99, + 0x9c, 0x9d, 0x5a, 0x22, 0xc1, 0x0c, 0xd2, 0x16, 0x04, 0xe5, 0x39, 0x39, 0x9c, 0x78, 0x24, 0xc7, + 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, + 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x5a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, + 0x7e, 0xae, 0x7e, 0x71, 0x7a, 0xaa, 0x2e, 0xd4, 0x3b, 0x20, 0xb6, 0x7e, 0x05, 0xd8, 0xc3, 0x25, + 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x7f, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x70, + 0xf1, 0xda, 0x76, 0x08, 0x01, 0x00, 0x00, } func (m *WagerProps) Marshal() (dAtA []byte, err error) { diff --git a/x/bet/types/wager_test.go b/x/bet/types/wager_test.go index a3b33acd..b1200a9c 100644 --- a/x/bet/types/wager_test.go +++ b/x/bet/types/wager_test.go @@ -3,9 +3,10 @@ package types_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sge-network/sge/x/bet/types" + sdkmath "cosmossdk.io/math" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/bet/types" ) func TestBetFieldsValidation(t *testing.T) { @@ -18,7 +19,7 @@ func TestBetFieldsValidation(t *testing.T) { desc: "space in UID", bet: &types.WagerProps{ UID: " ", - Amount: sdk.NewInt(int64(10)), + Amount: sdkmath.NewInt(int64(10)), Ticket: "Ticket", }, err: types.ErrInvalidBetUID, @@ -27,7 +28,7 @@ func TestBetFieldsValidation(t *testing.T) { desc: "invalid UID", bet: &types.WagerProps{ UID: "invalidUID", - Amount: sdk.NewInt(int64(10)), + Amount: sdkmath.NewInt(int64(10)), Ticket: "Ticket", }, err: types.ErrInvalidBetUID, @@ -36,7 +37,7 @@ func TestBetFieldsValidation(t *testing.T) { desc: "invalid amount", bet: &types.WagerProps{ UID: "6e31c60f-2025-48ce-ae79-1dc110f16355", - Amount: sdk.NewInt(int64(-1)), + Amount: sdkmath.NewInt(int64(-1)), Ticket: "Ticket", }, err: types.ErrInvalidAmount, @@ -53,7 +54,7 @@ func TestBetFieldsValidation(t *testing.T) { desc: "space in ticket", bet: &types.WagerProps{ UID: "6e31c60f-2025-48ce-ae79-1dc110f16355", - Amount: sdk.NewInt(int64(10)), + Amount: sdkmath.NewInt(int64(10)), Ticket: " ", }, err: types.ErrInvalidTicket, @@ -62,7 +63,7 @@ func TestBetFieldsValidation(t *testing.T) { desc: "valid message", bet: &types.WagerProps{ UID: "6e31c60f-2025-48ce-ae79-1dc110f16355", - Amount: sdk.NewInt(int64(10)), + Amount: sdkmath.NewInt(int64(10)), Ticket: "Ticket", }, }, diff --git a/x/house/client/cli/query.go b/x/house/client/cli/query.go index ecf01d49..cbf61221 100644 --- a/x/house/client/cli/query.go +++ b/x/house/client/cli/query.go @@ -3,9 +3,10 @@ package cli import ( "fmt" - "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" + "github.com/sge-network/sge/x/house/types" ) diff --git a/x/house/client/cli/query_deposit.go b/x/house/client/cli/query_deposit.go index 71587a7a..6b58f896 100644 --- a/x/house/client/cli/query_deposit.go +++ b/x/house/client/cli/query_deposit.go @@ -4,12 +4,14 @@ import ( "fmt" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/house/types" - "github.com/spf13/cobra" ) // GetCmdQueryDeposits implements the query deposits command. diff --git a/x/house/client/cli/query_deposit_test.go b/x/house/client/cli/query_deposit_test.go index bb5ec45d..3150657b 100644 --- a/x/house/client/cli/query_deposit_test.go +++ b/x/house/client/cli/query_deposit_test.go @@ -5,18 +5,21 @@ import ( "testing" "time" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + tmcli "github.com/tendermint/tendermint/libs/cli" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/house/client/cli" "github.com/sge-network/sge/x/house/types" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" ) const testMarketUID = "5db09053-2901-4110-8fb5-c14e21f8d555" @@ -31,7 +34,7 @@ func networkWithDepositObjects(t *testing.T, n int) (*network.Network, []types.D market := markettypes.Market{ UID: testMarketUID, - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), StartTS: 1111111111, EndTS: uint64(time.Now().Unix()) + 5000, Odds: []*markettypes.Odds{ @@ -58,9 +61,9 @@ func networkWithDepositObjects(t *testing.T, n int) (*network.Network, []types.D DepositorAddress: testAddress, MarketUID: market.UID, ParticipationIndex: cast.ToUint64(i + 1), - Amount: sdk.NewInt(10), + Amount: sdkmath.NewInt(10), WithdrawalCount: 0, - TotalWithdrawalAmount: sdk.NewInt(0), + TotalWithdrawalAmount: sdkmath.NewInt(0), } nullify.Fill(&deposit) diff --git a/x/house/client/cli/query_params.go b/x/house/client/cli/query_params.go index ea058705..cefaa2d6 100644 --- a/x/house/client/cli/query_params.go +++ b/x/house/client/cli/query_params.go @@ -3,10 +3,12 @@ package cli import ( "context" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/house/types" - "github.com/spf13/cobra" ) // CmdQueryParams returns a command object instance for module params diff --git a/x/house/client/cli/query_params_test.go b/x/house/client/cli/query_params_test.go index df3878d7..933c9662 100644 --- a/x/house/client/cli/query_params_test.go +++ b/x/house/client/cli/query_params_test.go @@ -4,11 +4,13 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/house/client/cli" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func TestQueryParams(t *testing.T) { diff --git a/x/house/client/cli/query_test.go b/x/house/client/cli/query_test.go index 7544fe7a..16bac795 100644 --- a/x/house/client/cli/query_test.go +++ b/x/house/client/cli/query_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/sge-network/sge/testutil/network" + "github.com/sge-network/sge/x/house/client/cli" - "github.com/stretchr/testify/require" ) const testAddress = "cosmos1s4ycalgh3gjemd4hmqcvcgmnf647rnd0tpg2w9" diff --git a/x/house/client/cli/query_withdrawal.go b/x/house/client/cli/query_withdrawal.go index 3689d0c6..18f51d41 100644 --- a/x/house/client/cli/query_withdrawal.go +++ b/x/house/client/cli/query_withdrawal.go @@ -4,13 +4,15 @@ import ( "fmt" "strings" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/house/types" - "github.com/spf13/cast" - "github.com/spf13/cobra" ) // GetCmdQueryWithdrawal implements the command to query the withdrawal of a diff --git a/x/house/client/cli/query_withdrawal_test.go b/x/house/client/cli/query_withdrawal_test.go index d734b8ae..75b95ed5 100644 --- a/x/house/client/cli/query_withdrawal_test.go +++ b/x/house/client/cli/query_withdrawal_test.go @@ -4,13 +4,16 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/house/client/cli" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" ) func TestQueryWithdraw(t *testing.T) { diff --git a/x/house/client/cli/tx.go b/x/house/client/cli/tx.go index 5467d646..94df8614 100644 --- a/x/house/client/cli/tx.go +++ b/x/house/client/cli/tx.go @@ -1,9 +1,10 @@ package cli import ( - "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" + "github.com/sge-network/sge/x/house/types" ) diff --git a/x/house/client/cli/tx_deposit.go b/x/house/client/cli/tx_deposit.go index 531a9c67..6a21e219 100644 --- a/x/house/client/cli/tx_deposit.go +++ b/x/house/client/cli/tx_deposit.go @@ -4,13 +4,15 @@ import ( "fmt" "strings" + "github.com/spf13/cobra" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/house/types" - "github.com/spf13/cobra" ) func CmdDeposit() *cobra.Command { @@ -35,7 +37,7 @@ func CmdDeposit() *cobra.Command { argMarketUID := args[0] - argAmountCosmosInt, ok := sdk.NewIntFromString(args[1]) + argAmountCosmosInt, ok := sdkmath.NewIntFromString(args[1]) if !ok { return types.ErrInvalidAmount } diff --git a/x/house/client/cli/tx_deposit_test.go b/x/house/client/cli/tx_deposit_test.go index 5a99bc52..87200c54 100644 --- a/x/house/client/cli/tx_deposit_test.go +++ b/x/house/client/cli/tx_deposit_test.go @@ -4,12 +4,15 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/house/client/cli" - "github.com/stretchr/testify/require" ) func TestTXDepositCLI(t *testing.T) { @@ -24,7 +27,7 @@ func TestTXDepositCLI(t *testing.T) { fmt.Sprintf( "--%s=%s", flags.FlagFees, - sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String(), + sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String(), ), } diff --git a/x/house/client/cli/tx_test.go b/x/house/client/cli/tx_test.go index 2cafb953..bf375c7c 100644 --- a/x/house/client/cli/tx_test.go +++ b/x/house/client/cli/tx_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/house/client/cli" - "github.com/stretchr/testify/require" ) func TestGetTxCmd(t *testing.T) { diff --git a/x/house/client/cli/tx_withdraw.go b/x/house/client/cli/tx_withdraw.go index e7769aca..6295124f 100644 --- a/x/house/client/cli/tx_withdraw.go +++ b/x/house/client/cli/tx_withdraw.go @@ -4,15 +4,16 @@ import ( "fmt" "strings" + "github.com/spf13/cast" + "github.com/spf13/cobra" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/house/types" - "github.com/spf13/cast" - "github.com/spf13/cobra" ) func CmdWithdraw() *cobra.Command { @@ -56,7 +57,7 @@ func CmdWithdraw() *cobra.Command { } var ok bool - argAmountCosmosInt, ok = sdk.NewIntFromString(args[4]) + argAmountCosmosInt, ok = sdkmath.NewIntFromString(args[4]) if !ok { return types.ErrInvalidAmount } diff --git a/x/house/client/cli/tx_withdraw_test.go b/x/house/client/cli/tx_withdraw_test.go index 83c7eae8..1a21fd63 100644 --- a/x/house/client/cli/tx_withdraw_test.go +++ b/x/house/client/cli/tx_withdraw_test.go @@ -4,13 +4,16 @@ import ( "fmt" "testing" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/house/client/cli" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func TestTXWithdrawCLI(t *testing.T) { @@ -25,7 +28,7 @@ func TestTXWithdrawCLI(t *testing.T) { fmt.Sprintf( "--%s=%s", flags.FlagFees, - sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String(), + sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String(), ), } diff --git a/x/house/handler.go b/x/house/handler.go index a59128cc..d30821f6 100644 --- a/x/house/handler.go +++ b/x/house/handler.go @@ -3,8 +3,9 @@ package house import ( "fmt" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/x/house/keeper" "github.com/sge-network/sge/x/house/types" @@ -28,7 +29,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) } } } diff --git a/x/house/keeper/authorization.go b/x/house/keeper/authorization.go deleted file mode 100644 index 567a4f92..00000000 --- a/x/house/keeper/authorization.go +++ /dev/null @@ -1,52 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/sge-network/sge/x/house/types" -) - -func (k Keeper) ValidateMsgAuthorization( - ctx sdk.Context, - creator, depositor string, - msg sdk.Msg, -) error { - granteeAddr := sdk.MustAccAddressFromBech32(creator) - granterAddr, err := sdk.AccAddressFromBech32(depositor) - if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid depositor address (%s)", err) - } - authorization, expiration := k.authzKeeper.GetAuthorization( - ctx, - granteeAddr, - granterAddr, - sdk.MsgTypeURL(msg), - ) - if authorization == nil { - return sdkerrors.Wrapf( - types.ErrAuthorizationNotFound, - "grantee: %s, granter: %s", - creator, - depositor, - ) - } - authRes, err := authorization.Accept(ctx, msg) - if err != nil { - return sdkerrors.Wrapf(types.ErrAuthorizationNotAccepted, "%s", err) - } - - if authRes.Delete { - err = k.authzKeeper.DeleteGrant(ctx, granteeAddr, granterAddr, sdk.MsgTypeURL(msg)) - } else if authRes.Updated != nil { - err = k.authzKeeper.SaveGrant(ctx, granteeAddr, granterAddr, authRes.Updated, expiration) - } - if err != nil { - return err - } - - if !authRes.Accept { - return types.ErrAuthorizationNotAccepted - } - - return nil -} diff --git a/x/house/keeper/deposit.go b/x/house/keeper/deposit.go index 2661b6d9..f8bfc97a 100644 --- a/x/house/keeper/deposit.go +++ b/x/house/keeper/deposit.go @@ -1,9 +1,10 @@ package keeper import ( + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/x/house/types" ) @@ -63,7 +64,7 @@ func (k Keeper) Deposit(ctx sdk.Context, creator, depositor string, depositorAddr, err := sdk.AccAddressFromBech32(depositor) if err != nil { - err = sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + err = sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) return } diff --git a/x/house/keeper/deposit_test.go b/x/house/keeper/deposit_test.go index 47b3c0fd..196b919d 100644 --- a/x/house/keeper/deposit_test.go +++ b/x/house/keeper/deposit_test.go @@ -3,13 +3,16 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/house/keeper" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func createNDeposits( @@ -24,8 +27,8 @@ func createNDeposits( items[i].MarketUID = testMarketUID items[i].ParticipationIndex = uint64(i + 1) items[i].DepositorAddress = testDepositorAddress - items[i].Amount = sdk.NewInt(100) - items[i].TotalWithdrawalAmount = sdk.NewInt(0) + items[i].Amount = sdkmath.NewInt(100) + items[i].TotalWithdrawalAmount = sdkmath.NewInt(0) keeper.SetDeposit(ctx, items[i]) } diff --git a/x/house/keeper/grpc_query_deposit.go b/x/house/keeper/grpc_query_deposit.go index 556e4851..48ea96bb 100644 --- a/x/house/keeper/grpc_query_deposit.go +++ b/x/house/keeper/grpc_query_deposit.go @@ -3,13 +3,15 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/house/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // Deposits queries all deposits @@ -25,7 +27,7 @@ func (k Keeper) Deposits( ctx := sdk.UnwrapSDKContext(c) store := k.getDepositStore(ctx) - pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error { + pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var deposit types.Deposit if err := k.cdc.Unmarshal(value, &deposit); err != nil { return err @@ -53,7 +55,7 @@ func (k Keeper) DepositsByAccount(c context.Context, ctx := sdk.UnwrapSDKContext(c) store := prefix.NewStore(k.getDepositStore(ctx), types.GetDepositListPrefix(req.Address)) - pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error { + pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var deposit types.Deposit if err := k.cdc.Unmarshal(value, &deposit); err != nil { return err diff --git a/x/house/keeper/grpc_query_deposit_test.go b/x/house/keeper/grpc_query_deposit_test.go index 57f4453e..0fafeae7 100644 --- a/x/house/keeper/grpc_query_deposit_test.go +++ b/x/house/keeper/grpc_query_deposit_test.go @@ -3,14 +3,16 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func TestDepositsQueryPaginated(t *testing.T) { diff --git a/x/house/keeper/grpc_query_params.go b/x/house/keeper/grpc_query_params.go index 7c0f6b26..4a436bba 100644 --- a/x/house/keeper/grpc_query_params.go +++ b/x/house/keeper/grpc_query_params.go @@ -3,10 +3,12 @@ package keeper import ( "context" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sge-network/sge/x/house/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/house/types" ) // Params returns the params of the module diff --git a/x/house/keeper/grpc_query_params_test.go b/x/house/keeper/grpc_query_params_test.go index 50bdfaf2..022197e2 100644 --- a/x/house/keeper/grpc_query_params_test.go +++ b/x/house/keeper/grpc_query_params_test.go @@ -3,9 +3,11 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func TestParamsQuery(t *testing.T) { diff --git a/x/house/keeper/grpc_query_withdrawal.go b/x/house/keeper/grpc_query_withdrawal.go index 038b38d2..077e9117 100644 --- a/x/house/keeper/grpc_query_withdrawal.go +++ b/x/house/keeper/grpc_query_withdrawal.go @@ -3,13 +3,15 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/house/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // WithdrawalsByAccount returns all withdrawals of a given account address @@ -24,7 +26,7 @@ func (k Keeper) WithdrawalsByAccount(c context.Context, ctx := sdk.UnwrapSDKContext(c) store := prefix.NewStore(k.getWithdrawalStore(ctx), types.GetWithdrawalListPrefix(req.Address)) - pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error { + pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error { var withdrawal types.Withdrawal if err := k.cdc.Unmarshal(value, &withdrawal); err != nil { return err diff --git a/x/house/keeper/grpc_query_withdrawal_test.go b/x/house/keeper/grpc_query_withdrawal_test.go index 0ef10341..3fdaca3f 100644 --- a/x/house/keeper/grpc_query_withdrawal_test.go +++ b/x/house/keeper/grpc_query_withdrawal_test.go @@ -3,15 +3,17 @@ package keeper_test import ( "testing" + "github.com/google/uuid" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/google/uuid" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func TestWithdrawQuerySingle(t *testing.T) { diff --git a/x/house/keeper/keeper_test.go b/x/house/keeper/keeper_test.go index ea6d7223..28d8d928 100644 --- a/x/house/keeper/keeper_test.go +++ b/x/house/keeper/keeper_test.go @@ -4,13 +4,15 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/sample" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/house/keeper" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) var ( @@ -29,8 +31,8 @@ func setupKeeper(t testing.TB) (*keeper.KeeperTest, sdk.Context) { return k, ctx } -func setupKeeperAndApp(t testing.TB) (*simappUtil.TestApp, *keeper.KeeperTest, sdk.Context) { - tApp, ctx, err := simappUtil.GetTestObjects() +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.KeeperTest, sdk.Context) { + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) return tApp, tApp.HouseKeeper, ctx.WithBlockTime(time.Now()) diff --git a/x/house/keeper/msg_server_deposit.go b/x/house/keeper/msg_server_deposit.go index 89c04e79..715ca4f7 100644 --- a/x/house/keeper/msg_server_deposit.go +++ b/x/house/keeper/msg_server_deposit.go @@ -3,8 +3,10 @@ package keeper import ( "context" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/house/types" ) @@ -14,27 +16,9 @@ func (k msgServer) Deposit(goCtx context.Context, ) (*types.MsgDepositResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - params := k.GetParams(ctx) - if err := msg.ValidateSanity(ctx, ¶ms); err != nil { - return nil, sdkerrors.Wrap(err, "invalid deposit") - } - - var payload types.DepositTicketPayload - if err := k.ovmKeeper.VerifyTicketUnmarshal(goCtx, msg.Ticket, &payload); err != nil { - return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) - } - - depositorAddr := msg.Creator - if payload.DepositorAddress != "" && - payload.DepositorAddress != msg.Creator { - if err := k.ValidateMsgAuthorization(ctx, msg.Creator, payload.DepositorAddress, msg); err != nil { - return nil, err - } - depositorAddr = payload.DepositorAddress - } - - if err := payload.Validate(depositorAddr); err != nil { - return nil, sdkerrors.Wrapf(types.ErrInTicketPayloadValidation, "%s", err) + depositorAddr, err := k.ParseDepositTicketAndValidate(goCtx, ctx, msg, true) + if err != nil { + return nil, err } participationIndex, err := k.Keeper.Deposit( @@ -55,3 +39,40 @@ func (k msgServer) Deposit(goCtx context.Context, ParticipationIndex: participationIndex, }, nil } + +// ParseDepositTicketAndValidate parses the deposit payload ticket and validate. +func (k Keeper) ParseDepositTicketAndValidate( + goCtx context.Context, + ctx sdk.Context, + msg *types.MsgDeposit, + authzAllowed bool, +) (string, error) { + params := k.GetParams(ctx) + if err := msg.ValidateSanity(ctx, ¶ms); err != nil { + return "", sdkerrors.Wrap(err, "invalid deposit") + } + + var payload types.DepositTicketPayload + if err := k.ovmKeeper.VerifyTicketUnmarshal(goCtx, msg.Ticket, &payload); err != nil { + return "", sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + } + + depositorAddr := msg.Creator + if payload.DepositorAddress != "" && + payload.DepositorAddress != msg.Creator { + if !authzAllowed { + return "", types.ErrAuthorizationNotAllowed + } + if err := utils.ValidateMsgAuthorization(k.authzKeeper, ctx, msg.Creator, payload.DepositorAddress, msg, + types.ErrAuthorizationNotFound, types.ErrAuthorizationNotAccepted); err != nil { + return "", err + } + depositorAddr = payload.DepositorAddress + } + + if err := payload.Validate(depositorAddr); err != nil { + return "", sdkerrors.Wrapf(types.ErrInTicketPayloadValidation, "%s", err) + } + + return depositorAddr, nil +} diff --git a/x/house/keeper/msg_server_deposit_test.go b/x/house/keeper/msg_server_deposit_test.go index 1103b875..c6facf98 100644 --- a/x/house/keeper/msg_server_deposit_test.go +++ b/x/house/keeper/msg_server_deposit_test.go @@ -4,20 +4,23 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/golang-jwt/jwt" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/simapp" sgetypes "github.com/sge-network/sge/types" "github.com/sge-network/sge/x/house/types" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func TestMsgServerDeposit(t *testing.T) { tApp, k, msgk, ctx, wctx := setupMsgServerAndApp(t) - creator := simappUtil.TestParamUsers["user1"] - depositor := simappUtil.TestParamUsers["user2"] + creator := simapp.TestParamUsers["user1"] + depositor := simapp.TestParamUsers["user2"] // var err error marketItem := markettypes.Market{ @@ -41,7 +44,7 @@ func TestMsgServerDeposit(t *testing.T) { t.Run("min deposit", func(t *testing.T) { inputDeposit := &types.MsgDeposit{ Creator: creator.Address.String(), - Amount: sdk.NewInt(1), + Amount: sdkmath.NewInt(1), } _, err := msgk.Deposit(wctx, inputDeposit) @@ -51,7 +54,7 @@ func TestMsgServerDeposit(t *testing.T) { t.Run("no ticket", func(t *testing.T) { inputDeposit := &types.MsgDeposit{ Creator: creator.Address.String(), - Amount: sdk.NewInt(1000), + Amount: sdkmath.NewInt(1000), } _, err := msgk.Deposit(wctx, inputDeposit) @@ -69,13 +72,13 @@ func TestMsgServerDeposit(t *testing.T) { "kyc_data": testKyc, "depositor_address": depositor.Address.String(), } - ticket, err := simappUtil.CreateJwtTicket(ticketClaim) + ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) inputDeposit := &types.MsgDeposit{ Creator: creator.Address.String(), MarketUID: testMarketUID, - Amount: sdk.NewInt(1000), + Amount: sdkmath.NewInt(1000), Ticket: ticket, } @@ -93,13 +96,13 @@ func TestMsgServerDeposit(t *testing.T) { "iat": time.Now().Unix(), "kyc_data": testKyc, } - ticket, err := simappUtil.CreateJwtTicket(ticketClaim) + ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) inputDeposit := &types.MsgDeposit{ Creator: depositor.Address.String(), MarketUID: testMarketUID, - Amount: sdk.NewInt(1000), + Amount: sdkmath.NewInt(1000), Ticket: ticket, } @@ -115,7 +118,7 @@ func TestMsgServerDeposit(t *testing.T) { }) t.Run("success with authorization", func(t *testing.T) { - grantAmount := sdk.NewInt(1000) + grantAmount := sdkmath.NewInt(1000) expTime := time.Now().Add(5 * time.Minute) err := tApp.AuthzKeeper.SaveGrant(ctx, @@ -146,13 +149,13 @@ func TestMsgServerDeposit(t *testing.T) { "depositor_address": depositor.Address.String(), "kyc_data": testKyc, } - ticket, err := simappUtil.CreateJwtTicket(ticketClaim) + ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) inputDeposit := &types.MsgDeposit{ Creator: creator.Address.String(), MarketUID: testMarketUID, - Amount: sdk.NewInt(1000), + Amount: sdkmath.NewInt(1000), Ticket: ticket, } diff --git a/x/house/keeper/msg_server_test.go b/x/house/keeper/msg_server_test.go index 26e1f1a3..89704cd2 100644 --- a/x/house/keeper/msg_server_test.go +++ b/x/house/keeper/msg_server_test.go @@ -6,14 +6,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/house/keeper" "github.com/sge-network/sge/x/house/types" ) func setupMsgServerAndApp( t testing.TB, -) (*simappUtil.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { +) (*simapp.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { tApp, k, ctx := setupKeeperAndApp(t) return tApp, k, keeper.NewMsgServerImpl(*k), ctx, sdk.WrapSDKContext(ctx) } diff --git a/x/house/keeper/msg_server_withdraw.go b/x/house/keeper/msg_server_withdraw.go index 23d0893a..899ef94f 100644 --- a/x/house/keeper/msg_server_withdraw.go +++ b/x/house/keeper/msg_server_withdraw.go @@ -3,8 +3,10 @@ package keeper import ( "context" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" + "github.com/sge-network/sge/x/house/types" ) @@ -14,26 +16,65 @@ func (k msgServer) Withdraw(goCtx context.Context, ) (*types.MsgWithdrawResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + depositorAddr, isOnBehalf, err := k.Keeper.ParseWithdrawTicketAndValidate(goCtx, ctx, msg, true) + if err != nil { + return nil, err + } + + id, err := k.Keeper.CalcAndWithdraw(ctx, msg, depositorAddr, isOnBehalf) + if err != nil { + return nil, err + } + + msg.EmitEvent(&ctx, depositorAddr, id) + + return &types.MsgWithdrawResponse{ + ID: id, + MarketUID: msg.MarketUID, + ParticipationIndex: msg.ParticipationIndex, + }, nil +} + +// ParseWithdrawTicketAndValidate parses the withdraw payload ticket and validate. +func (k Keeper) ParseWithdrawTicketAndValidate( + goCtx context.Context, + ctx sdk.Context, + msg *types.MsgWithdraw, + authzAllowed bool, +) (string, bool, error) { var payload types.WithdrawTicketPayload if err := k.ovmKeeper.VerifyTicketUnmarshal(goCtx, msg.Ticket, &payload); err != nil { - return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + return "", false, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) } isOnBehalf := false depositorAddr := msg.Creator if payload.DepositorAddress != "" { + if !authzAllowed { + return "", false, types.ErrAuthorizationNotAllowed + } depositorAddr = payload.DepositorAddress isOnBehalf = true } if err := payload.Validate(depositorAddr); err != nil { - return nil, sdkerrors.Wrapf(types.ErrInTicketPayloadValidation, "%s", err) + return "", false, sdkerrors.Wrapf(types.ErrInTicketPayloadValidation, "%s", err) } + return depositorAddr, isOnBehalf, nil +} + +// CalcAndWithdraw calculates the withdrawable amount and withdraws the deposit. +func (k Keeper) CalcAndWithdraw( + ctx sdk.Context, + msg *types.MsgWithdraw, + depositorAddr string, + isOnBehalf bool, +) (uint64, error) { // Get the deposit object deposit, found := k.GetDeposit(ctx, depositorAddr, msg.MarketUID, msg.ParticipationIndex) if !found { - return nil, sdkerrors.Wrapf(types.ErrDepositNotFound, ": %s, %d", msg.MarketUID, msg.ParticipationIndex) + return 0, sdkerrors.Wrapf(types.ErrDepositNotFound, ": %s, %d", msg.MarketUID, msg.ParticipationIndex) } var err error @@ -46,26 +87,21 @@ func (k msgServer) Withdraw(goCtx context.Context, msg.Amount, ) if err != nil { - return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + return 0, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) } if isOnBehalf { - if err := k.ValidateMsgAuthorization(ctx, msg.Creator, payload.DepositorAddress, msg); err != nil { - return nil, err + if err := utils.ValidateMsgAuthorization(k.authzKeeper, ctx, msg.Creator, depositorAddr, msg, + types.ErrAuthorizationNotFound, types.ErrAuthorizationNotAccepted); err != nil { + return 0, err } } - id, err := k.Keeper.Withdraw(ctx, deposit, msg.Creator, depositorAddr, msg.MarketUID, + id, err := k.Withdraw(ctx, deposit, msg.Creator, depositorAddr, msg.MarketUID, msg.ParticipationIndex, msg.Mode, msg.Amount) if err != nil { - return nil, sdkerrors.Wrap(err, "process withdrawal") + return 0, sdkerrors.Wrap(err, "process withdrawal") } - msg.EmitEvent(&ctx, depositorAddr, id) - - return &types.MsgWithdrawResponse{ - ID: id, - MarketUID: msg.MarketUID, - ParticipationIndex: msg.ParticipationIndex, - }, nil + return id, nil } diff --git a/x/house/keeper/msg_server_withdraw_test.go b/x/house/keeper/msg_server_withdraw_test.go index ba6d1023..beb60a44 100644 --- a/x/house/keeper/msg_server_withdraw_test.go +++ b/x/house/keeper/msg_server_withdraw_test.go @@ -4,20 +4,23 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/golang-jwt/jwt" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/simapp" sgetypes "github.com/sge-network/sge/types" "github.com/sge-network/sge/x/house/types" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func TestMsgServerWithdraw(t *testing.T) { tApp, k, msgk, ctx, wctx := setupMsgServerAndApp(t) - creator := simappUtil.TestParamUsers["user1"] - depositor := simappUtil.TestParamUsers["user2"] + creator := simapp.TestParamUsers["user1"] + depositor := simapp.TestParamUsers["user2"] // var err error marketItem := markettypes.Market{ @@ -42,7 +45,7 @@ func TestMsgServerWithdraw(t *testing.T) { err = tApp.AuthzKeeper.SaveGrant(ctx, creator.Address, depositor.Address, - types.NewDepositAuthorization(sdk.NewInt(1000)), + types.NewDepositAuthorization(sdkmath.NewInt(1000)), &expTime, ) require.NoError(t, err) @@ -57,13 +60,13 @@ func TestMsgServerWithdraw(t *testing.T) { "depositor_address": depositor.Address.String(), "kyc_data": depositKyc, } - ticket, err := simappUtil.CreateJwtTicket(ticketClaim) + ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) inputDeposit := &types.MsgDeposit{ Creator: creator.Address.String(), MarketUID: testMarketUID, - Amount: sdk.NewInt(1000), + Amount: sdkmath.NewInt(1000), Ticket: ticket, } @@ -73,7 +76,7 @@ func TestMsgServerWithdraw(t *testing.T) { t.Run("no ticket", func(t *testing.T) { inputWithdraw := &types.MsgWithdraw{ Creator: creator.Address.String(), - Amount: sdk.NewInt(1), + Amount: sdkmath.NewInt(1), } _, err := msgk.Withdraw(wctx, inputWithdraw) @@ -91,7 +94,7 @@ func TestMsgServerWithdraw(t *testing.T) { "kyc_data": testKyc, "depositor_address": depositor.Address.String(), } - ticket, err := simappUtil.CreateJwtTicket(ticketClaim) + ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) inputWithdraw := &types.MsgWithdraw{ @@ -99,7 +102,7 @@ func TestMsgServerWithdraw(t *testing.T) { MarketUID: testMarketUID, ParticipationIndex: deposit.ParticipationIndex, Mode: types.WithdrawalMode_WITHDRAWAL_MODE_FULL, - Amount: sdk.NewInt(1000), + Amount: sdkmath.NewInt(1000), Ticket: ticket, } @@ -108,7 +111,7 @@ func TestMsgServerWithdraw(t *testing.T) { }) t.Run("success", func(t *testing.T) { - grantAmount := sdk.NewInt(1000) + grantAmount := sdkmath.NewInt(1000) expTime := time.Now().Add(5 * time.Minute) err := tApp.AuthzKeeper.SaveGrant(ctx, creator.Address, @@ -138,13 +141,13 @@ func TestMsgServerWithdraw(t *testing.T) { "depositor_address": depositor.Address.String(), "kyc_data": testKyc, } - ticket, err := simappUtil.CreateJwtTicket(ticketClaim) + ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) inputWithdraw := &types.MsgWithdraw{ Creator: creator.Address.String(), MarketUID: testMarketUID, - Amount: sdk.NewInt(1000), + Amount: sdkmath.NewInt(1000), ParticipationIndex: deposit.ParticipationIndex, Mode: types.WithdrawalMode_WITHDRAWAL_MODE_FULL, Ticket: ticket, @@ -163,7 +166,7 @@ func TestMsgServerWithdraw(t *testing.T) { ) authzAfterW, ok := authzAfter.(*types.WithdrawAuthorization) require.True(t, ok) - expectedAuthzGrant := grantAmount.Sub(sdk.NewInt(rst[0].Amount.Int64())) + expectedAuthzGrant := grantAmount.Sub(sdkmath.NewInt(rst[0].Amount.Int64())) require.Equal(t, expectedAuthzGrant, authzAfterW.WithdrawLimit) }) } diff --git a/x/house/keeper/params_test.go b/x/house/keeper/params_test.go index 62829d96..184ad637 100644 --- a/x/house/keeper/params_test.go +++ b/x/house/keeper/params_test.go @@ -3,8 +3,9 @@ package keeper_test import ( "testing" - "github.com/sge-network/sge/x/house/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/house/types" ) func TestGetParams(t *testing.T) { diff --git a/x/house/keeper/view.go b/x/house/keeper/view.go index 396e999f..93743853 100644 --- a/x/house/keeper/view.go +++ b/x/house/keeper/view.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/house/types" ) diff --git a/x/house/keeper/withdrawal.go b/x/house/keeper/withdrawal.go index bafdad0e..988b4acf 100644 --- a/x/house/keeper/withdrawal.go +++ b/x/house/keeper/withdrawal.go @@ -1,9 +1,9 @@ package keeper import ( + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/x/house/types" ) diff --git a/x/house/keeper/withdrawal_test.go b/x/house/keeper/withdrawal_test.go index 083f4c41..34d135ed 100644 --- a/x/house/keeper/withdrawal_test.go +++ b/x/house/keeper/withdrawal_test.go @@ -3,12 +3,15 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/house/keeper" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func createNWithdrawals( @@ -25,7 +28,7 @@ func createNWithdrawals( items[i].MarketUID = testMarketUID items[i].ParticipationIndex = uint64(i + 1) items[i].Mode = types.WithdrawalMode_WITHDRAWAL_MODE_FULL - items[i].Amount = sdk.NewInt(100) + items[i].Amount = sdkmath.NewInt(100) keeper.SetWithdrawal(ctx, items[i]) } diff --git a/x/house/module.go b/x/house/module.go index 3a2c5330..8dfeff34 100644 --- a/x/house/module.go +++ b/x/house/module.go @@ -5,15 +5,17 @@ import ( "encoding/json" "fmt" + "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" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/gorilla/mux" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" "github.com/sge-network/sge/x/house/client/cli" "github.com/sge-network/sge/x/house/keeper" diff --git a/x/house/module_simulation.go b/x/house/module_simulation.go index 60ddb63f..6d7c86e2 100644 --- a/x/house/module_simulation.go +++ b/x/house/module_simulation.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/bet/types" housesimulation "github.com/sge-network/sge/x/house/simulation" diff --git a/x/house/simulation/decoder.go b/x/house/simulation/decoder.go index 365740d5..596449ad 100644 --- a/x/house/simulation/decoder.go +++ b/x/house/simulation/decoder.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/x/house/types" ) diff --git a/x/house/simulation/decoder_test.go b/x/house/simulation/decoder_test.go index 56a9b720..6256162d 100644 --- a/x/house/simulation/decoder_test.go +++ b/x/house/simulation/decoder_test.go @@ -7,8 +7,9 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/house/simulation" @@ -23,8 +24,8 @@ func TestDecodeStore(t *testing.T) { sample.AccAddress(), sample.AccAddress(), uuid.NewString(), - sdk.NewInt(100), - sdk.NewInt(1000), + sdkmath.NewInt(100), + sdkmath.NewInt(1000), 1, ) @@ -34,7 +35,7 @@ func TestDecodeStore(t *testing.T) { MarketUID: deposit.MarketUID, ParticipationIndex: 1, Mode: types.WithdrawalMode_WITHDRAWAL_MODE_FULL, - Amount: sdk.NewInt(100), + Amount: sdkmath.NewInt(100), } kvPairs := kv.Pairs{ diff --git a/x/house/simulation/genesis.go b/x/house/simulation/genesis.go index cb3e0cbb..1e665afc 100644 --- a/x/house/simulation/genesis.go +++ b/x/house/simulation/genesis.go @@ -7,11 +7,13 @@ import ( //#nosec "math/rand" + "github.com/spf13/cast" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/house/types" - "github.com/spf13/cast" ) // Simulation parameter constants @@ -27,7 +29,7 @@ func GenHouseParticipationFee(r *rand.Rand) sdk.Dec { // GenMinDeposit randomized house by uid query count func GenMinDeposit(r *rand.Rand) sdkmath.Int { - return sdk.NewInt(cast.ToInt64(r.Intn(99))) + return sdkmath.NewInt(cast.ToInt64(r.Intn(99))) } // RandomizedGenState generates a random GenesisState for house diff --git a/x/house/simulation/genesis_test.go b/x/house/simulation/genesis_test.go index 571332e7..7865688b 100644 --- a/x/house/simulation/genesis_test.go +++ b/x/house/simulation/genesis_test.go @@ -6,13 +6,14 @@ import ( "math/rand" "testing" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "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" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/stretchr/testify/require" "github.com/sge-network/sge/x/house/simulation" "github.com/sge-network/sge/x/house/types" @@ -44,7 +45,7 @@ func TestRandomizedGenState(t *testing.T) { simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &houseGenesis) require.Equal(t, sdk.NewDecWithPrec(1, 1), houseGenesis.Params.HouseParticipationFee) - require.Equal(t, sdk.NewInt(100), houseGenesis.Params.MinDeposit) + require.Equal(t, sdkmath.NewInt(100), houseGenesis.Params.MinDeposit) } // TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. diff --git a/x/house/simulation/params.go b/x/house/simulation/params.go index d8b6ee04..83b38c93 100644 --- a/x/house/simulation/params.go +++ b/x/house/simulation/params.go @@ -7,9 +7,9 @@ import ( //#nosec "math/rand" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/sge-network/sge/x/house/types" ) diff --git a/x/house/types/authz.pb.go b/x/house/types/authz.pb.go index 4455a49f..d2739962 100644 --- a/x/house/types/authz.pb.go +++ b/x/house/types/authz.pb.go @@ -4,8 +4,8 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -27,7 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // DepositAuthorization allows the grantee to spend up to spend_limit from // the granter's account for deposit. type DepositAuthorization struct { - SpendLimit github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=spend_limit,json=spendLimit,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"spend_limit"` + SpendLimit cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=spend_limit,json=spendLimit,proto3,customtype=cosmossdk.io/math.Int" json:"spend_limit"` } func (m *DepositAuthorization) Reset() { *m = DepositAuthorization{} } @@ -66,7 +66,7 @@ var xxx_messageInfo_DepositAuthorization proto.InternalMessageInfo // WithdrawAuthorization allows the grantee to withdraw up to withdraw_limit // from the granter's account for deposit. type WithdrawAuthorization struct { - WithdrawLimit github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=withdraw_limit,json=withdrawLimit,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"withdraw_limit"` + WithdrawLimit cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=withdraw_limit,json=withdrawLimit,proto3,customtype=cosmossdk.io/math.Int" json:"withdraw_limit"` } func (m *WithdrawAuthorization) Reset() { *m = WithdrawAuthorization{} } @@ -110,23 +110,23 @@ func init() { func init() { proto.RegisterFile("sge/house/authz.proto", fileDescriptor_65362c36d170cdf0) } var fileDescriptor_65362c36d170cdf0 = []byte{ - // 254 bytes of a gzipped FileDescriptorProto + // 253 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2d, 0x4e, 0x4f, 0xd5, 0xcf, 0xc8, 0x2f, 0x2d, 0x4e, 0xd5, 0x4f, 0x2c, 0x2d, 0xc9, 0xa8, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x29, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x2b, 0x4e, 0x4f, 0xd5, 0x03, 0xab, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, 0xd0, 0x07, 0xb1, 0x20, - 0x6a, 0x95, 0xd2, 0xb9, 0x44, 0x5c, 0x52, 0x0b, 0xf2, 0x8b, 0x33, 0x4b, 0x1c, 0x4b, 0x4b, 0x32, - 0xf2, 0x8b, 0x32, 0xab, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x84, 0xfc, 0xb9, 0xb8, 0x8b, 0x0b, 0x52, - 0xf3, 0x52, 0xe2, 0x73, 0x32, 0x73, 0x33, 0x4b, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x9d, 0xf4, - 0x4e, 0xdc, 0x93, 0x67, 0xb8, 0x75, 0x4f, 0x5e, 0x2d, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, - 0x39, 0x3f, 0x57, 0x3f, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0x18, 0x4a, 0xe9, 0x16, 0xa7, 0x64, 0xeb, - 0x97, 0x54, 0x16, 0xa4, 0x16, 0xeb, 0x79, 0xe6, 0x95, 0x04, 0x71, 0x81, 0x8d, 0xf0, 0x01, 0x99, - 0xa0, 0x94, 0xc7, 0x25, 0x1a, 0x9e, 0x59, 0x92, 0x91, 0x52, 0x94, 0x58, 0x8e, 0x6a, 0x53, 0x28, - 0x17, 0x5f, 0x39, 0x54, 0x82, 0x22, 0xcb, 0x78, 0x61, 0xa6, 0x80, 0xed, 0x73, 0x72, 0x3a, 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, 0x0d, 0x24, 0x03, 0x8b, 0xd3, 0x53, 0x75, - 0xa1, 0x41, 0x05, 0x62, 0xeb, 0x57, 0x40, 0x83, 0x13, 0x6c, 0x6c, 0x12, 0x1b, 0x38, 0x8c, 0x8c, - 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x64, 0xe1, 0x49, 0xb6, 0x68, 0x01, 0x00, 0x00, + 0x6a, 0x95, 0xc2, 0xb8, 0x44, 0x5c, 0x52, 0x0b, 0xf2, 0x8b, 0x33, 0x4b, 0x1c, 0x4b, 0x4b, 0x32, + 0xf2, 0x8b, 0x32, 0xab, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x84, 0xec, 0xb8, 0xb8, 0x8b, 0x0b, 0x52, + 0xf3, 0x52, 0xe2, 0x73, 0x32, 0x73, 0x33, 0x4b, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x9d, 0x64, + 0x4f, 0xdc, 0x93, 0x67, 0xb8, 0x75, 0x4f, 0x5e, 0x34, 0x39, 0xbf, 0x38, 0x37, 0xbf, 0xb8, 0x38, + 0x25, 0x5b, 0x2f, 0x33, 0x5f, 0x3f, 0x37, 0xb1, 0x24, 0x43, 0xcf, 0x33, 0xaf, 0x24, 0x88, 0x0b, + 0xac, 0xc3, 0x07, 0xa4, 0x41, 0x29, 0x96, 0x4b, 0x34, 0x3c, 0xb3, 0x24, 0x23, 0xa5, 0x28, 0xb1, + 0x1c, 0xd5, 0x60, 0x17, 0x2e, 0xbe, 0x72, 0xa8, 0x04, 0x29, 0x66, 0xf3, 0xc2, 0x34, 0x81, 0x8d, + 0x77, 0x72, 0x3a, 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, 0x8d, 0xf4, 0xcc, + 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe2, 0xf4, 0x54, 0x5d, 0x68, 0x40, 0x80, + 0xd8, 0xfa, 0x15, 0xd0, 0xc0, 0x2a, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x87, 0x80, 0x31, + 0x20, 0x00, 0x00, 0xff, 0xff, 0xb3, 0xfb, 0xb1, 0x8e, 0x46, 0x01, 0x00, 0x00, } func (m *DepositAuthorization) Marshal() (dAtA []byte, err error) { diff --git a/x/house/types/codec.go b/x/house/types/codec.go index 39be4517..6d73157b 100644 --- a/x/house/types/codec.go +++ b/x/house/types/codec.go @@ -4,9 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/authz" - "github.com/cosmos/cosmos-sdk/types/msgservice" + "github.com/cosmos/cosmos-sdk/x/authz" ) // RegisterLegacyAminoCodec registers the necessary x/house interfaces and concrete types diff --git a/x/house/types/consts.go b/x/house/types/consts.go index 36d5261d..fd71d9de 100644 --- a/x/house/types/consts.go +++ b/x/house/types/consts.go @@ -1,10 +1,10 @@ package types -import sdk "github.com/cosmos/cosmos-sdk/types" +import sdkmath "cosmossdk.io/math" var ( // minDepositGrant is the minimum deposit allowed grant. - minDepositGrant = sdk.NewInt(100) + minDepositGrant = sdkmath.NewInt(100) // maxWithdrawGrant is the maximum withdraw allowed grant. - maxWithdrawGrant = sdk.NewInt(100) + maxWithdrawGrant = sdkmath.NewInt(100) ) diff --git a/x/house/types/deposit.go b/x/house/types/deposit.go index 9b77b2d1..4f6b5a4e 100644 --- a/x/house/types/deposit.go +++ b/x/house/types/deposit.go @@ -1,9 +1,10 @@ package types import ( + yaml "gopkg.in/yaml.v2" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - yaml "gopkg.in/yaml.v2" ) // NewDeposit creates a new deposit object diff --git a/x/house/types/deposit.pb.go b/x/house/types/deposit.pb.go index c6d672de..3f79ad91 100644 --- a/x/house/types/deposit.pb.go +++ b/x/house/types/deposit.pb.go @@ -4,8 +4,8 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -37,12 +37,12 @@ type Deposit struct { // participation ParticipationIndex uint64 `protobuf:"varint,4,opt,name=participation_index,json=participationIndex,proto3" json:"participation_index,omitempty" yaml:"participation_index"` // amount is the amount being deposited on an order book to be a house - Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount" yaml:"amount"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,5,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount" yaml:"amount"` // withdrawal_count is the total count of the withdrawals from an order book WithdrawalCount uint64 `protobuf:"varint,6,opt,name=withdrawal_count,json=withdrawalCount,proto3" json:"withdrawal_count,omitempty" yaml:"withdrawals"` // total_withdrawal_amount is the total amount withdrawn from the liquidity // provided - TotalWithdrawalAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,7,opt,name=total_withdrawal_amount,json=totalWithdrawalAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"total_withdrawal_amount" yaml:"total_withdrawal_amount"` + TotalWithdrawalAmount cosmossdk_io_math.Int `protobuf:"bytes,7,opt,name=total_withdrawal_amount,json=totalWithdrawalAmount,proto3,customtype=cosmossdk.io/math.Int" json:"total_withdrawal_amount" yaml:"total_withdrawal_amount"` } func (m *Deposit) Reset() { *m = Deposit{} } @@ -84,35 +84,35 @@ func init() { func init() { proto.RegisterFile("sge/house/deposit.proto", fileDescriptor_c6f2840908fc45a1) } var fileDescriptor_c6f2840908fc45a1 = []byte{ - // 446 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x3f, 0x6f, 0xd4, 0x30, - 0x18, 0xc6, 0x13, 0x38, 0xee, 0x54, 0x8b, 0x3f, 0xc5, 0x14, 0x1a, 0x15, 0x64, 0x57, 0x1e, 0xd0, - 0x0d, 0x34, 0x19, 0xd8, 0xca, 0x80, 0xee, 0xe8, 0x72, 0x03, 0x02, 0x45, 0x42, 0x95, 0x58, 0x22, - 0x37, 0xb1, 0x72, 0xd6, 0x5d, 0xe2, 0xc8, 0xf6, 0xe9, 0xda, 0x6f, 0xd0, 0x91, 0x91, 0xf1, 0xbe, - 0x0c, 0x52, 0xc7, 0x8e, 0x88, 0xc1, 0x42, 0xb9, 0x05, 0x31, 0xe6, 0x13, 0xa0, 0xb3, 0x43, 0x1b, - 0x04, 0x0c, 0x9d, 0xfc, 0xfa, 0x79, 0x9f, 0xf7, 0x79, 0x7f, 0xc3, 0x0b, 0x76, 0x55, 0xce, 0xa2, - 0xa9, 0x58, 0x28, 0x16, 0x65, 0xac, 0x12, 0x8a, 0xeb, 0xb0, 0x92, 0x42, 0x0b, 0xb8, 0xa3, 0x72, - 0x56, 0x32, 0xbd, 0x14, 0x72, 0x16, 0xaa, 0x9c, 0x85, 0xd6, 0xb3, 0xb7, 0x93, 0x8b, 0x5c, 0x58, - 0x43, 0xb4, 0xa9, 0x9c, 0x97, 0x7c, 0xe9, 0x81, 0xc1, 0x91, 0x9b, 0x86, 0x2f, 0xc0, 0x20, 0x95, - 0x8c, 0x6a, 0x21, 0x03, 0x7f, 0xdf, 0x1f, 0x6e, 0x8d, 0x61, 0x63, 0xf0, 0xfd, 0x33, 0x5a, 0xcc, - 0x0f, 0x49, 0xdb, 0x20, 0xf1, 0x6f, 0x0b, 0x9c, 0x80, 0x87, 0xed, 0x5a, 0x21, 0x13, 0x9a, 0x65, - 0x92, 0x29, 0x15, 0xdc, 0xb2, 0x73, 0xcf, 0x1a, 0x83, 0x03, 0x37, 0xf7, 0x97, 0x85, 0xc4, 0xdb, - 0x57, 0xda, 0xc8, 0x49, 0xf0, 0x15, 0x00, 0x05, 0x95, 0x33, 0xa6, 0x93, 0x05, 0xcf, 0x82, 0xdb, - 0x36, 0xe3, 0x69, 0x6d, 0xf0, 0xd6, 0x5b, 0xab, 0x7e, 0x98, 0x1c, 0xfd, 0x34, 0xb8, 0x63, 0x89, - 0x3b, 0x35, 0x7c, 0x07, 0x1e, 0x55, 0x54, 0x6a, 0x9e, 0xf2, 0x8a, 0x6a, 0x2e, 0xca, 0x84, 0x97, - 0x19, 0x3b, 0x0d, 0x7a, 0xfb, 0xfe, 0xb0, 0x37, 0x46, 0x8d, 0xc1, 0x7b, 0x8e, 0xe4, 0x1f, 0x26, - 0x12, 0xc3, 0x3f, 0xd4, 0xc9, 0x46, 0x84, 0xc7, 0xa0, 0x4f, 0x0b, 0xb1, 0x28, 0x75, 0x70, 0xc7, - 0x92, 0xbc, 0xbe, 0x30, 0xd8, 0xfb, 0x66, 0xf0, 0xf3, 0x9c, 0xeb, 0xe9, 0xe2, 0x24, 0x4c, 0x45, - 0x11, 0xa5, 0x42, 0x15, 0x42, 0xb5, 0xcf, 0x81, 0xca, 0x66, 0x91, 0x3e, 0xab, 0x98, 0x0a, 0x27, - 0xa5, 0x6e, 0x0c, 0xbe, 0xe7, 0x36, 0xba, 0x14, 0x12, 0xb7, 0x71, 0x70, 0x04, 0xb6, 0x97, 0x5c, - 0x4f, 0x33, 0x49, 0x97, 0x74, 0x9e, 0xa4, 0x76, 0x45, 0xdf, 0x62, 0x3e, 0x69, 0x0c, 0x86, 0x6e, - 0xe8, 0xda, 0xa1, 0x48, 0xfc, 0xe0, 0xfa, 0xf7, 0xc6, 0x46, 0x9c, 0xfb, 0x60, 0x57, 0x0b, 0x4d, - 0xe7, 0x49, 0x27, 0xa9, 0xa5, 0x1d, 0x58, 0xda, 0xf7, 0x37, 0xa6, 0x45, 0x6e, 0xf1, 0x7f, 0x62, - 0x49, 0xfc, 0xd8, 0x76, 0x8e, 0xaf, 0x1a, 0x23, 0xab, 0x1f, 0xde, 0x3d, 0x5f, 0x61, 0xef, 0xf3, - 0x0a, 0x7b, 0x3f, 0x56, 0xd8, 0x1b, 0x8f, 0x2f, 0x6a, 0xe4, 0x5f, 0xd6, 0xc8, 0xff, 0x5e, 0x23, - 0xff, 0xd3, 0x1a, 0x79, 0x97, 0x6b, 0xe4, 0x7d, 0x5d, 0x23, 0xef, 0xe3, 0xb0, 0x03, 0xa2, 0x72, - 0x76, 0xd0, 0x5e, 0xe6, 0xa6, 0x8e, 0x4e, 0xdb, 0xfb, 0xb5, 0x38, 0x27, 0x7d, 0x7b, 0x92, 0x2f, - 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x7b, 0x52, 0xf4, 0xc7, 0xd9, 0x02, 0x00, 0x00, + // 441 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x3f, 0x6f, 0xd3, 0x40, + 0x18, 0xc6, 0x6d, 0x08, 0x89, 0x7a, 0xe2, 0x4f, 0x39, 0x5a, 0x6a, 0x15, 0xe4, 0xab, 0x6e, 0xca, + 0x00, 0xf6, 0xc0, 0x56, 0x06, 0x94, 0x50, 0x21, 0x65, 0x40, 0x48, 0x96, 0x10, 0x12, 0x8b, 0x75, + 0xb5, 0x4f, 0xce, 0x29, 0xb1, 0x5f, 0xeb, 0xee, 0xa2, 0xb4, 0xdf, 0x80, 0x91, 0x91, 0x31, 0xe2, + 0xd3, 0x74, 0xec, 0x88, 0x18, 0x4e, 0xc8, 0x59, 0x10, 0xa3, 0x3f, 0x01, 0xca, 0x9d, 0x69, 0x83, + 0x00, 0xb1, 0xdd, 0x3d, 0xef, 0xef, 0x79, 0xde, 0x67, 0x78, 0xd1, 0x81, 0x2a, 0x78, 0x3c, 0x85, + 0x85, 0xe2, 0x71, 0xce, 0x6b, 0x50, 0x42, 0x47, 0xb5, 0x04, 0x0d, 0x78, 0x4f, 0x15, 0xbc, 0xe2, + 0x7a, 0x09, 0x72, 0x16, 0xa9, 0x82, 0x47, 0x96, 0x39, 0xdc, 0x2b, 0xa0, 0x00, 0x0b, 0xc4, 0x9b, + 0x97, 0x63, 0xe9, 0xe7, 0x1e, 0x1a, 0x9c, 0x38, 0x37, 0x7e, 0x82, 0x06, 0x99, 0xe4, 0x4c, 0x83, + 0x0c, 0xfc, 0x23, 0x7f, 0xb8, 0x33, 0xc6, 0xad, 0x21, 0x77, 0xcf, 0x59, 0x39, 0x3f, 0xa6, 0xdd, + 0x80, 0x26, 0xbf, 0x10, 0x3c, 0x41, 0xf7, 0xbb, 0xb5, 0x20, 0x53, 0x96, 0xe7, 0x92, 0x2b, 0x15, + 0xdc, 0xb0, 0xbe, 0xc7, 0xad, 0x21, 0x81, 0xf3, 0xfd, 0x81, 0xd0, 0x64, 0xf7, 0x4a, 0x1b, 0x39, + 0x09, 0x3f, 0x47, 0xa8, 0x64, 0x72, 0xc6, 0x75, 0xba, 0x10, 0x79, 0x70, 0xd3, 0x66, 0x3c, 0x6a, + 0x0c, 0xd9, 0x79, 0x6d, 0xd5, 0xb7, 0x93, 0x93, 0x1f, 0x86, 0x6c, 0x21, 0xc9, 0xd6, 0x1b, 0xbf, + 0x41, 0x0f, 0x6a, 0x26, 0xb5, 0xc8, 0x44, 0xcd, 0xb4, 0x80, 0x2a, 0x15, 0x55, 0xce, 0xcf, 0x82, + 0xde, 0x91, 0x3f, 0xec, 0x8d, 0xc3, 0xd6, 0x90, 0x43, 0xd7, 0xe4, 0x2f, 0x10, 0x4d, 0xf0, 0x6f, + 0xea, 0x64, 0x23, 0xe2, 0x57, 0xa8, 0xcf, 0x4a, 0x58, 0x54, 0x3a, 0xb8, 0x65, 0x9b, 0x44, 0x17, + 0x86, 0x78, 0x5f, 0x0d, 0xd9, 0xcf, 0x40, 0x95, 0xa0, 0x54, 0x3e, 0x8b, 0x04, 0xc4, 0x25, 0xd3, + 0xd3, 0x68, 0x52, 0xe9, 0xd6, 0x90, 0x3b, 0x6e, 0x81, 0x33, 0xd1, 0xa4, 0x73, 0xe3, 0x11, 0xda, + 0x5d, 0x0a, 0x3d, 0xcd, 0x25, 0x5b, 0xb2, 0x79, 0x9a, 0xd9, 0xc4, 0xbe, 0x6d, 0xf5, 0xb0, 0x35, + 0x04, 0x3b, 0xd3, 0x35, 0xa1, 0x68, 0x72, 0xef, 0xfa, 0xf7, 0xd2, 0x46, 0x2c, 0xd1, 0x81, 0x06, + 0xcd, 0xe6, 0xe9, 0x56, 0x50, 0xd7, 0x6d, 0x60, 0xbb, 0xbd, 0xf8, 0x5f, 0xb7, 0xd0, 0xad, 0xf9, + 0x47, 0x0a, 0x4d, 0xf6, 0xed, 0xe4, 0xdd, 0xd5, 0x60, 0x64, 0xf5, 0xe3, 0xdb, 0x1f, 0x56, 0xc4, + 0xfb, 0xb4, 0x22, 0xde, 0xf7, 0x15, 0xf1, 0xc6, 0xe3, 0x8b, 0x26, 0xf4, 0x2f, 0x9b, 0xd0, 0xff, + 0xd6, 0x84, 0xfe, 0xc7, 0x75, 0xe8, 0x5d, 0xae, 0x43, 0xef, 0xcb, 0x3a, 0xf4, 0xde, 0x0f, 0x0b, + 0xa1, 0xa7, 0x8b, 0xd3, 0x28, 0x83, 0x32, 0x56, 0x05, 0x7f, 0xda, 0x9d, 0xdd, 0xe6, 0x1d, 0x9f, + 0x75, 0xc7, 0xa9, 0xcf, 0x6b, 0xae, 0x4e, 0xfb, 0xf6, 0xde, 0x9e, 0xfd, 0x0c, 0x00, 0x00, 0xff, + 0xff, 0xce, 0xd4, 0x22, 0x0c, 0xb6, 0x02, 0x00, 0x00, } func (m *Deposit) Marshal() (dAtA []byte, err error) { diff --git a/x/house/types/deposit_authorizaton.go b/x/house/types/deposit_authorizaton.go index f1fe2e8e..f67e413b 100644 --- a/x/house/types/deposit_authorizaton.go +++ b/x/house/types/deposit_authorizaton.go @@ -3,7 +3,7 @@ package types import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" ) @@ -25,12 +25,12 @@ func (DepositAuthorization) MsgTypeURL() string { func (a DepositAuthorization) Accept(_ sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) { mDeposit, ok := msg.(*MsgDeposit) if !ok { - return authz.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch") + return authz.AcceptResponse{}, sdkerrtypes.ErrInvalidType.Wrap("type mismatch") } limitLeft := a.SpendLimit.Sub(mDeposit.Amount) if limitLeft.IsNegative() { - return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf( + return authz.AcceptResponse{}, sdkerrtypes.ErrInsufficientFunds.Wrapf( "requested amount is more than spend limit", ) } @@ -48,13 +48,13 @@ func (a DepositAuthorization) Accept(_ sdk.Context, msg sdk.Msg) (authz.AcceptRe // ValidateBasic implements Authorization.ValidateBasic. func (a DepositAuthorization) ValidateBasic() error { if a.SpendLimit.IsNil() { - return sdkerrors.ErrInvalidCoins.Wrap("spend limit cannot be nil") + return sdkerrtypes.ErrInvalidCoins.Wrap("spend limit cannot be nil") } if a.SpendLimit.LTE(sdk.ZeroInt()) { - return sdkerrors.ErrInvalidCoins.Wrap("spend limit cannot be less than or equal to zero") + return sdkerrtypes.ErrInvalidCoins.Wrap("spend limit cannot be less than or equal to zero") } if a.SpendLimit.LT(minDepositGrant) { - return sdkerrors.ErrInvalidCoins.Wrapf("spend limit cannot be less than %s", minDepositGrant) + return sdkerrtypes.ErrInvalidCoins.Wrapf("spend limit cannot be less than %s", minDepositGrant) } return nil diff --git a/x/house/types/deposit_authorizaton_test.go b/x/house/types/deposit_authorizaton_test.go index a323508a..493aafbf 100644 --- a/x/house/types/deposit_authorizaton_test.go +++ b/x/house/types/deposit_authorizaton_test.go @@ -4,13 +4,15 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" authz "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func TestDepositGrantValidateBasic(t *testing.T) { @@ -24,11 +26,11 @@ func TestDepositGrantValidateBasic(t *testing.T) { name: "invalid coins", spendLimit: sdkmath.Int{}, expiration: time.Now().Add(5 * time.Minute), - err: sdkerrors.ErrInvalidCoins, + err: sdkerrtypes.ErrInvalidCoins, }, { name: "valid", - spendLimit: sdk.NewInt(10000), + spendLimit: sdkmath.NewInt(10000), expiration: time.Now().Add(5 * time.Minute), }, } diff --git a/x/house/types/errors.go b/x/house/types/errors.go index 39acaa56..54d900a2 100644 --- a/x/house/types/errors.go +++ b/x/house/types/errors.go @@ -3,7 +3,7 @@ package types // DONTCOVER import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "cosmossdk.io/errors" ) // x/house module sentinel errors @@ -22,4 +22,5 @@ var ( ErrUserKycFailed = sdkerrors.Register(ModuleName, 5012, "the account failed the KYC Validation") ErrAuthorizationNotFound = sdkerrors.Register(ModuleName, 5013, "no authorization found") ErrAuthorizationNotAccepted = sdkerrors.Register(ModuleName, 5014, "authorization not accepted") + ErrAuthorizationNotAllowed = sdkerrors.Register(ModuleName, 5015, "authorization not allowed") ) diff --git a/x/house/types/expected_keepers.go b/x/house/types/expected_keepers.go index 08da49b0..bb54a892 100644 --- a/x/house/types/expected_keepers.go +++ b/x/house/types/expected_keepers.go @@ -14,7 +14,7 @@ type OrderbookKeeper interface { InitiateOrderBookParticipation(ctx sdk.Context, addr sdk.AccAddress, bookUID string, liquidity, fee sdkmath.Int, ) (uint64, error) - CalcWithdrawalAmount(ctx sdk.Context, depositorAddress string, marketUID string, + CalcWithdrawalAmount(ctx sdk.Context, depositorAddress, marketUID string, participationIndex uint64, mode WithdrawalMode, totalWithdrawnAmount, amount sdkmath.Int, ) (sdkmath.Int, error) WithdrawOrderBookParticipation(ctx sdk.Context, marketUID string, diff --git a/x/house/types/genesis_test.go b/x/house/types/genesis_test.go index b32ca04b..b702a5b8 100644 --- a/x/house/types/genesis_test.go +++ b/x/house/types/genesis_test.go @@ -3,10 +3,12 @@ package types_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" - "github.com/sge-network/sge/x/house/types" "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + + "github.com/sge-network/sge/x/house/types" ) const ( @@ -21,9 +23,9 @@ func TestGenesisState_Validate(t *testing.T) { Creator: testAddress, MarketUID: MarketUID, ParticipationIndex: 1, - Amount: sdk.NewInt(10), + Amount: sdkmath.NewInt(10), WithdrawalCount: 1, - TotalWithdrawalAmount: sdk.NewInt(10), + TotalWithdrawalAmount: sdkmath.NewInt(10), }, }, WithdrawalList: []types.Withdrawal{ @@ -33,7 +35,7 @@ func TestGenesisState_Validate(t *testing.T) { MarketUID: MarketUID, ParticipationIndex: 1, Mode: types.WithdrawalMode_WITHDRAWAL_MODE_FULL, - Amount: sdk.NewInt(10), + Amount: sdkmath.NewInt(10), }, }, Params: types.DefaultParams(), diff --git a/x/house/types/keys.go b/x/house/types/keys.go index 22ae9c78..706cb2f2 100644 --- a/x/house/types/keys.go +++ b/x/house/types/keys.go @@ -30,7 +30,7 @@ var ( ) // GetDepositKey creates the key for deposit bond with market and participation -func GetDepositKey(depositorAddr string, marketUID string, participationIndex uint64) []byte { +func GetDepositKey(depositorAddr, marketUID string, participationIndex uint64) []byte { return append( GetDepositListPrefix(depositorAddr), append(utils.StrBytes(marketUID), utils.Uint64ToBytes(participationIndex)...)...) diff --git a/x/house/types/message_deposit.go b/x/house/types/message_deposit.go index ec500605..300d4bc0 100644 --- a/x/house/types/message_deposit.go +++ b/x/house/types/message_deposit.go @@ -3,11 +3,13 @@ package types import ( "strings" - sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/utils" "github.com/spf13/cast" + + sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" ) const typeMsgDeposit = "house_deposit" @@ -49,7 +51,7 @@ func (msg *MsgDeposit) GetSignBytes() []byte { func (msg *MsgDeposit) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) } if !utils.IsValidUID(msg.MarketUID) { @@ -58,7 +60,7 @@ func (msg *MsgDeposit) ValidateBasic() error { if !msg.Amount.IsPositive() { return sdkerrors.Wrap( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "invalid deposit amount", ) } diff --git a/x/house/types/message_deposit_test.go b/x/house/types/message_deposit_test.go index f339ff51..ea1e5aef 100644 --- a/x/house/types/message_deposit_test.go +++ b/x/house/types/message_deposit_test.go @@ -3,12 +3,15 @@ package types_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func TestMsgDepositValidateBasic(t *testing.T) { @@ -22,14 +25,14 @@ func TestMsgDepositValidateBasic(t *testing.T) { msg: types.MsgDeposit{ Creator: "invalid_address", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "valid", msg: types.MsgDeposit{ Creator: sample.AccAddress(), MarketUID: uuid.NewString(), - Amount: sdk.NewInt(100), + Amount: sdkmath.NewInt(100), Ticket: "Ticket", }, }, @@ -49,7 +52,7 @@ func TestMsgDepositValidateBasic(t *testing.T) { Amount: sdk.ZeroInt(), Ticket: "Ticket", }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, } for _, tt := range tests { @@ -70,7 +73,7 @@ func TestNewDeposit(t *testing.T) { Creator: uuid.NewString(), DepositorAddress: uuid.NewString(), MarketUID: uuid.NewString(), - Amount: sdk.NewInt(100), + Amount: sdkmath.NewInt(100), ParticipationIndex: 0, WithdrawalCount: 0, TotalWithdrawalAmount: sdk.ZeroInt(), diff --git a/x/house/types/message_withdraw.go b/x/house/types/message_withdraw.go index daeff926..b7b0c973 100644 --- a/x/house/types/message_withdraw.go +++ b/x/house/types/message_withdraw.go @@ -3,11 +3,13 @@ package types import ( "strings" - sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/utils" "github.com/spf13/cast" + + sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" ) const typeMsgWithdraw = "house_withdraw" @@ -15,7 +17,7 @@ const typeMsgWithdraw = "house_withdraw" var _ sdk.Msg = &MsgWithdraw{} // NewMsgWithdraw creates the new input for withdrawal of a deposit -func NewMsgWithdraw(creator string, marketUID string, amount sdkmath.Int, +func NewMsgWithdraw(creator, marketUID string, amount sdkmath.Int, participationIndex uint64, mode WithdrawalMode, ticket string, ) *MsgWithdraw { return &MsgWithdraw{ @@ -53,7 +55,7 @@ func (msg *MsgWithdraw) GetSignBytes() []byte { func (msg *MsgWithdraw) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) } if msg.Mode != WithdrawalMode_WITHDRAWAL_MODE_FULL && @@ -71,7 +73,7 @@ func (msg *MsgWithdraw) ValidateBasic() error { if msg.Mode == WithdrawalMode_WITHDRAWAL_MODE_PARTIAL { if !msg.Amount.IsPositive() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid withdrawal amount") + return sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "invalid withdrawal amount") } } diff --git a/x/house/types/message_withdraw_test.go b/x/house/types/message_withdraw_test.go index 3ef98575..04ed2215 100644 --- a/x/house/types/message_withdraw_test.go +++ b/x/house/types/message_withdraw_test.go @@ -3,12 +3,14 @@ package types_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func TestMsgWithdrawValidateBasic(t *testing.T) { @@ -22,14 +24,14 @@ func TestMsgWithdrawValidateBasic(t *testing.T) { msg: types.MsgWithdraw{ Creator: "invalid_address", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "valid", msg: types.MsgWithdraw{ Creator: sample.AccAddress(), MarketUID: uuid.NewString(), - Amount: sdk.NewInt(100), + Amount: sdkmath.NewInt(100), Mode: types.WithdrawalMode_WITHDRAWAL_MODE_FULL, ParticipationIndex: 1, Ticket: "Ticket", @@ -69,12 +71,12 @@ func TestMsgWithdrawValidateBasic(t *testing.T) { msg: types.MsgWithdraw{ Creator: sample.AccAddress(), MarketUID: uuid.NewString(), - Amount: sdk.NewInt(-1), + Amount: sdkmath.NewInt(-1), Mode: types.WithdrawalMode_WITHDRAWAL_MODE_PARTIAL, ParticipationIndex: 1, Ticket: "Ticket", }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, } for _, tt := range tests { @@ -95,7 +97,7 @@ func TestNewWithdraw(t *testing.T) { ID: 1, Creator: uuid.NewString(), MarketUID: uuid.NewString(), - Amount: sdk.NewInt(100), + Amount: sdkmath.NewInt(100), ParticipationIndex: 0, Address: sample.AccAddress(), Mode: types.WithdrawalMode_WITHDRAWAL_MODE_FULL, diff --git a/x/house/types/params.go b/x/house/types/params.go index faab4fbe..24cd8364 100644 --- a/x/house/types/params.go +++ b/x/house/types/params.go @@ -3,10 +3,11 @@ package types import ( "fmt" + yaml "gopkg.in/yaml.v2" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - yaml "gopkg.in/yaml.v2" ) // House params default values @@ -55,7 +56,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { // DefaultParams returns a default set of parameters. func DefaultParams() Params { return NewParams( - sdk.NewInt(DefaultMinDeposit), + sdkmath.NewInt(DefaultMinDeposit), sdk.MustNewDecFromStr(DefaultHouseParticipationFee), ) } diff --git a/x/house/types/params.pb.go b/x/house/types/params.pb.go index a001ac4f..8d61d844 100644 --- a/x/house/types/params.pb.go +++ b/x/house/types/params.pb.go @@ -4,6 +4,7 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" @@ -27,7 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params define the parameters for the house module. type Params struct { // min_deposit is the minimum acceptable deposit amount. - MinDeposit github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=min_deposit,json=minDeposit,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"min_deposit" yaml:"min_deposit"` + MinDeposit cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=min_deposit,json=minDeposit,proto3,customtype=cosmossdk.io/math.Int" json:"min_deposit" yaml:"min_deposit"` // house_participation_fee is the % of the deposit to be paid for a house // participation by the depositor. HouseParticipationFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=house_participation_fee,json=houseParticipationFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"house_participation_fee"` @@ -72,25 +73,25 @@ func init() { func init() { proto.RegisterFile("sge/house/params.proto", fileDescriptor_632fcdf2e68e6d32) } var fileDescriptor_632fcdf2e68e6d32 = []byte{ - // 277 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2b, 0x4e, 0x4f, 0xd5, - 0xcf, 0xc8, 0x2f, 0x2d, 0x4e, 0xd5, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, - 0x2f, 0xc9, 0x17, 0x12, 0x29, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x2b, - 0x4e, 0x4f, 0xd5, 0x03, 0x2b, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, 0xd0, 0x07, 0xb1, - 0x20, 0x6a, 0x95, 0xee, 0x32, 0x72, 0xb1, 0x05, 0x80, 0x35, 0x0b, 0xa5, 0x72, 0x71, 0xe7, 0x66, - 0xe6, 0xc5, 0xa7, 0xa4, 0x16, 0xe4, 0x17, 0x67, 0x96, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x3a, - 0xb9, 0x9c, 0xb8, 0x27, 0xcf, 0x70, 0xeb, 0x9e, 0xbc, 0x5a, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, - 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0x31, 0x94, 0xd2, 0x2d, 0x4e, 0xc9, - 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0xf3, 0xcc, 0x2b, 0xf9, 0x74, 0x4f, 0x5e, 0xa8, 0x32, - 0x31, 0x37, 0xc7, 0x4a, 0x09, 0xc9, 0x28, 0xa5, 0x20, 0xae, 0xdc, 0xcc, 0x3c, 0x17, 0x08, 0x47, - 0x28, 0x8d, 0x4b, 0x1c, 0xec, 0xa0, 0xf8, 0x82, 0xc4, 0xa2, 0x92, 0xcc, 0xe4, 0xcc, 0x82, 0xc4, - 0x92, 0xcc, 0xfc, 0xbc, 0xf8, 0xb4, 0xd4, 0x54, 0x09, 0x26, 0xb0, 0x95, 0x7a, 0x24, 0x58, 0xe9, - 0x92, 0x9a, 0x1c, 0x24, 0x0a, 0x36, 0x2e, 0x00, 0xd9, 0x34, 0xb7, 0xd4, 0x54, 0x2b, 0x96, 0x19, - 0x0b, 0xe4, 0x19, 0x9c, 0x9c, 0x4e, 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, 0x4a, - 0x03, 0xc9, 0xf8, 0xe2, 0xf4, 0x54, 0x5d, 0x68, 0x88, 0x81, 0xd8, 0xfa, 0x15, 0xd0, 0x60, 0x05, - 0x5b, 0x92, 0xc4, 0x06, 0x0e, 0x2a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x9e, 0x0a, - 0x2d, 0x70, 0x01, 0x00, 0x00, + // 288 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x6a, 0x32, 0x41, + 0x14, 0x85, 0x77, 0x7e, 0x7e, 0x84, 0x6c, 0xba, 0x45, 0x13, 0x49, 0x31, 0x1b, 0x2c, 0x82, 0x8d, + 0x33, 0x85, 0x9d, 0xa5, 0x48, 0x20, 0x9d, 0x48, 0xaa, 0x34, 0x32, 0xae, 0xd7, 0x71, 0x30, 0xb3, + 0x77, 0xd8, 0x3b, 0x92, 0xf8, 0x16, 0x29, 0x53, 0xe6, 0x71, 0x2c, 0x52, 0x58, 0x86, 0x14, 0x12, + 0xdc, 0x37, 0xc8, 0x13, 0x04, 0x67, 0xb7, 0xd8, 0xea, 0x9e, 0x0b, 0xe7, 0x9c, 0x0f, 0x4e, 0x7c, + 0x45, 0x1a, 0xe4, 0x1a, 0xb7, 0x04, 0xd2, 0xa9, 0x42, 0x59, 0x12, 0xae, 0x40, 0x8f, 0x49, 0x9b, + 0x34, 0xe4, 0xe0, 0x5f, 0xb0, 0xd8, 0x08, 0xd2, 0x20, 0x82, 0xe5, 0xa6, 0xad, 0x51, 0x63, 0x30, + 0xc8, 0xb3, 0xaa, 0xbc, 0xbd, 0x4f, 0x16, 0xb7, 0xa6, 0x21, 0x9c, 0x3c, 0xc6, 0x97, 0xd6, 0xe4, + 0xf3, 0x25, 0x38, 0x24, 0xe3, 0xbb, 0xec, 0x96, 0xf5, 0x2f, 0xc6, 0xc3, 0xfd, 0x31, 0x8d, 0xbe, + 0x8f, 0x69, 0x27, 0x43, 0xb2, 0x48, 0xb4, 0xdc, 0x08, 0x83, 0xd2, 0x2a, 0xbf, 0x16, 0x0f, 0xb9, + 0xff, 0x3d, 0xa6, 0xc9, 0x4e, 0xd9, 0xe7, 0x51, 0xaf, 0x91, 0xec, 0xcd, 0x62, 0x6b, 0xf2, 0x49, + 0xf5, 0x24, 0xab, 0xf8, 0x3a, 0xf0, 0xe7, 0x4e, 0x15, 0xde, 0x64, 0xc6, 0x29, 0x6f, 0x30, 0x9f, + 0xaf, 0x00, 0xba, 0xff, 0x02, 0x41, 0xd4, 0x84, 0x3b, 0x6d, 0xfc, 0x7a, 0xbb, 0x10, 0x19, 0x5a, + 0x59, 0xc1, 0xea, 0x33, 0xa0, 0xe5, 0x46, 0xfa, 0x9d, 0x03, 0x12, 0x13, 0xc8, 0x66, 0x9d, 0x50, + 0x37, 0x6d, 0xb6, 0xdd, 0x03, 0x8c, 0xfe, 0xbf, 0x7f, 0xa4, 0xd1, 0x78, 0xbc, 0x3f, 0x71, 0x76, + 0x38, 0x71, 0xf6, 0x73, 0xe2, 0xec, 0xad, 0xe4, 0xd1, 0xa1, 0xe4, 0xd1, 0x57, 0xc9, 0xa3, 0xa7, + 0x7e, 0xa3, 0x9e, 0x34, 0x0c, 0xea, 0x81, 0xce, 0x5a, 0xbe, 0xd6, 0x2b, 0x06, 0xc8, 0xa2, 0x15, + 0x96, 0x19, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0xde, 0xc0, 0xb8, 0x21, 0x5f, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { diff --git a/x/house/types/ticket.go b/x/house/types/ticket.go index aad281c4..5fd20948 100644 --- a/x/house/types/ticket.go +++ b/x/house/types/ticket.go @@ -1,15 +1,16 @@ package types import ( + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" ) // Validate validates deposit ticket payload. func (payload *DepositTicketPayload) Validate(depositor string) error { _, err := sdk.AccAddressFromBech32(depositor) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid depositor address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid depositor address (%s)", err) } if !payload.KycData.Validate(depositor) { @@ -23,7 +24,7 @@ func (payload *DepositTicketPayload) Validate(depositor string) error { func (payload *WithdrawTicketPayload) Validate(depositor string) error { _, err := sdk.AccAddressFromBech32(depositor) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid depositor address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid depositor address (%s)", err) } if !payload.KycData.Validate(depositor) { diff --git a/x/house/types/ticket_test.go b/x/house/types/ticket_test.go index 11ca9d25..b17a92f6 100644 --- a/x/house/types/ticket_test.go +++ b/x/house/types/ticket_test.go @@ -3,11 +3,13 @@ package types_test import ( "testing" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/testutil/sample" sgetypes "github.com/sge-network/sge/types" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func TestDepositTicketPayloadValidation(t *testing.T) { @@ -45,7 +47,7 @@ func TestDepositTicketPayloadValidation(t *testing.T) { Ignore: true, }, }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "invalid valid kyc", @@ -107,7 +109,7 @@ func TestWithdrawTicketPayloadValidation(t *testing.T) { Ignore: true, }, }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "invalid valid kyc", diff --git a/x/house/types/tx.pb.go b/x/house/types/tx.pb.go index f7e28712..c035bcbe 100644 --- a/x/house/types/tx.pb.go +++ b/x/house/types/tx.pb.go @@ -5,8 +5,8 @@ package types import ( context "context" + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" @@ -38,7 +38,7 @@ type MsgDeposit struct { // made. MarketUID string `protobuf:"bytes,2,opt,name=market_uid,proto3" json:"market_uid"` // amount is the amount being deposited on an order book to be a house - Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` // ticket is the jwt ticket data. Ticket string `protobuf:"bytes,4,opt,name=ticket,proto3" json:"ticket,omitempty"` } @@ -144,7 +144,7 @@ type MsgWithdraw struct { // mode is the withdrawal mode. It can be full or partial withdraw Mode WithdrawalMode `protobuf:"varint,4,opt,name=mode,proto3,enum=sgenetwork.sge.house.WithdrawalMode" json:"mode,omitempty" yaml:"mode"` // amount is the requested withdrawal amount - Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,5,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` // ticket is the jwt ticket data. Ticket string `protobuf:"bytes,6,opt,name=ticket,proto3" json:"ticket,omitempty"` } @@ -257,40 +257,40 @@ func init() { func init() { proto.RegisterFile("sge/house/tx.proto", fileDescriptor_d3891d05e499977f) } var fileDescriptor_d3891d05e499977f = []byte{ - // 525 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x54, 0x41, 0x6b, 0xd4, 0x40, - 0x14, 0xce, 0xa4, 0xeb, 0xb6, 0x3b, 0x85, 0x0a, 0xd3, 0x22, 0xeb, 0x0a, 0x99, 0x1a, 0x44, 0xb6, - 0x60, 0x13, 0xa8, 0xb7, 0x7a, 0x0b, 0x45, 0xd8, 0x43, 0x10, 0x02, 0x45, 0xf1, 0x52, 0xd2, 0x64, - 0x98, 0x1d, 0xb6, 0xc9, 0x84, 0xcc, 0x2c, 0xbb, 0xfd, 0x07, 0x1e, 0xfd, 0x09, 0xc5, 0x1f, 0xe1, - 0x6f, 0xe8, 0x49, 0x7a, 0x14, 0x0f, 0x41, 0xb3, 0x17, 0xf1, 0xb8, 0x3f, 0x40, 0x24, 0x93, 0x64, - 0x37, 0xca, 0x2e, 0x45, 0x11, 0xf1, 0xb4, 0xb3, 0xef, 0x7d, 0xdf, 0xcb, 0x7b, 0xef, 0xfb, 0x66, - 0x20, 0x12, 0x94, 0xd8, 0x43, 0x3e, 0x16, 0xc4, 0x96, 0x53, 0x2b, 0x49, 0xb9, 0xe4, 0x68, 0x4f, - 0x50, 0x12, 0x13, 0x39, 0xe1, 0xe9, 0xc8, 0x12, 0x94, 0x58, 0x2a, 0xdd, 0xdb, 0xa3, 0x9c, 0x72, - 0x05, 0xb0, 0x8b, 0x53, 0x89, 0xed, 0x75, 0x97, 0xfc, 0x09, 0x93, 0xc3, 0x30, 0xf5, 0x27, 0x65, - 0xc6, 0xfc, 0x02, 0x20, 0x74, 0x05, 0x3d, 0x21, 0x09, 0x17, 0x4c, 0xa2, 0x27, 0x70, 0x33, 0x48, - 0x89, 0x2f, 0x79, 0xda, 0x05, 0xfb, 0xa0, 0xdf, 0x71, 0xd0, 0x3c, 0xc3, 0x3b, 0x97, 0x7e, 0x74, - 0x71, 0x6c, 0x56, 0x09, 0xd3, 0xab, 0x21, 0xe8, 0x19, 0x84, 0x91, 0x9f, 0x8e, 0x88, 0x3c, 0x1b, - 0xb3, 0xb0, 0xab, 0x2b, 0xc2, 0x83, 0x3c, 0xc3, 0x1d, 0x57, 0x45, 0x4f, 0x07, 0x27, 0xdf, 0x32, - 0xdc, 0x80, 0x78, 0x8d, 0x33, 0x7a, 0x0e, 0xdb, 0x7e, 0xc4, 0xc7, 0xb1, 0xec, 0x6e, 0x28, 0xa2, - 0x75, 0x9d, 0x61, 0xed, 0x53, 0x86, 0x1f, 0x53, 0x26, 0x87, 0xe3, 0x73, 0x2b, 0xe0, 0x91, 0x1d, - 0x70, 0x11, 0x71, 0x51, 0xfd, 0x1c, 0x8a, 0x70, 0x64, 0xcb, 0xcb, 0x84, 0x08, 0x6b, 0x10, 0x4b, - 0xaf, 0x62, 0xa3, 0x7b, 0xb0, 0x2d, 0x59, 0x30, 0x22, 0xb2, 0xdb, 0x2a, 0xea, 0x78, 0xd5, 0xbf, - 0xe3, 0xad, 0x37, 0x57, 0x58, 0xfb, 0x7a, 0x85, 0x35, 0xf3, 0x1d, 0x80, 0x68, 0x39, 0xa3, 0x47, - 0x44, 0xc2, 0x63, 0x41, 0x7e, 0xe9, 0x1e, 0xfc, 0x5e, 0xf7, 0x2f, 0xe0, 0x6e, 0xe2, 0xa7, 0x92, - 0x05, 0x2c, 0xf1, 0x25, 0xe3, 0xf1, 0x19, 0x8b, 0x43, 0x32, 0x55, 0x3b, 0x68, 0x39, 0xc6, 0x3c, - 0xc3, 0xbd, 0x72, 0x69, 0x2b, 0x40, 0xa6, 0x87, 0x7e, 0x8a, 0x0e, 0x54, 0xf0, 0xbb, 0x0e, 0xb7, - 0x5d, 0x41, 0x5f, 0x56, 0xf2, 0xfc, 0x4b, 0x25, 0xd6, 0xcc, 0xb2, 0xf1, 0xa7, 0xb3, 0xa0, 0x01, - 0x6c, 0x45, 0x3c, 0x24, 0x4a, 0x90, 0x9d, 0xa3, 0x47, 0xd6, 0x2a, 0xa7, 0x5a, 0xf5, 0xa4, 0xfe, - 0x85, 0xcb, 0x43, 0xe2, 0xdc, 0x9d, 0x67, 0x78, 0xbb, 0xfc, 0x4e, 0xc1, 0x35, 0x3d, 0x55, 0xa2, - 0xe1, 0x92, 0x3b, 0x7f, 0xc9, 0x25, 0xed, 0x35, 0x2e, 0xf9, 0x00, 0xe0, 0x6e, 0x43, 0x80, 0x85, - 0x4d, 0x0e, 0xa0, 0x5e, 0xd9, 0xa3, 0xe5, 0xdc, 0xcf, 0x33, 0xac, 0xab, 0x5d, 0xea, 0x2c, 0x9c, - 0x67, 0xb8, 0x53, 0x36, 0xcc, 0x42, 0xd3, 0xd3, 0x59, 0xf8, 0x7f, 0xa9, 0x70, 0xf4, 0x1e, 0xc0, - 0x0d, 0x57, 0x50, 0x74, 0x0a, 0x37, 0xeb, 0xeb, 0xbd, 0xbf, 0x5a, 0x8a, 0xe5, 0xe5, 0xe8, 0xf5, - 0x6f, 0x43, 0x2c, 0xf6, 0xf2, 0x0a, 0x6e, 0x2d, 0xcc, 0xfa, 0x70, 0x2d, 0xab, 0x86, 0xf4, 0x0e, - 0x6e, 0x85, 0xd4, 0x95, 0x1d, 0xe7, 0x3a, 0x37, 0xc0, 0x4d, 0x6e, 0x80, 0xcf, 0xb9, 0x01, 0xde, - 0xce, 0x0c, 0xed, 0x66, 0x66, 0x68, 0x1f, 0x67, 0x86, 0xf6, 0xba, 0xdf, 0x50, 0x5d, 0x50, 0x72, - 0x58, 0xd5, 0x2b, 0xce, 0xf6, 0xb4, 0x7e, 0x20, 0x0b, 0xed, 0xcf, 0xdb, 0xea, 0x79, 0x7b, 0xfa, - 0x23, 0x00, 0x00, 0xff, 0xff, 0x08, 0x13, 0x20, 0xef, 0x3a, 0x05, 0x00, 0x00, + // 522 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x54, 0xc1, 0x6a, 0xdb, 0x40, + 0x10, 0xd5, 0xca, 0xae, 0x13, 0x6f, 0x20, 0x85, 0x4d, 0x5a, 0x5c, 0x95, 0x6a, 0x53, 0xd1, 0x83, + 0x03, 0xad, 0x04, 0x29, 0xbd, 0xa4, 0x37, 0x91, 0x8b, 0x0f, 0xa2, 0x20, 0x08, 0x2d, 0xbd, 0x04, + 0x45, 0x5a, 0xd6, 0x8b, 0x23, 0xad, 0xd0, 0xae, 0xb1, 0xf3, 0x07, 0x3d, 0xf6, 0x13, 0x42, 0x3f, + 0xa2, 0xdf, 0x90, 0x53, 0xf1, 0xb1, 0xf4, 0x20, 0x8a, 0x7c, 0x29, 0x85, 0x5e, 0xfc, 0x05, 0xc5, + 0x2b, 0xc9, 0x76, 0x8b, 0x4d, 0x68, 0x0e, 0x25, 0xb7, 0xd1, 0xcc, 0x7b, 0xa3, 0x99, 0xb7, 0x6f, + 0x17, 0x22, 0x41, 0x89, 0xd3, 0xe7, 0x43, 0x41, 0x1c, 0x39, 0xb6, 0xd3, 0x8c, 0x4b, 0x8e, 0xf6, + 0x05, 0x25, 0x09, 0x91, 0x23, 0x9e, 0x0d, 0x6c, 0x41, 0x89, 0xad, 0xca, 0xc6, 0x3e, 0xe5, 0x94, + 0x2b, 0x80, 0x33, 0x8f, 0x4a, 0xac, 0xd1, 0x59, 0xf2, 0x47, 0x4c, 0xf6, 0xa3, 0x2c, 0x18, 0x95, + 0x15, 0x6b, 0x02, 0x20, 0xf4, 0x04, 0x3d, 0x21, 0x29, 0x17, 0x4c, 0xa2, 0xe7, 0x70, 0x2b, 0xcc, + 0x48, 0x20, 0x79, 0xd6, 0x01, 0x07, 0xa0, 0xdb, 0x76, 0xd1, 0x2c, 0xc7, 0xbb, 0x97, 0x41, 0x7c, + 0x71, 0x6c, 0x55, 0x05, 0xcb, 0xaf, 0x21, 0xe8, 0x35, 0x84, 0x71, 0x90, 0x0d, 0x88, 0x3c, 0x1b, + 0xb2, 0xa8, 0xa3, 0x2b, 0xc2, 0xe3, 0x22, 0xc7, 0x6d, 0x4f, 0x65, 0x4f, 0x7b, 0x27, 0x3f, 0x73, + 0xbc, 0x02, 0xf1, 0x57, 0x62, 0xf4, 0x0a, 0xb6, 0x82, 0x98, 0x0f, 0x13, 0xd9, 0x69, 0x28, 0xe2, + 0x93, 0xeb, 0x1c, 0x6b, 0xdf, 0x72, 0xfc, 0x20, 0xe4, 0x22, 0xe6, 0x42, 0x44, 0x03, 0x9b, 0x71, + 0x27, 0x0e, 0x64, 0xdf, 0xee, 0x25, 0xd2, 0xaf, 0xc0, 0xe8, 0x21, 0x6c, 0x49, 0x16, 0x0e, 0x88, + 0xec, 0x34, 0xe7, 0x34, 0xbf, 0xfa, 0x3a, 0xde, 0xfe, 0x70, 0x85, 0xb5, 0x1f, 0x57, 0x58, 0xb3, + 0x3e, 0x01, 0x88, 0x96, 0x2b, 0xf9, 0x44, 0xa4, 0x3c, 0x11, 0xe4, 0xaf, 0x61, 0xc1, 0xbf, 0x0d, + 0xfb, 0x06, 0xee, 0xa5, 0x41, 0x26, 0x59, 0xc8, 0xd2, 0x40, 0x32, 0x9e, 0x9c, 0xb1, 0x24, 0x22, + 0x63, 0xb5, 0x72, 0xd3, 0x35, 0x67, 0x39, 0x36, 0x4a, 0x8d, 0xd6, 0x80, 0x2c, 0x1f, 0xfd, 0x91, + 0xed, 0xa9, 0xe4, 0x2f, 0x1d, 0xee, 0x78, 0x82, 0xbe, 0xad, 0x4e, 0xe3, 0x7f, 0x0a, 0xbf, 0x61, + 0x97, 0xc6, 0x6d, 0x77, 0x41, 0x3d, 0xd8, 0x8c, 0x79, 0x44, 0xd4, 0x81, 0xec, 0x1e, 0x3d, 0xb3, + 0xd7, 0x19, 0xd3, 0xae, 0x37, 0x0d, 0x2e, 0x3c, 0x1e, 0x11, 0xf7, 0xfe, 0x2c, 0xc7, 0x3b, 0xe5, + 0x7f, 0xe6, 0x5c, 0xcb, 0x57, 0x2d, 0x56, 0x4c, 0x71, 0xef, 0x76, 0xa6, 0x68, 0x6d, 0x30, 0xc5, + 0x17, 0x00, 0xf7, 0x56, 0xf4, 0x5e, 0xb8, 0xe2, 0x10, 0xea, 0x95, 0x1b, 0x9a, 0xee, 0xa3, 0x22, + 0xc7, 0xba, 0x92, 0x4e, 0x67, 0xd1, 0x2c, 0xc7, 0xed, 0x72, 0x3e, 0x16, 0x59, 0xbe, 0xce, 0xa2, + 0xbb, 0x25, 0xfa, 0xd1, 0x67, 0x00, 0x1b, 0x9e, 0xa0, 0xe8, 0x14, 0x6e, 0xd5, 0x97, 0xf7, 0x60, + 0xbd, 0xf2, 0xcb, 0xbb, 0x60, 0x74, 0x6f, 0x42, 0x2c, 0x74, 0x79, 0x07, 0xb7, 0x17, 0xde, 0x7c, + 0xba, 0x91, 0x55, 0x43, 0x8c, 0xc3, 0x1b, 0x21, 0x75, 0x67, 0xd7, 0xbd, 0x2e, 0x4c, 0x30, 0x29, + 0x4c, 0xf0, 0xbd, 0x30, 0xc1, 0xc7, 0xa9, 0xa9, 0x4d, 0xa6, 0xa6, 0xf6, 0x75, 0x6a, 0x6a, 0xef, + 0xbb, 0x94, 0xc9, 0xfe, 0xf0, 0xdc, 0x0e, 0x79, 0xec, 0x08, 0x4a, 0x5e, 0x54, 0xfd, 0xe6, 0xb1, + 0x33, 0xae, 0x9f, 0xbf, 0xcb, 0x94, 0x88, 0xf3, 0x96, 0x7a, 0xbc, 0x5e, 0xfe, 0x0e, 0x00, 0x00, + 0xff, 0xff, 0x1f, 0x56, 0x9f, 0x21, 0x18, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/house/types/withdraw.pb.go b/x/house/types/withdraw.pb.go index c5c9c735..2fb807e9 100644 --- a/x/house/types/withdraw.pb.go +++ b/x/house/types/withdraw.pb.go @@ -4,8 +4,8 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -72,7 +72,7 @@ type Withdrawal struct { // mode is the withdrawal mode enum value Mode WithdrawalMode `protobuf:"varint,6,opt,name=mode,proto3,enum=sgenetwork.sge.house.WithdrawalMode" json:"mode,omitempty" yaml:"mode"` // amount is the amount being withdrawn. - Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,7,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount" yaml:"amount"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,7,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount" yaml:"amount"` } func (m *Withdrawal) Reset() { *m = Withdrawal{} } @@ -115,38 +115,38 @@ func init() { func init() { proto.RegisterFile("sge/house/withdraw.proto", fileDescriptor_9ca852402ebf549d) } var fileDescriptor_9ca852402ebf549d = []byte{ - // 493 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0xc1, 0x6a, 0xdb, 0x4c, - 0x10, 0xc7, 0x25, 0xc5, 0x9f, 0x83, 0xf7, 0x6b, 0x5d, 0xb3, 0x35, 0x54, 0x8d, 0x41, 0x6b, 0x44, - 0x29, 0x6e, 0x69, 0x24, 0x68, 0x6f, 0xe9, 0xa1, 0xd8, 0xb5, 0x43, 0x05, 0x76, 0x13, 0xd4, 0x18, - 0x43, 0x2f, 0x46, 0xf1, 0x2e, 0xf2, 0xe2, 0x48, 0x6b, 0xb4, 0x6b, 0x9c, 0xbc, 0x41, 0x8f, 0x3d, - 0xf6, 0xe8, 0xc7, 0xc9, 0x31, 0xd0, 0x4b, 0xe9, 0x61, 0x29, 0xf2, 0xa5, 0xf4, 0xa8, 0x27, 0x28, - 0x5a, 0x2b, 0xd4, 0x31, 0x39, 0xed, 0x30, 0xf3, 0x9b, 0xff, 0xec, 0xfc, 0x19, 0x60, 0xf2, 0x90, - 0xb8, 0x53, 0xb6, 0xe0, 0xc4, 0x5d, 0x52, 0x31, 0xc5, 0x49, 0xb0, 0x74, 0xe6, 0x09, 0x13, 0x0c, - 0xd6, 0x79, 0x48, 0x62, 0x22, 0x96, 0x2c, 0x99, 0x39, 0x3c, 0x24, 0x8e, 0x82, 0x0e, 0xea, 0x21, - 0x0b, 0x99, 0x02, 0xdc, 0x3c, 0xda, 0xb0, 0xf6, 0xf7, 0x3d, 0x00, 0x46, 0x45, 0x7b, 0x70, 0x01, - 0x5f, 0x81, 0xfd, 0x49, 0x42, 0x02, 0xc1, 0x12, 0x53, 0x6f, 0xea, 0xad, 0x4a, 0x07, 0x66, 0x12, - 0x55, 0xaf, 0x82, 0xe8, 0xe2, 0xc8, 0x2e, 0x0a, 0xb6, 0x7f, 0x8b, 0xc0, 0x17, 0xc0, 0xa0, 0xd8, - 0x34, 0x9a, 0x7a, 0xab, 0xd4, 0x79, 0x9a, 0x4a, 0x64, 0x78, 0xdd, 0x3f, 0x12, 0x19, 0x14, 0x67, - 0x12, 0x55, 0x36, 0x4d, 0x14, 0xdb, 0xbe, 0x41, 0x71, 0x2e, 0x1c, 0x60, 0x9c, 0x10, 0xce, 0xcd, - 0xbd, 0x5d, 0xe1, 0xa2, 0x60, 0xfb, 0xb7, 0x08, 0x7c, 0x0b, 0x40, 0x14, 0x24, 0x33, 0x22, 0xc6, - 0x0b, 0x8a, 0xcd, 0x92, 0x6a, 0x68, 0xa4, 0x12, 0x55, 0x06, 0x2a, 0x3b, 0x54, 0x73, 0xb6, 0x10, - 0x7f, 0x2b, 0x86, 0x27, 0xe0, 0xf1, 0x3c, 0x48, 0x04, 0x9d, 0xd0, 0x79, 0x20, 0x28, 0x8b, 0xc7, - 0x34, 0xc6, 0xe4, 0xd2, 0xfc, 0x4f, 0x7d, 0xd3, 0xca, 0x24, 0x3a, 0xd8, 0x8c, 0xbd, 0x07, 0xb2, - 0x7d, 0x78, 0x27, 0xeb, 0xe5, 0x49, 0xe8, 0x81, 0x52, 0xc4, 0x30, 0x31, 0xcb, 0x4d, 0xbd, 0x55, - 0x7d, 0xfd, 0xcc, 0xb9, 0xcf, 0x5e, 0xe7, 0x9f, 0x89, 0x03, 0x86, 0x49, 0xe7, 0x51, 0x26, 0xd1, - 0xff, 0x9b, 0x39, 0x79, 0xaf, 0xed, 0x2b, 0x09, 0x38, 0x02, 0xe5, 0x20, 0x62, 0x8b, 0x58, 0x98, - 0xfb, 0x6a, 0xa9, 0x77, 0xd7, 0x12, 0x69, 0x3f, 0x25, 0x7a, 0x1e, 0x52, 0x31, 0x5d, 0x9c, 0x3b, - 0x13, 0x16, 0xb9, 0x13, 0xc6, 0x23, 0xc6, 0x8b, 0xe7, 0x90, 0xe3, 0x99, 0x2b, 0xae, 0xe6, 0x84, - 0x3b, 0x5e, 0x2c, 0x32, 0x89, 0x1e, 0x16, 0x9e, 0x29, 0x15, 0xdb, 0x2f, 0xe4, 0x8e, 0x1e, 0x7c, - 0x59, 0x21, 0xed, 0xdb, 0x0a, 0x69, 0xbf, 0x57, 0x48, 0x7b, 0x39, 0x05, 0xd5, 0xbb, 0xff, 0x81, - 0x08, 0x34, 0x46, 0xde, 0xd9, 0x87, 0xae, 0xdf, 0x1e, 0xb5, 0xfb, 0xe3, 0xc1, 0x49, 0xb7, 0x37, - 0x1e, 0x7e, 0xfc, 0x74, 0xda, 0x7b, 0xef, 0x1d, 0x7b, 0xbd, 0x6e, 0x4d, 0x83, 0x26, 0xa8, 0xef, - 0x02, 0xc7, 0xc3, 0x7e, 0xbf, 0xa6, 0xc3, 0x06, 0x78, 0xb2, 0x5b, 0x39, 0x6d, 0xfb, 0x67, 0x5e, - 0xbb, 0x5f, 0x33, 0x3a, 0x9d, 0xeb, 0xd4, 0xd2, 0x6f, 0x52, 0x4b, 0xff, 0x95, 0x5a, 0xfa, 0xd7, - 0xb5, 0xa5, 0xdd, 0xac, 0x2d, 0xed, 0xc7, 0xda, 0xd2, 0x3e, 0xb7, 0xb6, 0x56, 0xe2, 0x21, 0x39, - 0x2c, 0x2c, 0xcb, 0x63, 0xf7, 0xb2, 0x38, 0x5c, 0xb5, 0xd8, 0x79, 0x59, 0x9d, 0xe2, 0x9b, 0xbf, - 0x01, 0x00, 0x00, 0xff, 0xff, 0xf3, 0x82, 0xd0, 0x4f, 0xd2, 0x02, 0x00, 0x00, + // 488 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0x41, 0x6f, 0x12, 0x41, + 0x14, 0xc7, 0x77, 0xb7, 0x48, 0xc3, 0xa8, 0x48, 0x46, 0x8c, 0x6b, 0x49, 0x76, 0xc8, 0xc6, 0x03, + 0x1a, 0xdd, 0x4d, 0xf4, 0x56, 0x4f, 0x20, 0x10, 0x37, 0x01, 0xdb, 0xac, 0x25, 0x24, 0x5e, 0xc8, + 0x94, 0x99, 0x2c, 0x13, 0xba, 0x0c, 0xd9, 0x19, 0x42, 0xfb, 0x0d, 0x3c, 0x7a, 0xf4, 0xc8, 0x67, + 0xf1, 0xd4, 0x63, 0x8f, 0xc6, 0xc3, 0xc4, 0xc0, 0xc5, 0x78, 0xdc, 0x4f, 0x60, 0x76, 0xd8, 0xa6, + 0x2d, 0xe9, 0xed, 0xe5, 0xbd, 0xdf, 0xff, 0xfd, 0x67, 0xfe, 0x79, 0xc0, 0x16, 0x11, 0xf5, 0x27, + 0x7c, 0x21, 0xa8, 0xbf, 0x64, 0x72, 0x42, 0x12, 0xbc, 0xf4, 0xe6, 0x09, 0x97, 0x1c, 0x56, 0x45, + 0x44, 0x67, 0x54, 0x2e, 0x79, 0x32, 0xf5, 0x44, 0x44, 0x3d, 0x0d, 0x1d, 0x54, 0x23, 0x1e, 0x71, + 0x0d, 0xf8, 0x59, 0xb5, 0x65, 0xdd, 0x9f, 0x7b, 0x00, 0x0c, 0x73, 0x39, 0x3e, 0x83, 0x6f, 0xc0, + 0xfe, 0x38, 0xa1, 0x58, 0xf2, 0xc4, 0x36, 0xeb, 0x66, 0xa3, 0xd4, 0x82, 0xa9, 0x42, 0xe5, 0x0b, + 0x1c, 0x9f, 0x1d, 0xba, 0xf9, 0xc0, 0x0d, 0xaf, 0x11, 0xf8, 0x0a, 0x58, 0x8c, 0xd8, 0x56, 0xdd, + 0x6c, 0x14, 0x5a, 0x2f, 0xd6, 0x0a, 0x59, 0x41, 0xfb, 0x9f, 0x42, 0x16, 0x23, 0xa9, 0x42, 0xa5, + 0xad, 0x88, 0x11, 0x37, 0xb4, 0x18, 0xc9, 0x16, 0x63, 0x42, 0x12, 0x2a, 0x84, 0xbd, 0xb7, 0xbb, + 0x38, 0x1f, 0xb8, 0xe1, 0x35, 0x02, 0x3f, 0x00, 0x10, 0xe3, 0x64, 0x4a, 0xe5, 0x68, 0xc1, 0x88, + 0x5d, 0xd0, 0x82, 0xda, 0x5a, 0xa1, 0x52, 0x5f, 0x77, 0x07, 0xda, 0xe7, 0x16, 0x12, 0xde, 0xaa, + 0xe1, 0x11, 0x78, 0x3a, 0xc7, 0x89, 0x64, 0x63, 0x36, 0xc7, 0x92, 0xf1, 0xd9, 0x88, 0xcd, 0x08, + 0x3d, 0xb7, 0x1f, 0xe8, 0x67, 0x3a, 0xa9, 0x42, 0x07, 0x5b, 0xdb, 0x7b, 0x20, 0x37, 0x84, 0x77, + 0xba, 0x41, 0xd6, 0x84, 0x01, 0x28, 0xc4, 0x9c, 0x50, 0xbb, 0x58, 0x37, 0x1b, 0xe5, 0x77, 0x2f, + 0xbd, 0xfb, 0xe2, 0xf5, 0x6e, 0x42, 0xec, 0x73, 0x42, 0x5b, 0x4f, 0x52, 0x85, 0x1e, 0x6e, 0x7d, + 0x32, 0xad, 0x1b, 0xea, 0x15, 0xb0, 0x0b, 0x8a, 0x38, 0xe6, 0x8b, 0x99, 0xb4, 0xf7, 0xf5, 0xa7, + 0xbc, 0x4b, 0x85, 0x8c, 0xdf, 0x0a, 0x3d, 0x1b, 0x73, 0x11, 0x73, 0x21, 0xc8, 0xd4, 0x63, 0xdc, + 0x8f, 0xb1, 0x9c, 0x78, 0xc1, 0x4c, 0xa6, 0x0a, 0x3d, 0xce, 0x23, 0xd2, 0x22, 0x37, 0xcc, 0xd5, + 0x87, 0x8f, 0xbe, 0xad, 0x90, 0xf1, 0x63, 0x85, 0x8c, 0xbf, 0x2b, 0x64, 0xbc, 0x9e, 0x80, 0xf2, + 0x5d, 0x7b, 0x88, 0x40, 0x6d, 0x18, 0x9c, 0x7c, 0x6a, 0x87, 0xcd, 0x61, 0xb3, 0x37, 0xea, 0x1f, + 0xb5, 0x3b, 0xa3, 0xc1, 0xe7, 0x2f, 0xc7, 0x9d, 0x8f, 0x41, 0x37, 0xe8, 0xb4, 0x2b, 0x06, 0xb4, + 0x41, 0x75, 0x17, 0xe8, 0x0e, 0x7a, 0xbd, 0x8a, 0x09, 0x6b, 0xe0, 0xf9, 0xee, 0xe4, 0xb8, 0x19, + 0x9e, 0x04, 0xcd, 0x5e, 0xc5, 0x6a, 0xb5, 0x2e, 0xd7, 0x8e, 0x79, 0xb5, 0x76, 0xcc, 0x3f, 0x6b, + 0xc7, 0xfc, 0xbe, 0x71, 0x8c, 0xab, 0x8d, 0x63, 0xfc, 0xda, 0x38, 0xc6, 0xd7, 0x46, 0xc4, 0xe4, + 0x64, 0x71, 0xea, 0x8d, 0x79, 0xec, 0x8b, 0x88, 0xbe, 0xcd, 0x13, 0xca, 0x6a, 0xff, 0x3c, 0xbf, + 0x53, 0x79, 0x31, 0xa7, 0xe2, 0xb4, 0xa8, 0x2f, 0xef, 0xfd, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xc5, 0x1c, 0xf6, 0x34, 0xc1, 0x02, 0x00, 0x00, } func (m *Withdrawal) Marshal() (dAtA []byte, err error) { diff --git a/x/house/types/withdraw_authorizaton.go b/x/house/types/withdraw_authorizaton.go index dbf97fcc..0fb4d5ac 100644 --- a/x/house/types/withdraw_authorizaton.go +++ b/x/house/types/withdraw_authorizaton.go @@ -3,7 +3,7 @@ package types import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" ) @@ -25,12 +25,12 @@ func (WithdrawAuthorization) MsgTypeURL() string { func (a WithdrawAuthorization) Accept(_ sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) { mWithdraw, ok := msg.(*MsgWithdraw) if !ok { - return authz.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch") + return authz.AcceptResponse{}, sdkerrtypes.ErrInvalidType.Wrap("type mismatch") } limitLeft := a.WithdrawLimit.Sub(mWithdraw.Amount) if limitLeft.IsNegative() { - return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf( + return authz.AcceptResponse{}, sdkerrtypes.ErrInsufficientFunds.Wrapf( "requested amount is more than withdraw limit", ) } @@ -48,13 +48,13 @@ func (a WithdrawAuthorization) Accept(_ sdk.Context, msg sdk.Msg) (authz.AcceptR // ValidateBasic implements Authorization.ValidateBasic. func (a WithdrawAuthorization) ValidateBasic() error { if a.WithdrawLimit.IsNil() { - return sdkerrors.ErrInvalidCoins.Wrap("withdraw limit cannot be nil") + return sdkerrtypes.ErrInvalidCoins.Wrap("withdraw limit cannot be nil") } if a.WithdrawLimit.LTE(sdk.ZeroInt()) { - return sdkerrors.ErrInvalidCoins.Wrap("withdraw limit cannot be less than or equal to zero") + return sdkerrtypes.ErrInvalidCoins.Wrap("withdraw limit cannot be less than or equal to zero") } if a.WithdrawLimit.GT(maxWithdrawGrant) { - return sdkerrors.ErrInvalidCoins.Wrapf( + return sdkerrtypes.ErrInvalidCoins.Wrapf( "withdraw limit cannot be grated than %s", maxWithdrawGrant, ) diff --git a/x/house/types/withdraw_authorizaton_test.go b/x/house/types/withdraw_authorizaton_test.go index babde320..8bd54567 100644 --- a/x/house/types/withdraw_authorizaton_test.go +++ b/x/house/types/withdraw_authorizaton_test.go @@ -4,13 +4,15 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" authz "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func TestWithdrawGrantValidateBasic(t *testing.T) { @@ -22,13 +24,13 @@ func TestWithdrawGrantValidateBasic(t *testing.T) { }{ { name: "invalid coins", - withdrawLimit: sdk.NewInt(10000), + withdrawLimit: sdkmath.NewInt(10000), expiration: time.Now().Add(5 * time.Minute), - err: sdkerrors.ErrInvalidCoins, + err: sdkerrtypes.ErrInvalidCoins, }, { name: "valid", - withdrawLimit: sdk.NewInt(100), + withdrawLimit: sdkmath.NewInt(100), expiration: time.Now().Add(5 * time.Minute), }, } diff --git a/x/house/types/withdrawal.go b/x/house/types/withdrawal.go index 3f92b09f..2df43d3e 100644 --- a/x/house/types/withdrawal.go +++ b/x/house/types/withdrawal.go @@ -1,9 +1,10 @@ package types import ( + yaml "gopkg.in/yaml.v2" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" - yaml "gopkg.in/yaml.v2" ) // NewWithdrawal creates a new withdrawal object diff --git a/x/market/client/cli/query.go b/x/market/client/cli/query.go index 56fe3942..edf31911 100644 --- a/x/market/client/cli/query.go +++ b/x/market/client/cli/query.go @@ -3,9 +3,10 @@ package cli import ( "fmt" - "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/client/cli/query_market.go b/x/market/client/cli/query_market.go index 4f6a930e..0404dcad 100644 --- a/x/market/client/cli/query_market.go +++ b/x/market/client/cli/query_market.go @@ -4,10 +4,12 @@ import ( "context" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cobra" ) // CmdListMarkets implements a command to return all markets diff --git a/x/market/client/cli/query_market_test.go b/x/market/client/cli/query_market_test.go index 5b38cd58..00a4cd57 100644 --- a/x/market/client/cli/query_market_test.go +++ b/x/market/client/cli/query_market_test.go @@ -4,13 +4,15 @@ import ( "fmt" "testing" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/spf13/cast" "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + tmcli "github.com/tendermint/tendermint/libs/cli" + + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/market/client/cli" diff --git a/x/market/client/cli/query_params.go b/x/market/client/cli/query_params.go index 4e8417f7..2fc3feb4 100644 --- a/x/market/client/cli/query_params.go +++ b/x/market/client/cli/query_params.go @@ -3,10 +3,12 @@ package cli import ( "context" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cobra" ) // CmdQueryParams returns the cmd function of params diff --git a/x/market/client/cli/query_params_test.go b/x/market/client/cli/query_params_test.go index 3ca0493e..2efe1568 100644 --- a/x/market/client/cli/query_params_test.go +++ b/x/market/client/cli/query_params_test.go @@ -4,11 +4,13 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/market/client/cli" "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) func TestQueryParams(t *testing.T) { diff --git a/x/market/client/cli/query_test.go b/x/market/client/cli/query_test.go index 01a4c78a..0377677a 100644 --- a/x/market/client/cli/query_test.go +++ b/x/market/client/cli/query_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/market/client/cli" - "github.com/stretchr/testify/require" ) func TestGetQueryCmd(t *testing.T) { diff --git a/x/market/client/cli/tx.go b/x/market/client/cli/tx.go index 7edfc47c..2fbc06c6 100644 --- a/x/market/client/cli/tx.go +++ b/x/market/client/cli/tx.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/client/cli/tx_market.go b/x/market/client/cli/tx_market.go index 7a0ff78d..da3d909e 100644 --- a/x/market/client/cli/tx_market.go +++ b/x/market/client/cli/tx_market.go @@ -1,11 +1,13 @@ package cli import ( + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cobra" ) // CmdAddMarket CLI registration for add market command diff --git a/x/market/client/cli/tx_resolve_market.go b/x/market/client/cli/tx_resolve_market.go index af2ef113..c163589b 100644 --- a/x/market/client/cli/tx_resolve_market.go +++ b/x/market/client/cli/tx_resolve_market.go @@ -1,11 +1,13 @@ package cli import ( + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cobra" ) // CmdResolveMarket registers the resolve market command diff --git a/x/market/client/cli/tx_test.go b/x/market/client/cli/tx_test.go index 831bfd07..d8003081 100644 --- a/x/market/client/cli/tx_test.go +++ b/x/market/client/cli/tx_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/sge-network/sge/testutil/network" + "github.com/sge-network/sge/x/market/client/cli" - "github.com/stretchr/testify/require" ) func TestGetTxCmd(t *testing.T) { diff --git a/x/market/genesis.go b/x/market/genesis.go index 3fdc04b6..fa4ee40b 100644 --- a/x/market/genesis.go +++ b/x/market/genesis.go @@ -2,6 +2,7 @@ package market import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/market/keeper" "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/genesis_test.go b/x/market/genesis_test.go index d60bbca5..52dd23a0 100644 --- a/x/market/genesis_test.go +++ b/x/market/genesis_test.go @@ -3,11 +3,12 @@ package market_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" market "github.com/sge-network/sge/x/market" "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) func TestGenesis(t *testing.T) { @@ -24,7 +25,7 @@ func TestGenesis(t *testing.T) { }, } - tApp, ctx, err := simappUtil.GetTestObjects() + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) market.InitGenesis(ctx, *tApp.MarketKeeper, genesisState) diff --git a/x/market/handler.go b/x/market/handler.go index 4a235182..220bb5f5 100644 --- a/x/market/handler.go +++ b/x/market/handler.go @@ -3,8 +3,10 @@ package market import ( "fmt" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/market/keeper" "github.com/sge-network/sge/x/market/types" ) @@ -29,7 +31,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) } } } diff --git a/x/market/keeper/grpc_query_market.go b/x/market/keeper/grpc_query_market.go index bb555844..2bf1ffdb 100644 --- a/x/market/keeper/grpc_query_market.go +++ b/x/market/keeper/grpc_query_market.go @@ -3,12 +3,14 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/market/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // Markets returns all the markets @@ -25,7 +27,7 @@ func (k Keeper) Markets( marketStore := k.getMarketsStore(ctx) - pageRes, err := query.Paginate(marketStore, req.Pagination, func(key []byte, value []byte) error { + pageRes, err := query.Paginate(marketStore, req.Pagination, func(key, value []byte) error { var market types.Market if err := k.cdc.Unmarshal(value, &market); err != nil { return err diff --git a/x/market/keeper/grpc_query_market_test.go b/x/market/keeper/grpc_query_market_test.go index fffe8c9c..c7e2cbfb 100644 --- a/x/market/keeper/grpc_query_market_test.go +++ b/x/market/keeper/grpc_query_market_test.go @@ -3,14 +3,16 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sge-network/sge/consts" - "github.com/sge-network/sge/testutil/nullify" - "github.com/sge-network/sge/x/market/types" "github.com/spf13/cast" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/consts" + "github.com/sge-network/sge/testutil/nullify" + "github.com/sge-network/sge/x/market/types" ) func TestMarketQuerySingle(t *testing.T) { diff --git a/x/market/keeper/grpc_query_params.go b/x/market/keeper/grpc_query_params.go index bba31b58..840ca7b1 100644 --- a/x/market/keeper/grpc_query_params.go +++ b/x/market/keeper/grpc_query_params.go @@ -3,11 +3,13 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/market/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // Params returns the params of the module diff --git a/x/market/keeper/grpc_query_params_test.go b/x/market/keeper/grpc_query_params_test.go index adab1b46..5d8ec98a 100644 --- a/x/market/keeper/grpc_query_params_test.go +++ b/x/market/keeper/grpc_query_params_test.go @@ -3,12 +3,14 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sge-network/sge/consts" - "github.com/sge-network/sge/x/market/types" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/consts" + "github.com/sge-network/sge/x/market/types" ) func TestParamsQuery(t *testing.T) { diff --git a/x/market/keeper/keeper.go b/x/market/keeper/keeper.go index 3aa518ae..735500b2 100644 --- a/x/market/keeper/keeper.go +++ b/x/market/keeper/keeper.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/keeper/keeper_test.go b/x/market/keeper/keeper_test.go index a6b4e417..9e41d9a8 100644 --- a/x/market/keeper/keeper_test.go +++ b/x/market/keeper/keeper_test.go @@ -4,22 +4,24 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/golang-jwt/jwt" - simappUtil "github.com/sge-network/sge/testutil/simapp" - "github.com/sge-network/sge/x/market/keeper" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/market/keeper" ) -func setupKeeperAndApp(t testing.TB) (*simappUtil.TestApp, *keeper.KeeperTest, sdk.Context) { - tApp, ctx, err := simappUtil.GetTestObjects() +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.KeeperTest, sdk.Context) { + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) return tApp, tApp.MarketKeeper, ctx.WithBlockTime(time.Now()) } func setupKeeper(t testing.TB) (*keeper.KeeperTest, sdk.Context) { - tApp, ctx, err := simappUtil.GetTestObjects() + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) return tApp.MarketKeeper, ctx @@ -27,5 +29,5 @@ func setupKeeper(t testing.TB) (*keeper.KeeperTest, sdk.Context) { func createJwtTicket(claim jwt.MapClaims) (string, error) { token := jwt.NewWithClaims(jwt.SigningMethodEdDSA, claim) - return token.SignedString(simappUtil.TestOVMPrivateKeys[0]) + return token.SignedString(simapp.TestOVMPrivateKeys[0]) } diff --git a/x/market/keeper/market.go b/x/market/keeper/market.go index dec3f8c7..a945e408 100644 --- a/x/market/keeper/market.go +++ b/x/market/keeper/market.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/keeper/market_test.go b/x/market/keeper/market_test.go index ca18fe0d..d1163208 100644 --- a/x/market/keeper/market_test.go +++ b/x/market/keeper/market_test.go @@ -3,12 +3,14 @@ package keeper_test import ( "testing" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/market/keeper" "github.com/sge-network/sge/x/market/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func createNMarket(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Market { diff --git a/x/market/keeper/msg_server_market.go b/x/market/keeper/msg_server_market.go index 00e5f550..d2412e77 100644 --- a/x/market/keeper/msg_server_market.go +++ b/x/market/keeper/msg_server_market.go @@ -3,8 +3,9 @@ package keeper import ( "context" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/keeper/msg_server_market_resolve.go b/x/market/keeper/msg_server_market_resolve.go index b520d77d..d8401242 100644 --- a/x/market/keeper/msg_server_market_resolve.go +++ b/x/market/keeper/msg_server_market_resolve.go @@ -3,8 +3,9 @@ package keeper import ( "context" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/keeper/msg_server_market_resolve_test.go b/x/market/keeper/msg_server_market_resolve_test.go index 37fd3dd9..cc776b78 100644 --- a/x/market/keeper/msg_server_market_resolve_test.go +++ b/x/market/keeper/msg_server_market_resolve_test.go @@ -6,10 +6,11 @@ import ( "github.com/golang-jwt/jwt" "github.com/google/uuid" - "github.com/sge-network/sge/testutil/sample" - "github.com/sge-network/sge/x/market/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/market/types" ) func TestMsgServerResolve(t *testing.T) { diff --git a/x/market/keeper/msg_server_market_test.go b/x/market/keeper/msg_server_market_test.go index a8793601..fe12ace0 100644 --- a/x/market/keeper/msg_server_market_test.go +++ b/x/market/keeper/msg_server_market_test.go @@ -6,10 +6,11 @@ import ( "github.com/golang-jwt/jwt" "github.com/google/uuid" - "github.com/sge-network/sge/testutil/sample" - "github.com/sge-network/sge/x/market/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/market/types" ) func TestMsgServerAdd(t *testing.T) { diff --git a/x/market/keeper/msg_server_test.go b/x/market/keeper/msg_server_test.go index bea8579c..fc2cebd7 100644 --- a/x/market/keeper/msg_server_test.go +++ b/x/market/keeper/msg_server_test.go @@ -5,7 +5,8 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - simappUtil "github.com/sge-network/sge/testutil/simapp" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/market/keeper" "github.com/sge-network/sge/x/market/types" ) @@ -19,7 +20,7 @@ func setupMsgServerAndKeeper( func setupMsgServerAndApp( t testing.TB, -) (*simappUtil.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { +) (*simapp.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { tApp, k, ctx := setupKeeperAndApp(t) return tApp, k, keeper.NewMsgServerImpl(*k), ctx, sdk.WrapSDKContext(ctx) } diff --git a/x/market/keeper/params.go b/x/market/keeper/params.go index ebdf0b9a..dcae921d 100644 --- a/x/market/keeper/params.go +++ b/x/market/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/keeper/params_test.go b/x/market/keeper/params_test.go index 2299b241..9cb8e512 100644 --- a/x/market/keeper/params_test.go +++ b/x/market/keeper/params_test.go @@ -3,8 +3,9 @@ package keeper_test import ( "testing" - "github.com/sge-network/sge/x/market/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/market/types" ) func TestGetParams(t *testing.T) { diff --git a/x/market/keeper/stats.go b/x/market/keeper/stats.go index 8e2fc9d5..0c15cf05 100644 --- a/x/market/keeper/stats.go +++ b/x/market/keeper/stats.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/keeper/view.go b/x/market/keeper/view.go index c9686cea..d14e6350 100644 --- a/x/market/keeper/view.go +++ b/x/market/keeper/view.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/module.go b/x/market/module.go index d1d1f2ba..f3b2f69f 100644 --- a/x/market/module.go +++ b/x/market/module.go @@ -16,6 +16,7 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/market/client/cli" "github.com/sge-network/sge/x/market/keeper" "github.com/sge-network/sge/x/market/types" diff --git a/x/market/module_simulation.go b/x/market/module_simulation.go index b6e1bbc7..1269d364 100644 --- a/x/market/module_simulation.go +++ b/x/market/module_simulation.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/sge-network/sge/testutil/sample" marketsimulation "github.com/sge-network/sge/x/market/simulation" "github.com/sge-network/sge/x/market/types" diff --git a/x/market/simulation/decoder.go b/x/market/simulation/decoder.go index 4a2191ba..cedde969 100644 --- a/x/market/simulation/decoder.go +++ b/x/market/simulation/decoder.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/simulation/decoder_test.go b/x/market/simulation/decoder_test.go index d8f06bc5..a4bf0f94 100644 --- a/x/market/simulation/decoder_test.go +++ b/x/market/simulation/decoder_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/market/simulation" diff --git a/x/market/simulation/genesis.go b/x/market/simulation/genesis.go index 5bd6e40f..9b8d6ac9 100644 --- a/x/market/simulation/genesis.go +++ b/x/market/simulation/genesis.go @@ -7,6 +7,7 @@ import ( //#nosec "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/simulation/genesis_test.go b/x/market/simulation/genesis_test.go index f799661b..70cb7e30 100644 --- a/x/market/simulation/genesis_test.go +++ b/x/market/simulation/genesis_test.go @@ -6,12 +6,13 @@ import ( "math/rand" "testing" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/stretchr/testify/require" "github.com/sge-network/sge/x/market/simulation" "github.com/sge-network/sge/x/market/types" diff --git a/x/market/simulation/market.go b/x/market/simulation/market.go index 8a529691..abdab2fa 100644 --- a/x/market/simulation/market.go +++ b/x/market/simulation/market.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/market/keeper" "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/simulation/market_update.go b/x/market/simulation/market_update.go index 329aeec3..49fd8f1d 100644 --- a/x/market/simulation/market_update.go +++ b/x/market/simulation/market_update.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/market/keeper" "github.com/sge-network/sge/x/market/types" ) diff --git a/x/market/types/codec.go b/x/market/types/codec.go index bcee1258..1976d94d 100644 --- a/x/market/types/codec.go +++ b/x/market/types/codec.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/msgservice" ) diff --git a/x/market/types/errors.go b/x/market/types/errors.go index a5eade21..79b73c88 100644 --- a/x/market/types/errors.go +++ b/x/market/types/errors.go @@ -3,7 +3,7 @@ package types // DONTCOVER import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "cosmossdk.io/errors" ) // x/market module sentinel errors diff --git a/x/market/types/genesis_test.go b/x/market/types/genesis_test.go index 330ce92e..933f00ee 100644 --- a/x/market/types/genesis_test.go +++ b/x/market/types/genesis_test.go @@ -3,8 +3,9 @@ package types_test import ( "testing" - "github.com/sge-network/sge/x/market/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/market/types" ) func TestGenesisState_Validate(t *testing.T) { diff --git a/x/market/types/message_market.go b/x/market/types/message_market.go index 4abb7715..56ceea55 100644 --- a/x/market/types/message_market.go +++ b/x/market/types/message_market.go @@ -1,9 +1,11 @@ package types import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/utils" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" ) const typeMsgAdd = "market_add" @@ -11,7 +13,7 @@ const typeMsgAdd = "market_add" var _ sdk.Msg = &MsgAdd{} // NewMsgAdd creates the new input for adding a market to blockchain -func NewMsgAdd(creator string, ticket string) *MsgAdd { +func NewMsgAdd(creator, ticket string) *MsgAdd { return &MsgAdd{ Creator: creator, Ticket: ticket, @@ -43,11 +45,11 @@ func (msg *MsgAdd) GetSignBytes() []byte { func (msg *MsgAdd) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) } if msg.Ticket == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid ticket param") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket param") } return nil } @@ -100,11 +102,11 @@ func (msg *MsgUpdate) GetSignBytes() []byte { func (msg *MsgUpdate) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) } if msg.Ticket == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid ticket param") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket param") } return nil diff --git a/x/market/types/message_market_resolve.go b/x/market/types/message_market_resolve.go index 47774dc2..f74d5172 100644 --- a/x/market/types/message_market_resolve.go +++ b/x/market/types/message_market_resolve.go @@ -1,8 +1,10 @@ package types import ( + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" ) @@ -43,11 +45,11 @@ func (msg *MsgResolve) GetSignBytes() []byte { func (msg *MsgResolve) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) } if msg.Ticket == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid ticket param") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket param") } return nil diff --git a/x/market/types/message_market_resolve_test.go b/x/market/types/message_market_resolve_test.go index fb5d355d..cdce12fa 100644 --- a/x/market/types/message_market_resolve_test.go +++ b/x/market/types/message_market_resolve_test.go @@ -3,11 +3,13 @@ package types_test import ( "testing" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) func TestMsgResolveValidateBasic(t *testing.T) { @@ -21,7 +23,7 @@ func TestMsgResolveValidateBasic(t *testing.T) { msg: types.MsgResolve{ Creator: "invalid_address", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "valid", @@ -35,7 +37,7 @@ func TestMsgResolveValidateBasic(t *testing.T) { msg: types.MsgResolve{ Creator: sample.AccAddress(), }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, } for _, tt := range tests { diff --git a/x/market/types/message_market_test.go b/x/market/types/message_market_test.go index 4ee00521..f62a0dc5 100644 --- a/x/market/types/message_market_test.go +++ b/x/market/types/message_market_test.go @@ -3,11 +3,13 @@ package types_test import ( "testing" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) func TestMsgAddValidateBasic(t *testing.T) { @@ -21,7 +23,7 @@ func TestMsgAddValidateBasic(t *testing.T) { msg: types.MsgAdd{ Creator: "invalid_address", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "valid", @@ -35,7 +37,7 @@ func TestMsgAddValidateBasic(t *testing.T) { msg: types.MsgAdd{ Creator: sample.AccAddress(), }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, } for _, tt := range tests { @@ -75,7 +77,7 @@ func TestMsgUpdateValidateBasic(t *testing.T) { msg: types.MsgUpdate{ Creator: "invalid_address", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "valid", @@ -89,7 +91,7 @@ func TestMsgUpdateValidateBasic(t *testing.T) { msg: types.MsgUpdate{ Creator: sample.AccAddress(), }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, } for _, tt := range tests { diff --git a/x/market/types/params.go b/x/market/types/params.go index 43ea13cf..e90b4b7f 100644 --- a/x/market/types/params.go +++ b/x/market/types/params.go @@ -1,8 +1,9 @@ package types import ( + yaml "gopkg.in/yaml.v2" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "gopkg.in/yaml.v2" ) var _ paramtypes.ParamSet = (*Params)(nil) diff --git a/x/market/types/ticket.go b/x/market/types/ticket.go index e46c2ebf..3f1d394d 100644 --- a/x/market/types/ticket.go +++ b/x/market/types/ticket.go @@ -3,11 +3,14 @@ package types import ( "strings" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/mrz1836/go-sanitize" - "github.com/sge-network/sge/utils" "github.com/spf13/cast" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" ) // Validate validates market add ticket payload. @@ -20,24 +23,24 @@ func (payload *MarketAddTicketPayload) Validate(ctx sdk.Context) error { if !(payload.Status == MarketStatus_MARKET_STATUS_ACTIVE || payload.Status == MarketStatus_MARKET_STATUS_INACTIVE) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "acceptable status is active or inactive") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "acceptable status is active or inactive") } if !utils.IsValidUID(payload.UID) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid uid for the market") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid uid for the market") } if len(payload.Odds) < 2 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "not provided enough odds for the market") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "not provided enough odds for the market") } if strings.TrimSpace(payload.Meta) == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "meta is mandatory for the market") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "meta is mandatory for the market") } if len(payload.Meta) > MaxAllowedCharactersForMeta { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "meta length should be less than %d characters", MaxAllowedCharactersForMeta, ) @@ -47,24 +50,24 @@ func (payload *MarketAddTicketPayload) Validate(ctx sdk.Context) error { for _, o := range payload.Odds { if o.Meta == "" { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "meta is mandatory for odds with uuid %s", o.UID, ) } if len(o.Meta) > MaxAllowedCharactersForMeta { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "meta length should be less than %d characters", MaxAllowedCharactersForMeta, ) } o.Meta = sanitize.XSS(o.Meta) if !utils.IsValidUID(o.UID) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "odds-uid passed is invalid") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "odds-uid passed is invalid") } if _, exist := oddsSet[o.UID]; exist { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "duplicate odds-uid in request") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "duplicate odds-uid in request") } oddsSet[o.UID] = Odds{} } @@ -78,7 +81,7 @@ func (payload *MarketUpdateTicketPayload) Validate(ctx sdk.Context) error { if !(payload.Status == MarketStatus_MARKET_STATUS_ACTIVE || payload.Status == MarketStatus_MARKET_STATUS_INACTIVE) { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "supported update status is active or inactive", ) } @@ -93,7 +96,7 @@ func (payload *MarketResolutionTicketPayload) Validate() error { payload.Status == MarketStatus_MARKET_STATUS_ABORTED || payload.Status == MarketStatus_MARKET_STATUS_RESULT_DECLARED) { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "resolution status passed for the market is invalid", ) } @@ -102,7 +105,7 @@ func (payload *MarketResolutionTicketPayload) Validate() error { case MarketStatus_MARKET_STATUS_RESULT_DECLARED: if len(payload.WinnerOddsUIDs) > maxWinnerUIDs { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "currently only %d winner uid is allowed", maxWinnerUIDs, ) @@ -110,7 +113,7 @@ func (payload *MarketResolutionTicketPayload) Validate() error { default: if len(payload.WinnerOddsUIDs) > 0 { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "winner odds should be set if the status is 'result declared'", ) } @@ -118,25 +121,25 @@ func (payload *MarketResolutionTicketPayload) Validate() error { if payload.ResolutionTS == 0 { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "invalid resolution timestamp for the market", ) } if !utils.IsValidUID(payload.UID) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid uid for the market") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid uid for the market") } if payload.Status == MarketStatus_MARKET_STATUS_RESULT_DECLARED && len(payload.WinnerOddsUIDs) < 1 { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "not provided enough winner odds for the market", ) } for _, wid := range payload.WinnerOddsUIDs { if !utils.IsValidUID(wid) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "odds-uid passed is invalid") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "odds-uid passed is invalid") } } @@ -174,12 +177,12 @@ func (payload *MarketResolutionTicketPayload) ValidateWinnerOdds(market *Market) // validateMarketTS validates start and end timestamp of a market. func validateMarketTS(ctx sdk.Context, startTS, endTS uint64) error { if endTS <= cast.ToUint64(ctx.BlockTime().Unix()) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid end timestamp for the market") + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid end timestamp for the market") } if startTS >= endTS || startTS == 0 { return sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "invalid start timestamp for the market, cannot be (greater than eql to EndTs) or 0", ) } diff --git a/x/market/types/ticket_test.go b/x/market/types/ticket_test.go index 77394de4..58fb68e3 100644 --- a/x/market/types/ticket_test.go +++ b/x/market/types/ticket_test.go @@ -4,16 +4,18 @@ import ( "testing" "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/google/uuid" - simappUtil "github.com/sge-network/sge/testutil/simapp" - "github.com/sge-network/sge/x/market/types" "github.com/spf13/cast" "github.com/stretchr/testify/require" + + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/market/types" ) func TestAddMarketTicketPayloadValidation(t *testing.T) { - _, ctx, err := simappUtil.GetTestObjects() + _, ctx, err := simapp.GetTestObjects() require.NoError(t, err) ctx = ctx.WithBlockTime(time.Now()) @@ -46,7 +48,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { StartTS: cast.ToUint64(ctx.BlockTime().Unix()), EndTS: cast.ToUint64(ctx.BlockTime().Unix()), }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid status", @@ -56,7 +58,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { EndTS: cast.ToUint64(ctx.BlockTime().Add(5 * time.Minute).Unix()), Status: types.MarketStatus_MARKET_STATUS_UNSPECIFIED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid uuid", @@ -66,7 +68,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { EndTS: cast.ToUint64(ctx.BlockTime().Add(5 * time.Minute).Unix()), Status: types.MarketStatus_MARKET_STATUS_ACTIVE, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid odds count", @@ -79,7 +81,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { }, Status: types.MarketStatus_MARKET_STATUS_ACTIVE, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "empty meta", @@ -94,7 +96,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { Status: types.MarketStatus_MARKET_STATUS_ACTIVE, Meta: "", }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "large meta", @@ -107,9 +109,9 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { {UID: uuid.NewString(), Meta: "odds 2"}, }, Status: types.MarketStatus_MARKET_STATUS_ACTIVE, - Meta: simappUtil.RandomString(types.MaxAllowedCharactersForMeta + 1), + Meta: simapp.RandomString(types.MaxAllowedCharactersForMeta + 1), }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid odds meta", @@ -124,7 +126,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { Status: types.MarketStatus_MARKET_STATUS_ACTIVE, Meta: "sample market", }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid odds long meta", @@ -133,12 +135,12 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { StartTS: cast.ToUint64(ctx.BlockTime().Unix()), EndTS: cast.ToUint64(ctx.BlockTime().Add(5 * time.Minute).Unix()), Odds: []*types.Odds{ - {UID: uuid.NewString(), Meta: simappUtil.RandomString(types.MaxAllowedCharactersForMeta + 1)}, + {UID: uuid.NewString(), Meta: simapp.RandomString(types.MaxAllowedCharactersForMeta + 1)}, }, Status: types.MarketStatus_MARKET_STATUS_ACTIVE, Meta: "sample market", }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid odds uuid", @@ -153,7 +155,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { Status: types.MarketStatus_MARKET_STATUS_ACTIVE, Meta: "sample market", }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "duplicate odds uuid", @@ -168,7 +170,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { Status: types.MarketStatus_MARKET_STATUS_ACTIVE, Meta: "sample market", }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, } for _, tt := range tests { @@ -184,7 +186,7 @@ func TestAddMarketTicketPayloadValidation(t *testing.T) { } func TestUpdateMarketTicketPayloadValidation(t *testing.T) { - _, ctx, err := simappUtil.GetTestObjects() + _, ctx, err := simapp.GetTestObjects() require.NoError(t, err) ctx = ctx.WithBlockTime(time.Now()) @@ -210,7 +212,7 @@ func TestUpdateMarketTicketPayloadValidation(t *testing.T) { StartTS: cast.ToUint64(ctx.BlockTime().Unix()), EndTS: cast.ToUint64(ctx.BlockTime().Unix()), }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid status", @@ -220,7 +222,7 @@ func TestUpdateMarketTicketPayloadValidation(t *testing.T) { EndTS: cast.ToUint64(ctx.BlockTime().Add(5 * time.Minute).Unix()), Status: types.MarketStatus_MARKET_STATUS_UNSPECIFIED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, } for _, tt := range tests { @@ -236,7 +238,7 @@ func TestUpdateMarketTicketPayloadValidation(t *testing.T) { } func TestResolveMarketTicketPayloadValidation(t *testing.T) { - _, ctx, err := simappUtil.GetTestObjects() + _, ctx, err := simapp.GetTestObjects() require.NoError(t, err) ctx = ctx.WithBlockTime(time.Now()) @@ -262,7 +264,7 @@ func TestResolveMarketTicketPayloadValidation(t *testing.T) { ResolutionTS: cast.ToUint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), Status: types.MarketStatus_MARKET_STATUS_UNSPECIFIED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "winner set when result not declared", @@ -272,7 +274,7 @@ func TestResolveMarketTicketPayloadValidation(t *testing.T) { WinnerOddsUIDs: []string{uuid.NewString()}, Status: types.MarketStatus_MARKET_STATUS_UNSPECIFIED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "excessive winner odds", @@ -282,7 +284,7 @@ func TestResolveMarketTicketPayloadValidation(t *testing.T) { WinnerOddsUIDs: []string{uuid.NewString(), uuid.NewString()}, Status: types.MarketStatus_MARKET_STATUS_RESULT_DECLARED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "no resolution time set", @@ -291,7 +293,7 @@ func TestResolveMarketTicketPayloadValidation(t *testing.T) { WinnerOddsUIDs: []string{uuid.NewString()}, Status: types.MarketStatus_MARKET_STATUS_RESULT_DECLARED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid uuid", @@ -301,7 +303,7 @@ func TestResolveMarketTicketPayloadValidation(t *testing.T) { WinnerOddsUIDs: []string{uuid.NewString()}, Status: types.MarketStatus_MARKET_STATUS_RESULT_DECLARED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "result declared no winner odds", @@ -311,7 +313,7 @@ func TestResolveMarketTicketPayloadValidation(t *testing.T) { WinnerOddsUIDs: []string{}, Status: types.MarketStatus_MARKET_STATUS_RESULT_DECLARED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, { name: "invalid odds uuid", @@ -321,7 +323,7 @@ func TestResolveMarketTicketPayloadValidation(t *testing.T) { WinnerOddsUIDs: []string{"invalid uuid"}, Status: types.MarketStatus_MARKET_STATUS_RESULT_DECLARED, }, - err: sdkerrors.ErrInvalidRequest, + err: sdkerrtypes.ErrInvalidRequest, }, } for _, tt := range tests { diff --git a/x/mint/abci.go b/x/mint/abci.go index 0e6dc63c..44dfd389 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -3,12 +3,14 @@ package mint import ( "time" + "github.com/spf13/cast" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/sge-network/sge/x/mint/keeper" sgeMintTypes "github.com/sge-network/sge/x/mint/types" - "github.com/spf13/cast" ) var gaugeKeys = []string{"minted_tokens"} diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go index 21744eb9..2d16dba1 100644 --- a/x/mint/client/cli/query.go +++ b/x/mint/client/cli/query.go @@ -3,9 +3,11 @@ package cli import ( "fmt" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" + "github.com/sge-network/sge/x/mint/types" - "github.com/spf13/cobra" ) // GetQueryCmd returns the cli query commands for this module diff --git a/x/mint/client/cli/query_minter.go b/x/mint/client/cli/query_minter.go index e5739edb..8c256ef1 100644 --- a/x/mint/client/cli/query_minter.go +++ b/x/mint/client/cli/query_minter.go @@ -3,10 +3,11 @@ package cli import ( "fmt" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/sge-network/sge/x/mint/types" - "github.com/spf13/cobra" ) // GetCmdQueryInflation implements a command to return the current minting diff --git a/x/mint/client/cli/query_minter_test.go b/x/mint/client/cli/query_minter_test.go index b209432b..2da04737 100644 --- a/x/mint/client/cli/query_minter_test.go +++ b/x/mint/client/cli/query_minter_test.go @@ -5,11 +5,13 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/mint/client/cli" "github.com/sge-network/sge/x/mint/types" - "github.com/stretchr/testify/require" ) func TestQueryInflation(t *testing.T) { diff --git a/x/mint/client/cli/query_params.go b/x/mint/client/cli/query_params.go index 52d6f622..a8079812 100644 --- a/x/mint/client/cli/query_params.go +++ b/x/mint/client/cli/query_params.go @@ -3,10 +3,12 @@ package cli import ( "context" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/mint/types" - "github.com/spf13/cobra" ) // GetCmdQueryParams returns the cmd function of params diff --git a/x/mint/client/cli/query_params_test.go b/x/mint/client/cli/query_params_test.go index 7de71ec0..e91d1eaa 100644 --- a/x/mint/client/cli/query_params_test.go +++ b/x/mint/client/cli/query_params_test.go @@ -5,11 +5,13 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/mint/client/cli" "github.com/sge-network/sge/x/mint/types" - "github.com/stretchr/testify/require" ) func TestQueryParams(t *testing.T) { diff --git a/x/mint/client/cli/query_test.go b/x/mint/client/cli/query_test.go index 50978de2..ae639d98 100644 --- a/x/mint/client/cli/query_test.go +++ b/x/mint/client/cli/query_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/mint/client/cli" - "github.com/stretchr/testify/require" ) func TestGetQueryCmd(t *testing.T) { diff --git a/x/mint/genesis.go b/x/mint/genesis.go index 9c24804e..f4a67dba 100644 --- a/x/mint/genesis.go +++ b/x/mint/genesis.go @@ -2,6 +2,7 @@ package mint import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/mint/keeper" "github.com/sge-network/sge/x/mint/types" ) diff --git a/x/mint/genesis_test.go b/x/mint/genesis_test.go index 63a85a4b..2e0b292d 100644 --- a/x/mint/genesis_test.go +++ b/x/mint/genesis_test.go @@ -3,11 +3,12 @@ package mint_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/mint" "github.com/sge-network/sge/x/mint/types" - "github.com/stretchr/testify/require" ) func TestGenesis(t *testing.T) { @@ -15,7 +16,7 @@ func TestGenesis(t *testing.T) { Params: types.DefaultParams(), } - tApp, ctx, err := simappUtil.GetTestObjects() + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) mint.InitGenesis(ctx, tApp.MintKeeper, genesisState) diff --git a/x/mint/keeper/grpc_query_minter.go b/x/mint/keeper/grpc_query_minter.go index fb03536b..47242ad7 100644 --- a/x/mint/keeper/grpc_query_minter.go +++ b/x/mint/keeper/grpc_query_minter.go @@ -4,6 +4,7 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/mint/types" ) diff --git a/x/mint/keeper/grpc_query_minter_test.go b/x/mint/keeper/grpc_query_minter_test.go index 1aa1895f..25a0d04c 100644 --- a/x/mint/keeper/grpc_query_minter_test.go +++ b/x/mint/keeper/grpc_query_minter_test.go @@ -3,9 +3,11 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/mint/types" - "github.com/stretchr/testify/require" ) func TestMinterQuery(t *testing.T) { diff --git a/x/mint/keeper/grpc_query_params.go b/x/mint/keeper/grpc_query_params.go index 887436f5..055454e9 100644 --- a/x/mint/keeper/grpc_query_params.go +++ b/x/mint/keeper/grpc_query_params.go @@ -3,11 +3,13 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/mint/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // Params returns the params of the module diff --git a/x/mint/keeper/grpc_query_params_test.go b/x/mint/keeper/grpc_query_params_test.go index 8aba96e3..069352c3 100644 --- a/x/mint/keeper/grpc_query_params_test.go +++ b/x/mint/keeper/grpc_query_params_test.go @@ -3,9 +3,11 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/mint/types" - "github.com/stretchr/testify/require" ) func TestParamsQuery(t *testing.T) { diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index 4bdf16b3..cba36e0d 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -3,13 +3,15 @@ package keeper import ( "fmt" + "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/mint/types" - "github.com/tendermint/tendermint/libs/log" ) // Keeper is the type for module properties diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index bb5c0e35..d84c69c2 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -3,14 +3,16 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" - simappUtil "github.com/sge-network/sge/testutil/simapp" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/mint/keeper" - "github.com/stretchr/testify/require" ) -func setupKeeperAndApp(t testing.TB) (*simappUtil.TestApp, *keeper.KeeperTest, sdk.Context) { - tApp, ctx, err := simappUtil.GetTestObjects() +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.KeeperTest, sdk.Context) { + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) return tApp, &tApp.MintKeeper, ctx diff --git a/x/mint/keeper/minter.go b/x/mint/keeper/minter.go index a8d74589..c6bcc1af 100644 --- a/x/mint/keeper/minter.go +++ b/x/mint/keeper/minter.go @@ -3,6 +3,7 @@ package keeper import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/mint/types" ) diff --git a/x/mint/keeper/minter_test.go b/x/mint/keeper/minter_test.go index df5e6877..20797dba 100644 --- a/x/mint/keeper/minter_test.go +++ b/x/mint/keeper/minter_test.go @@ -3,9 +3,12 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/app/params" - "github.com/stretchr/testify/require" ) func TestTokenSupply(t *testing.T) { @@ -30,10 +33,10 @@ func TestBondedRatio(t *testing.T) { func TestMintCoins(t *testing.T) { k, ctx := setupKeeper(t) mintAmount := int64(100) - err := k.MintCoins(ctx, sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdk.NewInt(mintAmount)))) + err := k.MintCoins(ctx, sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdkmath.NewInt(mintAmount)))) require.NoError(t, err) totalSupply := k.TokenSupply(ctx, params.DefaultBondDenom) - totalSupply = totalSupply.Add(sdk.NewInt(mintAmount)) + totalSupply = totalSupply.Add(sdkmath.NewInt(mintAmount)) require.Equal(t, int64(10020000200), totalSupply.Int64()) } diff --git a/x/mint/keeper/params.go b/x/mint/keeper/params.go index f678e4ca..adad8aa4 100644 --- a/x/mint/keeper/params.go +++ b/x/mint/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/mint/types" ) diff --git a/x/mint/keeper/params_test.go b/x/mint/keeper/params_test.go index a4a24d83..9d0d05bb 100644 --- a/x/mint/keeper/params_test.go +++ b/x/mint/keeper/params_test.go @@ -3,8 +3,9 @@ package keeper_test import ( "testing" - "github.com/sge-network/sge/x/mint/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/mint/types" ) func TestGetParams(t *testing.T) { diff --git a/x/mint/module.go b/x/mint/module.go index 03291a48..97c8fc68 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -16,6 +16,7 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/mint/client/cli" "github.com/sge-network/sge/x/mint/keeper" "github.com/sge-network/sge/x/mint/types" diff --git a/x/mint/module_simulation.go b/x/mint/module_simulation.go index d2291a23..eac6e281 100644 --- a/x/mint/module_simulation.go +++ b/x/mint/module_simulation.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/sge-network/sge/testutil/sample" mintsimulation "github.com/sge-network/sge/x/mint/simulation" "github.com/sge-network/sge/x/mint/types" diff --git a/x/mint/module_test.go b/x/mint/module_test.go index 9623218f..3d9d7ec2 100644 --- a/x/mint/module_test.go +++ b/x/mint/module_test.go @@ -3,15 +3,16 @@ package mint_test import ( "testing" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/require" - simappUtil "github.com/sge-network/sge/testutil/simapp" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/mint/types" ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { - tApp, ctx, err := simappUtil.GetTestObjects() + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) acc := tApp.AccountKeeper.GetAccount(ctx, authtypes.NewModuleAddress(types.ModuleName)) diff --git a/x/mint/simulation/decoder.go b/x/mint/simulation/decoder.go index b20f471f..185bcc47 100644 --- a/x/mint/simulation/decoder.go +++ b/x/mint/simulation/decoder.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/x/mint/types" ) diff --git a/x/mint/simulation/decoder_test.go b/x/mint/simulation/decoder_test.go index 8cccfea0..72a1aa7c 100644 --- a/x/mint/simulation/decoder_test.go +++ b/x/mint/simulation/decoder_test.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/x/mint/simulation" "github.com/sge-network/sge/x/mint/types" diff --git a/x/mint/simulation/genesis.go b/x/mint/simulation/genesis.go index 324763e0..417a38fe 100644 --- a/x/mint/simulation/genesis.go +++ b/x/mint/simulation/genesis.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/app/params" "github.com/sge-network/sge/x/mint/types" ) diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go index 3d67fd38..02208a8b 100644 --- a/x/mint/simulation/genesis_test.go +++ b/x/mint/simulation/genesis_test.go @@ -6,13 +6,14 @@ import ( "math/rand" "testing" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "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" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/stretchr/testify/require" "github.com/sge-network/sge/x/mint/simulation" "github.com/sge-network/sge/x/mint/types" diff --git a/x/mint/simulation/params.go b/x/mint/simulation/params.go index ead32943..d54c342f 100644 --- a/x/mint/simulation/params.go +++ b/x/mint/simulation/params.go @@ -7,9 +7,9 @@ import ( //#nosec "math/rand" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/sge-network/sge/x/mint/types" ) diff --git a/x/mint/types/errors.go b/x/mint/types/errors.go index 150cf264..a89ea40b 100644 --- a/x/mint/types/errors.go +++ b/x/mint/types/errors.go @@ -3,7 +3,7 @@ package types // DONTCOVER import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "cosmossdk.io/errors" ) // ErrMintDenomIsBlank x/mint module sentinel errors diff --git a/x/mint/types/genesis_test.go b/x/mint/types/genesis_test.go index 30d4c619..5e02b62f 100644 --- a/x/mint/types/genesis_test.go +++ b/x/mint/types/genesis_test.go @@ -3,9 +3,12 @@ package types_test import ( "testing" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/mint/types" - "github.com/stretchr/testify/require" ) func TestNewGenesisState(t *testing.T) { @@ -140,7 +143,7 @@ func TestGenesisStateValidate(t *testing.T) { MintDenom: types.DefaultParams().MintDenom, BlocksPerYear: types.DefaultParams().BlocksPerYear, Phases: types.DefaultParams().Phases, - ExcludeAmount: sdk.NewInt(-1), + ExcludeAmount: sdkmath.NewInt(-1), }, ), valid: false, diff --git a/x/mint/types/minter.go b/x/mint/types/minter.go index b8c0fdb8..5376099d 100644 --- a/x/mint/types/minter.go +++ b/x/mint/types/minter.go @@ -84,7 +84,7 @@ func (Minter) CurrentPhase(params Params, currentBlock int64) (Phase, int) { // NextPhaseProvisions returns the phase provisions based on current total // supply and inflation rate. -func (m Minter) NextPhaseProvisions(totalSupply sdkmath.Int, excludeAmount sdkmath.Int, phase Phase) sdk.Dec { +func (m Minter) NextPhaseProvisions(totalSupply, excludeAmount sdkmath.Int, phase Phase) sdk.Dec { // calculate annual provisions as normal annualProvisions := m.Inflation.MulInt(totalSupply.Sub(excludeAmount)) diff --git a/x/mint/types/minter_test.go b/x/mint/types/minter_test.go index c515ae9b..20d00a14 100644 --- a/x/mint/types/minter_test.go +++ b/x/mint/types/minter_test.go @@ -6,10 +6,12 @@ import ( "math/rand" "testing" - "github.com/sge-network/sge/x/mint/types" "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/mint/types" ) func TestPhaseInflation(t *testing.T) { @@ -205,7 +207,7 @@ func TestBlockProvision(t *testing.T) { provisions, _ := minter.BlockProvisions(params, 1) expProvisions := sdk.NewCoin(params.MintDenom, - sdk.NewInt(tc.expProvisions)) + sdkmath.NewInt(tc.expProvisions)) require.True(t, expProvisions.IsEqual(provisions), "test: %v\n\tExp: %v\n\tGot: %v\n", @@ -230,8 +232,8 @@ func TestBlockProvisions(t *testing.T) { params := types.DefaultParams() blocksPerYear := int64(51480) - totalSupply := sdk.NewIntFromUint64(1150000000000000) - params.ExcludeAmount = sdk.NewInt(445000000000025) + totalSupply := sdkmath.NewIntFromUint64(1150000000000000) + params.ExcludeAmount = sdkmath.NewInt(445000000000025) tests := []struct { phaseindex int expProvision int64 @@ -263,7 +265,7 @@ func TestBlockProvisions(t *testing.T) { params.BlocksPerYear = blocksPerYear minter.PhaseProvisions = minter.NextPhaseProvisions(totalSupply, params.ExcludeAmount, phase) - currentPhaseProvision := sdk.NewInt(0) + currentPhaseProvision := sdkmath.NewInt(0) if !types.IsEndPhase(phase) { for phaseStep == currentPhaseStep { blockIProvision, truncatedToken := minter.BlockProvisions(params, phaseStep) @@ -279,7 +281,7 @@ func TestBlockProvisions(t *testing.T) { t.Logf("Total Supply after phase %v: %v", phaseStep, totalSupply) } - phaseDeviation := sdk.NewInt(tc.expProvision).Sub(currentPhaseProvision).Abs().Int64() + phaseDeviation := sdkmath.NewInt(tc.expProvision).Sub(currentPhaseProvision).Abs().Int64() allowedPhaseDeviation := int64(4) require.LessOrEqual( t, @@ -293,7 +295,7 @@ func TestBlockProvisions(t *testing.T) { ) } - expTotalSupply := sdk.NewInt(1600000000000000) + expTotalSupply := sdkmath.NewInt(1600000000000000) deviation := totalSupply.Sub(expTotalSupply).Abs().Int64() allowedTotalSupplyDeviation := int64(17) require.LessOrEqual(t, deviation, allowedTotalSupplyDeviation, @@ -310,8 +312,8 @@ func TestAnnualProvisions(t *testing.T) { minter.PhaseStep = 1 minter.Inflation = firstPhase.Inflation minter.PhaseProvisions = minter.NextPhaseProvisions( - sdk.NewInt(totalSupply), - sdk.NewInt(excludeAmount), + sdkmath.NewInt(totalSupply), + sdkmath.NewInt(excludeAmount), firstPhase, ) t.Log(minter.PhaseProvisions) @@ -361,7 +363,7 @@ func BenchmarkNextPhaseProvisions(b *testing.B) { b.ReportAllocs() minter := types.InitialMinter(sdk.NewDecWithPrec(1, 1)) params := types.DefaultParams() - totalSupply := sdk.NewInt(100000000000000) + totalSupply := sdkmath.NewInt(100000000000000) phase := params.GetPhaseAtStep(1) // run the NextPhaseProvisions function b.N times diff --git a/x/mint/types/params.go b/x/mint/types/params.go index d03a047f..2d0a546f 100644 --- a/x/mint/types/params.go +++ b/x/mint/types/params.go @@ -6,11 +6,13 @@ import ( "math/big" "strings" + yaml "gopkg.in/yaml.v2" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/sge-network/sge/app/params" - "gopkg.in/yaml.v2" ) var _ paramtypes.ParamSet = (*Params)(nil) @@ -52,7 +54,7 @@ var ( var ( // DefaultExcludeAmount is the default value for exclude amount - DefaultExcludeAmount = sdk.NewInt(int64(0)) + DefaultExcludeAmount = sdkmath.NewInt(int64(0)) // DefaultPhases is the default value for inflation phases DefaultPhases = []Phase{ diff --git a/x/mint/types/params.pb.go b/x/mint/types/params.pb.go index 41a365ae..b2f10cda 100644 --- a/x/mint/types/params.pb.go +++ b/x/mint/types/params.pb.go @@ -4,8 +4,8 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -33,7 +33,7 @@ type Params struct { // phases contains phases of inflation. Phases []Phase `protobuf:"bytes,3,rep,name=phases,proto3" json:"phases" yaml:"phases"` // exclude_amount is the excluded amount form being calculated in inflation. - ExcludeAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=exclude_amount,json=excludeAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"exclude_amount" yaml:"exclude_amount"` + ExcludeAmount cosmossdk_io_math.Int `protobuf:"bytes,4,opt,name=exclude_amount,json=excludeAmount,proto3,customtype=cosmossdk.io/math.Int" json:"exclude_amount" yaml:"exclude_amount"` } func (m *Params) Reset() { *m = Params{} } @@ -96,29 +96,29 @@ func init() { func init() { proto.RegisterFile("sge/mint/params.proto", fileDescriptor_a4bb1a108a109550) } var fileDescriptor_a4bb1a108a109550 = []byte{ - // 349 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xcf, 0x6a, 0xea, 0x40, - 0x14, 0xc6, 0x13, 0x15, 0xc1, 0x5c, 0xbc, 0x17, 0x72, 0xb5, 0x84, 0x40, 0x13, 0xc9, 0xa2, 0x75, - 0xe3, 0x04, 0xda, 0x9d, 0x3b, 0x43, 0xa1, 0xb8, 0x93, 0xec, 0xda, 0x4d, 0x18, 0xe3, 0x61, 0x14, - 0x9d, 0x4c, 0x98, 0x19, 0xa9, 0xbe, 0x45, 0x97, 0x5d, 0xf6, 0x01, 0xfa, 0x20, 0x2e, 0x5d, 0x96, - 0x2e, 0x42, 0xd1, 0x37, 0xf0, 0x09, 0xca, 0x64, 0x02, 0xfd, 0x43, 0x57, 0x39, 0xf9, 0xce, 0x77, - 0x7e, 0xdf, 0x99, 0x63, 0x75, 0x05, 0x81, 0x90, 0x2e, 0x32, 0x19, 0xe6, 0x98, 0x63, 0x2a, 0x50, - 0xce, 0x99, 0x64, 0xf6, 0x7f, 0x41, 0x20, 0x03, 0xf9, 0xc0, 0xf8, 0x12, 0x09, 0x02, 0x48, 0x39, - 0xdc, 0x0e, 0x61, 0x84, 0x95, 0xfd, 0x50, 0x55, 0xda, 0xea, 0x76, 0x3e, 0x09, 0x73, 0x2c, 0x40, - 0xab, 0xc1, 0x4b, 0xcd, 0x6a, 0x4e, 0x4a, 0xa2, 0x7d, 0x6e, 0x59, 0xaa, 0x9d, 0xcc, 0x20, 0x63, - 0xd4, 0x31, 0x7b, 0x66, 0xbf, 0x15, 0xb7, 0x94, 0x72, 0xa3, 0x04, 0x3b, 0xb2, 0xfe, 0x4d, 0x57, - 0x2c, 0x5d, 0x8a, 0x24, 0x07, 0x9e, 0x6c, 0x01, 0x73, 0xa7, 0xd6, 0x33, 0xfb, 0xf5, 0xc8, 0x3d, - 0x15, 0xfe, 0xd9, 0x16, 0xd3, 0xd5, 0x30, 0xf8, 0x61, 0x08, 0xe2, 0xb6, 0x56, 0x26, 0xc0, 0xef, - 0x00, 0x73, 0x7b, 0x6c, 0x35, 0xcb, 0x70, 0xe1, 0xd4, 0x7b, 0xf5, 0xfe, 0x9f, 0x2b, 0x17, 0xfd, - 0xb2, 0x3f, 0x9a, 0x28, 0x4b, 0xd4, 0xdd, 0x15, 0xbe, 0x71, 0x2a, 0xfc, 0xb6, 0x46, 0xeb, 0xb9, - 0x20, 0xae, 0x00, 0x76, 0x66, 0xfd, 0x85, 0x4d, 0xba, 0x5a, 0xcf, 0x20, 0xc1, 0x94, 0xad, 0x33, - 0xe9, 0x34, 0xd4, 0xc6, 0xd1, 0xad, 0x1a, 0x7b, 0x2b, 0xfc, 0x0b, 0xb2, 0x90, 0xf3, 0xf5, 0x14, - 0xa5, 0x8c, 0x86, 0x29, 0x13, 0x94, 0x89, 0xea, 0x33, 0x10, 0xb3, 0x65, 0x28, 0xb7, 0x39, 0x08, - 0x34, 0xce, 0xe4, 0xa9, 0xf0, 0xbb, 0x3a, 0xe0, 0x3b, 0x2d, 0x88, 0xdb, 0x95, 0x30, 0x2a, 0xff, - 0x87, 0x8d, 0xa7, 0x67, 0xdf, 0x88, 0x46, 0xbb, 0x83, 0x67, 0xee, 0x0f, 0x9e, 0xf9, 0x7e, 0xf0, - 0xcc, 0xc7, 0xa3, 0x67, 0xec, 0x8f, 0x9e, 0xf1, 0x7a, 0xf4, 0x8c, 0xfb, 0xcb, 0x2f, 0x79, 0x82, - 0xc0, 0xa0, 0x7a, 0x95, 0xaa, 0xc3, 0x8d, 0xbe, 0x7b, 0x19, 0x3a, 0x6d, 0x96, 0x87, 0xbf, 0xfe, - 0x08, 0x00, 0x00, 0xff, 0xff, 0x46, 0xeb, 0x51, 0xa7, 0xd2, 0x01, 0x00, 0x00, + // 344 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xc1, 0x4a, 0xc3, 0x40, + 0x10, 0x86, 0x93, 0xb6, 0x14, 0x1a, 0xa9, 0x42, 0x6c, 0x24, 0x04, 0x4c, 0x4a, 0x2e, 0xf6, 0xe2, + 0x06, 0x14, 0x3c, 0xf4, 0xd6, 0xe0, 0xa5, 0xb7, 0x92, 0x9b, 0x82, 0x84, 0x6d, 0x3a, 0x6c, 0x4b, + 0xbb, 0xd9, 0xb0, 0xbb, 0xc5, 0xf6, 0x2d, 0x3c, 0x0a, 0x5e, 0x7c, 0x9c, 0x1e, 0x7b, 0x14, 0x0f, + 0x41, 0xda, 0x37, 0xe8, 0x13, 0xc8, 0x66, 0x0b, 0xa2, 0x78, 0x9b, 0xfd, 0xe7, 0xff, 0xbf, 0x9d, + 0x19, 0xcb, 0x11, 0x04, 0x22, 0x3a, 0xcb, 0x65, 0x54, 0x60, 0x8e, 0xa9, 0x40, 0x05, 0x67, 0x92, + 0xd9, 0xe7, 0x82, 0x40, 0x0e, 0xf2, 0x99, 0xf1, 0x39, 0x12, 0x04, 0x90, 0x72, 0x78, 0x1d, 0xc2, + 0x08, 0xab, 0xfa, 0x91, 0xaa, 0xb4, 0xd5, 0xeb, 0xfc, 0x10, 0xa6, 0x58, 0x80, 0x56, 0xc3, 0xb7, + 0x9a, 0xd5, 0x1c, 0x55, 0x44, 0xfb, 0xd2, 0xb2, 0x54, 0x3b, 0x9d, 0x40, 0xce, 0xa8, 0x6b, 0x76, + 0xcd, 0x5e, 0x2b, 0x69, 0x29, 0xe5, 0x5e, 0x09, 0x76, 0x6c, 0x9d, 0x8d, 0x17, 0x2c, 0x9b, 0x8b, + 0xb4, 0x00, 0x9e, 0xae, 0x01, 0x73, 0xb7, 0xd6, 0x35, 0x7b, 0xf5, 0xd8, 0x3b, 0x94, 0xc1, 0xc5, + 0x1a, 0xd3, 0x45, 0x3f, 0xfc, 0x63, 0x08, 0x93, 0xb6, 0x56, 0x46, 0xc0, 0x1f, 0x00, 0x73, 0x7b, + 0x68, 0x35, 0xab, 0xcf, 0x85, 0x5b, 0xef, 0xd6, 0x7b, 0x27, 0x37, 0x1e, 0xfa, 0x67, 0x7e, 0x34, + 0x52, 0x96, 0xd8, 0xd9, 0x94, 0x81, 0x71, 0x28, 0x83, 0xb6, 0x46, 0xeb, 0x5c, 0x98, 0x1c, 0x01, + 0xf6, 0x93, 0x75, 0x0a, 0xab, 0x6c, 0xb1, 0x9c, 0x40, 0x8a, 0x29, 0x5b, 0xe6, 0xd2, 0x6d, 0xa8, + 0x89, 0xe3, 0x3b, 0x15, 0xfb, 0x2c, 0x03, 0x27, 0x63, 0x82, 0x32, 0x21, 0x26, 0x73, 0x34, 0x63, + 0x11, 0xc5, 0x72, 0x8a, 0x86, 0xb9, 0x3c, 0x94, 0x81, 0xa3, 0x79, 0xbf, 0xc3, 0x61, 0xd2, 0x3e, + 0x0a, 0x83, 0xea, 0xdd, 0x6f, 0xbc, 0xbe, 0x07, 0x46, 0x3c, 0xd8, 0xec, 0x7c, 0x73, 0xbb, 0xf3, + 0xcd, 0xaf, 0x9d, 0x6f, 0xbe, 0xec, 0x7d, 0x63, 0xbb, 0xf7, 0x8d, 0x8f, 0xbd, 0x6f, 0x3c, 0x5e, + 0x91, 0x99, 0x9c, 0x2e, 0xc7, 0x28, 0x63, 0x34, 0x12, 0x04, 0xae, 0x8f, 0x4b, 0xa8, 0x3a, 0x5a, + 0xe9, 0x33, 0xcb, 0x75, 0x01, 0x62, 0xdc, 0xac, 0xee, 0x7c, 0xfb, 0x1d, 0x00, 0x00, 0xff, 0xff, + 0x6c, 0x98, 0x2f, 0x26, 0xc1, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { diff --git a/x/mint/types/params_test.go b/x/mint/types/params_test.go index e798c161..5cf13a99 100644 --- a/x/mint/types/params_test.go +++ b/x/mint/types/params_test.go @@ -4,10 +4,13 @@ import ( "reflect" "testing" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/app/params" "github.com/sge-network/sge/x/mint/types" - "github.com/stretchr/testify/require" ) func TestParamsYML(t *testing.T) { @@ -17,7 +20,7 @@ func TestParamsYML(t *testing.T) { Phases: []types.Phase{ {Inflation: sdk.NewDec(10), YearCoefficient: sdk.NewDec(1)}, }, - ExcludeAmount: sdk.NewInt(100), + ExcludeAmount: sdkmath.NewInt(100), } ymlStr := param.String() diff --git a/x/mint/types/phase_test.go b/x/mint/types/phase_test.go index 9883a684..d7aee158 100644 --- a/x/mint/types/phase_test.go +++ b/x/mint/types/phase_test.go @@ -3,9 +3,11 @@ package types_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/mint/types" - "github.com/stretchr/testify/require" ) func TestPhaseYML(t *testing.T) { diff --git a/x/orderbook/abci.go b/x/orderbook/abci.go index 1cda690f..b4a9700d 100644 --- a/x/orderbook/abci.go +++ b/x/orderbook/abci.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/orderbook/keeper" ) diff --git a/x/orderbook/client/cli/query.go b/x/orderbook/client/cli/query.go index 6ca744ba..bd521d51 100644 --- a/x/orderbook/client/cli/query.go +++ b/x/orderbook/client/cli/query.go @@ -1,9 +1,10 @@ package cli import ( - "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" + "github.com/sge-network/sge/x/orderbook/types" ) diff --git a/x/orderbook/client/cli/query_bet.go b/x/orderbook/client/cli/query_bet.go index 170280d2..cc5d1e33 100644 --- a/x/orderbook/client/cli/query_bet.go +++ b/x/orderbook/client/cli/query_bet.go @@ -4,12 +4,14 @@ import ( "fmt" "strings" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/spf13/cobra" ) // GetCmdQueryParticipationBets implements the command to query all the participation fulfilled bets to a specific orderbook. diff --git a/x/orderbook/client/cli/query_bet_test.go b/x/orderbook/client/cli/query_bet_test.go index 8b27dcb5..13f835da 100644 --- a/x/orderbook/client/cli/query_bet_test.go +++ b/x/orderbook/client/cli/query_bet_test.go @@ -4,18 +4,21 @@ import ( "fmt" "testing" + "github.com/google/uuid" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/google/uuid" "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" + bettypes "github.com/sge-network/sge/x/bet/types" "github.com/sge-network/sge/x/orderbook/client/cli" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" ) func networkWithParticipationBetObjects(t *testing.T, n int) (*network.Network, []types.ParticipationBetPair) { @@ -35,7 +38,7 @@ func networkWithParticipationBetObjects(t *testing.T, n int) (*network.Network, for i := 0; i < n; i++ { bet := bettypes.Bet{ UID: uuid.NewString(), - Creator: simappUtil.TestParamUsers["user"+cast.ToString(i+1)].Address.String(), + Creator: simapp.TestParamUsers["user"+cast.ToString(i+1)].Address.String(), } nullify.Fill(&bet) betState.BetList = append(betState.BetList, bet) diff --git a/x/orderbook/client/cli/query_exposure_odds.go b/x/orderbook/client/cli/query_exposure_odds.go index 19d11d4f..506897e0 100644 --- a/x/orderbook/client/cli/query_exposure_odds.go +++ b/x/orderbook/client/cli/query_exposure_odds.go @@ -4,11 +4,13 @@ import ( "fmt" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cobra" ) // GetCmdQueryOrderBookExposure implements the book-exposure query command. diff --git a/x/orderbook/client/cli/query_exposure_odds_test.go b/x/orderbook/client/cli/query_exposure_odds_test.go index 59508277..911b750e 100644 --- a/x/orderbook/client/cli/query_exposure_odds_test.go +++ b/x/orderbook/client/cli/query_exposure_odds_test.go @@ -4,18 +4,21 @@ import ( "fmt" "testing" + "github.com/google/uuid" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/google/uuid" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/orderbook/client/cli" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func networkWithOddsExposureObjects(t *testing.T, n int) (*network.Network, []types.OrderBookOddsExposure) { diff --git a/x/orderbook/client/cli/query_exposure_participation.go b/x/orderbook/client/cli/query_exposure_participation.go index d066a0d1..8e51f151 100644 --- a/x/orderbook/client/cli/query_exposure_participation.go +++ b/x/orderbook/client/cli/query_exposure_participation.go @@ -4,12 +4,14 @@ import ( "fmt" "strings" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/spf13/cobra" ) // GetCmdQueryOrderBookParticipationExposures implements the command to query all the participation exposures to a specific orderbook. diff --git a/x/orderbook/client/cli/query_exposure_participation_test.go b/x/orderbook/client/cli/query_exposure_participation_test.go index 3cd0fc79..4b9b9917 100644 --- a/x/orderbook/client/cli/query_exposure_participation_test.go +++ b/x/orderbook/client/cli/query_exposure_participation_test.go @@ -4,17 +4,20 @@ import ( "fmt" "testing" + "github.com/google/uuid" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + tmcli "github.com/tendermint/tendermint/libs/cli" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/google/uuid" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/orderbook/client/cli" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" ) func networkWithParticipationExposureObjects(t *testing.T, n int) (*network.Network, []types.ParticipationExposure) { @@ -30,8 +33,8 @@ func networkWithParticipationExposureObjects(t *testing.T, n int) (*network.Netw OddsUID: uuid.NewString(), ParticipationIndex: testParticipationIndex, OrderBookUID: testMarketUID, - Exposure: sdk.NewInt(1000), - BetAmount: sdk.NewInt(1000), + Exposure: sdkmath.NewInt(1000), + BetAmount: sdkmath.NewInt(1000), IsFulfilled: false, Round: 1, } diff --git a/x/orderbook/client/cli/query_orderbook.go b/x/orderbook/client/cli/query_orderbook.go index 061b588e..d78cbd8f 100644 --- a/x/orderbook/client/cli/query_orderbook.go +++ b/x/orderbook/client/cli/query_orderbook.go @@ -4,11 +4,13 @@ import ( "fmt" "strings" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cobra" ) // GetCmdQueryOrderBooks implements the query all order books command. diff --git a/x/orderbook/client/cli/query_orderbook_test.go b/x/orderbook/client/cli/query_orderbook_test.go index feafbb4a..44b2bc63 100644 --- a/x/orderbook/client/cli/query_orderbook_test.go +++ b/x/orderbook/client/cli/query_orderbook_test.go @@ -4,18 +4,21 @@ import ( "fmt" "testing" + "github.com/google/uuid" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + tmcli "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - "github.com/google/uuid" "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" + "github.com/sge-network/sge/x/orderbook/client/cli" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func networkWithOrderBookObjects(t *testing.T, n int) (*network.Network, []types.OrderBook) { diff --git a/x/orderbook/client/cli/query_params.go b/x/orderbook/client/cli/query_params.go index a6477a1e..1983bdcb 100644 --- a/x/orderbook/client/cli/query_params.go +++ b/x/orderbook/client/cli/query_params.go @@ -3,10 +3,12 @@ package cli import ( "context" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cobra" ) // CmdQueryParams returns a command object instance for module params diff --git a/x/orderbook/client/cli/query_params_test.go b/x/orderbook/client/cli/query_params_test.go index df3878d7..933c9662 100644 --- a/x/orderbook/client/cli/query_params_test.go +++ b/x/orderbook/client/cli/query_params_test.go @@ -4,11 +4,13 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/house/client/cli" "github.com/sge-network/sge/x/house/types" - "github.com/stretchr/testify/require" ) func TestQueryParams(t *testing.T) { diff --git a/x/orderbook/client/cli/query_participation.go b/x/orderbook/client/cli/query_participation.go index 168405bb..291b05be 100644 --- a/x/orderbook/client/cli/query_participation.go +++ b/x/orderbook/client/cli/query_participation.go @@ -4,12 +4,14 @@ import ( "fmt" "strings" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/version" + "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/spf13/cobra" ) // GetCmdQueryOrderBookParticipations implements the command to query all the participations to a specific orderbook. diff --git a/x/orderbook/client/cli/query_participation_test.go b/x/orderbook/client/cli/query_participation_test.go index ffdea63b..f5fd2a56 100644 --- a/x/orderbook/client/cli/query_participation_test.go +++ b/x/orderbook/client/cli/query_participation_test.go @@ -4,18 +4,21 @@ import ( "fmt" "testing" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + tmcli "github.com/tendermint/tendermint/libs/cli" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/orderbook/client/cli" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) const ( @@ -36,16 +39,16 @@ func networkWithParticipationObjects(t *testing.T, n int) (*network.Network, []t Index: cast.ToUint64(i + 1), OrderBookUID: testMarketUID, ParticipantAddress: testAddress, - Liquidity: sdk.NewInt(1000), - Fee: sdk.NewInt(10), - CurrentRoundLiquidity: sdk.NewInt(1000), + Liquidity: sdkmath.NewInt(1000), + Fee: sdkmath.NewInt(10), + CurrentRoundLiquidity: sdkmath.NewInt(1000), ExposuresNotFilled: 1, - TotalBetAmount: sdk.NewInt(0), - CurrentRoundTotalBetAmount: sdk.NewInt(0), - MaxLoss: sdk.NewInt(0), - CurrentRoundMaxLoss: sdk.NewInt(0), + TotalBetAmount: sdkmath.NewInt(0), + CurrentRoundTotalBetAmount: sdkmath.NewInt(0), + MaxLoss: sdkmath.NewInt(0), + CurrentRoundMaxLoss: sdkmath.NewInt(0), CurrentRoundMaxLossOddsUID: "6db09053-2901-4110-8fb5-c14e21f8d666", - ActualProfit: sdk.NewInt(0), + ActualProfit: sdkmath.NewInt(0), IsSettled: false, } nullify.Fill(&participation) diff --git a/x/orderbook/client/cli/query_test.go b/x/orderbook/client/cli/query_test.go index ce06db1c..aadc5295 100644 --- a/x/orderbook/client/cli/query_test.go +++ b/x/orderbook/client/cli/query_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/sge-network/sge/testutil/network" + "github.com/sge-network/sge/x/orderbook/client/cli" - "github.com/stretchr/testify/require" ) const testAddress = "cosmos1s4ycalgh3gjemd4hmqcvcgmnf647rnd0tpg2w9" diff --git a/x/orderbook/keeper/bet_settle.go b/x/orderbook/keeper/bet_settle.go index c6c8655a..6c725436 100644 --- a/x/orderbook/keeper/bet_settle.go +++ b/x/orderbook/keeper/bet_settle.go @@ -1,9 +1,9 @@ package keeper import ( + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bettypes "github.com/sge-network/sge/x/bet/types" "github.com/sge-network/sge/x/orderbook/types" @@ -23,7 +23,13 @@ func (k Keeper) RefundBettor( } // refund bettor's account from bet fee collector. - return k.refund(bettypes.BetFeeCollectorFunder{}, ctx, bettorAddress, betFee) + if err := k.refund(bettypes.BetFeeCollectorFunder{}, ctx, bettorAddress, betFee); err != nil { + return err + } + + k.hooks.AfterBettorRefund(ctx, bettorAddress, betAmount, betFee) + + return nil } // BettorWins process bets in case bettor is the winner, @@ -32,8 +38,8 @@ func (k Keeper) RefundBettor( func (k Keeper) BettorWins( ctx sdk.Context, bettorAddress sdk.AccAddress, - _ sdkmath.Int, - _ sdkmath.Int, + betAmount sdkmath.Int, + payoutProfit sdkmath.Int, _ string, betFulfillments []*bettypes.BetFulfillment, orderBookUID string, @@ -67,6 +73,8 @@ func (k Keeper) BettorWins( k.SetOrderBookParticipation(ctx, orderBookParticipation) } + k.hooks.AfterBettorWin(ctx, bettorAddress, betAmount, payoutProfit) + return nil } @@ -74,8 +82,10 @@ func (k Keeper) BettorWins( // adds the bet amount to the actual profit of the participation // for each of the bet fulfillment records and, // removes the payout lock. -func (k Keeper) BettorLoses(ctx sdk.Context, _ sdk.AccAddress, - _ sdkmath.Int, +func (k Keeper) BettorLoses( + ctx sdk.Context, + bettorAddress sdk.AccAddress, + betAmount sdkmath.Int, _ sdkmath.Int, _ string, betFulfillments []*bettypes.BetFulfillment, @@ -105,5 +115,7 @@ func (k Keeper) BettorLoses(ctx sdk.Context, _ sdk.AccAddress, k.SetOrderBookParticipation(ctx, orderBookParticipation) } + k.hooks.AfterBettorLoss(ctx, bettorAddress, betAmount) + return nil } diff --git a/x/orderbook/keeper/bet_settle_test.go b/x/orderbook/keeper/bet_settle_test.go index 725de2b0..9f2efa3b 100644 --- a/x/orderbook/keeper/bet_settle_test.go +++ b/x/orderbook/keeper/bet_settle_test.go @@ -3,11 +3,12 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sge-network/sge/app/params" bettypes "github.com/sge-network/sge/x/bet/types" markettypes "github.com/sge-network/sge/x/market/types" - "github.com/stretchr/testify/require" ) func TestBetSettlement(t *testing.T) { diff --git a/x/orderbook/keeper/bet_wager.go b/x/orderbook/keeper/bet_wager.go index cfa1902e..d576bb6e 100644 --- a/x/orderbook/keeper/bet_wager.go +++ b/x/orderbook/keeper/bet_wager.go @@ -3,10 +3,11 @@ package keeper import ( "fmt" + "github.com/spf13/cast" + + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/spf13/cast" bettypes "github.com/sge-network/sge/x/bet/types" "github.com/sge-network/sge/x/orderbook/types" @@ -139,7 +140,7 @@ func (k Keeper) fulfillBetByParticipationQueue( // availableLiquidity is positive and more than remaining payout profit that // need to be paid, so we can cover all payout profits with available liquidity. // this case appends the last fulfillment - if fInfo.isLiquidityLessThanThreshold(sdk.NewIntFromUint64(k.GetRequeueThreshold(ctx))) { + if fInfo.isLiquidityLessThanThreshold(sdkmath.NewIntFromUint64(k.GetRequeueThreshold(ctx))) { setFulfilled = true } k.fulfill(ctx, fInfo, fInfo.betAmount, fInfo.payoutProfit.TruncateInt()) @@ -199,13 +200,13 @@ func (k Keeper) initFulfillmentInfo( oddsType: oddsType, oddsVal: oddsVal, maxLossMultiplier: maxLossMultiplier, - totalAvailableLiquidity: sdk.NewInt(0), + totalAvailableLiquidity: sdkmath.NewInt(0), // in process maps fulfillmentMap: make(map[uint64]fulfillmentItem), // initialize the fulfilled bet amount with 0 - fulfilledBetAmount: sdk.NewInt(0), + fulfilledBetAmount: sdkmath.NewInt(0), } bps, err := k.GetParticipationsOfOrderBook(ctx, book.UID) diff --git a/x/orderbook/keeper/bet_wager_test.go b/x/orderbook/keeper/bet_wager_test.go index e46eced4..e14c4df2 100644 --- a/x/orderbook/keeper/bet_wager_test.go +++ b/x/orderbook/keeper/bet_wager_test.go @@ -4,18 +4,20 @@ import ( "testing" "time" + "github.com/google/uuid" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/google/uuid" + "github.com/sge-network/sge/app/params" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" bettypes "github.com/sge-network/sge/x/bet/types" housetypes "github.com/sge-network/sge/x/house/types" markettypes "github.com/sge-network/sge/x/market/types" "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func TestWager(t *testing.T) { @@ -27,7 +29,7 @@ type testBetSuite struct { t *testing.T k *keeper.KeeperTest ctx sdk.Context - tApp simappUtil.TestApp + tApp simapp.TestApp betFee sdkmath.Int market markettypes.Market deposits []housetypes.Deposit @@ -37,7 +39,7 @@ type testBetSuite struct { func newTestBetSuite(t *testing.T) testBetSuite { tApp, k, ctx := setupKeeperAndApp(t) - betFee := sdk.NewInt(10) + betFee := sdkmath.NewInt(10) marketUID := uuid.NewString() market := markettypes.Market{ @@ -50,23 +52,23 @@ func newTestBetSuite(t *testing.T) testBetSuite { {UID: uuid.NewString(), Meta: "test odds3"}, }, Status: markettypes.MarketStatus_MARKET_STATUS_ACTIVE, - Creator: simappUtil.TestParamUsers["user1"].Address.String(), + Creator: simapp.TestParamUsers["user1"].Address.String(), Meta: "test market", BookUID: marketUID, } deposits := []housetypes.Deposit{ { - DepositorAddress: simappUtil.TestParamUsers["user2"].Address.String(), - Amount: sdk.NewInt(8000), + DepositorAddress: simapp.TestParamUsers["user2"].Address.String(), + Amount: sdkmath.NewInt(8000), }, { - DepositorAddress: simappUtil.TestParamUsers["user3"].Address.String(), - Amount: sdk.NewInt(10000), + DepositorAddress: simapp.TestParamUsers["user3"].Address.String(), + Amount: sdkmath.NewInt(10000), }, { - DepositorAddress: simappUtil.TestParamUsers["user4"].Address.String(), - Amount: sdk.NewInt(10000), + DepositorAddress: simapp.TestParamUsers["user4"].Address.String(), + Amount: sdkmath.NewInt(10000), }, } @@ -160,12 +162,12 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) { require.True(ts.t, found) require.Equal(ts.t, []uint64{1, 2, 3}, oddsExposures.FulfillmentQueue) - defaultBetAmount := sdk.NewInt(400) + defaultBetAmount := sdkmath.NewInt(400) ///// winner1 bet placement // // - winner1BettorAddr := simappUtil.TestParamUsers["user5"].Address + winner1BettorAddr := simapp.TestParamUsers["user5"].Address winner1Bal := ts.tApp.BankKeeper.GetBalance(ts.ctx, winner1BettorAddr, params.DefaultBondDenom) winner1BetID := uint64(1) winner1Bet, winner1PayoutProfit, winner1BetFulfillment := ts.placeTestBet( @@ -202,7 +204,7 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) { ///// winner2 bet placement // // - winner2BettorAddr := simappUtil.TestParamUsers["user6"].Address + winner2BettorAddr := simapp.TestParamUsers["user6"].Address winner2Bal := ts.tApp.BankKeeper.GetBalance(ts.ctx, winner2BettorAddr, params.DefaultBondDenom) winner2BetID := uint64(2) winner2Bet, winner2PayoutProfit, winner2BetFulfillment := ts.placeTestBet( @@ -239,14 +241,14 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) { ///// failed winner bet placement // should fail because there is not participation to fulfill this bet. // - failedWinnerBettorAddr := simappUtil.TestParamUsers["user7"].Address + failedWinnerBettorAddr := simapp.TestParamUsers["user7"].Address failedWinnerBetID := uint64(3) ts.placeTestBet( failedWinnerBettorAddr, ts.market.UID, ts.market.Odds[0].UID, failedWinnerBetID, - sdk.NewInt(100000000000), + sdkmath.NewInt(100000000000), ts.betFee, types.ErrInsufficientFundToCoverPayout, ) @@ -254,7 +256,7 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) { ///// loser bet placement // // - loserBettorAddr := simappUtil.TestParamUsers["user8"].Address + loserBettorAddr := simapp.TestParamUsers["user8"].Address loserBal := ts.tApp.BankKeeper.GetBalance(ts.ctx, loserBettorAddr, params.DefaultBondDenom) loserBetID := uint64(4) loserBet, _, loserBetFulfillment := ts.placeTestBet( diff --git a/x/orderbook/keeper/exposure_odds_test.go b/x/orderbook/keeper/exposure_odds_test.go index fddb5d55..97d7d937 100644 --- a/x/orderbook/keeper/exposure_odds_test.go +++ b/x/orderbook/keeper/exposure_odds_test.go @@ -3,17 +3,19 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/orderbook/types" - "github.com/stretchr/testify/require" ) func createNOrderBookOddsExposure( - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, keeper *keeper.KeeperTest, ctx sdk.Context, n int, diff --git a/x/orderbook/keeper/exposure_participation_test.go b/x/orderbook/keeper/exposure_participation_test.go index ed97966f..ac054957 100644 --- a/x/orderbook/keeper/exposure_participation_test.go +++ b/x/orderbook/keeper/exposure_participation_test.go @@ -3,17 +3,20 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/orderbook/types" - "github.com/stretchr/testify/require" ) func createNParticipationExposure( - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, keeper *keeper.KeeperTest, ctx sdk.Context, n int, @@ -26,8 +29,8 @@ func createNParticipationExposure( items[i].OddsUID = uuid.NewString() items[i].Round = 1 items[i].IsFulfilled = false - items[i].BetAmount = sdk.NewInt(100) - items[i].Exposure = sdk.NewInt(100) + items[i].BetAmount = sdkmath.NewInt(100) + items[i].Exposure = sdkmath.NewInt(100) keeper.SetParticipationExposure(ctx, items[i]) keeper.SetParticipationExposureByIndex(ctx, items[i]) diff --git a/x/orderbook/keeper/fund.go b/x/orderbook/keeper/fund.go index cb7dbaff..5c486fd6 100644 --- a/x/orderbook/keeper/fund.go +++ b/x/orderbook/keeper/fund.go @@ -1,9 +1,9 @@ package keeper import ( + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/app/params" "github.com/sge-network/sge/x/orderbook/types" diff --git a/x/orderbook/keeper/fund_test.go b/x/orderbook/keeper/fund_test.go index 63fbae27..14e98c91 100644 --- a/x/orderbook/keeper/fund_test.go +++ b/x/orderbook/keeper/fund_test.go @@ -3,21 +3,21 @@ package keeper_test import ( "testing" - sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" + "github.com/sge-network/sge/app/params" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/orderbook/types" ) func TestFund(t *testing.T) { tApp, k, ctx := setupKeeperAndApp(t) - senderAddr := simappUtil.TestParamUsers["user1"].Address + senderAddr := simapp.TestParamUsers["user1"].Address initialBalance := tApp.BankKeeper.GetBalance(ctx, senderAddr, params.DefaultBondDenom) - successAmount := sdk.NewInt(1000) + successAmount := sdkmath.NewInt(1000) for _, tc := range []struct { desc string @@ -27,7 +27,7 @@ func TestFund(t *testing.T) { }{ { desc: "not enough balance", - amount: sdk.NewInt(100000000000000), + amount: sdkmath.NewInt(100000000000000), err: types.ErrInsufficientAccountBalance, }, { @@ -57,16 +57,16 @@ func TestFund(t *testing.T) { func TestReFund(t *testing.T) { tApp, k, ctx := setupKeeperAndApp(t) - successAmount := sdk.NewInt(1000) + successAmount := sdkmath.NewInt(1000) err := k.Fund( types.OrderBookLiquidityFunder{}, ctx, - simappUtil.TestParamUsers["user2"].Address, + simapp.TestParamUsers["user2"].Address, successAmount, ) require.NoError(t, err) - receiverAddr := simappUtil.TestParamUsers["user1"].Address + receiverAddr := simapp.TestParamUsers["user1"].Address initialBalance := tApp.BankKeeper.GetBalance(ctx, receiverAddr, params.DefaultBondDenom) for _, tc := range []struct { @@ -77,7 +77,7 @@ func TestReFund(t *testing.T) { }{ { desc: "not enough balance", - amount: successAmount.Add(sdk.NewInt(1)), + amount: successAmount.Add(sdkmath.NewInt(1)), err: types.ErrInsufficientBalanceInModuleAccount, }, { diff --git a/x/orderbook/keeper/grpc_query_exposure_odds.go b/x/orderbook/keeper/grpc_query_exposure_odds.go index 5f1846e8..eec7ff04 100644 --- a/x/orderbook/keeper/grpc_query_exposure_odds.go +++ b/x/orderbook/keeper/grpc_query_exposure_odds.go @@ -3,13 +3,15 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/orderbook/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // OrderBookExposure queries book exposure info for given order book id and odds id @@ -63,7 +65,7 @@ func (k Keeper) OrderBookExposures( pageRes, err := query.FilteredPaginate( exposureStore, req.Pagination, - func(key []byte, value []byte, accumulate bool) (bool, error) { + func(key, value []byte, accumulate bool) (bool, error) { var orderBookExposure types.OrderBookOddsExposure if err := k.cdc.Unmarshal(value, &orderBookExposure); err != nil { return false, err diff --git a/x/orderbook/keeper/grpc_query_exposure_odds_test.go b/x/orderbook/keeper/grpc_query_exposure_odds_test.go index ed0d6204..a6d2af62 100644 --- a/x/orderbook/keeper/grpc_query_exposure_odds_test.go +++ b/x/orderbook/keeper/grpc_query_exposure_odds_test.go @@ -3,15 +3,17 @@ package keeper_test import ( "testing" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func TestOrderBookExposureQuerySingle(t *testing.T) { diff --git a/x/orderbook/keeper/grpc_query_exposure_participation.go b/x/orderbook/keeper/grpc_query_exposure_participation.go index 0676acaa..fcdf49b8 100644 --- a/x/orderbook/keeper/grpc_query_exposure_participation.go +++ b/x/orderbook/keeper/grpc_query_exposure_participation.go @@ -3,13 +3,15 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/orderbook/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // OrderBookParticipationExposures queries participation exposures info for a given orderbook @@ -35,7 +37,7 @@ func (k Keeper) OrderBookParticipationExposures( pageRes, err := query.FilteredPaginate( exposureStore, req.Pagination, - func(key []byte, value []byte, accumulate bool) (bool, error) { + func(key, value []byte, accumulate bool) (bool, error) { var participationExposure types.ParticipationExposure if err := k.cdc.Unmarshal(value, &participationExposure); err != nil { return false, err @@ -85,7 +87,7 @@ func (k Keeper) ParticipationExposures( pageRes, err := query.FilteredPaginate( exposureStore, req.Pagination, - func(key []byte, value []byte, accumulate bool) (bool, error) { + func(key, value []byte, accumulate bool) (bool, error) { var participationExposure types.ParticipationExposure if err := k.cdc.Unmarshal(value, &participationExposure); err != nil { return false, err @@ -129,7 +131,7 @@ func (k Keeper) HistoricalParticipationExposures( pageRes, err := query.FilteredPaginate( exposureStore, req.Pagination, - func(key []byte, value []byte, accumulate bool) (bool, error) { + func(key, value []byte, accumulate bool) (bool, error) { var participationExposure types.ParticipationExposure if err := k.cdc.Unmarshal(value, &participationExposure); err != nil { return false, err diff --git a/x/orderbook/keeper/grpc_query_exposure_participation_test.go b/x/orderbook/keeper/grpc_query_exposure_participation_test.go index b40aea9e..2ea5cd0f 100644 --- a/x/orderbook/keeper/grpc_query_exposure_participation_test.go +++ b/x/orderbook/keeper/grpc_query_exposure_participation_test.go @@ -3,14 +3,16 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/orderbook/types" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func TestOrderBookParticipationExposuresQueryPaginated(t *testing.T) { diff --git a/x/orderbook/keeper/grpc_query_orderbook.go b/x/orderbook/keeper/grpc_query_orderbook.go index d9d14e40..9c461a11 100644 --- a/x/orderbook/keeper/grpc_query_orderbook.go +++ b/x/orderbook/keeper/grpc_query_orderbook.go @@ -4,13 +4,15 @@ import ( "context" "strings" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/orderbook/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // OrderBook queries orderbook info for given order book id @@ -60,7 +62,7 @@ func (k Keeper) OrderBooks( pageRes, err := query.FilteredPaginate( bookStore, req.Pagination, - func(key []byte, value []byte, accumulate bool) (bool, error) { + func(key, value []byte, accumulate bool) (bool, error) { orderBook, err := types.UnmarshalOrderBook(k.cdc, value) if err != nil { return false, err diff --git a/x/orderbook/keeper/grpc_query_orderbook_test.go b/x/orderbook/keeper/grpc_query_orderbook_test.go index b6397be5..646b462e 100644 --- a/x/orderbook/keeper/grpc_query_orderbook_test.go +++ b/x/orderbook/keeper/grpc_query_orderbook_test.go @@ -3,15 +3,17 @@ package keeper_test import ( "testing" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func TestOrderBookQuerySingle(t *testing.T) { diff --git a/x/orderbook/keeper/grpc_query_params.go b/x/orderbook/keeper/grpc_query_params.go index 504202d9..ea51b5db 100644 --- a/x/orderbook/keeper/grpc_query_params.go +++ b/x/orderbook/keeper/grpc_query_params.go @@ -3,10 +3,12 @@ package keeper import ( "context" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sge-network/sge/x/orderbook/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/orderbook/types" ) // Params returns the params of the module diff --git a/x/orderbook/keeper/grpc_query_params_test.go b/x/orderbook/keeper/grpc_query_params_test.go index 36cc8026..3f81d520 100644 --- a/x/orderbook/keeper/grpc_query_params_test.go +++ b/x/orderbook/keeper/grpc_query_params_test.go @@ -3,9 +3,11 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/orderbook/types" - "github.com/stretchr/testify/require" ) func TestParamsQuery(t *testing.T) { diff --git a/x/orderbook/keeper/grpc_query_participation.go b/x/orderbook/keeper/grpc_query_participation.go index aeab159f..7e6c93dc 100644 --- a/x/orderbook/keeper/grpc_query_participation.go +++ b/x/orderbook/keeper/grpc_query_participation.go @@ -3,13 +3,15 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/orderbook/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // OrderBookParticipation queries book participation info for given order book id and participation index @@ -69,7 +71,7 @@ func (k Keeper) OrderBookParticipations( pageRes, err := query.FilteredPaginate( participationStore, req.Pagination, - func(key []byte, value []byte, accumulate bool) (bool, error) { + func(key, value []byte, accumulate bool) (bool, error) { var bookParticipation types.OrderBookParticipation if err := k.cdc.Unmarshal(value, &bookParticipation); err != nil { return false, err diff --git a/x/orderbook/keeper/grpc_query_participation_bet.go b/x/orderbook/keeper/grpc_query_participation_bet.go index f9fdd352..bd1123e3 100644 --- a/x/orderbook/keeper/grpc_query_participation_bet.go +++ b/x/orderbook/keeper/grpc_query_participation_bet.go @@ -3,13 +3,15 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/orderbook/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // ParticipationFulfilledBets queries participation fulfilled bets info for given order book id and participation index @@ -40,7 +42,7 @@ func (k Keeper) ParticipationFulfilledBets( pageRes, err := query.FilteredPaginate( betsStore, req.Pagination, - func(key []byte, value []byte, accumulate bool) (bool, error) { + func(key, value []byte, accumulate bool) (bool, error) { var participationBet types.ParticipationBetPair if err := k.cdc.Unmarshal(value, &participationBet); err != nil { return false, err diff --git a/x/orderbook/keeper/grpc_query_participation_bet_test.go b/x/orderbook/keeper/grpc_query_participation_bet_test.go index 361ad07d..5a986c2c 100644 --- a/x/orderbook/keeper/grpc_query_participation_bet_test.go +++ b/x/orderbook/keeper/grpc_query_participation_bet_test.go @@ -3,14 +3,16 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/orderbook/types" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func TestParticipationFulfilledBetsQueryPaginated(t *testing.T) { diff --git a/x/orderbook/keeper/grpc_query_participation_test.go b/x/orderbook/keeper/grpc_query_participation_test.go index 19372561..19aa16ef 100644 --- a/x/orderbook/keeper/grpc_query_participation_test.go +++ b/x/orderbook/keeper/grpc_query_participation_test.go @@ -3,15 +3,17 @@ package keeper_test import ( "testing" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func TestParticipationQuerySingle(t *testing.T) { diff --git a/x/orderbook/keeper/keeper.go b/x/orderbook/keeper/keeper.go index 0945bca0..7139353f 100644 --- a/x/orderbook/keeper/keeper.go +++ b/x/orderbook/keeper/keeper.go @@ -3,12 +3,12 @@ package keeper import ( "fmt" - storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/tendermint/tendermint/libs/log" "github.com/sge-network/sge/x/orderbook/types" ) @@ -25,6 +25,7 @@ type Keeper struct { houseKeeper types.HouseKeeper ovmKeeper types.OVMKeeper feeGrantKeeper types.FeeGrantKeeper + hooks types.OrderBookHooks } // SdkExpectedKeepers contains expected keepers parameter needed by NewKeeper @@ -76,6 +77,17 @@ func (k *Keeper) SetOVMKeeper(ovmKeeper types.OVMKeeper) { k.ovmKeeper = ovmKeeper } +// SetHooks sets the hooks for governance +func (k *Keeper) SetHooks(gh types.OrderBookHooks) *Keeper { + if k.hooks != nil { + panic("cannot set orderbook hooks twice") + } + + k.hooks = gh + + return k +} + // Logger returns the logger of the keeper func (Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) diff --git a/x/orderbook/keeper/keeper_test.go b/x/orderbook/keeper/keeper_test.go index 60fa4a11..8e19f0d6 100644 --- a/x/orderbook/keeper/keeper_test.go +++ b/x/orderbook/keeper/keeper_test.go @@ -4,11 +4,13 @@ import ( "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" - simappUtil "github.com/sge-network/sge/testutil/simapp" - "github.com/sge-network/sge/x/orderbook/keeper" "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/orderbook/keeper" ) var ( @@ -22,8 +24,8 @@ func setupKeeper(t testing.TB) (*keeper.KeeperTest, sdk.Context) { return k, ctx } -func setupKeeperAndApp(t testing.TB) (*simappUtil.TestApp, *keeper.KeeperTest, sdk.Context) { - tApp, ctx, err := simappUtil.GetTestObjects() +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.KeeperTest, sdk.Context) { + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) return tApp, tApp.OrderbookKeeper, ctx.WithBlockTime(time.Now()) diff --git a/x/orderbook/keeper/orderbook.go b/x/orderbook/keeper/orderbook.go index acd044d8..68a2218f 100644 --- a/x/orderbook/keeper/orderbook.go +++ b/x/orderbook/keeper/orderbook.go @@ -1,8 +1,8 @@ package keeper import ( + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/x/orderbook/types" ) diff --git a/x/orderbook/keeper/orderbook_settle.go b/x/orderbook/keeper/orderbook_settle.go index 6e384c84..1b57866b 100644 --- a/x/orderbook/keeper/orderbook_settle.go +++ b/x/orderbook/keeper/orderbook_settle.go @@ -3,10 +3,12 @@ package keeper import ( "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/spf13/cast" + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + housetypes "github.com/sge-network/sge/x/house/types" markettypes "github.com/sge-network/sge/x/market/types" "github.com/sge-network/sge/x/orderbook/types" @@ -103,7 +105,7 @@ func (k Keeper) settleParticipation( depositorAddress, err := sdk.AccAddressFromBech32(bp.ParticipantAddress) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, types.ErrTextInvalidDepositor, err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, types.ErrTextInvalidDepositor, err) } refundHouseDepositFeeToDepositor := false @@ -118,6 +120,12 @@ func (k Keeper) settleParticipation( if bp.NotParticipatedInBetFulfillment() { refundHouseDepositFeeToDepositor = true } + if bp.ActualProfit.IsNegative() { + k.hooks.AfterHouseLoss(ctx, depositorAddress, bp.Liquidity, bp.ActualProfit.Abs()) + } else { + k.hooks.AfterHouseWin(ctx, depositorAddress, bp.Liquidity, bp.ActualProfit) + } + case markettypes.MarketStatus_MARKET_STATUS_CANCELED, markettypes.MarketStatus_MARKET_STATUS_ABORTED: // refund participant's account from orderbook liquidity pool. @@ -125,6 +133,7 @@ func (k Keeper) settleParticipation( return err } refundHouseDepositFeeToDepositor = true + k.hooks.AfterHouseRefund(ctx, depositorAddress, bp.Liquidity) default: return sdkerrors.Wrapf( types.ErrUnknownMarketStatus, @@ -139,6 +148,7 @@ func (k Keeper) settleParticipation( if err := k.refund(housetypes.HouseFeeCollectorFunder{}, ctx, depositorAddress, bp.Fee); err != nil { return err } + k.hooks.AfterHouseFeeRefund(ctx, depositorAddress, bp.Fee) } else { // refund participant's account from house fee collector. if err := k.refund(housetypes.HouseFeeCollectorFunder{}, ctx, sdk.MustAccAddressFromBech32(market.Creator), bp.Fee); err != nil { @@ -148,5 +158,6 @@ func (k Keeper) settleParticipation( bp.IsSettled = true k.SetOrderBookParticipation(ctx, bp) + return nil } diff --git a/x/orderbook/keeper/orderbook_settle_test.go b/x/orderbook/keeper/orderbook_settle_test.go index e5d1d97c..0a527510 100644 --- a/x/orderbook/keeper/orderbook_settle_test.go +++ b/x/orderbook/keeper/orderbook_settle_test.go @@ -3,9 +3,10 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sge-network/sge/app/params" - "github.com/stretchr/testify/require" ) func TestOrderBookSettlement(t *testing.T) { diff --git a/x/orderbook/keeper/orderbook_test.go b/x/orderbook/keeper/orderbook_test.go index 8589a247..5a816ca6 100644 --- a/x/orderbook/keeper/orderbook_test.go +++ b/x/orderbook/keeper/orderbook_test.go @@ -3,18 +3,20 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func createNOrderBook( - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, keeper *keeper.KeeperTest, ctx sdk.Context, n int, diff --git a/x/orderbook/keeper/params_test.go b/x/orderbook/keeper/params_test.go index f52f43bb..0643e31c 100644 --- a/x/orderbook/keeper/params_test.go +++ b/x/orderbook/keeper/params_test.go @@ -3,8 +3,9 @@ package keeper_test import ( "testing" - "github.com/sge-network/sge/x/orderbook/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/orderbook/types" ) func TestGetParams(t *testing.T) { diff --git a/x/orderbook/keeper/participation.go b/x/orderbook/keeper/participation.go index 6bf52ebb..353f8c54 100644 --- a/x/orderbook/keeper/participation.go +++ b/x/orderbook/keeper/participation.go @@ -1,9 +1,9 @@ package keeper import ( + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" housetypes "github.com/sge-network/sge/x/house/types" markettypes "github.com/sge-network/sge/x/market/types" diff --git a/x/orderbook/keeper/participation_bet_test.go b/x/orderbook/keeper/participation_bet_test.go index 80af5136..a66a212c 100644 --- a/x/orderbook/keeper/participation_bet_test.go +++ b/x/orderbook/keeper/participation_bet_test.go @@ -3,18 +3,20 @@ package keeper_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/google/uuid" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func createNParticipationBetPair( - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, keeper *keeper.KeeperTest, ctx sdk.Context, n int, diff --git a/x/orderbook/keeper/participation_test.go b/x/orderbook/keeper/participation_test.go index 7d261b10..705d2b41 100644 --- a/x/orderbook/keeper/participation_test.go +++ b/x/orderbook/keeper/participation_test.go @@ -4,22 +4,24 @@ import ( "testing" "time" + "github.com/google/uuid" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/google/uuid" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/testutil/sample" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" housetypes "github.com/sge-network/sge/x/house/types" markettypes "github.com/sge-network/sge/x/market/types" "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func createNParticipation( - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, keeper *keeper.KeeperTest, ctx sdk.Context, n int, @@ -28,16 +30,16 @@ func createNParticipation( for i := range items { items[i].Index = cast.ToUint64(i + 1) - items[i].ParticipantAddress = simappUtil.TestParamUsers["user1"].Address.String() + items[i].ParticipantAddress = simapp.TestParamUsers["user1"].Address.String() items[i].OrderBookUID = testOrderBookUID - items[i].ActualProfit = sdk.NewInt(100) - items[i].CurrentRoundLiquidity = sdk.NewInt(100) - items[i].CurrentRoundMaxLoss = sdk.NewInt(100) - items[i].CurrentRoundTotalBetAmount = sdk.NewInt(100) - items[i].Liquidity = sdk.NewInt(100) - items[i].Fee = sdk.NewInt(10) - items[i].MaxLoss = sdk.NewInt(100) - items[i].TotalBetAmount = sdk.NewInt(100) + items[i].ActualProfit = sdkmath.NewInt(100) + items[i].CurrentRoundLiquidity = sdkmath.NewInt(100) + items[i].CurrentRoundMaxLoss = sdkmath.NewInt(100) + items[i].CurrentRoundTotalBetAmount = sdkmath.NewInt(100) + items[i].Liquidity = sdkmath.NewInt(100) + items[i].Fee = sdkmath.NewInt(10) + items[i].MaxLoss = sdkmath.NewInt(100) + items[i].TotalBetAmount = sdkmath.NewInt(100) keeper.SetOrderBookParticipation(ctx, items[i]) } @@ -45,7 +47,7 @@ func createNParticipation( } func createTestMarket( - tApp *simappUtil.TestApp, + tApp *simapp.TestApp, keeper *keeper.KeeperTest, ctx sdk.Context, marketUID string, @@ -136,10 +138,10 @@ func TestInitiateOrderBookParticipationNoMarket(t *testing.T) { k, ctx := setupKeeper(t) _, err := k.InitiateOrderBookParticipation(ctx, - simappUtil.TestParamUsers["user1"].Address, + simapp.TestParamUsers["user1"].Address, testOrderBookUID, - sdk.NewInt(1000), - sdk.NewInt(100)) + sdkmath.NewInt(1000), + sdkmath.NewInt(100)) require.ErrorIs(t, types.ErrMarketNotFound, err) } @@ -157,7 +159,7 @@ func TestInitiateOrderBookParticipation(t *testing.T) { }{ { desc: "not active market", - depositorAddr: simappUtil.TestParamUsers["user1"].Address, + depositorAddr: simapp.TestParamUsers["user1"].Address, marketStatus: markettypes.MarketStatus_MARKET_STATUS_INACTIVE, err: types.ErrParticipationOnInactiveMarket, }, @@ -169,7 +171,7 @@ func TestInitiateOrderBookParticipation(t *testing.T) { }, { desc: "success", - depositorAddr: simappUtil.TestParamUsers["user1"].Address, + depositorAddr: simapp.TestParamUsers["user1"].Address, marketStatus: markettypes.MarketStatus_MARKET_STATUS_ACTIVE, }, } { @@ -183,8 +185,8 @@ func TestInitiateOrderBookParticipation(t *testing.T) { participationIndex, err := k.InitiateOrderBookParticipation(ctx, tc.depositorAddr, marketUID, - sdk.NewInt(1000), - sdk.NewInt(100)) + sdkmath.NewInt(1000), + sdkmath.NewInt(100)) if tc.err != nil { require.ErrorIs(t, err, tc.err) @@ -200,7 +202,7 @@ func TestWithdrawOrderBookParticipation(t *testing.T) { tApp, k, ctx := setupKeeperAndApp(t) oddsUIDs := []string{uuid.NewString(), uuid.NewString()} - fee := sdk.NewInt(100) + fee := sdkmath.NewInt(100) for _, tc := range []struct { desc string @@ -214,32 +216,32 @@ func TestWithdrawOrderBookParticipation(t *testing.T) { }{ { desc: "no participation", - depositorAddr: simappUtil.TestParamUsers["user1"].Address, + depositorAddr: simapp.TestParamUsers["user1"].Address, depositAmount: sdk.ZeroInt(), withdrawMode: housetypes.WithdrawalMode_WITHDRAWAL_MODE_FULL, err: types.ErrOrderBookParticipationNotFound, }, { desc: "withdraw amount too large", - depositorAddr: simappUtil.TestParamUsers["user1"].Address, - depositAmount: sdk.NewInt(1000), + depositorAddr: simapp.TestParamUsers["user1"].Address, + depositAmount: sdkmath.NewInt(1000), withdrawMode: housetypes.WithdrawalMode_WITHDRAWAL_MODE_PARTIAL, - withdrawAmount: sdk.NewInt(10000), + withdrawAmount: sdkmath.NewInt(10000), err: types.ErrWithdrawalTooLarge, }, { desc: "success full", - depositorAddr: simappUtil.TestParamUsers["user1"].Address, - depositAmount: sdk.NewInt(1000), + depositorAddr: simapp.TestParamUsers["user1"].Address, + depositAmount: sdkmath.NewInt(1000), withdrawMode: housetypes.WithdrawalMode_WITHDRAWAL_MODE_FULL, - expWithdrawnAmount: sdk.NewInt(1000).Sub(fee), + expWithdrawnAmount: sdkmath.NewInt(1000).Sub(fee), }, { desc: "success partial", - depositorAddr: simappUtil.TestParamUsers["user1"].Address, - depositAmount: sdk.NewInt(500), + depositorAddr: simapp.TestParamUsers["user1"].Address, + depositAmount: sdkmath.NewInt(500), withdrawMode: housetypes.WithdrawalMode_WITHDRAWAL_MODE_FULL, - expWithdrawnAmount: sdk.NewInt(500).Sub(fee), + expWithdrawnAmount: sdkmath.NewInt(500).Sub(fee), }, } { t.Run(tc.desc, func(t *testing.T) { @@ -255,7 +257,7 @@ func TestWithdrawOrderBookParticipation(t *testing.T) { tc.depositorAddr, marketUID, tc.depositAmount, - sdk.NewInt(100)) + sdkmath.NewInt(100)) require.NoError(t, err) } diff --git a/x/orderbook/keeper/stats.go b/x/orderbook/keeper/stats.go index 55835376..aaa3a144 100644 --- a/x/orderbook/keeper/stats.go +++ b/x/orderbook/keeper/stats.go @@ -1,8 +1,8 @@ package keeper import ( + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/orderbook/types" diff --git a/x/orderbook/keeper/stats_test.go b/x/orderbook/keeper/stats_test.go index 3069a294..f2f0631f 100644 --- a/x/orderbook/keeper/stats_test.go +++ b/x/orderbook/keeper/stats_test.go @@ -5,8 +5,9 @@ import ( "github.com/google/uuid" "github.com/sge-network/sge/testutil/nullify" - "github.com/sge-network/sge/x/orderbook/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/orderbook/types" ) func TestStatsGet(t *testing.T) { diff --git a/x/orderbook/keeper/view.go b/x/orderbook/keeper/view.go index 517119ad..95c6ae82 100644 --- a/x/orderbook/keeper/view.go +++ b/x/orderbook/keeper/view.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/orderbook/types" ) diff --git a/x/orderbook/module.go b/x/orderbook/module.go index df3349e0..235df5a5 100644 --- a/x/orderbook/module.go +++ b/x/orderbook/module.go @@ -5,15 +5,17 @@ import ( "encoding/json" "fmt" + "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" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/gorilla/mux" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" "github.com/sge-network/sge/x/orderbook/client/cli" "github.com/sge-network/sge/x/orderbook/keeper" diff --git a/x/orderbook/module_simulation.go b/x/orderbook/module_simulation.go index be771e5f..259fa9f8 100644 --- a/x/orderbook/module_simulation.go +++ b/x/orderbook/module_simulation.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/sge-network/sge/testutil/sample" orderbooksimulation "github.com/sge-network/sge/x/orderbook/simulation" "github.com/sge-network/sge/x/orderbook/types" diff --git a/x/orderbook/simulation/decoder.go b/x/orderbook/simulation/decoder.go index ae3c9c23..b17332b7 100644 --- a/x/orderbook/simulation/decoder.go +++ b/x/orderbook/simulation/decoder.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/x/orderbook/types" ) diff --git a/x/orderbook/simulation/decoder_test.go b/x/orderbook/simulation/decoder_test.go index b890cdbf..bf861b21 100644 --- a/x/orderbook/simulation/decoder_test.go +++ b/x/orderbook/simulation/decoder_test.go @@ -4,11 +4,12 @@ import ( "fmt" "testing" + sdkmath "cosmossdk.io/math" "github.com/google/uuid" "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/orderbook/simulation" @@ -31,15 +32,15 @@ func TestDecodeStore(t *testing.T) { Index: 1, OrderBookUID: orderBookUID, ParticipantAddress: sample.AccAddress(), - Liquidity: sdk.NewInt(100), - CurrentRoundLiquidity: sdk.NewInt(50), + Liquidity: sdkmath.NewInt(100), + CurrentRoundLiquidity: sdkmath.NewInt(50), ExposuresNotFilled: 1, - TotalBetAmount: sdk.NewInt(10), - CurrentRoundTotalBetAmount: sdk.NewInt(10), - MaxLoss: sdk.NewInt(10), - CurrentRoundMaxLoss: sdk.NewInt(10), + TotalBetAmount: sdkmath.NewInt(10), + CurrentRoundTotalBetAmount: sdkmath.NewInt(10), + MaxLoss: sdkmath.NewInt(10), + CurrentRoundMaxLoss: sdkmath.NewInt(10), CurrentRoundMaxLossOddsUID: uuid.NewString(), - ActualProfit: sdk.NewInt(20), + ActualProfit: sdkmath.NewInt(20), IsSettled: false, } @@ -53,8 +54,8 @@ func TestDecodeStore(t *testing.T) { OrderBookUID: orderBookUID, OddsUID: uuid.NewString(), ParticipationIndex: 1, - Exposure: sdk.NewInt(10), - BetAmount: sdk.NewInt(10), + Exposure: sdkmath.NewInt(10), + BetAmount: sdkmath.NewInt(10), IsFulfilled: false, Round: 1, } diff --git a/x/orderbook/simulation/genesis.go b/x/orderbook/simulation/genesis.go index 91de4dfc..7dc6a0b3 100644 --- a/x/orderbook/simulation/genesis.go +++ b/x/orderbook/simulation/genesis.go @@ -7,9 +7,11 @@ import ( //#nosec "math/rand" + "github.com/spf13/cast" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/orderbook/types" - "github.com/spf13/cast" ) // Simulation parameter constants diff --git a/x/orderbook/simulation/genesis_test.go b/x/orderbook/simulation/genesis_test.go index 83e26072..2a87283c 100644 --- a/x/orderbook/simulation/genesis_test.go +++ b/x/orderbook/simulation/genesis_test.go @@ -6,12 +6,13 @@ import ( "math/rand" "testing" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/stretchr/testify/require" "github.com/sge-network/sge/x/orderbook/simulation" "github.com/sge-network/sge/x/orderbook/types" diff --git a/x/orderbook/simulation/params.go b/x/orderbook/simulation/params.go index 78dc96a0..d08bafba 100644 --- a/x/orderbook/simulation/params.go +++ b/x/orderbook/simulation/params.go @@ -7,9 +7,9 @@ import ( //#nosec "math/rand" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/sge-network/sge/x/orderbook/types" ) diff --git a/x/orderbook/types/errors.go b/x/orderbook/types/errors.go index f73373ef..77cf636d 100644 --- a/x/orderbook/types/errors.go +++ b/x/orderbook/types/errors.go @@ -3,7 +3,7 @@ package types // DONTCOVER import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "cosmossdk.io/errors" ) // x/orderbook module sentinel errors diff --git a/x/orderbook/types/expected_keepers.go b/x/orderbook/types/expected_keepers.go index 9bb157c8..edcc8ae6 100644 --- a/x/orderbook/types/expected_keepers.go +++ b/x/orderbook/types/expected_keepers.go @@ -3,8 +3,10 @@ package types import ( context "context" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" sdkfeegrant "github.com/cosmos/cosmos-sdk/x/feegrant" + bettypes "github.com/sge-network/sge/x/bet/types" housetypes "github.com/sge-network/sge/x/house/types" markettypes "github.com/sge-network/sge/x/market/types" @@ -71,3 +73,19 @@ type FeeGrantKeeper interface { ) error GetAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress) (sdkfeegrant.FeeAllowanceI, error) } + +// Event Hooks +// These can be utilized to communicate between a orderbook keeper and another +// keepers. + +// OrderBookHooks event hooks for orderbook methods. +type OrderBookHooks interface { + AfterBettorWin(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, profit sdkmath.Int) + AfterBettorLoss(ctx sdk.Context, bettor sdk.AccAddress, originalAmount sdkmath.Int) + AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, fee sdkmath.Int) + + AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdkmath.Int) + AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount, lostAmt sdkmath.Int) + AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount sdkmath.Int) + AfterHouseFeeRefund(ctx sdk.Context, house sdk.AccAddress, fee sdkmath.Int) +} diff --git a/x/orderbook/types/exposure.go b/x/orderbook/types/exposure.go index 3052c930..1ab973f9 100644 --- a/x/orderbook/types/exposure.go +++ b/x/orderbook/types/exposure.go @@ -1,9 +1,10 @@ package types import ( + yaml "gopkg.in/yaml.v2" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - yaml "gopkg.in/yaml.v2" ) // NewOrderBookOddsExposure creates a new book odds exposure object diff --git a/x/orderbook/types/exposure.pb.go b/x/orderbook/types/exposure.pb.go index 9b8f8885..11d1594d 100644 --- a/x/orderbook/types/exposure.pb.go +++ b/x/orderbook/types/exposure.pb.go @@ -4,8 +4,8 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -80,9 +80,9 @@ type ParticipationExposure struct { // participation_index is the index of participation in the queue. ParticipationIndex uint64 `protobuf:"varint,3,opt,name=participation_index,json=participationIndex,proto3" json:"participation_index,omitempty" yaml:"participation_index"` // exposure is the total exposure taken on given odds. - Exposure github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=exposure,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"exposure" yaml:"exposure"` + Exposure cosmossdk_io_math.Int `protobuf:"bytes,4,opt,name=exposure,proto3,customtype=cosmossdk.io/math.Int" json:"exposure" yaml:"exposure"` // bet_amount is the total bet amount corresponding to the exposure. - BetAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=bet_amount,json=betAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"bet_amount" yaml:"bet_amount"` + BetAmount cosmossdk_io_math.Int `protobuf:"bytes,5,opt,name=bet_amount,json=betAmount,proto3,customtype=cosmossdk.io/math.Int" json:"bet_amount" yaml:"bet_amount"` // is_fulfilled represents if the participation exposure is fulfilled or not. IsFulfilled bool `protobuf:"varint,6,opt,name=is_fulfilled,json=isFulfilled,proto3" json:"is_fulfilled,omitempty" yaml:"is_fulfilled"` // round is the current round number in the queue. @@ -129,38 +129,38 @@ func init() { func init() { proto.RegisterFile("sge/orderbook/exposure.proto", fileDescriptor_3aa5f8fec7488c62) } var fileDescriptor_3aa5f8fec7488c62 = []byte{ - // 492 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x53, 0x3f, 0x6f, 0xd3, 0x40, - 0x14, 0xb7, 0x49, 0xda, 0xa6, 0x47, 0x04, 0xad, 0x4b, 0x55, 0xab, 0xaa, 0x7c, 0xd1, 0x0d, 0x55, - 0x06, 0x6a, 0x0f, 0xdd, 0xb2, 0xd5, 0x40, 0xa5, 0xb0, 0x04, 0x2c, 0xb1, 0x20, 0x21, 0x2b, 0xce, - 0x5d, 0xcd, 0x29, 0xb1, 0xcf, 0xf8, 0xce, 0x22, 0xfd, 0x06, 0x8c, 0x8c, 0x4c, 0x28, 0x1f, 0xa7, - 0x63, 0x47, 0xc4, 0x70, 0x42, 0xce, 0x82, 0xd8, 0xf0, 0x27, 0x40, 0x3e, 0x27, 0xc6, 0x0d, 0x2c, - 0x6c, 0x4c, 0x79, 0xf7, 0x7b, 0xbf, 0x3f, 0xf7, 0xe2, 0x7b, 0xe0, 0x84, 0x87, 0xc4, 0x61, 0x29, - 0x26, 0x69, 0xc0, 0xd8, 0xd4, 0x21, 0xf3, 0x84, 0xf1, 0x2c, 0x25, 0x76, 0x92, 0x32, 0xc1, 0x0c, - 0x93, 0x87, 0x24, 0x26, 0xe2, 0x3d, 0x4b, 0xa7, 0x36, 0x0f, 0x89, 0x5d, 0x13, 0x8f, 0x1f, 0x85, - 0x2c, 0x64, 0x8a, 0xe4, 0x94, 0x55, 0xc5, 0x47, 0x3f, 0x75, 0x70, 0x38, 0x2a, 0x39, 0x2e, 0x63, - 0xd3, 0x11, 0xc6, 0xfc, 0xd9, 0xca, 0xcf, 0x78, 0x0e, 0x1e, 0x28, 0xb1, 0x5f, 0xaa, 0xfd, 0x8c, - 0x62, 0x53, 0xef, 0xe9, 0xfd, 0x5d, 0x17, 0xe5, 0x12, 0x76, 0x6b, 0xc9, 0xab, 0xe1, 0xd3, 0x1f, - 0x12, 0x6e, 0x30, 0xbd, 0x8d, 0xb3, 0x71, 0x0e, 0x3a, 0x0c, 0x63, 0xae, 0x5c, 0xee, 0x29, 0x97, - 0xa3, 0x5c, 0xc2, 0x9d, 0x32, 0xaf, 0x32, 0xa8, 0xdb, 0x5e, 0x5d, 0x19, 0x43, 0xb0, 0x7f, 0x95, - 0xcd, 0xae, 0xe8, 0x6c, 0x16, 0x91, 0x58, 0xf8, 0xef, 0x32, 0x92, 0x11, 0xb3, 0xd5, 0x6b, 0xf5, - 0xdb, 0xee, 0x49, 0x21, 0xa1, 0x79, 0x3d, 0x8e, 0x66, 0x03, 0xf4, 0x07, 0x05, 0x79, 0x7b, 0x0d, - 0xec, 0x65, 0x09, 0x0d, 0xba, 0x1f, 0x16, 0x50, 0xfb, 0xb4, 0x80, 0xda, 0xf7, 0x05, 0xd4, 0xd0, - 0xe7, 0x36, 0x38, 0x7c, 0x31, 0x4e, 0x05, 0x9d, 0xd0, 0x64, 0x2c, 0x28, 0x8b, 0xff, 0x9f, 0x99, - 0x47, 0xe0, 0x20, 0x69, 0xde, 0xcc, 0xa7, 0x31, 0x26, 0x73, 0xb3, 0xd5, 0xd3, 0xfb, 0x6d, 0xd7, - 0x2a, 0x24, 0x3c, 0xae, 0xa6, 0xfe, 0x0b, 0x09, 0x79, 0xc6, 0x1d, 0x74, 0x58, 0x82, 0xc6, 0x1b, - 0xd0, 0x59, 0xbf, 0x10, 0xb3, 0xad, 0x6e, 0x71, 0x71, 0x23, 0xa1, 0xf6, 0x55, 0xc2, 0xd3, 0x90, - 0x8a, 0xb7, 0x59, 0x60, 0x4f, 0x58, 0xe4, 0x4c, 0x18, 0x8f, 0x18, 0x5f, 0xfd, 0x9c, 0x71, 0x3c, - 0x75, 0xc4, 0x75, 0x42, 0xb8, 0x3d, 0x8c, 0x45, 0x21, 0xe1, 0xc3, 0x2a, 0x73, 0xed, 0x83, 0xbc, - 0xda, 0xd2, 0x08, 0x00, 0x08, 0x88, 0xf0, 0xc7, 0x11, 0xcb, 0x62, 0x61, 0x6e, 0xa9, 0x80, 0x27, - 0xff, 0x1c, 0xb0, 0x5f, 0x05, 0xfc, 0x76, 0x42, 0xde, 0x6e, 0x40, 0xc4, 0x85, 0xaa, 0x8d, 0x01, - 0xe8, 0x52, 0xee, 0xaf, 0xbe, 0x29, 0xc1, 0xe6, 0x76, 0x4f, 0xef, 0x77, 0xdc, 0xa3, 0x42, 0xc2, - 0x83, 0x4a, 0xd7, 0xec, 0x22, 0xef, 0x3e, 0xe5, 0x97, 0xeb, 0x93, 0x71, 0x0a, 0xb6, 0x52, 0x96, - 0xc5, 0xd8, 0xdc, 0x51, 0xff, 0xe0, 0x5e, 0x21, 0x61, 0xb7, 0x12, 0x29, 0x18, 0x79, 0x55, 0xfb, - 0xee, 0x03, 0x71, 0x2f, 0x6f, 0x72, 0x4b, 0xbf, 0xcd, 0x2d, 0xfd, 0x5b, 0x6e, 0xe9, 0x1f, 0x97, - 0x96, 0x76, 0xbb, 0xb4, 0xb4, 0x2f, 0x4b, 0x4b, 0x7b, 0xfd, 0xb8, 0x31, 0x13, 0x0f, 0xc9, 0xd9, - 0x6a, 0xd5, 0xca, 0xda, 0x99, 0x37, 0xb6, 0x52, 0x4d, 0x17, 0x6c, 0xab, 0x1d, 0x3b, 0xff, 0x15, - 0x00, 0x00, 0xff, 0xff, 0xb7, 0x6c, 0xd1, 0xe8, 0xb3, 0x03, 0x00, 0x00, + // 491 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0xb1, 0x6f, 0xd3, 0x40, + 0x14, 0xc6, 0x6d, 0x92, 0xb6, 0xe9, 0x11, 0x41, 0xeb, 0x12, 0xd5, 0xaa, 0x2a, 0x5f, 0x74, 0x03, + 0xca, 0x00, 0x36, 0xa2, 0x5b, 0x36, 0x2c, 0xa8, 0x14, 0x84, 0x14, 0x6a, 0x89, 0x85, 0xc5, 0xb2, + 0x73, 0x57, 0xf7, 0x94, 0xd8, 0x67, 0x7c, 0x67, 0x91, 0xfe, 0x07, 0x8c, 0x8c, 0x8c, 0xf9, 0x73, + 0x3a, 0x76, 0x44, 0x0c, 0x27, 0xe4, 0x2c, 0x88, 0x0d, 0xcf, 0x0c, 0xc8, 0xe7, 0xc4, 0xa4, 0x05, + 0x89, 0x95, 0xed, 0xdd, 0xf7, 0xbe, 0xef, 0x77, 0x77, 0x3e, 0x3f, 0x70, 0xcc, 0x23, 0xe2, 0xb0, + 0x0c, 0x93, 0x2c, 0x64, 0x6c, 0xea, 0x90, 0x79, 0xca, 0x78, 0x9e, 0x11, 0x3b, 0xcd, 0x98, 0x60, + 0x86, 0xc9, 0x23, 0x92, 0x10, 0xf1, 0x9e, 0x65, 0x53, 0x9b, 0x47, 0xc4, 0x6e, 0x8c, 0x47, 0x0f, + 0x22, 0x16, 0x31, 0x65, 0x72, 0xaa, 0xaa, 0xf6, 0xa3, 0x1f, 0x3a, 0xe8, 0x8d, 0x2b, 0x8f, 0xcb, + 0xd8, 0x74, 0x8c, 0x31, 0x7f, 0xb1, 0xe2, 0x19, 0x2f, 0xc1, 0x3d, 0x15, 0xf6, 0xab, 0xb4, 0x9f, + 0x53, 0x6c, 0xea, 0x7d, 0x7d, 0xb0, 0xeb, 0xa2, 0x42, 0xc2, 0x6e, 0x13, 0x79, 0x33, 0x7a, 0xfe, + 0x5d, 0xc2, 0x5b, 0x4e, 0xef, 0xd6, 0xda, 0x38, 0x01, 0x1d, 0x86, 0x31, 0x57, 0x94, 0x3b, 0x8a, + 0x72, 0x58, 0x48, 0xb8, 0x53, 0xed, 0x57, 0x03, 0x9a, 0xb6, 0xd7, 0x54, 0xc6, 0x08, 0xec, 0x9f, + 0xe7, 0xb3, 0x73, 0x3a, 0x9b, 0xc5, 0x24, 0x11, 0xfe, 0xbb, 0x9c, 0xe4, 0xc4, 0x6c, 0xf5, 0x5b, + 0x83, 0xb6, 0x7b, 0x5c, 0x4a, 0x68, 0x5e, 0x06, 0xf1, 0x6c, 0x88, 0xfe, 0xb0, 0x20, 0x6f, 0x6f, + 0x43, 0x3b, 0xab, 0xa4, 0x61, 0xf7, 0xc3, 0x02, 0x6a, 0x9f, 0x16, 0x50, 0xfb, 0xb6, 0x80, 0x1a, + 0xfa, 0xd9, 0x02, 0xbd, 0xd7, 0x41, 0x26, 0xe8, 0x84, 0xa6, 0x81, 0xa0, 0x2c, 0xf9, 0x7f, 0xee, + 0x3c, 0x06, 0x07, 0xe9, 0xe6, 0xc9, 0x7c, 0x9a, 0x60, 0x32, 0x37, 0x5b, 0x7d, 0x7d, 0xd0, 0x76, + 0xad, 0x52, 0xc2, 0xa3, 0xfa, 0xd6, 0x7f, 0x31, 0x21, 0xcf, 0xb8, 0xa1, 0x8e, 0x2a, 0xd1, 0x78, + 0x05, 0x3a, 0xeb, 0x3f, 0xc4, 0x6c, 0xab, 0x53, 0x3c, 0xb9, 0x92, 0x50, 0xfb, 0x22, 0x61, 0x6f, + 0xc2, 0x78, 0xcc, 0x38, 0xc7, 0x53, 0x9b, 0x32, 0x27, 0x0e, 0xc4, 0x85, 0x3d, 0x4a, 0x44, 0x29, + 0xe1, 0xfd, 0x7a, 0x8b, 0x75, 0x0c, 0x79, 0x0d, 0xc1, 0x38, 0x03, 0x20, 0x24, 0xc2, 0x0f, 0x62, + 0x96, 0x27, 0xc2, 0xdc, 0x52, 0xbc, 0xa7, 0xff, 0xe2, 0xed, 0xd7, 0xbc, 0xdf, 0x41, 0xe4, 0xed, + 0x86, 0x44, 0x3c, 0x53, 0xb5, 0x31, 0x04, 0x5d, 0xca, 0xfd, 0xd5, 0x8b, 0x11, 0x6c, 0x6e, 0xf7, + 0xf5, 0x41, 0xc7, 0x3d, 0x2c, 0x25, 0x3c, 0xa8, 0x73, 0x9b, 0x5d, 0xe4, 0xdd, 0xa5, 0xfc, 0x74, + 0xbd, 0x32, 0x1e, 0x82, 0xad, 0x8c, 0xe5, 0x09, 0x36, 0x77, 0xd4, 0xf7, 0xd9, 0x2b, 0x25, 0xec, + 0xd6, 0x21, 0x25, 0x23, 0xaf, 0x6e, 0xdf, 0x7c, 0x7e, 0xf7, 0xf4, 0xaa, 0xb0, 0xf4, 0xeb, 0xc2, + 0xd2, 0xbf, 0x16, 0x96, 0xfe, 0x71, 0x69, 0x69, 0xd7, 0x4b, 0x4b, 0xfb, 0xbc, 0xb4, 0xb4, 0xb7, + 0x8f, 0x22, 0x2a, 0x2e, 0xf2, 0xd0, 0x9e, 0xb0, 0xd8, 0xe1, 0x11, 0x79, 0xbc, 0x1a, 0xa4, 0xaa, + 0x76, 0xe6, 0x1b, 0x33, 0x27, 0x2e, 0x53, 0xc2, 0xc3, 0x6d, 0x35, 0x41, 0x27, 0xbf, 0x02, 0x00, + 0x00, 0xff, 0xff, 0xbc, 0x8f, 0x3f, 0x07, 0x91, 0x03, 0x00, 0x00, } func (m *OrderBookOddsExposure) Marshal() (dAtA []byte, err error) { diff --git a/x/orderbook/types/genesis.go b/x/orderbook/types/genesis.go index 3c9ee7f8..fcb4ea5f 100644 --- a/x/orderbook/types/genesis.go +++ b/x/orderbook/types/genesis.go @@ -3,8 +3,9 @@ package types import ( "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cast" + + sdk "github.com/cosmos/cosmos-sdk/types" ) // DefaultGenesis returns the default genesis state diff --git a/x/orderbook/types/genesis_test.go b/x/orderbook/types/genesis_test.go index 9d760cc5..93fc3e4a 100644 --- a/x/orderbook/types/genesis_test.go +++ b/x/orderbook/types/genesis_test.go @@ -4,8 +4,9 @@ import ( "testing" "github.com/google/uuid" - "github.com/sge-network/sge/x/orderbook/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/orderbook/types" ) const ( diff --git a/x/orderbook/types/hooks.go b/x/orderbook/types/hooks.go new file mode 100644 index 00000000..51a1e274 --- /dev/null +++ b/x/orderbook/types/hooks.go @@ -0,0 +1,65 @@ +package types + +import ( + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ OrderBookHooks = MultiOrderBookHooks{} + +// MultiOrderBookHooks combine multiple orderbook hooks, all hook functions are run in array sequence +type MultiOrderBookHooks []OrderBookHooks + +// NewMultiOrderBookHooks returns list of hooks defined for the orderbook module. +func NewMultiOrderBookHooks(hooks ...OrderBookHooks) MultiOrderBookHooks { + return hooks +} + +// AfterBettorWin registers all of hooks for this method. +func (h MultiOrderBookHooks) AfterBettorWin(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, profit sdkmath.Int) { + for i := range h { + h[i].AfterBettorWin(ctx, bettor, originalAmount, profit) + } +} + +// AfterBettorLoss registers all of hooks for this method. +func (h MultiOrderBookHooks) AfterBettorLoss(ctx sdk.Context, bettor sdk.AccAddress, originalAmount sdkmath.Int) { + for i := range h { + h[i].AfterBettorLoss(ctx, bettor, originalAmount) + } +} + +// AfterBettorRefund registers all of hooks for this method. +func (h MultiOrderBookHooks) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, fee sdkmath.Int) { + for i := range h { + h[i].AfterBettorRefund(ctx, bettor, originalAmount, fee) + } +} + +// AfterHouseWin registers all of hooks for this method. +func (h MultiOrderBookHooks) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdkmath.Int) { + for i := range h { + h[i].AfterHouseWin(ctx, house, originalAmount, profit) + } +} + +// AfterHouseLoss registers all of hooks for this method. +func (h MultiOrderBookHooks) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount, lostAmt sdkmath.Int) { + for i := range h { + h[i].AfterHouseLoss(ctx, house, originalAmount, lostAmt) + } +} + +// AfterHouseRefund registers all of hooks for this method. +func (h MultiOrderBookHooks) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount sdkmath.Int) { + for i := range h { + h[i].AfterHouseRefund(ctx, house, originalAmount) + } +} + +// AfterHouseFeeRefund registers all of hooks for this method. +func (h MultiOrderBookHooks) AfterHouseFeeRefund(ctx sdk.Context, house sdk.AccAddress, fee sdkmath.Int) { + for i := range h { + h[i].AfterHouseRefund(ctx, house, fee) + } +} diff --git a/x/orderbook/types/keys.go b/x/orderbook/types/keys.go index d88eda32..0fa85c10 100644 --- a/x/orderbook/types/keys.go +++ b/x/orderbook/types/keys.go @@ -104,7 +104,7 @@ func GetHistoricalParticipationExposureKey(bookUID, oddsUID string, index, round } // GetParticipationBetPairKey creates the bond between participation and bet -func GetParticipationBetPairKey(bookUID string, bookParticipationIndex uint64, betID uint64) []byte { +func GetParticipationBetPairKey(bookUID string, bookParticipationIndex, betID uint64) []byte { return append( GetParticipationByIndexKey(bookUID, bookParticipationIndex), utils.Uint64ToBytes(betID)...) diff --git a/x/orderbook/types/order_book_event.go b/x/orderbook/types/order_book_event.go index bf121c92..cd6834b7 100644 --- a/x/orderbook/types/order_book_event.go +++ b/x/orderbook/types/order_book_event.go @@ -2,6 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/utils" ) diff --git a/x/orderbook/types/orderbook.go b/x/orderbook/types/orderbook.go index 4b820c77..ea7198b1 100644 --- a/x/orderbook/types/orderbook.go +++ b/x/orderbook/types/orderbook.go @@ -1,8 +1,9 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" yaml "gopkg.in/yaml.v2" + + "github.com/cosmos/cosmos-sdk/codec" ) // NewOrderBook creates a new orderbook object diff --git a/x/orderbook/types/params.go b/x/orderbook/types/params.go index 3cff019e..e707bd8c 100644 --- a/x/orderbook/types/params.go +++ b/x/orderbook/types/params.go @@ -3,8 +3,9 @@ package types import ( "fmt" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" yaml "gopkg.in/yaml.v2" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) // Orderbook params default values diff --git a/x/orderbook/types/participation.go b/x/orderbook/types/participation.go index e056fa3a..b96c6798 100644 --- a/x/orderbook/types/participation.go +++ b/x/orderbook/types/participation.go @@ -1,11 +1,13 @@ package types import ( + yaml "gopkg.in/yaml.v2" + + sdkerrors "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + housetypes "github.com/sge-network/sge/x/house/types" - yaml "gopkg.in/yaml.v2" ) // NewOrderBookParticipation creates a new book participation object diff --git a/x/orderbook/types/participation.pb.go b/x/orderbook/types/participation.pb.go index a453156c..71e56002 100644 --- a/x/orderbook/types/participation.pb.go +++ b/x/orderbook/types/participation.pb.go @@ -4,8 +4,8 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -33,28 +33,28 @@ type OrderBookParticipation struct { // participant_address is the bech32-encoded address of the participant. ParticipantAddress string `protobuf:"bytes,3,opt,name=participant_address,json=participantAddress,proto3" json:"participant_address,omitempty" yaml:"participant_address"` // liquidity is the total initial liquidity provided. - Liquidity github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=liquidity,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"liquidity" yaml:"liquidity"` + Liquidity cosmossdk_io_math.Int `protobuf:"bytes,4,opt,name=liquidity,proto3,customtype=cosmossdk.io/math.Int" json:"liquidity" yaml:"liquidity"` // fee is the amount of fee to be paid if participation happens. - Fee github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=fee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"fee" yaml:"fee"` + Fee cosmossdk_io_math.Int `protobuf:"bytes,5,opt,name=fee,proto3,customtype=cosmossdk.io/math.Int" json:"fee" yaml:"fee"` // current_round_liquidity is the liquidity provided for the current round. - CurrentRoundLiquidity github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=current_round_liquidity,json=currentRoundLiquidity,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"current_round_liquidity" yaml:"current_round_liquidity"` + CurrentRoundLiquidity cosmossdk_io_math.Int `protobuf:"bytes,6,opt,name=current_round_liquidity,json=currentRoundLiquidity,proto3,customtype=cosmossdk.io/math.Int" json:"current_round_liquidity" yaml:"current_round_liquidity"` // exposures_not_filled represents if all of the exposures of the // participation are filled or not. ExposuresNotFilled uint64 `protobuf:"varint,7,opt,name=exposures_not_filled,json=exposuresNotFilled,proto3" json:"exposures_not_filled,omitempty" yaml:"exposures_not_filled"` // total_bet_amount is the total bet amount corresponding to all exposures. - TotalBetAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,8,opt,name=total_bet_amount,json=totalBetAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"total_bet_amount" yaml:"total_bet_amount"` + TotalBetAmount cosmossdk_io_math.Int `protobuf:"bytes,8,opt,name=total_bet_amount,json=totalBetAmount,proto3,customtype=cosmossdk.io/math.Int" json:"total_bet_amount" yaml:"total_bet_amount"` // current_round_total_bet_amount is the total bet amount corresponding to all // exposures in the current round. - CurrentRoundTotalBetAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,9,opt,name=current_round_total_bet_amount,json=currentRoundTotalBetAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"current_round_total_bet_amount" yaml:"current_round_total_bet_amount"` + CurrentRoundTotalBetAmount cosmossdk_io_math.Int `protobuf:"bytes,9,opt,name=current_round_total_bet_amount,json=currentRoundTotalBetAmount,proto3,customtype=cosmossdk.io/math.Int" json:"current_round_total_bet_amount" yaml:"current_round_total_bet_amount"` // max_loss is the total bet amount corresponding to all exposure. - MaxLoss github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,10,opt,name=max_loss,json=maxLoss,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"max_loss" yaml:"max_loss"` + MaxLoss cosmossdk_io_math.Int `protobuf:"bytes,10,opt,name=max_loss,json=maxLoss,proto3,customtype=cosmossdk.io/math.Int" json:"max_loss" yaml:"max_loss"` // current_round_max_loss is the current round max loss. - CurrentRoundMaxLoss github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,11,opt,name=current_round_max_loss,json=currentRoundMaxLoss,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"current_round_max_loss" yaml:"current_round_max_loss"` + CurrentRoundMaxLoss cosmossdk_io_math.Int `protobuf:"bytes,11,opt,name=current_round_max_loss,json=currentRoundMaxLoss,proto3,customtype=cosmossdk.io/math.Int" json:"current_round_max_loss" yaml:"current_round_max_loss"` // current_round_max_loss_odds_uid is the total max loss corresponding to // all exposures. CurrentRoundMaxLossOddsUID string `protobuf:"bytes,12,opt,name=current_round_max_loss_odds_uid,proto3" json:"current_round_max_loss_odds_uid" yaml:"current_round_max_loss_odds_uid"` // actual_profit is the actual profit of the participation fulfillment. - ActualProfit github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,13,opt,name=actual_profit,json=actualProfit,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"actual_profit" yaml:"actual_profit"` + ActualProfit cosmossdk_io_math.Int `protobuf:"bytes,13,opt,name=actual_profit,json=actualProfit,proto3,customtype=cosmossdk.io/math.Int" json:"actual_profit" yaml:"actual_profit"` // is_settled represents if the participation is settled or not. IsSettled bool `protobuf:"varint,14,opt,name=is_settled,json=isSettled,proto3" json:"is_settled,omitempty" yaml:"is_settled"` } @@ -165,54 +165,54 @@ func init() { func init() { proto.RegisterFile("sge/orderbook/participation.proto", fileDescriptor_2962bcb47b63c36a) } var fileDescriptor_2962bcb47b63c36a = []byte{ - // 747 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x4f, 0x6f, 0xd3, 0x3e, - 0x18, 0x6e, 0xf6, 0xbf, 0x5e, 0xb7, 0xdf, 0x7e, 0x59, 0xb7, 0x45, 0x45, 0xc4, 0xc3, 0x12, 0xd3, - 0x0e, 0xac, 0x3d, 0xc0, 0x69, 0xe2, 0xb2, 0x80, 0x26, 0x15, 0x8d, 0xb5, 0x18, 0x10, 0x12, 0x42, - 0x32, 0x69, 0xe3, 0x16, 0xab, 0x6d, 0x5c, 0x62, 0x47, 0x74, 0x77, 0x0e, 0x3b, 0x72, 0x44, 0xe2, - 0xb2, 0x2f, 0xc1, 0x77, 0xd8, 0x09, 0xed, 0x88, 0x38, 0x44, 0xa8, 0xe3, 0x80, 0x38, 0xf6, 0x13, - 0xa0, 0xd8, 0x5d, 0xda, 0x6e, 0x85, 0xa9, 0x12, 0xa7, 0xda, 0xaf, 0x9f, 0x3e, 0xcf, 0xf3, 0x3a, - 0xc9, 0xf3, 0x82, 0x5b, 0xa2, 0x4e, 0x0b, 0x3c, 0xf0, 0x68, 0x50, 0xe1, 0xbc, 0x51, 0x68, 0xbb, - 0x81, 0x64, 0x55, 0xd6, 0x76, 0x25, 0xe3, 0x7e, 0xbe, 0x1d, 0x70, 0xc9, 0x4d, 0x4b, 0xd4, 0xa9, - 0x4f, 0xe5, 0x3b, 0x1e, 0x34, 0xf2, 0xa2, 0x4e, 0xf3, 0x09, 0x3a, 0x97, 0xad, 0xf3, 0x3a, 0x57, - 0xa0, 0x42, 0xbc, 0xd2, 0x78, 0xf4, 0x65, 0x11, 0xac, 0x97, 0x62, 0x8c, 0xc3, 0x79, 0xa3, 0x3c, - 0x4c, 0x68, 0x6e, 0x81, 0x59, 0xe6, 0x7b, 0xb4, 0x63, 0x19, 0x9b, 0xc6, 0xf6, 0x8c, 0xb3, 0xd2, - 0x8b, 0x60, 0xe6, 0xc8, 0x6d, 0x35, 0x77, 0x91, 0x2a, 0x23, 0xac, 0x8f, 0xcd, 0x47, 0x60, 0x59, - 0xa9, 0x90, 0x58, 0x86, 0x84, 0xcc, 0xb3, 0xa6, 0x36, 0x8d, 0xed, 0xb4, 0x83, 0xba, 0x11, 0xcc, - 0x24, 0xdc, 0xcf, 0x8b, 0x0f, 0x7f, 0x45, 0xf0, 0x12, 0x12, 0x5f, 0xda, 0x9b, 0x25, 0xb0, 0x9a, - 0x74, 0xe5, 0x4b, 0xe2, 0x7a, 0x5e, 0x40, 0x85, 0xb0, 0xa6, 0x15, 0xa1, 0xdd, 0x8b, 0x60, 0x4e, - 0x3b, 0x18, 0x03, 0x42, 0xd8, 0x1c, 0xaa, 0xee, 0xe9, 0xa2, 0xf9, 0x1a, 0xa4, 0x9b, 0xec, 0x6d, - 0xc8, 0x3c, 0x26, 0x8f, 0xac, 0x19, 0x45, 0xe3, 0x9c, 0x46, 0x30, 0xf5, 0x2d, 0x82, 0x5b, 0x75, - 0x26, 0xdf, 0x84, 0x95, 0x7c, 0x95, 0xb7, 0x0a, 0x55, 0x2e, 0x5a, 0x5c, 0xf4, 0x7f, 0x76, 0x84, - 0xd7, 0x28, 0xc8, 0xa3, 0x36, 0x15, 0xf9, 0xa2, 0x2f, 0x7b, 0x11, 0x5c, 0xd1, 0xa2, 0x09, 0x11, - 0xc2, 0x03, 0x52, 0xf3, 0x10, 0x4c, 0xd7, 0x28, 0xb5, 0x66, 0x15, 0xf7, 0xfd, 0x89, 0xb9, 0x81, - 0xe6, 0xae, 0x51, 0x8a, 0x70, 0x4c, 0x64, 0x1e, 0x1b, 0x60, 0xa3, 0x1a, 0x06, 0x01, 0xf5, 0x25, - 0x09, 0x78, 0xe8, 0x7b, 0x64, 0xd0, 0xc0, 0x9c, 0x12, 0x29, 0x4f, 0x2c, 0x62, 0x6b, 0x91, 0x3f, - 0xd0, 0x22, 0xbc, 0xd6, 0x3f, 0xc1, 0xf1, 0xc1, 0x41, 0xd2, 0xda, 0x13, 0x90, 0xa5, 0x9d, 0x36, - 0x17, 0x61, 0x40, 0x05, 0xf1, 0xb9, 0x24, 0x35, 0xd6, 0x6c, 0x52, 0xcf, 0x9a, 0x57, 0x2f, 0x04, - 0xec, 0x45, 0xf0, 0x86, 0x26, 0x1e, 0x87, 0x42, 0xd8, 0x4c, 0xca, 0x87, 0x5c, 0xee, 0xab, 0xa2, - 0x29, 0xc0, 0x8a, 0xe4, 0xd2, 0x6d, 0x92, 0x0a, 0x95, 0xc4, 0x6d, 0xf1, 0xd0, 0x97, 0xd6, 0x82, - 0xea, 0xaa, 0x38, 0x71, 0x57, 0x1b, 0x5a, 0xfc, 0x32, 0x1f, 0xc2, 0xcb, 0xaa, 0xe4, 0x50, 0xb9, - 0xa7, 0x0a, 0xe6, 0x27, 0x03, 0xd8, 0xa3, 0xbd, 0x5f, 0xf1, 0x90, 0x56, 0x1e, 0x5e, 0x4c, 0xec, - 0xe1, 0xf6, 0xb8, 0x9b, 0xbd, 0xea, 0x28, 0x37, 0x7c, 0xc1, 0xcf, 0x46, 0xdd, 0xbd, 0x02, 0x0b, - 0x2d, 0xb7, 0x43, 0x9a, 0x5c, 0x08, 0x0b, 0x28, 0x1b, 0x7b, 0x13, 0xdb, 0xf8, 0x4f, 0xdb, 0xb8, - 0xe0, 0x41, 0x78, 0xbe, 0xe5, 0x76, 0x0e, 0xb8, 0x10, 0xe6, 0x7b, 0x03, 0xac, 0x8f, 0xba, 0x4b, - 0xc4, 0x16, 0x95, 0x58, 0x69, 0x62, 0xb1, 0x9b, 0xe3, 0x7a, 0x1e, 0x48, 0xaf, 0x0e, 0xf7, 0xfa, - 0xb8, 0x6f, 0xe3, 0xb3, 0x01, 0xe0, 0xf8, 0x3f, 0x10, 0xee, 0x79, 0x42, 0xc5, 0x46, 0x46, 0xf9, - 0x69, 0x74, 0x23, 0x98, 0x7b, 0x70, 0x95, 0xa2, 0xe4, 0x79, 0x42, 0x87, 0xc8, 0x75, 0x44, 0xbd, - 0x08, 0x6e, 0xfd, 0xcd, 0x62, 0x02, 0x44, 0xf8, 0x3a, 0x2a, 0xb3, 0x01, 0x96, 0xdc, 0xaa, 0x0c, - 0xdd, 0x26, 0x69, 0x07, 0xbc, 0xc6, 0xa4, 0xb5, 0xa4, 0x4c, 0xee, 0x4f, 0x7c, 0x69, 0x59, 0xed, - 0x68, 0x84, 0x0c, 0xe1, 0x8c, 0xde, 0x97, 0xd5, 0xd6, 0xbc, 0x07, 0x00, 0x13, 0x44, 0x50, 0x29, - 0xe3, 0xaf, 0x6c, 0x79, 0xd3, 0xd8, 0x5e, 0x70, 0xd6, 0x7a, 0x11, 0xfc, 0xbf, 0x1f, 0xbb, 0xc9, - 0x19, 0xc2, 0x69, 0x26, 0x9e, 0xea, 0xf5, 0x6e, 0xe6, 0xf8, 0x04, 0xa6, 0x3e, 0x9e, 0xc0, 0xd4, - 0xcf, 0x13, 0x98, 0x42, 0x3f, 0x0c, 0x90, 0x1d, 0xc9, 0x71, 0x87, 0xca, 0xb2, 0xcb, 0x82, 0x31, - 0x31, 0x6d, 0xfc, 0x93, 0x98, 0x8e, 0x35, 0x88, 0x1e, 0x14, 0x53, 0x2a, 0x17, 0xc6, 0xc5, 0xf4, - 0x00, 0x34, 0x1c, 0xd3, 0x71, 0xb5, 0xa8, 0x66, 0x48, 0x01, 0xcc, 0xc7, 0x9f, 0x4b, 0xec, 0x4a, - 0x67, 0xfd, 0x5a, 0x37, 0x82, 0x73, 0x0e, 0x95, 0xda, 0xcf, 0xc5, 0x21, 0xbe, 0x58, 0x38, 0xfb, - 0xa7, 0x5d, 0xdb, 0x38, 0xeb, 0xda, 0xc6, 0xf7, 0xae, 0x6d, 0x7c, 0x38, 0xb7, 0x53, 0x67, 0xe7, - 0x76, 0xea, 0xeb, 0xb9, 0x9d, 0x7a, 0x79, 0x67, 0xe8, 0x91, 0x88, 0x3a, 0xdd, 0xe9, 0x4f, 0xc3, - 0x78, 0x5d, 0xe8, 0x0c, 0x4d, 0x4f, 0xf5, 0x70, 0x2a, 0x73, 0x6a, 0x0c, 0xde, 0xfd, 0x1d, 0x00, - 0x00, 0xff, 0xff, 0x32, 0xe0, 0x24, 0x5d, 0x5b, 0x07, 0x00, 0x00, + // 740 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0x9b, 0xfd, 0xaf, 0xe9, 0xc6, 0xc8, 0xda, 0x2d, 0x2a, 0x22, 0x1e, 0x96, 0x98, 0x26, + 0x01, 0x2d, 0x08, 0x90, 0xd0, 0x24, 0x40, 0x0b, 0x68, 0xd2, 0x60, 0xd0, 0x11, 0xe0, 0xb2, 0x8b, + 0x95, 0x36, 0x6e, 0x67, 0xb5, 0x8d, 0x4b, 0xec, 0x68, 0xdd, 0x37, 0x40, 0x9c, 0x38, 0x72, 0xdc, + 0x97, 0xe0, 0x1b, 0x70, 0xd8, 0x71, 0x47, 0xc4, 0x21, 0x42, 0x1d, 0x07, 0xc4, 0xb1, 0x9f, 0x00, + 0xc5, 0xee, 0xd2, 0x76, 0x0b, 0xe4, 0xc2, 0xcd, 0x79, 0xfd, 0xbe, 0xbf, 0xe7, 0x79, 0xdd, 0xfa, + 0x35, 0xb8, 0xce, 0x1b, 0xa4, 0xcc, 0x7c, 0x97, 0xf8, 0x55, 0xc6, 0x9a, 0xe5, 0x8e, 0xe3, 0x0b, + 0x5a, 0xa3, 0x1d, 0x47, 0x50, 0xe6, 0x95, 0x3a, 0x3e, 0x13, 0x4c, 0x37, 0x78, 0x83, 0x78, 0x44, + 0x1c, 0x30, 0xbf, 0x59, 0xe2, 0x0d, 0x52, 0x8a, 0xb3, 0x8b, 0xf9, 0x06, 0x6b, 0x30, 0x99, 0x54, + 0x8e, 0x56, 0x2a, 0x1f, 0x7d, 0x05, 0x60, 0xb9, 0x12, 0xe5, 0x58, 0x8c, 0x35, 0x77, 0x47, 0x81, + 0xfa, 0x1a, 0x98, 0xa6, 0x9e, 0x4b, 0xba, 0x86, 0xb6, 0xaa, 0xad, 0x4f, 0x59, 0x8b, 0xfd, 0x10, + 0xe6, 0x0e, 0x9d, 0x76, 0x6b, 0x03, 0xc9, 0x30, 0xb2, 0xd5, 0xb6, 0xfe, 0x1c, 0x2c, 0x48, 0x15, + 0x1c, 0xc9, 0xe0, 0x80, 0xba, 0xc6, 0xc4, 0xaa, 0xb6, 0x9e, 0xb5, 0x50, 0x2f, 0x84, 0xb9, 0x98, + 0xfd, 0x6e, 0xfb, 0xd9, 0xef, 0x10, 0x9e, 0xcb, 0xb4, 0xcf, 0x7d, 0xeb, 0x15, 0xb0, 0x14, 0x77, + 0xe5, 0x09, 0xec, 0xb8, 0xae, 0x4f, 0x38, 0x37, 0x26, 0x25, 0xd0, 0xec, 0x87, 0xb0, 0xa8, 0x1c, + 0x24, 0x24, 0x21, 0x5b, 0x1f, 0x89, 0x6e, 0xaa, 0xa0, 0x5e, 0x01, 0xd9, 0x16, 0x7d, 0x1f, 0x50, + 0x97, 0x8a, 0x43, 0x63, 0x4a, 0x62, 0xee, 0x1e, 0x87, 0x30, 0xf3, 0x3d, 0x84, 0x85, 0x1a, 0xe3, + 0x6d, 0xc6, 0xb9, 0xdb, 0x2c, 0x51, 0x56, 0x6e, 0x3b, 0x62, 0xbf, 0xb4, 0xed, 0x89, 0x7e, 0x08, + 0x17, 0x95, 0x46, 0x5c, 0x87, 0xec, 0x21, 0x43, 0x7f, 0x04, 0x26, 0xeb, 0x84, 0x18, 0xd3, 0x12, + 0x75, 0x33, 0x0d, 0x05, 0x14, 0xaa, 0x4e, 0x08, 0xb2, 0xa3, 0x3a, 0xfd, 0x00, 0xac, 0xd4, 0x02, + 0xdf, 0x27, 0x9e, 0xc0, 0x3e, 0x0b, 0x3c, 0x17, 0x0f, 0xdd, 0xcd, 0x48, 0xe4, 0x93, 0x34, 0xa4, + 0xa9, 0x90, 0x7f, 0xa1, 0x20, 0xbb, 0x30, 0xd8, 0xb1, 0xa3, 0x8d, 0x9d, 0xd8, 0xf7, 0x6b, 0x90, + 0x27, 0xdd, 0x0e, 0xe3, 0x81, 0x4f, 0x38, 0xf6, 0x98, 0xc0, 0x75, 0xda, 0x6a, 0x11, 0xd7, 0x98, + 0x95, 0x3f, 0x2e, 0xec, 0x87, 0xf0, 0xaa, 0x02, 0x27, 0x65, 0x21, 0x5b, 0x8f, 0xc3, 0xaf, 0x98, + 0xd8, 0x92, 0x41, 0xbd, 0x0a, 0x16, 0x05, 0x13, 0x4e, 0x0b, 0x57, 0x89, 0xc0, 0x4e, 0x9b, 0x05, + 0x9e, 0x30, 0xe6, 0x64, 0x13, 0x0f, 0xd3, 0x9a, 0x58, 0x51, 0x5a, 0xe7, 0xcb, 0x91, 0xbd, 0x20, + 0x43, 0x16, 0x11, 0x9b, 0x32, 0xa0, 0x7f, 0xd4, 0x80, 0x39, 0xde, 0xea, 0x05, 0xc9, 0xac, 0x94, + 0xdc, 0x4a, 0x93, 0xbc, 0x91, 0x74, 0x6e, 0x17, 0x0d, 0x14, 0x47, 0x8f, 0xef, 0xed, 0xb8, 0x99, + 0x17, 0x60, 0xae, 0xed, 0x74, 0x71, 0x8b, 0x71, 0x6e, 0x00, 0xa9, 0x7a, 0x27, 0x4d, 0xf5, 0xb2, + 0x52, 0x3d, 0x2b, 0x43, 0xf6, 0x6c, 0xdb, 0xe9, 0xee, 0x30, 0xce, 0x75, 0x0e, 0x96, 0xc7, 0xbd, + 0xc4, 0xe8, 0x4b, 0x12, 0xfd, 0x38, 0x0d, 0x7d, 0x2d, 0xa9, 0xa1, 0xa1, 0xd0, 0xd2, 0x68, 0x23, + 0x2f, 0x07, 0xa2, 0x5f, 0x34, 0x00, 0x93, 0x0b, 0x30, 0x73, 0x5d, 0x2e, 0x6f, 0x6f, 0x4e, 0xca, + 0x37, 0x7b, 0x21, 0x2c, 0x3e, 0xbd, 0x88, 0xa8, 0xb8, 0x2e, 0x57, 0x77, 0x39, 0x0d, 0xd4, 0x0f, + 0xe1, 0xda, 0xbf, 0x2c, 0xc6, 0x89, 0xc8, 0x4e, 0x43, 0xe9, 0x7b, 0x60, 0xde, 0xa9, 0x89, 0xc0, + 0x69, 0xe1, 0x8e, 0xcf, 0xea, 0x54, 0x18, 0xf3, 0xd2, 0xe4, 0x83, 0xb4, 0x33, 0xca, 0x2b, 0x03, + 0x63, 0xb5, 0xc8, 0xce, 0xa9, 0xef, 0x5d, 0xf9, 0xa9, 0xdf, 0x07, 0x80, 0x72, 0xcc, 0x89, 0x10, + 0xd1, 0x7d, 0x58, 0x58, 0xd5, 0xd6, 0xe7, 0xac, 0x42, 0x3f, 0x84, 0x57, 0x06, 0xc3, 0x2e, 0xde, + 0x43, 0x76, 0x96, 0xf2, 0x37, 0x6a, 0xbd, 0x91, 0xfb, 0x70, 0x04, 0x33, 0x9f, 0x8f, 0x60, 0xe6, + 0xd7, 0x11, 0xcc, 0xa0, 0x9f, 0x1a, 0xc8, 0x8f, 0x4d, 0x4f, 0x8b, 0x88, 0x5d, 0x87, 0xfa, 0x09, + 0xc3, 0x51, 0xfb, 0x2f, 0xc3, 0x31, 0xd2, 0xc0, 0x6a, 0x3c, 0x4f, 0xc8, 0x1b, 0x9c, 0x34, 0x1c, + 0x87, 0x49, 0xa3, 0xc3, 0x31, 0x8a, 0x6e, 0xcb, 0xc9, 0x5d, 0x06, 0xb3, 0xd1, 0x5f, 0x3f, 0x72, + 0xa5, 0x26, 0x6c, 0xa1, 0x17, 0xc2, 0x19, 0x8b, 0x08, 0xe5, 0xe7, 0x6c, 0xd3, 0x3e, 0x5b, 0x58, + 0x5b, 0xc7, 0x3d, 0x53, 0x3b, 0xe9, 0x99, 0xda, 0x8f, 0x9e, 0xa9, 0x7d, 0x3a, 0x35, 0x33, 0x27, + 0xa7, 0x66, 0xe6, 0xdb, 0xa9, 0x99, 0xd9, 0xbb, 0xd5, 0xa0, 0x62, 0x3f, 0xa8, 0x96, 0x6a, 0xac, + 0x5d, 0xe6, 0x0d, 0x72, 0x7b, 0xf0, 0x06, 0x45, 0xeb, 0x72, 0x77, 0xe4, 0xcd, 0x12, 0x87, 0x1d, + 0xc2, 0xab, 0x33, 0xf2, 0xf1, 0xb9, 0xf7, 0x27, 0x00, 0x00, 0xff, 0xff, 0xa2, 0xb1, 0xc3, 0x6d, + 0xd1, 0x06, 0x00, 0x00, } func (m *OrderBookParticipation) Marshal() (dAtA []byte, err error) { diff --git a/x/ovm/abci.go b/x/ovm/abci.go index c8992a1b..2319ff66 100644 --- a/x/ovm/abci.go +++ b/x/ovm/abci.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/keeper" ) diff --git a/x/ovm/client/cli/query.go b/x/ovm/client/cli/query.go index 4c9a0726..ad85861d 100644 --- a/x/ovm/client/cli/query.go +++ b/x/ovm/client/cli/query.go @@ -2,13 +2,10 @@ package cli import ( "fmt" - // "strings" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" - // sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/client/cli/query_params.go b/x/ovm/client/cli/query_params.go index 2b71406f..3d215641 100644 --- a/x/ovm/client/cli/query_params.go +++ b/x/ovm/client/cli/query_params.go @@ -3,10 +3,12 @@ package cli import ( "context" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cobra" ) // CmdQueryParams returns a command object instance for module params diff --git a/x/ovm/client/cli/query_params_test.go b/x/ovm/client/cli/query_params_test.go index 87a6b3ad..f020ee3d 100644 --- a/x/ovm/client/cli/query_params_test.go +++ b/x/ovm/client/cli/query_params_test.go @@ -4,11 +4,13 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/sge-network/sge/testutil/network" + "github.com/sge-network/sge/x/ovm/client/cli" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestQueryParams(t *testing.T) { diff --git a/x/ovm/client/cli/query_proposal.go b/x/ovm/client/cli/query_proposal.go index 7b26f929..ee012715 100644 --- a/x/ovm/client/cli/query_proposal.go +++ b/x/ovm/client/cli/query_proposal.go @@ -4,11 +4,13 @@ import ( "context" "strconv" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cast" - "github.com/spf13/cobra" ) var _ = strconv.Itoa(0) diff --git a/x/ovm/client/cli/query_proposal_test.go b/x/ovm/client/cli/query_proposal_test.go index d30df598..d2c1f551 100644 --- a/x/ovm/client/cli/query_proposal_test.go +++ b/x/ovm/client/cli/query_proposal_test.go @@ -6,16 +6,19 @@ import ( "testing" "time" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + tmcli "github.com/tendermint/tendermint/libs/cli" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/ovm/client/cli" "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // Prevent strconv unused error diff --git a/x/ovm/client/cli/query_pub_keys.go b/x/ovm/client/cli/query_pub_keys.go index 94a72d0d..9fd2ed26 100644 --- a/x/ovm/client/cli/query_pub_keys.go +++ b/x/ovm/client/cli/query_pub_keys.go @@ -1,10 +1,12 @@ package cli import ( + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cobra" ) // CmdPubKeysList returns a command object instance for querying the public keys diff --git a/x/ovm/client/cli/query_pub_keys_test.go b/x/ovm/client/cli/query_pub_keys_test.go index 5206c057..3b1b5b1e 100644 --- a/x/ovm/client/cli/query_pub_keys_test.go +++ b/x/ovm/client/cli/query_pub_keys_test.go @@ -4,14 +4,17 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/status" + + tmcli "github.com/tendermint/tendermint/libs/cli" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/sge-network/sge/testutil/network" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/ovm/client/cli" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" - tmcli "github.com/tendermint/tendermint/libs/cli" - "google.golang.org/grpc/status" ) func networkWithPublicKeys(t *testing.T) (*network.Network, *types.KeyVault) { @@ -20,7 +23,7 @@ func networkWithPublicKeys(t *testing.T) (*network.Network, *types.KeyVault) { state := types.GenesisState{} require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) - pubkeys := simappUtil.GenerateOvmPublicKeys(types.MinPubKeysCount) + pubkeys := simapp.GenerateOvmPublicKeys(types.MinPubKeysCount) state.KeyVault = types.KeyVault{ PublicKeys: pubkeys, diff --git a/x/ovm/client/cli/query_test.go b/x/ovm/client/cli/query_test.go index 8c182a15..2894135e 100644 --- a/x/ovm/client/cli/query_test.go +++ b/x/ovm/client/cli/query_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/ovm/client/cli" - "github.com/stretchr/testify/require" ) func TestGetQueryCmd(t *testing.T) { diff --git a/x/ovm/client/cli/tx.go b/x/ovm/client/cli/tx.go index 21d7d20d..c495abe5 100644 --- a/x/ovm/client/cli/tx.go +++ b/x/ovm/client/cli/tx.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/client/cli/tx_pubkeys_proposal.go b/x/ovm/client/cli/tx_pubkeys_proposal.go index 85461a71..ef75a71c 100644 --- a/x/ovm/client/cli/tx_pubkeys_proposal.go +++ b/x/ovm/client/cli/tx_pubkeys_proposal.go @@ -1,11 +1,13 @@ package cli import ( + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cobra" ) // CmdChangePubkeysListProposal is the command object for change of public keys diff --git a/x/ovm/client/cli/tx_pubkeys_proposal_test.go b/x/ovm/client/cli/tx_pubkeys_proposal_test.go index b3087964..ce7bb8c0 100644 --- a/x/ovm/client/cli/tx_pubkeys_proposal_test.go +++ b/x/ovm/client/cli/tx_pubkeys_proposal_test.go @@ -8,15 +8,18 @@ import ( "testing" "time" + "github.com/golang-jwt/jwt/v4" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/golang-jwt/jwt/v4" - simappUtil "github.com/sge-network/sge/testutil/simapp" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/ovm/client/cli" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestCmdChangePubkeysListProposal(t *testing.T) { @@ -31,7 +34,7 @@ func TestCmdChangePubkeysListProposal(t *testing.T) { fmt.Sprintf( "--%s=%s", flags.FlagFees, - sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String(), + sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String(), ), } @@ -49,7 +52,7 @@ func TestCmdChangePubkeysListProposal(t *testing.T) { "leader_index": 0, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedT1, err := t1.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedT1, err := t1.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) TestCases := []struct { diff --git a/x/ovm/client/cli/tx_pubkeys_vote.go b/x/ovm/client/cli/tx_pubkeys_vote.go index 52b63517..1aa1ab61 100644 --- a/x/ovm/client/cli/tx_pubkeys_vote.go +++ b/x/ovm/client/cli/tx_pubkeys_vote.go @@ -3,12 +3,14 @@ package cli import ( "strconv" + "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cast" - "github.com/spf13/cobra" ) var _ = strconv.Itoa(0) diff --git a/x/ovm/client/cli/tx_test.go b/x/ovm/client/cli/tx_test.go index 3d914bea..c8aa7d74 100644 --- a/x/ovm/client/cli/tx_test.go +++ b/x/ovm/client/cli/tx_test.go @@ -4,10 +4,12 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/sge-network/sge/testutil/network" "github.com/sge-network/sge/x/ovm/client/cli" - "github.com/stretchr/testify/require" ) func TestGetTxCmd(t *testing.T) { diff --git a/x/ovm/genesis.go b/x/ovm/genesis.go index 9c376ffb..5b2ce56b 100644 --- a/x/ovm/genesis.go +++ b/x/ovm/genesis.go @@ -2,6 +2,7 @@ package ovm import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/keeper" "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/genesis_test.go b/x/ovm/genesis_test.go index 0e144b69..0613f0bc 100644 --- a/x/ovm/genesis_test.go +++ b/x/ovm/genesis_test.go @@ -3,11 +3,13 @@ package ovm_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/ovm" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestGenesis(t *testing.T) { @@ -18,7 +20,7 @@ func TestGenesis(t *testing.T) { }, } - tApp, ctx, err := simappUtil.GetTestObjects() + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) ovm.InitGenesis(ctx, *tApp.OVMKeeper, genesisState) diff --git a/x/ovm/handler.go b/x/ovm/handler.go index 90474f57..e16934ce 100644 --- a/x/ovm/handler.go +++ b/x/ovm/handler.go @@ -3,8 +3,10 @@ package ovm import ( "fmt" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/ovm/keeper" "github.com/sge-network/sge/x/ovm/types" ) @@ -25,7 +27,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) } } } diff --git a/x/ovm/keeper/grpc_query_params.go b/x/ovm/keeper/grpc_query_params.go index 4f2bd7c4..69b9001f 100644 --- a/x/ovm/keeper/grpc_query_params.go +++ b/x/ovm/keeper/grpc_query_params.go @@ -3,10 +3,12 @@ package keeper import ( "context" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sge-network/sge/x/ovm/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/ovm/types" ) // Params returns the params of the module diff --git a/x/ovm/keeper/grpc_query_params_test.go b/x/ovm/keeper/grpc_query_params_test.go index f9296b27..10b603dd 100644 --- a/x/ovm/keeper/grpc_query_params_test.go +++ b/x/ovm/keeper/grpc_query_params_test.go @@ -3,9 +3,11 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestParamsQuery(t *testing.T) { diff --git a/x/ovm/keeper/grpc_query_pubkeys.go b/x/ovm/keeper/grpc_query_pubkeys.go index 92e50bcf..740c3ff8 100644 --- a/x/ovm/keeper/grpc_query_pubkeys.go +++ b/x/ovm/keeper/grpc_query_pubkeys.go @@ -3,10 +3,12 @@ package keeper import ( "context" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sge-network/sge/x/ovm/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/ovm/types" ) // PubKeys returns list of the public keys diff --git a/x/ovm/keeper/grpc_query_pubkeys_proposal.go b/x/ovm/keeper/grpc_query_pubkeys_proposal.go index 32caef4b..af5947bf 100644 --- a/x/ovm/keeper/grpc_query_pubkeys_proposal.go +++ b/x/ovm/keeper/grpc_query_pubkeys_proposal.go @@ -3,13 +3,15 @@ package keeper import ( "context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/x/ovm/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // PublicKeysChangeProposal returns a specific proposal by its id and status @@ -49,7 +51,7 @@ func (k Keeper) PublicKeysChangeProposals( marketStore := k.getPubKeysChangeProposalStore(ctx) proposalStore := prefix.NewStore(marketStore, types.PubkeysChangeProposalPrefix(req.Status)) - pageRes, err := query.Paginate(proposalStore, req.Pagination, func(key []byte, value []byte) error { + pageRes, err := query.Paginate(proposalStore, req.Pagination, func(key, value []byte) error { var proposal types.PublicKeysChangeProposal if err := k.cdc.Unmarshal(value, &proposal); err != nil { return err diff --git a/x/ovm/keeper/grpc_query_pubkeys_proposal_test.go b/x/ovm/keeper/grpc_query_pubkeys_proposal_test.go index e1ca0ec3..efc67504 100644 --- a/x/ovm/keeper/grpc_query_pubkeys_proposal_test.go +++ b/x/ovm/keeper/grpc_query_pubkeys_proposal_test.go @@ -4,13 +4,15 @@ import ( "strconv" "testing" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/consts" "github.com/sge-network/sge/testutil/nullify" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // Prevent strconv unused error diff --git a/x/ovm/keeper/grpc_query_pubkeys_test.go b/x/ovm/keeper/grpc_query_pubkeys_test.go index b5525e75..9fe20480 100644 --- a/x/ovm/keeper/grpc_query_pubkeys_test.go +++ b/x/ovm/keeper/grpc_query_pubkeys_test.go @@ -3,9 +3,11 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestPubKeysList(t *testing.T) { diff --git a/x/ovm/keeper/keeper.go b/x/ovm/keeper/keeper.go index 510a49db..2c7b32b6 100644 --- a/x/ovm/keeper/keeper.go +++ b/x/ovm/keeper/keeper.go @@ -3,12 +3,14 @@ package keeper import ( "fmt" + "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/sge-network/sge/x/ovm/types" - "github.com/tendermint/tendermint/libs/log" ) // Keeper is the type for module properties diff --git a/x/ovm/keeper/keeper_test.go b/x/ovm/keeper/keeper_test.go index 7b0be621..91097a7a 100644 --- a/x/ovm/keeper/keeper_test.go +++ b/x/ovm/keeper/keeper_test.go @@ -3,14 +3,16 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" - simappUtil "github.com/sge-network/sge/testutil/simapp" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/ovm/keeper" - "github.com/stretchr/testify/require" ) -func setupKeeperAndApp(t testing.TB) (*simappUtil.TestApp, *keeper.KeeperTest, sdk.Context) { - tApp, ctx, err := simappUtil.GetTestObjects() +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.KeeperTest, sdk.Context) { + tApp, ctx, err := simapp.GetTestObjects() require.NoError(t, err) return tApp, tApp.OVMKeeper, ctx diff --git a/x/ovm/keeper/key_vault.go b/x/ovm/keeper/key_vault.go index 82a1e10d..65fe7451 100644 --- a/x/ovm/keeper/key_vault.go +++ b/x/ovm/keeper/key_vault.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/keeper/key_vault_test.go b/x/ovm/keeper/key_vault_test.go index e1c5016d..db4c8dc3 100644 --- a/x/ovm/keeper/key_vault_test.go +++ b/x/ovm/keeper/key_vault_test.go @@ -8,16 +8,17 @@ import ( "time" "github.com/golang-jwt/jwt/v4" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestQueryPublicKeys(t *testing.T) { k, msgk, ctx, wctx := setupMsgServerAndKeeper(t) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] var pubs []string for i := 0; i < types.MaxPubKeysCount; i++ { pub, _, err := ed25519.GenerateKey(rand.Reader) @@ -32,7 +33,7 @@ func TestQueryPublicKeys(t *testing.T) { "leader_index": 0, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedT1, err := T1.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedT1, err := T1.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) resp, err := msgk.SubmitPubkeysChangeProposal(wctx, &types.MsgSubmitPubkeysChangeProposalRequest{ diff --git a/x/ovm/keeper/msg_server_pubkeys_proposal.go b/x/ovm/keeper/msg_server_pubkeys_proposal.go index ffe5d4ef..334b4b3e 100644 --- a/x/ovm/keeper/msg_server_pubkeys_proposal.go +++ b/x/ovm/keeper/msg_server_pubkeys_proposal.go @@ -3,8 +3,10 @@ package keeper import ( "context" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/ovm/types" ) @@ -32,7 +34,7 @@ func (k msgServer) SubmitPubkeysChangeProposal( err = payload.Validate(payload.LeaderIndex) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "ticket payload is not valid %s", err) + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "ticket payload is not valid %s", err) } stats := k.GetProposalStats(ctx) diff --git a/x/ovm/keeper/msg_server_pubkeys_proposal_test.go b/x/ovm/keeper/msg_server_pubkeys_proposal_test.go index 8740096a..a9fd47a0 100644 --- a/x/ovm/keeper/msg_server_pubkeys_proposal_test.go +++ b/x/ovm/keeper/msg_server_pubkeys_proposal_test.go @@ -7,12 +7,14 @@ import ( "testing" "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/golang-jwt/jwt/v4" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/stretchr/testify/require" + + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func createNTestPubKeys(n int) ([]string, error) { @@ -39,7 +41,7 @@ func createNTestPubKeys(n int) ([]string, error) { func TestChangePubkeysListProposal(t *testing.T) { t.Run("success", func(t *testing.T) { msgk, _, wctx := setupMsgServer(t) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] pubs, err := createNTestPubKeys(types.MinPubKeysCount) require.NoError(t, err) @@ -48,7 +50,7 @@ func TestChangePubkeysListProposal(t *testing.T) { "leader_index": 0, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedT1, err := T1.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedT1, err := T1.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) resp, err := msgk.SubmitPubkeysChangeProposal( @@ -66,7 +68,7 @@ func TestChangePubkeysListProposal(t *testing.T) { k, msgk, ctx, wctx := setupMsgServerAndKeeper(t) createNActiveProposal(k, ctx, 1) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] pubs, err := createNTestPubKeys(types.MinPubKeysCount - 1) require.NoError(t, err) @@ -75,7 +77,7 @@ func TestChangePubkeysListProposal(t *testing.T) { "leader_index": 0, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedProposalTicket, err := proposalTicket.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedProposalTicket, err := proposalTicket.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) resp, err := msgk.SubmitPubkeysChangeProposal( @@ -85,7 +87,7 @@ func TestChangePubkeysListProposal(t *testing.T) { Ticket: singedProposalTicket, }, ) - require.ErrorIs(t, sdkerrors.ErrInvalidRequest, err) + require.ErrorIs(t, sdkerrtypes.ErrInvalidRequest, err) require.Nil(t, resp) }) @@ -93,7 +95,7 @@ func TestChangePubkeysListProposal(t *testing.T) { k, msgk, ctx, wctx := setupMsgServerAndKeeper(t) createNActiveProposal(k, ctx, 1) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] pubs, err := createNTestPubKeys(types.MaxPubKeysCount + 1) require.NoError(t, err) @@ -102,7 +104,7 @@ func TestChangePubkeysListProposal(t *testing.T) { "leader_index": 0, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedProposalTicket, err := proposalTicket.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedProposalTicket, err := proposalTicket.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) resp, err := msgk.SubmitPubkeysChangeProposal( @@ -112,7 +114,7 @@ func TestChangePubkeysListProposal(t *testing.T) { Ticket: singedProposalTicket, }, ) - require.ErrorIs(t, sdkerrors.ErrInvalidRequest, err) + require.ErrorIs(t, sdkerrtypes.ErrInvalidRequest, err) require.Nil(t, resp) }) @@ -120,7 +122,7 @@ func TestChangePubkeysListProposal(t *testing.T) { k, msgk, ctx, wctx := setupMsgServerAndKeeper(t) createNActiveProposal(k, ctx, 1) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] pubs, err := createNTestPubKeys(types.MinPubKeysCount) require.NoError(t, err) @@ -129,7 +131,7 @@ func TestChangePubkeysListProposal(t *testing.T) { "leader_index": types.MaxPubKeysCount, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedProposalTicket, err := proposalTicket.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedProposalTicket, err := proposalTicket.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) resp, err := msgk.SubmitPubkeysChangeProposal( @@ -139,14 +141,14 @@ func TestChangePubkeysListProposal(t *testing.T) { Ticket: singedProposalTicket, }, ) - require.ErrorIs(t, sdkerrors.ErrInvalidRequest, err) + require.ErrorIs(t, sdkerrtypes.ErrInvalidRequest, err) require.Nil(t, resp) }) t.Run("fails", func(t *testing.T) { msgk, _, wctx := setupMsgServer(t) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] t.Run("public keys change proposal", func(t *testing.T) { _, err := msgk.SubmitPubkeysChangeProposal( wctx, diff --git a/x/ovm/keeper/msg_server_test.go b/x/ovm/keeper/msg_server_test.go index c85e719c..bdb4f78f 100644 --- a/x/ovm/keeper/msg_server_test.go +++ b/x/ovm/keeper/msg_server_test.go @@ -4,11 +4,13 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" - simappUtil "github.com/sge-network/sge/testutil/simapp" + + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/x/ovm/keeper" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func setupMsgServer(t testing.TB) (types.MsgServer, sdk.Context, context.Context) { @@ -25,7 +27,7 @@ func setupMsgServerAndKeeper( func setupMsgServerAndApp( t testing.TB, -) (*simappUtil.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { +) (*simapp.TestApp, *keeper.KeeperTest, types.MsgServer, sdk.Context, context.Context) { tApp, k, ctx := setupKeeperAndApp(t) return tApp, k, keeper.NewMsgServerImpl(*k), ctx, sdk.WrapSDKContext(ctx) } diff --git a/x/ovm/keeper/msg_server_vote.go b/x/ovm/keeper/msg_server_vote.go index 77d1f1fc..86c0e2ab 100644 --- a/x/ovm/keeper/msg_server_vote.go +++ b/x/ovm/keeper/msg_server_vote.go @@ -3,10 +3,13 @@ package keeper import ( "context" + "github.com/spf13/cast" + + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cast" ) // VotePubkeysChange is the main transaction of OVM to vote for a pubkeys list change proposal. @@ -24,7 +27,7 @@ func (k msgServer) VotePubkeysChange( // voter index is out of range of current public keys in the vault if cast.ToUint32(len(keyVault.PublicKeys)) <= msg.VoterKeyIndex { return nil, sdkerrors.Wrapf( - sdkerrors.ErrInvalidPubKey, + sdkerrtypes.ErrInvalidPubKey, "index is not in the valid range of public keys indices", ) } @@ -39,7 +42,7 @@ func (k msgServer) VotePubkeysChange( err := k.verifyTicketWithKeyUnmarshal(goCtx, msg.Ticket, &payload, voterPubKey) if err != nil { return nil, sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "ticket should be signed by the provided pub key: %s", err, ) @@ -47,7 +50,7 @@ func (k msgServer) VotePubkeysChange( err = payload.Validate() if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "ticket payload is not valid %s", err) + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "ticket payload is not valid %s", err) } // get public key change proposal @@ -58,7 +61,7 @@ func (k msgServer) VotePubkeysChange( ) if !found { return nil, sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "proposal not fount with id %d", &payload.ProposalId, ) @@ -69,7 +72,7 @@ func (k msgServer) VotePubkeysChange( for _, voter := range proposal.Votes { if voter.PublicKey == voterPubKey { return nil, sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, + sdkerrtypes.ErrInvalidRequest, "vote already set for this pubkey %s", msg.Creator, ) diff --git a/x/ovm/keeper/msg_server_vote_test.go b/x/ovm/keeper/msg_server_vote_test.go index e39b94cb..4adf73c1 100644 --- a/x/ovm/keeper/msg_server_vote_test.go +++ b/x/ovm/keeper/msg_server_vote_test.go @@ -4,11 +4,13 @@ import ( "testing" "time" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/golang-jwt/jwt/v4" - simappUtil "github.com/sge-network/sge/testutil/simapp" - "github.com/sge-network/sge/x/ovm/types" "github.com/stretchr/testify/require" + + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/ovm/types" ) func TestChangePubkeysVote(t *testing.T) { @@ -16,7 +18,7 @@ func TestChangePubkeysVote(t *testing.T) { k, msgk, ctx, wctx := setupMsgServerAndKeeper(t) createNActiveProposal(k, ctx, 1) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] pubs, err := createNTestPubKeys(types.MinPubKeysCount) require.NoError(t, err) @@ -25,7 +27,7 @@ func TestChangePubkeysVote(t *testing.T) { "leader_index": 0, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedProposalTicket, err := proposalTicket.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedProposalTicket, err := proposalTicket.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) resp, err := msgk.SubmitPubkeysChangeProposal( @@ -43,7 +45,7 @@ func TestChangePubkeysVote(t *testing.T) { "vote": types.ProposalVote_PROPOSAL_VOTE_YES, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedVoteTicket, err := voteTicket.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedVoteTicket, err := voteTicket.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) respVote, err := msgk.VotePubkeysChange(wctx, &types.MsgVotePubkeysChangeRequest{ @@ -59,7 +61,7 @@ func TestChangePubkeysVote(t *testing.T) { k, msgk, ctx, wctx := setupMsgServerAndKeeper(t) createNActiveProposal(k, ctx, 1) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] pubs, err := createNTestPubKeys(types.MinPubKeysCount) require.NoError(t, err) @@ -68,7 +70,7 @@ func TestChangePubkeysVote(t *testing.T) { "leader_index": 0, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedProposalTicket, err := proposalTicket.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedProposalTicket, err := proposalTicket.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) resp, err := msgk.SubmitPubkeysChangeProposal( @@ -86,7 +88,7 @@ func TestChangePubkeysVote(t *testing.T) { "vote": types.ProposalVote_PROPOSAL_VOTE_YES, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedVote1Ticket, err := vote1Ticket.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedVote1Ticket, err := vote1Ticket.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) respVote, err := msgk.VotePubkeysChange(wctx, &types.MsgVotePubkeysChangeRequest{ @@ -102,7 +104,7 @@ func TestChangePubkeysVote(t *testing.T) { "vote": types.ProposalVote_PROPOSAL_VOTE_YES, "exp": jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), }) - singedVote2Ticket, err := vote2Ticket.SignedString(simappUtil.TestOVMPrivateKeys[0]) + singedVote2Ticket, err := vote2Ticket.SignedString(simapp.TestOVMPrivateKeys[0]) require.NoError(t, err) respVote, err = msgk.VotePubkeysChange(wctx, &types.MsgVotePubkeysChangeRequest{ @@ -110,7 +112,7 @@ func TestChangePubkeysVote(t *testing.T) { Ticket: singedVote2Ticket, VoterKeyIndex: 0, }) - require.ErrorIs(t, sdkerrors.ErrInvalidRequest, err) + require.ErrorIs(t, sdkerrtypes.ErrInvalidRequest, err) require.Nil(t, respVote) }) } diff --git a/x/ovm/keeper/params.go b/x/ovm/keeper/params.go index a78d9395..823a458c 100644 --- a/x/ovm/keeper/params.go +++ b/x/ovm/keeper/params.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/keeper/params_test.go b/x/ovm/keeper/params_test.go index a28fd1a5..1d4e906f 100644 --- a/x/ovm/keeper/params_test.go +++ b/x/ovm/keeper/params_test.go @@ -3,8 +3,9 @@ package keeper_test import ( "testing" - "github.com/sge-network/sge/x/ovm/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/ovm/types" ) func TestGetParams(t *testing.T) { diff --git a/x/ovm/keeper/proposal.go b/x/ovm/keeper/proposal.go index 76ed488f..9cd0c2e9 100644 --- a/x/ovm/keeper/proposal.go +++ b/x/ovm/keeper/proposal.go @@ -4,6 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/keeper/proposal_test.go b/x/ovm/keeper/proposal_test.go index edbf683d..f4e39244 100644 --- a/x/ovm/keeper/proposal_test.go +++ b/x/ovm/keeper/proposal_test.go @@ -5,14 +5,16 @@ import ( "testing" "time" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sge-network/sge/testutil/nullify" - simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/testutil/simapp" "github.com/sge-network/sge/utils" + "github.com/sge-network/sge/x/ovm/keeper" "github.com/sge-network/sge/x/ovm/types" - "github.com/spf13/cast" - "github.com/stretchr/testify/require" ) func createNActiveProposal( @@ -29,7 +31,7 @@ func createNActiveProposal( for i := range items { items[i].Id = uint64(i) - items[i].Creator = simappUtil.TestParamUsers["user"+cast.ToString(i)].Address.String() + items[i].Creator = simapp.TestParamUsers["user"+cast.ToString(i)].Address.String() items[i].Modifications = types.PubkeysChangeProposalPayload{PublicKeys: pubKeys, LeaderIndex: 0} items[i].StartTS = ctx.BlockTime().Unix() items[i].Status = types.ProposalStatus_PROPOSAL_STATUS_ACTIVE @@ -104,7 +106,7 @@ func TestFinishProposals(t *testing.T) { ctx = ctx.WithBlockTime(ctx.BlockTime().Add(types.MaxValidProposalMinutes / 2 * time.Minute)) for _, proposal := range items { - for _, p := range simappUtil.TestOVMPublicKeys { + for _, p := range simapp.TestOVMPublicKeys { bs, err := x509.MarshalPKIXPublicKey(p) if err != nil { panic(err) @@ -161,7 +163,7 @@ func TestFinishProposal(t *testing.T) { proposals := createNActiveProposal(k, ctx, 3) voteAll := func(proposal *types.PublicKeysChangeProposal, vote types.ProposalVote) { - for _, p := range simappUtil.TestOVMPublicKeys { + for _, p := range simapp.TestOVMPublicKeys { bs, err := x509.MarshalPKIXPublicKey(p) if err != nil { panic(err) diff --git a/x/ovm/keeper/stats.go b/x/ovm/keeper/stats.go index 2727fc5f..afb4e1b3 100644 --- a/x/ovm/keeper/stats.go +++ b/x/ovm/keeper/stats.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/keeper/ticket.go b/x/ovm/keeper/ticket.go index 0b181db7..250c98a1 100644 --- a/x/ovm/keeper/ticket.go +++ b/x/ovm/keeper/ticket.go @@ -5,6 +5,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/keeper/ticket_test.go b/x/ovm/keeper/ticket_test.go index 572ff368..2ad6e219 100644 --- a/x/ovm/keeper/ticket_test.go +++ b/x/ovm/keeper/ticket_test.go @@ -9,15 +9,16 @@ import ( "time" "github.com/golang-jwt/jwt/v4" - simappUtil "github.com/sge-network/sge/testutil/simapp" - "github.com/sge-network/sge/x/ovm/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/ovm/types" ) func TestVerifyTicket(t *testing.T) { k, msgk, _, wctx := setupMsgServerAndKeeper(t) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] t.Run("valid", func(t *testing.T) { Token := jwt.NewWithClaims(jwt.SigningMethodEdDSA, struct { @@ -30,7 +31,7 @@ func TestVerifyTicket(t *testing.T) { IssuedAt: jwt.NewNumericDate(time.Now()), }, }) - tkn, err := Token.SignedString(&simappUtil.TestOVMPrivateKeys[0]) + tkn, err := Token.SignedString(&simapp.TestOVMPrivateKeys[0]) require.Nil(t, err) err = k.VerifyTicket(wctx, tkn) @@ -66,7 +67,7 @@ func TestVerifyTicket(t *testing.T) { func TestVerifyTicketUnmarshal(t *testing.T) { k, msgk, ctx, wctx := setupMsgServerAndKeeper(t) - creator := simappUtil.TestParamUsers["user1"] + creator := simapp.TestParamUsers["user1"] Pub, Pri, err := ed25519.GenerateKey(rand.Reader) require.Nil(t, err) diff --git a/x/ovm/keeper/view.go b/x/ovm/keeper/view.go index 24e97f46..9852757e 100644 --- a/x/ovm/keeper/view.go +++ b/x/ovm/keeper/view.go @@ -3,6 +3,7 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/module.go b/x/ovm/module.go index 91e29601..e160caff 100644 --- a/x/ovm/module.go +++ b/x/ovm/module.go @@ -16,6 +16,7 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/ovm/client/cli" "github.com/sge-network/sge/x/ovm/keeper" "github.com/sge-network/sge/x/ovm/types" diff --git a/x/ovm/module_simulation.go b/x/ovm/module_simulation.go index 8c7c56ab..8dd719ab 100644 --- a/x/ovm/module_simulation.go +++ b/x/ovm/module_simulation.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/sge-network/sge/testutil/sample" ovmsimulation "github.com/sge-network/sge/x/ovm/simulation" diff --git a/x/ovm/simulation/decoder.go b/x/ovm/simulation/decoder.go index 823e5332..f1a3aea2 100644 --- a/x/ovm/simulation/decoder.go +++ b/x/ovm/simulation/decoder.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/simulation/decoder_test.go b/x/ovm/simulation/decoder_test.go index ca7a04a8..f4582de0 100644 --- a/x/ovm/simulation/decoder_test.go +++ b/x/ovm/simulation/decoder_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/kv" "github.com/sge-network/sge/app" "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/ovm/simulation" "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/simulation/genesis.go b/x/ovm/simulation/genesis.go index 1e64bea9..8e30ff56 100644 --- a/x/ovm/simulation/genesis.go +++ b/x/ovm/simulation/genesis.go @@ -7,6 +7,7 @@ import ( //#nosec "github.com/cosmos/cosmos-sdk/types/module" + "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/simulation/genesis_test.go b/x/ovm/simulation/genesis_test.go index aeeeffc6..7bc43ee6 100644 --- a/x/ovm/simulation/genesis_test.go +++ b/x/ovm/simulation/genesis_test.go @@ -6,14 +6,15 @@ import ( "math/rand" "testing" + "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/sge-network/sge/x/ovm/simulation" - "github.com/stretchr/testify/require" + "github.com/sge-network/sge/x/ovm/simulation" "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/simulation/proposal.go b/x/ovm/simulation/proposal.go index 3f09d15e..3ee0e1ea 100644 --- a/x/ovm/simulation/proposal.go +++ b/x/ovm/simulation/proposal.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sge-network/sge/x/ovm/keeper" "github.com/sge-network/sge/x/ovm/types" ) diff --git a/x/ovm/types/errors.go b/x/ovm/types/errors.go index 18f1e1be..d25a99c6 100644 --- a/x/ovm/types/errors.go +++ b/x/ovm/types/errors.go @@ -3,7 +3,7 @@ package types // DONTCOVER import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrors "cosmossdk.io/errors" ) // x/ovm module sentinel errors diff --git a/x/ovm/types/expected_keepers.go b/x/ovm/types/expected_keepers.go index 6aa6e977..298564e1 100644 --- a/x/ovm/types/expected_keepers.go +++ b/x/ovm/types/expected_keepers.go @@ -2,6 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) diff --git a/x/ovm/types/export_test.go b/x/ovm/types/export_test.go index ab64243a..790dee47 100644 --- a/x/ovm/types/export_test.go +++ b/x/ovm/types/export_test.go @@ -7,7 +7,7 @@ type JwtTestToken = jwtTicket // NewTestJwtToken create new jwt token object // //nolint:revive -func NewTestJwtToken(header, payload string, signature string) *JwtTestToken { +func NewTestJwtToken(header, payload, signature string) *JwtTestToken { return &jwtTicket{ header: header, payload: payload, diff --git a/x/ovm/types/genesis_test.go b/x/ovm/types/genesis_test.go index a056839b..dee26256 100644 --- a/x/ovm/types/genesis_test.go +++ b/x/ovm/types/genesis_test.go @@ -4,9 +4,10 @@ import ( "testing" "time" - simappUtil "github.com/sge-network/sge/testutil/simapp" - "github.com/sge-network/sge/x/ovm/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/ovm/types" ) const ( @@ -14,7 +15,7 @@ const ( ) func TestGenesisState_Validate(t *testing.T) { - pubkeys := simappUtil.GenerateOvmPublicKeys(types.MaxPubKeysCount) + pubkeys := simapp.GenerateOvmPublicKeys(types.MaxPubKeysCount) var votes []*types.Vote for _, v := range pubkeys { diff --git a/x/ovm/types/key_vault.go b/x/ovm/types/key_vault.go index 4a5db308..36f2c9fc 100644 --- a/x/ovm/types/key_vault.go +++ b/x/ovm/types/key_vault.go @@ -3,8 +3,10 @@ package types import ( fmt "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/golang-jwt/jwt/v4" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/utils" ) diff --git a/x/ovm/types/key_vault_test.go b/x/ovm/types/key_vault_test.go index ff9262ce..0a643381 100644 --- a/x/ovm/types/key_vault_test.go +++ b/x/ovm/types/key_vault_test.go @@ -3,9 +3,10 @@ package types_test import ( "testing" - simappUtil "github.com/sge-network/sge/testutil/simapp" - "github.com/sge-network/sge/x/ovm/types" "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/ovm/types" ) func TestMajority(t *testing.T) { @@ -17,22 +18,22 @@ func TestMajority(t *testing.T) { }{ { name: "odd public keys", - publicKeys: simappUtil.GenerateOvmPublicKeys(5), + publicKeys: simapp.GenerateOvmPublicKeys(5), exp: 4, }, { name: "even public keys", - publicKeys: simappUtil.GenerateOvmPublicKeys(4), + publicKeys: simapp.GenerateOvmPublicKeys(4), exp: 3, }, { name: "large odd number", - publicKeys: simappUtil.GenerateOvmPublicKeys(51), + publicKeys: simapp.GenerateOvmPublicKeys(51), exp: 35, }, { name: "large even number", - publicKeys: simappUtil.GenerateOvmPublicKeys(50), + publicKeys: simapp.GenerateOvmPublicKeys(50), exp: 34, }, } diff --git a/x/ovm/types/message_pubkeys_proposal.go b/x/ovm/types/message_pubkeys_proposal.go index 74bb040f..1861d2d3 100644 --- a/x/ovm/types/message_pubkeys_proposal.go +++ b/x/ovm/types/message_pubkeys_proposal.go @@ -1,10 +1,12 @@ package types import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/sge-network/sge/utils" "github.com/spf13/cast" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" ) // typeMsgPubkeysChangeProposal is type of message MsgPubkeysChangeProposalRequest @@ -48,7 +50,7 @@ func (msg *MsgSubmitPubkeysChangeProposalRequest) GetSignBytes() []byte { func (msg *MsgSubmitPubkeysChangeProposalRequest) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) } return nil } diff --git a/x/ovm/types/message_pubkeys_proposal_test.go b/x/ovm/types/message_pubkeys_proposal_test.go index 9f6bdbc7..a4d57057 100644 --- a/x/ovm/types/message_pubkeys_proposal_test.go +++ b/x/ovm/types/message_pubkeys_proposal_test.go @@ -3,10 +3,12 @@ package types_test import ( "testing" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestMsgChangePubkeysListProposalValidateBasic(t *testing.T) { @@ -20,7 +22,7 @@ func TestMsgChangePubkeysListProposalValidateBasic(t *testing.T) { msg: types.MsgSubmitPubkeysChangeProposalRequest{ Creator: "invalid_address", }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "valid address", msg: types.MsgSubmitPubkeysChangeProposalRequest{ diff --git a/x/ovm/types/message_pubkeys_vote.go b/x/ovm/types/message_pubkeys_vote.go index 39dca7c4..fae5c013 100644 --- a/x/ovm/types/message_pubkeys_vote.go +++ b/x/ovm/types/message_pubkeys_vote.go @@ -1,10 +1,13 @@ package types import ( + "github.com/spf13/cast" + + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" - "github.com/spf13/cast" ) // typeMsgVotePubkeysChange is type of message MsgPubkeysChangeProposalRequest @@ -49,7 +52,7 @@ func (msg *MsgVotePubkeysChangeRequest) GetSignBytes() []byte { func (msg *MsgVotePubkeysChangeRequest) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) } return nil diff --git a/x/ovm/types/message_pubkeys_vote_test.go b/x/ovm/types/message_pubkeys_vote_test.go index 6fadca70..400e4a42 100644 --- a/x/ovm/types/message_pubkeys_vote_test.go +++ b/x/ovm/types/message_pubkeys_vote_test.go @@ -3,10 +3,12 @@ package types_test import ( "testing" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestMsgChangePubkeysVoteValidateBasic(t *testing.T) { @@ -21,7 +23,7 @@ func TestMsgChangePubkeysVoteValidateBasic(t *testing.T) { Creator: "invalid_address", VoterKeyIndex: 0, }, - err: sdkerrors.ErrInvalidAddress, + err: sdkerrtypes.ErrInvalidAddress, }, { name: "valid address", diff --git a/x/ovm/types/params.go b/x/ovm/types/params.go index 188cddfc..a33e4b8a 100644 --- a/x/ovm/types/params.go +++ b/x/ovm/types/params.go @@ -1,8 +1,9 @@ package types import ( + yaml "gopkg.in/yaml.v2" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "gopkg.in/yaml.v2" ) var _ paramtypes.ParamSet = (*Params)(nil) diff --git a/x/ovm/types/ticket.go b/x/ovm/types/ticket.go index b738977a..2b421533 100644 --- a/x/ovm/types/ticket.go +++ b/x/ovm/types/ticket.go @@ -3,8 +3,9 @@ package types import ( "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cast" + + sdk "github.com/cosmos/cosmos-sdk/types" ) // Ticket is the Interface of ticket. diff --git a/x/ovm/types/ticket_jwt.go b/x/ovm/types/ticket_jwt.go index 83ef5b22..365e92df 100644 --- a/x/ovm/types/ticket_jwt.go +++ b/x/ovm/types/ticket_jwt.go @@ -7,9 +7,11 @@ import ( "strings" gtime "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/golang-jwt/jwt/v4" + "github.com/tendermint/tendermint/types/time" + + sdk "github.com/cosmos/cosmos-sdk/types" ) // jwtTicket is the Ticket implementer. diff --git a/x/ovm/types/ticket_jwt_test.go b/x/ovm/types/ticket_jwt_test.go index 7400d8c2..08282f6c 100644 --- a/x/ovm/types/ticket_jwt_test.go +++ b/x/ovm/types/ticket_jwt_test.go @@ -10,9 +10,10 @@ import ( "time" "github.com/golang-jwt/jwt/v4" + "github.com/stretchr/testify/require" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/ovm/types" - "github.com/stretchr/testify/require" ) func TestVerifyWithKey(t *testing.T) { diff --git a/x/reward/client/cli/query.go b/x/reward/client/cli/query.go new file mode 100644 index 00000000..b4e10199 --- /dev/null +++ b/x/reward/client/cli/query.go @@ -0,0 +1,29 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/sge-network/sge/x/reward/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + // Group reward queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdListCampaign()) + cmd.AddCommand(CmdShowCampaign()) + + return cmd +} diff --git a/x/reward/client/cli/query_campaign.go b/x/reward/client/cli/query_campaign.go new file mode 100644 index 00000000..4737dd1f --- /dev/null +++ b/x/reward/client/cli/query_campaign.go @@ -0,0 +1,75 @@ +package cli + +import ( + "context" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + "github.com/sge-network/sge/x/reward/types" +) + +func CmdListCampaign() *cobra.Command { + cmd := &cobra.Command{ + Use: "list-campaign", + Short: "list all campaign", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryCampaignAllRequest{ + Pagination: pageReq, + } + + res, err := queryClient.CampaignAll(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddPaginationFlagsToCmd(cmd, cmd.Use) + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdShowCampaign() *cobra.Command { + cmd := &cobra.Command{ + Use: "show-campaign [index]", + Short: "shows a campaign", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + argUID := args[0] + + params := &types.QueryCampaignRequest{ + Uid: argUID, + } + + res, err := queryClient.Campaign(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/reward/client/cli/query_campaign_test.go b/x/reward/client/cli/query_campaign_test.go new file mode 100644 index 00000000..926b820d --- /dev/null +++ b/x/reward/client/cli/query_campaign_test.go @@ -0,0 +1,179 @@ +package cli_test + +import ( + "fmt" + "strconv" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + tmcli "github.com/tendermint/tendermint/libs/cli" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/client/flags" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + + "github.com/sge-network/sge/testutil/network" + "github.com/sge-network/sge/testutil/nullify" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/reward/client/cli" + "github.com/sge-network/sge/x/reward/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func networkWithCampaignObjects(t *testing.T, n int) (*network.Network, []types.Campaign) { + t.Helper() + cfg := network.DefaultConfig() + state := types.GenesisState{} + require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) + + for i := 0; i < n; i++ { + campaign := types.Campaign{ + UID: uuid.NewString(), + Creator: sample.AccAddress(), + FunderAddress: sample.AccAddress(), + StartTS: uint64(time.Now().Unix()), + EndTS: uint64(time.Now().Add(5 * time.Minute).Unix()), + RewardType: types.RewardType_REWARD_TYPE_AFFILIATION, + RewardDefs: []types.Definition{{ + RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE, + Amount: sdkmath.NewInt(100), + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN, + }}, + Pool: types.Pool{Spent: sdkmath.NewInt(100), Total: sdkmath.NewInt(1000)}, + } + + nullify.Fill(&campaign) + state.CampaignList = append(state.CampaignList, campaign) + } + buf, err := cfg.Codec.MarshalJSON(&state) + require.NoError(t, err) + cfg.GenesisState[types.ModuleName] = buf + return network.New(t, cfg), state.CampaignList +} + +func TestShowCampaign(t *testing.T) { + net, objs := networkWithCampaignObjects(t, 2) + + ctx := net.Validators[0].ClientCtx + common := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + for _, tc := range []struct { + desc string + idIndex string + + args []string + err error + obj types.Campaign + }{ + { + desc: "found", + idIndex: objs[0].UID, + + args: common, + obj: objs[0], + }, + { + desc: "not found", + idIndex: strconv.Itoa(100000), + + args: common, + err: status.Error(codes.NotFound, "not found"), + }, + } { + t.Run(tc.desc, func(t *testing.T) { + args := []string{ + tc.idIndex, + } + args = append(args, tc.args...) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowCampaign(), args) + if tc.err != nil { + stat, ok := status.FromError(tc.err) + require.True(t, ok) + require.ErrorIs(t, stat.Err(), tc.err) + } else { + require.NoError(t, err) + var resp types.QueryCampaignResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NotNil(t, resp.Campaign) + require.Equal(t, + nullify.Fill(&tc.obj), + nullify.Fill(&resp.Campaign), + ) + } + }) + } +} + +func TestListCampaign(t *testing.T) { + net, objs := networkWithCampaignObjects(t, 5) + + ctx := net.Validators[0].ClientCtx + request := func(next []byte, offset, limit uint64, total bool) []string { + args := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + if next == nil { + args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset)) + } else { + args = append(args, fmt.Sprintf("--%s=%s", flags.FlagPageKey, next)) + } + args = append(args, fmt.Sprintf("--%s=%d", flags.FlagLimit, limit)) + if total { + args = append(args, fmt.Sprintf("--%s", flags.FlagCountTotal)) + } + return args + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < len(objs); i += step { + args := request(nil, uint64(i), uint64(step), false) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListCampaign(), args) + require.NoError(t, err) + var resp types.QueryCampaignAllResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.LessOrEqual(t, len(resp.Campaign), step) + require.Subset(t, + nullify.Fill(objs), + nullify.Fill(resp.Campaign), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < len(objs); i += step { + args := request(next, 0, uint64(step), false) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListCampaign(), args) + require.NoError(t, err) + var resp types.QueryCampaignAllResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.LessOrEqual(t, len(resp.Campaign), step) + require.Subset(t, + nullify.Fill(objs), + nullify.Fill(resp.Campaign), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + args := request(nil, 0, uint64(len(objs)), true) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListCampaign(), args) + require.NoError(t, err) + var resp types.QueryCampaignAllResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, err) + require.Equal(t, len(objs), int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(objs), + nullify.Fill(resp.Campaign), + ) + }) +} diff --git a/x/reward/client/cli/query_params.go b/x/reward/client/cli/query_params.go new file mode 100644 index 00000000..6edd3325 --- /dev/null +++ b/x/reward/client/cli/query_params.go @@ -0,0 +1,36 @@ +package cli + +import ( + "context" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + "github.com/sge-network/sge/x/reward/types" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/reward/client/cli/tx.go b/x/reward/client/cli/tx.go new file mode 100644 index 00000000..ed281064 --- /dev/null +++ b/x/reward/client/cli/tx.go @@ -0,0 +1,31 @@ +package cli + +import ( + "fmt" + "time" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/sge-network/sge/x/reward/types" +) + +var DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds()) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdCreateCampaign()) + cmd.AddCommand(CmdUpdateCampaign()) + cmd.AddCommand(CmdApplyReward()) + + return cmd +} diff --git a/x/reward/client/cli/tx_campaign.go b/x/reward/client/cli/tx_campaign.go new file mode 100644 index 00000000..61a484dd --- /dev/null +++ b/x/reward/client/cli/tx_campaign.go @@ -0,0 +1,79 @@ +package cli + +import ( + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + + "github.com/sge-network/sge/x/reward/types" +) + +func CmdCreateCampaign() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-campaign [uid] [ticket]", + Short: "Create a new campaign", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Get indexes + argUID := args[0] + + // Get value arguments + argTicket := args[1] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgCreateCampaign( + clientCtx.GetFromAddress().String(), + argUID, + argTicket, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func CmdUpdateCampaign() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-campaign [uid] [ticket]", + Short: "Update a campaign", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Get indexes + argUID := args[0] + + // Get value arguments + argTicket := args[1] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgUpdateCampaign( + clientCtx.GetFromAddress().String(), + argUID, + argTicket, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/reward/client/cli/tx_reward.go b/x/reward/client/cli/tx_reward.go new file mode 100644 index 00000000..bda3f399 --- /dev/null +++ b/x/reward/client/cli/tx_reward.go @@ -0,0 +1,45 @@ +package cli + +import ( + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + + "github.com/sge-network/sge/x/reward/types" +) + +func CmdApplyReward() *cobra.Command { + cmd := &cobra.Command{ + Use: "apply [campaign uid] [ticket]", + Short: "Apply a new reward", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Get indexes + argCampaignUID := args[0] + + // Get value arguments + argTicket := args[1] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgApplyReward( + clientCtx.GetFromAddress().String(), + argCampaignUID, + argTicket, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/reward/genesis.go b/x/reward/genesis.go new file mode 100644 index 00000000..c89a638f --- /dev/null +++ b/x/reward/genesis.go @@ -0,0 +1,27 @@ +package reward + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/reward/keeper" + "github.com/sge-network/sge/x/reward/types" +) + +// InitGenesis initializes the module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + // Set all the campaign + for _, elem := range genState.CampaignList { + k.SetCampaign(ctx, elem) + } + k.SetParams(ctx, genState.Params) +} + +// ExportGenesis returns the module's exported genesis +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) + + genesis.CampaignList = k.GetAllCampaign(ctx) + + return genesis +} diff --git a/x/reward/genesis_test.go b/x/reward/genesis_test.go new file mode 100644 index 00000000..f5475ea2 --- /dev/null +++ b/x/reward/genesis_test.go @@ -0,0 +1,39 @@ +package reward_test + +import ( + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/nullify" + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/reward" + "github.com/sge-network/sge/x/reward/types" +) + +func TestGenesis(t *testing.T) { + genesisState := types.GenesisState{ + Params: types.DefaultParams(), + + CampaignList: []types.Campaign{ + { + UID: uuid.NewString(), + }, + { + UID: uuid.NewString(), + }, + }, + } + + tApp, ctx, err := simapp.GetTestObjects() + require.NoError(t, err) + reward.InitGenesis(ctx, *tApp.RewardKeeper, genesisState) + got := reward.ExportGenesis(ctx, *tApp.RewardKeeper) + require.NotNil(t, got) + + nullify.Fill(&genesisState) + nullify.Fill(got) + + require.ElementsMatch(t, genesisState.CampaignList, got.CampaignList) +} diff --git a/x/reward/keeper/campaign.go b/x/reward/keeper/campaign.go new file mode 100644 index 00000000..e653ad8f --- /dev/null +++ b/x/reward/keeper/campaign.go @@ -0,0 +1,69 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/reward/types" +) + +// SetCampaign set a specific campaign in the store from its index +func (k Keeper) SetCampaign(ctx sdk.Context, campaign types.Campaign) { + store := k.getCampaignStore(ctx) + b := k.cdc.MustMarshal(&campaign) + store.Set(types.GetCampaignKey( + campaign.UID, + ), b) +} + +// GetCampaign returns a campaign from its index +func (k Keeper) GetCampaign( + ctx sdk.Context, + index string, +) (val types.Campaign, found bool) { + store := k.getCampaignStore(ctx) + + b := store.Get(types.GetCampaignKey( + index, + )) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// RemoveCampaign removes a campaign from the store +func (k Keeper) RemoveCampaign( + ctx sdk.Context, + index string, +) { + store := k.getCampaignStore(ctx) + store.Delete(types.GetCampaignKey( + index, + )) +} + +// GetAllCampaign returns all campaign +func (k Keeper) GetAllCampaign(ctx sdk.Context) (list []types.Campaign) { + store := k.getCampaignStore(ctx) + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.Campaign + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return +} + +func (k Keeper) UpdateCampaignPool(ctx sdk.Context, campaign types.Campaign, distributions []types.Distribution) { + for _, d := range distributions { + campaign.Pool.Spent = campaign.Pool.Spent.Add(d.Allocation.Amount) + } + + k.SetCampaign(ctx, campaign) +} diff --git a/x/reward/keeper/campaign_test.go b/x/reward/keeper/campaign_test.go new file mode 100644 index 00000000..b007858a --- /dev/null +++ b/x/reward/keeper/campaign_test.go @@ -0,0 +1,80 @@ +package keeper_test + +import ( + "strconv" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/nullify" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/reward/keeper" + "github.com/sge-network/sge/x/reward/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func createNCampaign(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Campaign { + items := make([]types.Campaign, n) + for i := range items { + items[i].UID = uuid.NewString() + items[i].Creator = sample.AccAddress() + items[i].FunderAddress = sample.AccAddress() + items[i].StartTS = uint64(time.Now().Unix()) + items[i].EndTS = uint64(time.Now().Add(5 * time.Minute).Unix()) + items[i].RewardType = types.RewardType_REWARD_TYPE_REFERRAL + items[i].RewardDefs = []types.Definition{{ + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB, + Amount: sdkmath.NewInt(100), + }} + items[i].Pool = types.Pool{Spent: sdk.ZeroInt(), Total: sdkmath.NewInt(100)} + + keeper.SetCampaign(ctx, items[i]) + } + return items +} + +func TestCampaignGet(t *testing.T) { + k, ctx := setupKeeper(t) + items := createNCampaign(k, ctx, 10) + for _, item := range items { + rst, found := k.GetCampaign(ctx, + item.UID, + ) + require.True(t, found) + require.Equal(t, + nullify.Fill(item), + nullify.Fill(rst), + ) + } +} + +func TestCampaignRemove(t *testing.T) { + k, ctx := setupKeeper(t) + items := createNCampaign(k, ctx, 10) + for _, item := range items { + k.RemoveCampaign(ctx, + item.UID, + ) + _, found := k.GetCampaign(ctx, + item.UID, + ) + require.False(t, found) + } +} + +func TestCampaignGetAll(t *testing.T) { + k, ctx := setupKeeper(t) + items := createNCampaign(k, ctx, 10) + require.ElementsMatch(t, + nullify.Fill(items), + nullify.Fill(k.GetAllCampaign(ctx)), + ) +} diff --git a/x/reward/keeper/distribution.go b/x/reward/keeper/distribution.go new file mode 100644 index 00000000..3fd9bf0b --- /dev/null +++ b/x/reward/keeper/distribution.go @@ -0,0 +1,36 @@ +package keeper + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/reward/types" + subaccounttypes "github.com/sge-network/sge/x/subaccount/types" +) + +// DistributeRewards distributes the rewards according to the input distribution list. +func (k Keeper) DistributeRewards(ctx sdk.Context, funderAddr string, distributions []types.Distribution) error { + for _, d := range distributions { + switch d.Allocation.RecAccType { + case types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN: + return k.modFunder.Refund( + types.RewardPoolFunder{}, ctx, + sdk.MustAccAddressFromBech32(d.AccAddr), + d.Allocation.Amount, + ) + case types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB: + if _, err := k.subaccountKeeper.TopUp(ctx, funderAddr, d.AccAddr, + []subaccounttypes.LockedBalance{ + { + UnlockTS: d.Allocation.UnlockTS, + Amount: d.Allocation.Amount, + }, + }); err != nil { + return sdkerrors.Wrapf(types.ErrSubAccRewardTopUp, "owner address %s, %s", d.AccAddr, err) + } + default: + return types.ErrUnknownAccType + } + } + return nil +} diff --git a/x/reward/keeper/export_test.go b/x/reward/keeper/export_test.go new file mode 100644 index 00000000..d22f197e --- /dev/null +++ b/x/reward/keeper/export_test.go @@ -0,0 +1,5 @@ +package keeper + +// KeeperTest is a wrapper object for the keeper, It is being used +// to export unexported methods of the keeper +type KeeperTest = Keeper diff --git a/x/reward/keeper/keeper.go b/x/reward/keeper/keeper.go new file mode 100644 index 00000000..df2e5bc3 --- /dev/null +++ b/x/reward/keeper/keeper.go @@ -0,0 +1,72 @@ +package keeper + +import ( + "fmt" + + "github.com/tendermint/tendermint/libs/log" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + "github.com/sge-network/sge/utils" + "github.com/sge-network/sge/x/reward/types" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + memKey storetypes.StoreKey + paramstore paramtypes.Subspace + modFunder *utils.ModuleAccFunder + authzKeeper types.AuthzKeeper + betKeeper types.BetKeeper + ovmKeeper types.OVMKeeper + subaccountKeeper types.SubAccountKeeper + } +) + +// SdkExpectedKeepers contains expected keepers parameter needed by NewKeeper +type SdkExpectedKeepers struct { + AuthzKeeper types.AuthzKeeper + BankKeeper types.BankKeeper + AccountKeeper types.AccountKeeper +} + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey, + memKey storetypes.StoreKey, + ps paramtypes.Subspace, + betKeeper types.BetKeeper, + ovmKeeper types.OVMKeeper, + subaccountKeeper types.SubAccountKeeper, + expectedKeepers SdkExpectedKeepers, +) *Keeper { + // set KeyTable if it has not already been set + if !ps.HasKeyTable() { + ps = ps.WithKeyTable(types.ParamKeyTable()) + } + + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + memKey: memKey, + paramstore: ps, + modFunder: utils.NewModuleAccFunder( + expectedKeepers.BankKeeper, + expectedKeepers.AccountKeeper, + types.ErrorBank, + ), + betKeeper: betKeeper, + ovmKeeper: ovmKeeper, + subaccountKeeper: subaccountKeeper, + authzKeeper: expectedKeepers.AuthzKeeper, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} diff --git a/x/reward/keeper/keeper_test.go b/x/reward/keeper/keeper_test.go new file mode 100644 index 00000000..02f9e83e --- /dev/null +++ b/x/reward/keeper/keeper_test.go @@ -0,0 +1,25 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/reward/keeper" +) + +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.KeeperTest, sdk.Context) { + tApp, ctx, err := simapp.GetTestObjects() + require.NoError(t, err) + + return tApp, tApp.RewardKeeper, ctx +} + +func setupKeeper(t testing.TB) (*keeper.KeeperTest, sdk.Context) { + _, k, ctx := setupKeeperAndApp(t) + + return k, ctx +} diff --git a/x/reward/keeper/msg_server.go b/x/reward/keeper/msg_server.go new file mode 100644 index 00000000..ba524e70 --- /dev/null +++ b/x/reward/keeper/msg_server.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "github.com/sge-network/sge/x/reward/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go new file mode 100644 index 00000000..2754ce71 --- /dev/null +++ b/x/reward/keeper/msg_server_campaign.go @@ -0,0 +1,108 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" + "github.com/sge-network/sge/x/reward/types" +) + +func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCampaign) (*types.MsgCreateCampaignResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Check if the value already exists + _, isFound := k.GetCampaign(ctx, msg.Uid) + if isFound { + return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "index already set") + } + + var payload types.CreateCampaignPayload + if err := k.ovmKeeper.VerifyTicketUnmarshal(goCtx, msg.Ticket, &payload); err != nil { + return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + } + + if msg.Creator != payload.FunderAddress { + if err := utils.ValidateMsgAuthorization(k.authzKeeper, ctx, msg.Creator, payload.FunderAddress, msg, + types.ErrAuthorizationNotFound, types.ErrAuthorizationNotAccepted); err != nil { + return nil, err + } + } + + if err := payload.Validate(uint64(ctx.BlockTime().Unix())); err != nil { + return nil, err + } + + campaign := types.NewCampaign( + msg.Creator, payload.FunderAddress, msg.Uid, + payload.StartTs, payload.EndTs, + payload.Type, + payload.RewardDefs, + types.NewPool(payload.PoolAmount), + ) + + rewardFactory, err := campaign.GetRewardsFactory() + if err != nil { + return nil, err + } + + for _, d := range campaign.RewardDefs { + if err := d.ValidateBasic(uint64(ctx.BlockTime().Unix())); err != nil { + return nil, err + } + } + + err = rewardFactory.VaidateDefinitions(campaign) + if err != nil { + return nil, err + } + + // transfer the pool amount to the reward pool module account + if err := k.modFunder.Fund( + types.RewardPoolFunder{}, ctx, + sdk.MustAccAddressFromBech32(payload.FunderAddress), + payload.PoolAmount, + ); err != nil { + return nil, sdkerrors.Wrapf(types.ErrInFundingCampaignPool, "%s", err) + } + + k.SetCampaign(ctx, campaign) + + return &types.MsgCreateCampaignResponse{}, nil +} + +func (k msgServer) UpdateCampaign(goCtx context.Context, msg *types.MsgUpdateCampaign) (*types.MsgUpdateCampaignResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + var payload types.UpdateCampaignPayload + if err := k.ovmKeeper.VerifyTicketUnmarshal(goCtx, msg.Ticket, &payload); err != nil { + return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + } + + if err := payload.Validate(uint64(ctx.BlockTime().Unix())); err != nil { + return nil, err + } + + // Check if the value exists + valFound, isFound := k.GetCampaign(ctx, msg.Uid) + if !isFound { + return nil, sdkerrors.Wrap(sdkerrtypes.ErrKeyNotFound, "index not set") + } + + // Checks if the the msg creator is the same as the current owner + if msg.Creator != valFound.FunderAddress { + if err := utils.ValidateMsgAuthorization(k.authzKeeper, ctx, msg.Creator, valFound.FunderAddress, msg, + types.ErrAuthorizationNotFound, types.ErrAuthorizationNotAccepted); err != nil { + return nil, err + } + } + + valFound.EndTS = payload.EndTs + + k.SetCampaign(ctx, valFound) + + return &types.MsgUpdateCampaignResponse{}, nil +} diff --git a/x/reward/keeper/msg_server_campaign_test.go b/x/reward/keeper/msg_server_campaign_test.go new file mode 100644 index 00000000..402eaa23 --- /dev/null +++ b/x/reward/keeper/msg_server_campaign_test.go @@ -0,0 +1,159 @@ +package keeper_test + +import ( + "strconv" + "testing" + "time" + + "github.com/golang-jwt/jwt" + "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/reward/keeper" + "github.com/sge-network/sge/x/reward/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func TestCampaignMsgServerCreate(t *testing.T) { + k, ctx := setupKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + creator := simapp.TestParamUsers["user1"].Address.String() + for i := 0; i < 5; i++ { + ticketClaim := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "funder_address": creator, + "start_ts": time.Now().Unix(), + "end_ts": time.Now().Add(5 * time.Minute).Unix(), + "type": types.RewardType_REWARD_TYPE_SIGNUP, + "reward_defs": []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB, + Amount: sdkmath.NewInt(100), + UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + }, + }, + "pool_amount": sdkmath.NewInt(1000000), + } + ticket, err := simapp.CreateJwtTicket(ticketClaim) + require.Nil(t, err) + + expected := &types.MsgCreateCampaign{ + Creator: creator, + Uid: uuid.NewString(), + Ticket: ticket, + } + _, err = srv.CreateCampaign(wctx, expected) + require.NoError(t, err) + rst, found := k.GetCampaign(ctx, + expected.Uid, + ) + require.True(t, found) + require.Equal(t, expected.Creator, rst.Creator) + } +} + +func TestCampaignMsgServerUpdate(t *testing.T) { + expectedUID := uuid.NewString() + + for _, tc := range []struct { + desc string + request *types.MsgUpdateCampaign + err error + }{ + { + desc: "Completed", + request: &types.MsgUpdateCampaign{ + Uid: expectedUID, + }, + }, + { + desc: "Unauthorized", + request: &types.MsgUpdateCampaign{ + Creator: sample.AccAddress(), + Uid: expectedUID, + }, + err: types.ErrAuthorizationNotFound, + }, + { + desc: "KeyNotFound", + request: &types.MsgUpdateCampaign{ + Uid: uuid.NewString(), + }, + err: sdkerrtypes.ErrKeyNotFound, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + k, ctx := setupKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + + creator := simapp.TestParamUsers["user1"].Address.String() + + ticketClaim := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "funder_address": creator, + "start_ts": time.Now().Unix(), + "end_ts": time.Now().Add(5 * time.Minute).Unix(), + "type": types.RewardType_REWARD_TYPE_SIGNUP, + "reward_defs": []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB, + Amount: sdkmath.NewInt(100), + UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + }, + }, + "pool_amount": sdkmath.NewInt(10000), + } + ticket, err := simapp.CreateJwtTicket(ticketClaim) + require.Nil(t, err) + + expected := &types.MsgCreateCampaign{ + Creator: creator, + Uid: expectedUID, + Ticket: ticket, + } + _, err = srv.CreateCampaign(wctx, expected) + require.NoError(t, err) + + ticketClaimUpdate := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "end_ts": time.Now().Add(5 * time.Minute).Unix(), + } + ticketUpdate, err := simapp.CreateJwtTicket(ticketClaimUpdate) + require.Nil(t, err) + tc.request.Ticket = ticketUpdate + + if tc.request.Creator == "" { + tc.request.Creator = creator + } + + _, err = srv.UpdateCampaign(wctx, tc.request) + if tc.err != nil { + require.ErrorIs(t, err, tc.err) + } else { + require.NoError(t, err) + rst, found := k.GetCampaign(ctx, + expected.Uid, + ) + require.True(t, found) + require.Equal(t, expected.Creator, rst.Creator) + } + }) + } +} diff --git a/x/reward/keeper/msg_server_reward.go b/x/reward/keeper/msg_server_reward.go new file mode 100644 index 00000000..de9a732b --- /dev/null +++ b/x/reward/keeper/msg_server_reward.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/x/reward/types" +) + +func (k msgServer) ApplyReward(goCtx context.Context, msg *types.MsgApplyReward) (*types.MsgApplyRewardResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + campaign, isFound := k.GetCampaign(ctx, msg.CampaignUid) + if !isFound { + return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "campaign with the uid not found") + } + + if err := campaign.CheckExpiration(uint64(ctx.BlockTime().Unix())); err != nil { + return nil, err + } + + rewardFactory, err := campaign.GetRewardsFactory() + if err != nil { + return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "failed to retrieve reward factory") + } + + distribution, err := rewardFactory.CalculateDistributions(goCtx, ctx, + types.RewardFactoryKeepers{ + OVMKeeper: k.ovmKeeper, + BetKeeper: k.betKeeper, + }, + campaign.RewardDefs, msg.Ticket) + if err != nil { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "distribution calculation failed %s", err) + } + + if err := campaign.CheckPoolBalance(distribution); err != nil { + return nil, types.ErrInsufficientPoolBalance + } + + if err := k.DistributeRewards(ctx, campaign.FunderAddress, distribution); err != nil { + return nil, sdkerrors.Wrapf(types.ErrInDistributionOfRewards, "%s", err) + } + + k.UpdateCampaignPool(ctx, campaign, distribution) + + return &types.MsgApplyRewardResponse{}, nil +} diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go new file mode 100644 index 00000000..c6eb1fed --- /dev/null +++ b/x/reward/keeper/msg_server_reward_test.go @@ -0,0 +1,580 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/golang-jwt/jwt" + "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/testutil/simapp" + bettypes "github.com/sge-network/sge/x/bet/types" + "github.com/sge-network/sge/x/reward/keeper" + "github.com/sge-network/sge/x/reward/types" + subaccounttypes "github.com/sge-network/sge/x/subaccount/types" +) + +func getDefaultClaim(creator string) jwt.MapClaims { + return jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "funder_address": creator, + "start_ts": time.Now().Unix(), + "end_ts": time.Now().Add(5 * time.Minute).Unix(), + "pool_amount": sdkmath.NewInt(1000000), + } +} + +func createCampaign(t *testing.T, k *keeper.Keeper, srv types.MsgServer, ctx sdk.Context, + funder string, claims jwt.MapClaims, +) string { + ticket, err := simapp.CreateJwtTicket(claims) + require.Nil(t, err) + + expected := &types.MsgCreateCampaign{ + Creator: funder, + Uid: uuid.NewString(), + Ticket: ticket, + } + _, err = srv.CreateCampaign(sdk.WrapSDKContext(ctx), expected) + require.NoError(t, err) + rst, found := k.GetCampaign(ctx, + expected.Uid, + ) + require.True(t, found) + require.Equal(t, expected.Creator, rst.Creator) + return expected.Uid +} + +func TestMsgApplySignupReward(t *testing.T) { + tApp, k, ctx := setupKeeperAndApp(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + + funder := simapp.TestParamUsers["user1"].Address.String() + receiverAddr := simapp.TestParamUsers["user2"].Address.String() + + _, err := tApp.SubaccountKeeper.CreateSubAccount(ctx, receiverAddr, receiverAddr, []subaccounttypes.LockedBalance{ + { + Amount: sdk.ZeroInt(), + UnlockTS: uint64(ctx.BlockTime().Add(60 * time.Minute).Unix()), + }, + }) + require.NoError(t, err) + + campClaims := getDefaultClaim(funder) + campClaims["type"] = types.RewardType_REWARD_TYPE_SIGNUP + campClaims["reward_defs"] = []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB, + Amount: sdkmath.NewInt(100), + UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + }, + } + + campUID := createCampaign(t, k, srv, ctx, funder, campClaims) + + for _, tc := range []struct { + desc string + claims jwt.MapClaims + err error + }{ + { + desc: "invalid ticket", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": "invalid", + }, + err: types.ErrInTicketVerification, + }, + { + desc: "invalid receiver type", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE, + Addr: receiverAddr, + }, + }, + err: types.ErrAccReceiverTypeNotFound, + }, + { + desc: "valid", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + Addr: receiverAddr, + }, + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + ticket, err := simapp.CreateJwtTicket(tc.claims) + require.Nil(t, err) + reward := &types.MsgApplyReward{ + Creator: funder, + CampaignUid: campUID, + Ticket: ticket, + } + _, err = srv.ApplyReward(wctx, reward) + if tc.err != nil { + require.ErrorContains(t, err, tc.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +} + +func TestMsgApplyAffiliationReward(t *testing.T) { + k, ctx := setupKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + + funder := simapp.TestParamUsers["user1"].Address.String() + receiverAddr := simapp.TestParamUsers["user2"].Address.String() + + campClaims := getDefaultClaim(funder) + campClaims["type"] = types.RewardType_REWARD_TYPE_AFFILIATION + campClaims["reward_defs"] = []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN, + Amount: sdkmath.NewInt(100), + UnlockTS: 0, + }, + } + + campUID := createCampaign(t, k, srv, ctx, funder, campClaims) + + for _, tc := range []struct { + desc string + claims jwt.MapClaims + err error + }{ + { + desc: "invalid ticket", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": "invalid", + }, + err: types.ErrInTicketVerification, + }, + { + desc: "invalid receiver type", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE, + Addr: receiverAddr, + }, + }, + err: types.ErrAccReceiverTypeNotFound, + }, + { + desc: "valid", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + Addr: receiverAddr, + }, + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + ticket, err := simapp.CreateJwtTicket(tc.claims) + require.Nil(t, err) + reward := &types.MsgApplyReward{ + Creator: funder, + CampaignUid: campUID, + Ticket: ticket, + } + _, err = srv.ApplyReward(wctx, reward) + if tc.err != nil { + require.ErrorContains(t, err, tc.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +} + +func TestMsgApplyReferralReward(t *testing.T) { + tApp, k, ctx := setupKeeperAndApp(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + + funder := simapp.TestParamUsers["user1"].Address.String() + referrerAddr := simapp.TestParamUsers["user2"].Address.String() + referreeAddr := simapp.TestParamUsers["user3"].Address.String() + + _, err := tApp.SubaccountKeeper.CreateSubAccount(ctx, referrerAddr, referrerAddr, []subaccounttypes.LockedBalance{ + { + Amount: sdk.ZeroInt(), + UnlockTS: uint64(ctx.BlockTime().Add(60 * time.Minute).Unix()), + }, + }) + require.NoError(t, err) + + _, err = tApp.SubaccountKeeper.CreateSubAccount(ctx, referreeAddr, referreeAddr, []subaccounttypes.LockedBalance{ + { + Amount: sdk.ZeroInt(), + UnlockTS: uint64(ctx.BlockTime().Add(60 * time.Minute).Unix()), + }, + }) + require.NoError(t, err) + + campClaims := getDefaultClaim(funder) + campClaims["type"] = types.RewardType_REWARD_TYPE_REFERRAL + campClaims["reward_defs"] = []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB, + Amount: sdkmath.NewInt(100), + UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + }, + { + RecType: types.ReceiverType_RECEIVER_TYPE_REFERRER, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB, + Amount: sdkmath.NewInt(150), + UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + }, + } + + campUID := createCampaign(t, k, srv, ctx, funder, campClaims) + + for _, tc := range []struct { + desc string + claims jwt.MapClaims + err error + }{ + { + desc: "invalid ticket", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receivers": "invalid", + }, + err: types.ErrInTicketVerification, + }, + { + desc: "invalid receiver type", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receivers": []types.Receiver{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + Addr: referrerAddr, + }, + { + RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE, + Addr: referreeAddr, + }, + }, + }, + err: types.ErrAccReceiverTypeNotFound, + }, + { + desc: "valid", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receivers": []types.Receiver{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_REFERRER, + Addr: referrerAddr, + }, + { + RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE, + Addr: referreeAddr, + }, + }, + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + ticket, err := simapp.CreateJwtTicket(tc.claims) + require.Nil(t, err) + reward := &types.MsgApplyReward{ + Creator: funder, + CampaignUid: campUID, + Ticket: ticket, + } + _, err = srv.ApplyReward(wctx, reward) + if tc.err != nil { + require.ErrorContains(t, err, tc.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +} + +func TestMsgApplyNoLossBetsReward(t *testing.T) { + tApp, k, ctx := setupKeeperAndApp(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + + funder := simapp.TestParamUsers["user1"].Address.String() + receiverAddr := simapp.TestParamUsers["user2"].Address.String() + + campClaims := getDefaultClaim(funder) + campClaims["type"] = types.RewardType_REWARD_TYPE_NOLOSS_BETS + campClaims["reward_defs"] = []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN, + Amount: sdkmath.NewInt(100), + UnlockTS: 0, + }, + } + + betUIDs := []string{} + for i := 1; i <= 10; i++ { + betUID := uuid.NewString() + betUIDs = append(betUIDs, betUID) + + tApp.BetKeeper.SetBet(ctx, bettypes.Bet{ + Creator: receiverAddr, + UID: betUID, + Result: bettypes.Bet_RESULT_LOST, + }, uint64(i)) + } + + campUID := createCampaign(t, k, srv, ctx, funder, campClaims) + + for _, tc := range []struct { + desc string + claims jwt.MapClaims + err error + }{ + { + desc: "invalid ticket", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": "invalid", + }, + err: types.ErrInTicketVerification, + }, + { + desc: "invalid receiver type", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE, + Addr: receiverAddr, + }, + "bet_uids": betUIDs, + }, + err: types.ErrAccReceiverTypeNotFound, + }, + { + desc: "valid", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + Addr: receiverAddr, + }, + "bet_uids": betUIDs, + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + ticket, err := simapp.CreateJwtTicket(tc.claims) + require.Nil(t, err) + reward := &types.MsgApplyReward{ + Creator: funder, + CampaignUid: campUID, + Ticket: ticket, + } + _, err = srv.ApplyReward(wctx, reward) + if tc.err != nil { + require.ErrorContains(t, err, tc.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +} + +func TestMsgApplySignupRewardSubAcc(t *testing.T) { + tApp, k, ctx := setupKeeperAndApp(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + + funder := simapp.TestParamUsers["user1"].Address.String() + receiverAddr := simapp.TestParamUsers["user2"].Address.String() + + campClaims := getDefaultClaim(funder) + campClaims["type"] = types.RewardType_REWARD_TYPE_SIGNUP + campClaims["reward_defs"] = []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB, + Amount: sdkmath.NewInt(100), + UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + }, + } + + campUID := createCampaign(t, k, srv, ctx, funder, campClaims) + + _, err := tApp.SubaccountKeeper.CreateSubAccount(ctx, receiverAddr, receiverAddr, []subaccounttypes.LockedBalance{ + { + Amount: sdk.ZeroInt(), + UnlockTS: uint64(ctx.BlockTime().Add(60 * time.Minute).Unix()), + }, + }) + require.NoError(t, err) + + for _, tc := range []struct { + desc string + claims jwt.MapClaims + err error + }{ + { + desc: "invalid ticket", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": "invalid", + }, + err: types.ErrInTicketVerification, + }, + { + desc: "invalid receiver type", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_REFEREE, + Addr: receiverAddr, + }, + }, + err: types.ErrAccReceiverTypeNotFound, + }, + { + desc: "subaccount not exists", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + Addr: sample.AccAddress(), + }, + }, + err: types.ErrSubAccRewardTopUp, + }, + { + desc: "valid", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + Addr: receiverAddr, + }, + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + ticket, err := simapp.CreateJwtTicket(tc.claims) + require.Nil(t, err) + reward := &types.MsgApplyReward{ + Creator: funder, + CampaignUid: campUID, + Ticket: ticket, + } + _, err = srv.ApplyReward(wctx, reward) + if tc.err != nil { + require.ErrorContains(t, err, tc.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +} + +func TestMsgApplySubAccFunds(t *testing.T) { + tApp, k, ctx := setupKeeperAndApp(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + + funder := simapp.TestParamUsers["user1"].Address.String() + receiverAddr := simapp.TestParamUsers["user2"].Address.String() + + rewardAmount := int64(100) + + campClaims := getDefaultClaim(funder) + campClaims["type"] = types.RewardType_REWARD_TYPE_SIGNUP + campClaims["reward_defs"] = []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB, + Amount: sdkmath.NewInt(rewardAmount), + UnlockTS: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + }, + } + + campUID := createCampaign(t, k, srv, ctx, funder, campClaims) + + _, err := tApp.SubaccountKeeper.CreateSubAccount(ctx, receiverAddr, receiverAddr, []subaccounttypes.LockedBalance{ + { + Amount: sdk.ZeroInt(), + UnlockTS: uint64(ctx.BlockTime().Add(60 * time.Minute).Unix()), + }, + }) + require.NoError(t, err) + + claims := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "receiver": types.Receiver{ + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + Addr: receiverAddr, + }, + } + + ticket, err := simapp.CreateJwtTicket(claims) + require.Nil(t, err) + + reward := &types.MsgApplyReward{ + Creator: funder, + CampaignUid: campUID, + Ticket: ticket, + } + _, err = srv.ApplyReward(wctx, reward) + require.NoError(t, err) + + subAccAddr, found := tApp.SubaccountKeeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(receiverAddr)) + require.True(t, found) + + balance, found := tApp.SubaccountKeeper.GetBalance(ctx, subAccAddr) + require.True(t, found) + + require.Equal(t, rewardAmount, balance.DepositedAmount.Int64()) +} diff --git a/x/reward/keeper/params.go b/x/reward/keeper/params.go new file mode 100644 index 00000000..16f132a7 --- /dev/null +++ b/x/reward/keeper/params.go @@ -0,0 +1,17 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/reward/types" +) + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams() +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramstore.SetParamSet(ctx, ¶ms) +} diff --git a/x/reward/keeper/query.go b/x/reward/keeper/query.go new file mode 100644 index 00000000..199fba49 --- /dev/null +++ b/x/reward/keeper/query.go @@ -0,0 +1,7 @@ +package keeper + +import ( + "github.com/sge-network/sge/x/reward/types" +) + +var _ types.QueryServer = Keeper{} diff --git a/x/reward/keeper/query_campaign.go b/x/reward/keeper/query_campaign.go new file mode 100644 index 00000000..5ab0f4d3 --- /dev/null +++ b/x/reward/keeper/query_campaign.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/x/reward/types" +) + +func (k Keeper) CampaignAll(goCtx context.Context, req *types.QueryCampaignAllRequest) (*types.QueryCampaignAllResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + var campaigns []types.Campaign + ctx := sdk.UnwrapSDKContext(goCtx) + + store := ctx.KVStore(k.storeKey) + campaignStore := prefix.NewStore(store, types.CampaignKeyPrefix) + + pageRes, err := query.Paginate(campaignStore, req.Pagination, func(key []byte, value []byte) error { + var campaign types.Campaign + if err := k.cdc.Unmarshal(value, &campaign); err != nil { + return err + } + + campaigns = append(campaigns, campaign) + return nil + }) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryCampaignAllResponse{Campaign: campaigns, Pagination: pageRes}, nil +} + +func (k Keeper) Campaign(goCtx context.Context, req *types.QueryCampaignRequest) (*types.QueryCampaignResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(goCtx) + + val, found := k.GetCampaign( + ctx, + req.Uid, + ) + if !found { + return nil, status.Error(codes.NotFound, "not found") + } + + return &types.QueryCampaignResponse{Campaign: val}, nil +} diff --git a/x/reward/keeper/query_campaign_test.go b/x/reward/keeper/query_campaign_test.go new file mode 100644 index 00000000..06bc8d66 --- /dev/null +++ b/x/reward/keeper/query_campaign_test.go @@ -0,0 +1,126 @@ +package keeper_test + +import ( + "strconv" + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + + "github.com/sge-network/sge/testutil/nullify" + "github.com/sge-network/sge/x/reward/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func TestCampaignQuerySingle(t *testing.T) { + k, ctx := setupKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + msgs := createNCampaign(k, ctx, 2) + for _, tc := range []struct { + desc string + request *types.QueryCampaignRequest + response *types.QueryCampaignResponse + err error + }{ + { + desc: "First", + request: &types.QueryCampaignRequest{ + Uid: msgs[0].UID, + }, + response: &types.QueryCampaignResponse{Campaign: msgs[0]}, + }, + { + desc: "Second", + request: &types.QueryCampaignRequest{ + Uid: msgs[1].UID, + }, + response: &types.QueryCampaignResponse{Campaign: msgs[1]}, + }, + { + desc: "KeyNotFound", + request: &types.QueryCampaignRequest{ + Uid: strconv.Itoa(100000), + }, + err: status.Error(codes.NotFound, "not found"), + }, + { + desc: "InvalidRequest", + err: status.Error(codes.InvalidArgument, "invalid request"), + }, + } { + t.Run(tc.desc, func(t *testing.T) { + response, err := k.Campaign(wctx, tc.request) + if tc.err != nil { + require.ErrorIs(t, err, tc.err) + } else { + require.NoError(t, err) + require.Equal(t, + nullify.Fill(tc.response), + nullify.Fill(response), + ) + } + }) + } +} + +func TestCampaignQueryPaginated(t *testing.T) { + k, ctx := setupKeeper(t) + wctx := sdk.WrapSDKContext(ctx) + msgs := createNCampaign(k, ctx, 5) + + request := func(next []byte, offset, limit uint64, total bool) *types.QueryCampaignAllRequest { + return &types.QueryCampaignAllRequest{ + Pagination: &query.PageRequest{ + Key: next, + Offset: offset, + Limit: limit, + CountTotal: total, + }, + } + } + t.Run("ByOffset", func(t *testing.T) { + step := 2 + for i := 0; i < len(msgs); i += step { + resp, err := k.CampaignAll(wctx, request(nil, uint64(i), uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.Campaign), step) + require.Subset(t, + nullify.Fill(msgs), + nullify.Fill(resp.Campaign), + ) + } + }) + t.Run("ByKey", func(t *testing.T) { + step := 2 + var next []byte + for i := 0; i < len(msgs); i += step { + resp, err := k.CampaignAll(wctx, request(next, 0, uint64(step), false)) + require.NoError(t, err) + require.LessOrEqual(t, len(resp.Campaign), step) + require.Subset(t, + nullify.Fill(msgs), + nullify.Fill(resp.Campaign), + ) + next = resp.Pagination.NextKey + } + }) + t.Run("Total", func(t *testing.T) { + resp, err := k.CampaignAll(wctx, request(nil, 0, 0, true)) + require.NoError(t, err) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.ElementsMatch(t, + nullify.Fill(msgs), + nullify.Fill(resp.Campaign), + ) + }) + t.Run("InvalidRequest", func(t *testing.T) { + _, err := k.CampaignAll(wctx, nil) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + }) +} diff --git a/x/reward/keeper/query_params.go b/x/reward/keeper/query_params.go new file mode 100644 index 00000000..00aacab5 --- /dev/null +++ b/x/reward/keeper/query_params.go @@ -0,0 +1,21 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/reward/types" +) + +func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(goCtx) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/reward/keeper/view.go b/x/reward/keeper/view.go new file mode 100644 index 00000000..90a84d99 --- /dev/null +++ b/x/reward/keeper/view.go @@ -0,0 +1,14 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/reward/types" +) + +// getCampaignStore gets the store containing all campaigns. +func (k Keeper) getCampaignStore(ctx sdk.Context) prefix.Store { + store := ctx.KVStore(k.storeKey) + return prefix.NewStore(store, types.CampaignKeyPrefix) +} diff --git a/x/reward/module.go b/x/reward/module.go new file mode 100644 index 00000000..ac2c4887 --- /dev/null +++ b/x/reward/module.go @@ -0,0 +1,161 @@ +package reward + +import ( + "context" + "encoding/json" + "fmt" + + "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" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/sge-network/sge/x/reward/client/cli" + "github.com/sge-network/sge/x/reward/keeper" + "github.com/sge-network/sge/x/reward/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the name of the module as a string +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + } +} + +// Deprecated: use RegisterServices +func (am AppModule) Route() sdk.Route { return sdk.Route{} } + +// Deprecated: use RegisterServices +func (AppModule) QuerierRoute() string { return types.RouterKey } + +// Deprecated: use RegisterServices +func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock contains the logic that is automatically triggered at the end of each block +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/reward/module_simulation.go b/x/reward/module_simulation.go new file mode 100644 index 00000000..4c70fa6e --- /dev/null +++ b/x/reward/module_simulation.go @@ -0,0 +1,120 @@ +package reward + +import ( + "math/rand" + + "github.com/google/uuid" + + "github.com/cosmos/cosmos-sdk/baseapp" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/testutil/sample" + rewardsimulation "github.com/sge-network/sge/x/reward/simulation" + "github.com/sge-network/sge/x/reward/types" +) + +// avoid unused import issue +var ( + _ = sample.AccAddress + _ = rewardsimulation.FindAccount + _ = simappparams.StakePerAccount + _ = simulation.MsgEntryKind + _ = baseapp.Paramspace +) + +const ( + //#nosec + opWeightMsgCreateCampaign = "op_weight_msg_campaign" + // TODO: Determine the simulation weight value + //#nosec + defaultWeightMsgCreateCampaign int = 100 + + //#nosec + opWeightMsgUpdateCampaign = "op_weight_msg_campaign" + // TODO: Determine the simulation weight value + defaultWeightMsgUpdateCampaign int = 100 + + //#nosec + opWeightMsgDeleteCampaign = "op_weight_msg_campaign" + // TODO: Determine the simulation weight value + defaultWeightMsgDeleteCampaign int = 100 +) + +// GenerateGenesisState creates a randomized GenState of the module +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + accs := make([]string, len(simState.Accounts)) + for i, acc := range simState.Accounts { + accs[i] = acc.Address.String() + } + rewardGenesis := types.GenesisState{ + Params: types.DefaultParams(), + CampaignList: []types.Campaign{ + { + Creator: sample.AccAddress(), + UID: uuid.NewString(), + }, + { + Creator: sample.AccAddress(), + UID: uuid.NewString(), + }, + }, + } + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&rewardGenesis) +} + +// ProposalContents doesn't return any content functions for governance proposals +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// RandomizedParams creates randomized param changes for the simulator +func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange { + return []simtypes.ParamChange{} +} + +// RegisterStoreDecoder registers a decoder +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the gov module operations with their respective weights. +func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + operations := make([]simtypes.WeightedOperation, 0) + + var weightMsgCreateCampaign int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCreateCampaign, &weightMsgCreateCampaign, nil, + func(_ *rand.Rand) { + weightMsgCreateCampaign = defaultWeightMsgCreateCampaign + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgCreateCampaign, + rewardsimulation.SimulateMsgCreateCampaign(am.accountKeeper, am.bankKeeper, am.keeper), + )) + + var weightMsgUpdateCampaign int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgUpdateCampaign, &weightMsgUpdateCampaign, nil, + func(_ *rand.Rand) { + weightMsgUpdateCampaign = defaultWeightMsgUpdateCampaign + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgUpdateCampaign, + rewardsimulation.SimulateMsgUpdateCampaign(am.accountKeeper, am.bankKeeper, am.keeper), + )) + + var weightMsgDeleteCampaign int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgDeleteCampaign, &weightMsgDeleteCampaign, nil, + func(_ *rand.Rand) { + weightMsgDeleteCampaign = defaultWeightMsgDeleteCampaign + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgDeleteCampaign, + rewardsimulation.SimulateMsgDeleteCampaign(am.accountKeeper, am.bankKeeper, am.keeper), + )) + + return operations +} diff --git a/x/reward/simulation/campaign.go b/x/reward/simulation/campaign.go new file mode 100644 index 00000000..58b43103 --- /dev/null +++ b/x/reward/simulation/campaign.go @@ -0,0 +1,150 @@ +package simulation + +import ( + "math/rand" + "strconv" + + "github.com/google/uuid" + + "github.com/cosmos/cosmos-sdk/baseapp" + simappparams "github.com/cosmos/cosmos-sdk/simapp/params" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + + "github.com/sge-network/sge/x/reward/keeper" + "github.com/sge-network/sge/x/reward/types" +) + +// Prevent strconv unused error +var _ = strconv.IntSize + +func SimulateMsgCreateCampaign( + ak types.AccountKeeper, + bk types.BankKeeper, + k keeper.Keeper, +) simtypes.Operation { + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + simAccount, _ := simtypes.RandomAcc(r, accs) + + msg := &types.MsgCreateCampaign{ + Creator: simAccount.Address.String(), + Uid: uuid.NewString(), + Ticket: "", + } + + _, found := k.GetCampaign(ctx, msg.Uid) + if found { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "Campaign already exist"), nil, nil + } + + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: simappparams.MakeTestEncodingConfig().TxConfig, + Cdc: nil, + Msg: msg, + MsgType: msg.Type(), + Context: ctx, + SimAccount: simAccount, + ModuleName: types.ModuleName, + CoinsSpentInMsg: sdk.NewCoins(), + AccountKeeper: ak, + Bankkeeper: bk, + } + return simulation.GenAndDeliverTxWithRandFees(txCtx) + } +} + +func SimulateMsgUpdateCampaign( + ak types.AccountKeeper, + bk types.BankKeeper, + k keeper.Keeper, +) simtypes.Operation { + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + var ( + simAccount = simtypes.Account{} + campaign = types.Campaign{} + msg = &types.MsgUpdateCampaign{} + allCampaign = k.GetAllCampaign(ctx) + found = false + ) + for _, obj := range allCampaign { + simAccount, found = FindAccount(accs, obj.Creator) + if found { + campaign = obj + break + } + } + if !found { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "campaign creator not found"), nil, nil + } + msg.Creator = simAccount.Address.String() + + msg.Uid = campaign.UID + + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: simappparams.MakeTestEncodingConfig().TxConfig, + Cdc: nil, + Msg: msg, + MsgType: msg.Type(), + Context: ctx, + SimAccount: simAccount, + ModuleName: types.ModuleName, + CoinsSpentInMsg: sdk.NewCoins(), + AccountKeeper: ak, + Bankkeeper: bk, + } + return simulation.GenAndDeliverTxWithRandFees(txCtx) + } +} + +func SimulateMsgDeleteCampaign( + ak types.AccountKeeper, + bk types.BankKeeper, + k keeper.Keeper, +) simtypes.Operation { + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + var ( + simAccount = simtypes.Account{} + campaign = types.Campaign{} + msg = &types.MsgUpdateCampaign{} + allCampaign = k.GetAllCampaign(ctx) + found = false + ) + for _, obj := range allCampaign { + simAccount, found = FindAccount(accs, obj.Creator) + if found { + campaign = obj + break + } + } + if !found { + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "campaign creator not found"), nil, nil + } + msg.Creator = simAccount.Address.String() + + msg.Uid = campaign.UID + + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: simappparams.MakeTestEncodingConfig().TxConfig, + Cdc: nil, + Msg: msg, + MsgType: msg.Type(), + Context: ctx, + SimAccount: simAccount, + ModuleName: types.ModuleName, + CoinsSpentInMsg: sdk.NewCoins(), + AccountKeeper: ak, + Bankkeeper: bk, + } + return simulation.GenAndDeliverTxWithRandFees(txCtx) + } +} diff --git a/x/reward/simulation/helpers.go b/x/reward/simulation/helpers.go new file mode 100644 index 00000000..92c437c0 --- /dev/null +++ b/x/reward/simulation/helpers.go @@ -0,0 +1,15 @@ +package simulation + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" +) + +// FindAccount find a specific address from an account list +func FindAccount(accs []simtypes.Account, address string) (simtypes.Account, bool) { + creator, err := sdk.AccAddressFromBech32(address) + if err != nil { + panic(err) + } + return simtypes.FindAccount(accs, creator) +} diff --git a/x/reward/types/campaign.go b/x/reward/types/campaign.go new file mode 100644 index 00000000..c9b5b085 --- /dev/null +++ b/x/reward/types/campaign.go @@ -0,0 +1,60 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" +) + +func NewCampaign( + creator, funderAddres, uID string, + startTS, endTS uint64, + rewardType RewardType, + rewardDefs []Definition, + pool Pool, +) Campaign { + return Campaign{ + Creator: creator, + FunderAddress: funderAddres, + UID: uID, + StartTS: startTS, + EndTS: endTS, + RewardType: rewardType, + RewardDefs: rewardDefs, + Pool: pool, + } +} + +// GetRewardsFactory returns reward factory according to the campaign. +func (c *Campaign) GetRewardsFactory() (IRewardFactory, error) { + switch c.RewardType { + case RewardType_REWARD_TYPE_SIGNUP: + return NewSignUpReward(), nil + case RewardType_REWARD_TYPE_REFERRAL: + return NewReferralReward(), nil + case RewardType_REWARD_TYPE_AFFILIATION: + return NewAffiliationReward(), nil + case RewardType_REWARD_TYPE_NOLOSS_BETS: + return NewNoLossBetsReward(), nil + default: + return nil, sdkerrors.Wrapf(ErrUnknownRewardType, "%d", c.RewardType) + } +} + +func (c *Campaign) CheckExpiration(blockTime uint64) error { + if blockTime > c.EndTS { + return sdkerrors.Wrapf(ErrCampaignEnded, "end timestamp %d, block time %d", c.EndTS, blockTime) + } + return nil +} + +// CheckPoolBalance checks if a pool balance of a capaign has enough fund to pay the rewards. +func (c *Campaign) CheckPoolBalance(distributions []Distribution) error { + totalAmount := sdkmath.ZeroInt() + for _, d := range distributions { + totalAmount.Add(d.Allocation.Amount) + } + if err := c.Pool.CheckBalance(totalAmount); err != nil { + return err + } + return nil +} diff --git a/x/reward/types/campaign.pb.go b/x/reward/types/campaign.pb.go new file mode 100644 index 00000000..1572def8 --- /dev/null +++ b/x/reward/types/campaign.pb.go @@ -0,0 +1,878 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/reward/campaign.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/gogoproto/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 + +// Campaign is type for defining the campaign properties. +type Campaign struct { + // creator is the address of campaign creator. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + UID string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"` + FunderAddress string `protobuf:"bytes,3,opt,name=funder_address,json=funderAddress,proto3" json:"funder_address,omitempty"` + // start_ts is the start timestamp of a campaign. + StartTS uint64 `protobuf:"varint,4,opt,name=start_ts,proto3" json:"start_ts"` + // end_ts is the end timestamp of a campaign. + EndTS uint64 `protobuf:"varint,5,opt,name=end_ts,proto3" json:"end_ts"` + // reward_type is the type of defined reward. + RewardType RewardType `protobuf:"varint,6,opt,name=reward_type,json=rewardType,proto3,enum=sgenetwork.sge.reward.RewardType" json:"reward_type,omitempty"` + // reward_defs is the list of definitions of the campaign rewards. + RewardDefs []Definition `protobuf:"bytes,7,rep,name=reward_defs,json=rewardDefs,proto3" json:"reward_defs"` + // pool is the tracker of pool funds of the campaign. + Pool Pool `protobuf:"bytes,8,opt,name=pool,proto3" json:"pool"` +} + +func (m *Campaign) Reset() { *m = Campaign{} } +func (m *Campaign) String() string { return proto.CompactTextString(m) } +func (*Campaign) ProtoMessage() {} +func (*Campaign) Descriptor() ([]byte, []int) { + return fileDescriptor_6d1d1b3139567e36, []int{0} +} +func (m *Campaign) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Campaign) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Campaign.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 *Campaign) XXX_Merge(src proto.Message) { + xxx_messageInfo_Campaign.Merge(m, src) +} +func (m *Campaign) XXX_Size() int { + return m.Size() +} +func (m *Campaign) XXX_DiscardUnknown() { + xxx_messageInfo_Campaign.DiscardUnknown(m) +} + +var xxx_messageInfo_Campaign proto.InternalMessageInfo + +func (m *Campaign) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *Campaign) GetUID() string { + if m != nil { + return m.UID + } + return "" +} + +func (m *Campaign) GetFunderAddress() string { + if m != nil { + return m.FunderAddress + } + return "" +} + +func (m *Campaign) GetStartTS() uint64 { + if m != nil { + return m.StartTS + } + return 0 +} + +func (m *Campaign) GetEndTS() uint64 { + if m != nil { + return m.EndTS + } + return 0 +} + +func (m *Campaign) GetRewardType() RewardType { + if m != nil { + return m.RewardType + } + return RewardType_REWARD_TYPE_UNSPECIFIED +} + +func (m *Campaign) GetRewardDefs() []Definition { + if m != nil { + return m.RewardDefs + } + return nil +} + +func (m *Campaign) GetPool() Pool { + if m != nil { + return m.Pool + } + return Pool{} +} + +// Pool is the type for the campaign funding pool. +type Pool struct { + Total cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=total,proto3,customtype=cosmossdk.io/math.Int" json:"total" yaml:"total"` + Spent cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=spent,proto3,customtype=cosmossdk.io/math.Int" json:"spent" yaml:"spent"` +} + +func (m *Pool) Reset() { *m = Pool{} } +func (m *Pool) String() string { return proto.CompactTextString(m) } +func (*Pool) ProtoMessage() {} +func (*Pool) Descriptor() ([]byte, []int) { + return fileDescriptor_6d1d1b3139567e36, []int{1} +} +func (m *Pool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Pool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Pool.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 *Pool) XXX_Merge(src proto.Message) { + xxx_messageInfo_Pool.Merge(m, src) +} +func (m *Pool) XXX_Size() int { + return m.Size() +} +func (m *Pool) XXX_DiscardUnknown() { + xxx_messageInfo_Pool.DiscardUnknown(m) +} + +var xxx_messageInfo_Pool proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Campaign)(nil), "sgenetwork.sge.reward.Campaign") + proto.RegisterType((*Pool)(nil), "sgenetwork.sge.reward.Pool") +} + +func init() { proto.RegisterFile("sge/reward/campaign.proto", fileDescriptor_6d1d1b3139567e36) } + +var fileDescriptor_6d1d1b3139567e36 = []byte{ + // 458 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0x6b, 0x92, 0xb5, 0xc5, 0x85, 0x1e, 0x0c, 0xd3, 0xc2, 0x90, 0x92, 0x10, 0x09, 0x29, + 0x08, 0x2d, 0x91, 0x36, 0x71, 0xe1, 0x46, 0x5a, 0x24, 0x76, 0x43, 0xd9, 0xb8, 0x70, 0xa9, 0xbc, + 0xda, 0xcd, 0xa2, 0x35, 0x76, 0x64, 0xbb, 0x1a, 0xfd, 0x16, 0x3b, 0xf0, 0xa1, 0x76, 0xdc, 0x11, + 0x71, 0x88, 0x50, 0x7a, 0xdb, 0x91, 0x4f, 0x80, 0x6c, 0xa7, 0x15, 0x07, 0x26, 0x71, 0xc9, 0x7b, + 0xf9, 0xbf, 0xff, 0xff, 0x27, 0xd9, 0xcf, 0xf0, 0x85, 0x2c, 0x68, 0x2a, 0xe8, 0x35, 0x16, 0x24, + 0x9d, 0xe3, 0xaa, 0xc6, 0x65, 0xc1, 0x92, 0x5a, 0x70, 0xc5, 0xd1, 0xbe, 0x2c, 0x28, 0xa3, 0xea, + 0x9a, 0x8b, 0xab, 0x44, 0x16, 0x34, 0xb1, 0xae, 0xc3, 0xe7, 0x05, 0x2f, 0xb8, 0x71, 0xa4, 0xba, + 0xb3, 0xe6, 0xc3, 0x83, 0xbf, 0x38, 0xb6, 0xd8, 0x41, 0xf4, 0xdd, 0x81, 0xc3, 0x49, 0x07, 0x46, + 0x1e, 0x1c, 0xcc, 0x05, 0xc5, 0x8a, 0x0b, 0x0f, 0x84, 0x20, 0x7e, 0x9c, 0x6f, 0x7f, 0x51, 0x08, + 0x9d, 0x55, 0x49, 0xbc, 0x47, 0x5a, 0xcd, 0xc6, 0x6d, 0x13, 0x38, 0x5f, 0x4e, 0xa7, 0xf7, 0x4d, + 0xa0, 0xd5, 0x5c, 0x7f, 0xd0, 0x6b, 0x38, 0x5e, 0xac, 0x18, 0xa1, 0x62, 0x86, 0x09, 0x11, 0x54, + 0x4a, 0xcf, 0x31, 0x88, 0xa7, 0x56, 0xfd, 0x60, 0x45, 0x74, 0x02, 0x87, 0x52, 0x61, 0xa1, 0x66, + 0x4a, 0x7a, 0x6e, 0x08, 0x62, 0x37, 0x3b, 0x68, 0x9b, 0x60, 0x70, 0xa6, 0xb5, 0xf3, 0xb3, 0xfb, + 0x26, 0xd8, 0x8d, 0xf3, 0x5d, 0x87, 0xde, 0xc2, 0x3e, 0x65, 0x44, 0x47, 0xf6, 0x4c, 0xe4, 0x59, + 0xdb, 0x04, 0x7b, 0x1f, 0x19, 0x31, 0x81, 0x6e, 0x94, 0x77, 0x15, 0x65, 0x70, 0x64, 0x4f, 0x38, + 0x53, 0xeb, 0x9a, 0x7a, 0xfd, 0x10, 0xc4, 0xe3, 0xe3, 0x57, 0xc9, 0x3f, 0x6f, 0x2b, 0xc9, 0x4d, + 0x39, 0x5f, 0xd7, 0x34, 0x87, 0x62, 0xd7, 0xa3, 0x4f, 0x3b, 0x06, 0xa1, 0x0b, 0xe9, 0x0d, 0x42, + 0x27, 0x1e, 0x3d, 0xc8, 0x98, 0xd2, 0x45, 0xc9, 0x4a, 0x55, 0x72, 0x96, 0xb9, 0xb7, 0x4d, 0xd0, + 0xdb, 0x92, 0xa6, 0x74, 0x21, 0xd1, 0x3b, 0xe8, 0xd6, 0x9c, 0x2f, 0xbd, 0x61, 0x08, 0xe2, 0xd1, + 0xf1, 0xcb, 0x07, 0x10, 0x9f, 0x39, 0x5f, 0x76, 0x61, 0x63, 0x8f, 0x6e, 0x00, 0x74, 0xb5, 0x88, + 0x26, 0x70, 0x4f, 0x71, 0x85, 0x97, 0x76, 0x21, 0xd9, 0x91, 0xf6, 0xfc, 0x6c, 0x82, 0xfd, 0x39, + 0x97, 0x15, 0x97, 0x92, 0x5c, 0x25, 0x25, 0x4f, 0x2b, 0xac, 0x2e, 0x93, 0x53, 0xa6, 0x7e, 0x37, + 0xc1, 0x93, 0x35, 0xae, 0x96, 0xef, 0x23, 0x93, 0x89, 0x72, 0x9b, 0xd5, 0x10, 0x59, 0x53, 0xa6, + 0xba, 0xfd, 0xfd, 0x2f, 0xc4, 0x64, 0xa2, 0xdc, 0x66, 0xb3, 0xc9, 0x6d, 0xeb, 0x83, 0xbb, 0xd6, + 0x07, 0xbf, 0x5a, 0x1f, 0xdc, 0x6c, 0xfc, 0xde, 0xdd, 0xc6, 0xef, 0xfd, 0xd8, 0xf8, 0xbd, 0xaf, + 0x6f, 0x8a, 0x52, 0x5d, 0xae, 0x2e, 0x92, 0x39, 0xaf, 0x52, 0x59, 0xd0, 0xa3, 0xee, 0x80, 0xba, + 0x4f, 0xbf, 0x6d, 0x5f, 0x9d, 0x5e, 0x86, 0xbc, 0xe8, 0x9b, 0x57, 0x77, 0xf2, 0x27, 0x00, 0x00, + 0xff, 0xff, 0x97, 0xaf, 0xe6, 0x6d, 0xd8, 0x02, 0x00, 0x00, +} + +func (m *Campaign) 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 *Campaign) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Campaign) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Pool.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCampaign(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + if len(m.RewardDefs) > 0 { + for iNdEx := len(m.RewardDefs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RewardDefs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCampaign(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + } + if m.RewardType != 0 { + i = encodeVarintCampaign(dAtA, i, uint64(m.RewardType)) + i-- + dAtA[i] = 0x30 + } + if m.EndTS != 0 { + i = encodeVarintCampaign(dAtA, i, uint64(m.EndTS)) + i-- + dAtA[i] = 0x28 + } + if m.StartTS != 0 { + i = encodeVarintCampaign(dAtA, i, uint64(m.StartTS)) + i-- + dAtA[i] = 0x20 + } + if len(m.FunderAddress) > 0 { + i -= len(m.FunderAddress) + copy(dAtA[i:], m.FunderAddress) + i = encodeVarintCampaign(dAtA, i, uint64(len(m.FunderAddress))) + i-- + dAtA[i] = 0x1a + } + if len(m.UID) > 0 { + i -= len(m.UID) + copy(dAtA[i:], m.UID) + i = encodeVarintCampaign(dAtA, i, uint64(len(m.UID))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintCampaign(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Pool) 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 *Pool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Spent.Size() + i -= size + if _, err := m.Spent.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCampaign(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.Total.Size() + i -= size + if _, err := m.Total.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCampaign(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintCampaign(dAtA []byte, offset int, v uint64) int { + offset -= sovCampaign(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Campaign) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovCampaign(uint64(l)) + } + l = len(m.UID) + if l > 0 { + n += 1 + l + sovCampaign(uint64(l)) + } + l = len(m.FunderAddress) + if l > 0 { + n += 1 + l + sovCampaign(uint64(l)) + } + if m.StartTS != 0 { + n += 1 + sovCampaign(uint64(m.StartTS)) + } + if m.EndTS != 0 { + n += 1 + sovCampaign(uint64(m.EndTS)) + } + if m.RewardType != 0 { + n += 1 + sovCampaign(uint64(m.RewardType)) + } + if len(m.RewardDefs) > 0 { + for _, e := range m.RewardDefs { + l = e.Size() + n += 1 + l + sovCampaign(uint64(l)) + } + } + l = m.Pool.Size() + n += 1 + l + sovCampaign(uint64(l)) + return n +} + +func (m *Pool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Total.Size() + n += 1 + l + sovCampaign(uint64(l)) + l = m.Spent.Size() + n += 1 + l + sovCampaign(uint64(l)) + return n +} + +func sovCampaign(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCampaign(x uint64) (n int) { + return sovCampaign(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Campaign) 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 ErrIntOverflowCampaign + } + 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: Campaign: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Campaign: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + 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 ErrInvalidLengthCampaign + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + 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 ErrInvalidLengthCampaign + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FunderAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + 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 ErrInvalidLengthCampaign + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FunderAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTS", wireType) + } + m.StartTS = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartTS |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTS", wireType) + } + m.EndTS = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EndTS |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardType", wireType) + } + m.RewardType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RewardType |= RewardType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardDefs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCampaign + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RewardDefs = append(m.RewardDefs, Definition{}) + if err := m.RewardDefs[len(m.RewardDefs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pool", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCampaign + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Pool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCampaign(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCampaign + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Pool) 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 ErrIntOverflowCampaign + } + 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: Pool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Pool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Total", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + 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 ErrInvalidLengthCampaign + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Total.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Spent", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + 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 ErrInvalidLengthCampaign + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Spent.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCampaign(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCampaign + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCampaign(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, ErrIntOverflowCampaign + } + 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, ErrIntOverflowCampaign + } + 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, ErrIntOverflowCampaign + } + 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, ErrInvalidLengthCampaign + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCampaign + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCampaign + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCampaign = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCampaign = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCampaign = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/reward/types/codec.go b/x/reward/types/codec.go new file mode 100644 index 00000000..669dedae --- /dev/null +++ b/x/reward/types/codec.go @@ -0,0 +1,37 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgCreateCampaign{}, "reward/CreateCampaign") + legacy.RegisterAminoMsg(cdc, &MsgUpdateCampaign{}, "reward/UpdateCampaign") + legacy.RegisterAminoMsg(cdc, &MsgApplyReward{}, "reward/ApplyReward") +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgCreateCampaign{}, + &MsgUpdateCampaign{}, + &MsgApplyReward{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +} diff --git a/x/reward/types/errors.go b/x/reward/types/errors.go new file mode 100644 index 00000000..44c1aac7 --- /dev/null +++ b/x/reward/types/errors.go @@ -0,0 +1,32 @@ +package types + +// DONTCOVER + +import ( + sdkerrors "cosmossdk.io/errors" +) + +// x/reward module sentinel errors +var ( + ErrInTicketVerification = sdkerrors.Register(ModuleName, 7100, "ticket verification failed") + ErrInTicketValidation = sdkerrors.Register(ModuleName, 7101, "ticket validation failed") + ErrAuthorizationNotFound = sdkerrors.Register(ModuleName, 7102, "no authorization found") + ErrAuthorizationNotAccepted = sdkerrors.Register(ModuleName, 7103, "authorization not accepted") + ErrorBank = sdkerrors.Register(ModuleName, 7104, "bank error") + ErrExpiredCampaign = sdkerrors.Register(ModuleName, 7105, "campaign is expired") + ErrCampaignPoolBalance = sdkerrors.Register(ModuleName, 7106, "not enough campaign pool balance") + ErrUnknownRewardType = sdkerrors.Register(ModuleName, 7107, "unknown reward type") + ErrInFundingCampaignPool = sdkerrors.Register(ModuleName, 7108, "error in funding the campaign pool") + ErrUnknownAccType = sdkerrors.Register(ModuleName, 7109, "unknown account type") + ErrCampaignEnded = sdkerrors.Register(ModuleName, 7110, "campaign validity period is ended") + ErrInsufficientPoolBalance = sdkerrors.Register(ModuleName, 7111, "insufficient campaign pool balance") + ErrInDistributionOfRewards = sdkerrors.Register(ModuleName, 7112, "reward distribution failed") + ErrInvalidReceiverType = sdkerrors.Register(ModuleName, 7113, "inappropriate receiver account type") + ErrWrongDefinitionsCount = sdkerrors.Register(ModuleName, 7114, "wrong reward definitions") + ErrMissingDefinition = sdkerrors.Register(ModuleName, 7115, "missing reward definition") + ErrSubAccRewardTopUp = sdkerrors.Register(ModuleName, 7116, "subaccount reward topup failed") + ErrUnlockTSIsSubAccOnly = sdkerrors.Register(ModuleName, 7117, "unlock timestamp is allowed for subaccount only") + ErrUnlockTSDefBeforeBlockTime = sdkerrors.Register(ModuleName, 7118, "unlock timestamp should not be before the current block time") + ErrAccReceiverTypeNotFound = sdkerrors.Register(ModuleName, 7119, "receiver type not found in the receivers") + ErrInvalidNoLossBetUID = sdkerrors.Register(ModuleName, 7120, "invalid no loss bet uid") +) diff --git a/x/reward/types/expected_keepers.go b/x/reward/types/expected_keepers.go new file mode 100644 index 00000000..3e9ef92b --- /dev/null +++ b/x/reward/types/expected_keepers.go @@ -0,0 +1,67 @@ +package types + +import ( + context "context" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/authz" + + bettypes "github.com/sge-network/sge/x/bet/types" + subaccounttypes "github.com/sge-network/sge/x/subaccount/types" +) + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + GetModuleAddress(moduleName string) sdk.AccAddress + // Methods imported from account should be defined here +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, ecipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + // Methods imported from bank should be defined here +} + +// BetKeeper defines the expected interface needed to access bet state. +type BetKeeper interface { + GetBet(ctx sdk.Context, creator string, id uint64) (val bettypes.Bet, found bool) + GetBetID(ctx sdk.Context, uid string) (val bettypes.UID2ID, found bool) +} + +// OVMKeeper defines the expected interface needed to verify ticket and unmarshal it +type OVMKeeper interface { + VerifyTicketUnmarshal(goCtx context.Context, ticket string, clm interface{}) error +} + +// AuthzKeeper defines the expected authz keeper. +type AuthzKeeper interface { + GetAuthorization( + ctx sdk.Context, + grantee sdk.AccAddress, + granter sdk.AccAddress, + msgType string, + ) (authz.Authorization, *time.Time) + SaveGrant( + ctx sdk.Context, + grantee, granter sdk.AccAddress, + authorization authz.Authorization, + expiration *time.Time, + ) error + DeleteGrant( + ctx sdk.Context, + grantee, granter sdk.AccAddress, + msgType string, + ) error +} + +// SubAccountKeeper defines the expected interface needed to ge/create/topup a subaccount. +type SubAccountKeeper interface { + TopUp(ctx sdk.Context, creator, subAccOwnerAddr string, lockedBalance []subaccounttypes.LockedBalance) (string, error) +} diff --git a/x/reward/types/funder.go b/x/reward/types/funder.go new file mode 100644 index 00000000..bb103f1e --- /dev/null +++ b/x/reward/types/funder.go @@ -0,0 +1,7 @@ +package types + +type RewardPoolFunder struct{} + +func (RewardPoolFunder) GetModuleAcc() string { + return rewardPool +} diff --git a/x/reward/types/genesis.go b/x/reward/types/genesis.go new file mode 100644 index 00000000..38b3932d --- /dev/null +++ b/x/reward/types/genesis.go @@ -0,0 +1,33 @@ +package types + +import ( + "fmt" +) + +// DefaultIndex is the default global index +const DefaultIndex uint64 = 1 + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + CampaignList: []Campaign{}, + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + // Check for duplicated index in campaign + campaignIndexMap := make(map[string]struct{}) + + for _, elem := range gs.CampaignList { + index := string(GetCampaignKey(elem.UID)) + if _, ok := campaignIndexMap[index]; ok { + return fmt.Errorf("duplicated index for campaign") + } + campaignIndexMap[index] = struct{}{} + } + + return gs.Params.Validate() +} diff --git a/x/reward/types/genesis.pb.go b/x/reward/types/genesis.pb.go new file mode 100644 index 00000000..511f4112 --- /dev/null +++ b/x/reward/types/genesis.pb.go @@ -0,0 +1,386 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/reward/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/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 + +// GenesisState defines the reward module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + CampaignList []Campaign `protobuf:"bytes,2,rep,name=campaign_list,json=campaignList,proto3" json:"campaign_list"` +} + +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_cf3f52dafc32b537, []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) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetCampaignList() []Campaign { + if m != nil { + return m.CampaignList + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "sgenetwork.sge.reward.GenesisState") +} + +func init() { proto.RegisterFile("sge/reward/genesis.proto", fileDescriptor_cf3f52dafc32b537) } + +var fileDescriptor_cf3f52dafc32b537 = []byte{ + // 245 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x4e, 0x4f, 0xd5, + 0x2f, 0x4a, 0x2d, 0x4f, 0x2c, 0x4a, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x2d, 0x06, 0xf1, 0x4b, 0xca, 0xf3, 0x8b, 0xb2, 0xf5, 0x8a, + 0xd3, 0x53, 0xf5, 0x20, 0x8a, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x2a, 0xf4, 0x41, 0x2c, + 0x88, 0x62, 0x29, 0x71, 0x24, 0x63, 0x0a, 0x12, 0x8b, 0x12, 0x73, 0xa1, 0xa6, 0x48, 0x49, 0x22, + 0x49, 0x24, 0x27, 0xe6, 0x16, 0x24, 0x66, 0xa6, 0xe7, 0x41, 0xa4, 0x94, 0xa6, 0x33, 0x72, 0xf1, + 0xb8, 0x43, 0xac, 0x0c, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0xb2, 0xe6, 0x62, 0x83, 0xe8, 0x95, 0x60, + 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x92, 0xd5, 0xc3, 0xea, 0x04, 0xbd, 0x00, 0xb0, 0x22, 0x27, 0x96, + 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xa0, 0x5a, 0x84, 0xbc, 0xb8, 0x78, 0x61, 0xe6, 0xc7, 0xe7, 0x64, + 0x16, 0x97, 0x48, 0x30, 0x29, 0x30, 0x6b, 0x70, 0x1b, 0xc9, 0xe3, 0x30, 0xc3, 0x19, 0xaa, 0x16, + 0x6a, 0x0a, 0x0f, 0x4c, 0xaf, 0x4f, 0x66, 0x71, 0x89, 0x93, 0xf3, 0x89, 0x47, 0x72, 0x8c, 0x17, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, + 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x69, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, + 0xea, 0x17, 0xa7, 0xa7, 0xea, 0x42, 0x4d, 0x06, 0xb1, 0xf5, 0x2b, 0x60, 0xfe, 0x2c, 0xa9, 0x2c, + 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xfb, 0xd2, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x4d, 0x2c, + 0x4a, 0x62, 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.CampaignList) > 0 { + for iNdEx := len(m.CampaignList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CampaignList[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 { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + 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 = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.CampaignList) > 0 { + for _, e := range m.CampaignList { + 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 Params", 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 + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CampaignList", 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.CampaignList = append(m.CampaignList, Campaign{}) + if err := m.CampaignList[len(m.CampaignList)-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/x/reward/types/genesis_test.go b/x/reward/types/genesis_test.go new file mode 100644 index 00000000..cf896403 --- /dev/null +++ b/x/reward/types/genesis_test.go @@ -0,0 +1,62 @@ +package types_test + +import ( + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/reward/types" +) + +func TestGenesisState_Validate(t *testing.T) { + dupplicateCampaign := uuid.NewString() + for _, tc := range []struct { + desc string + genState *types.GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: types.DefaultGenesis(), + valid: true, + }, + { + desc: "valid genesis state", + genState: &types.GenesisState{ + CampaignList: []types.Campaign{ + { + UID: uuid.NewString(), + }, + { + UID: uuid.NewString(), + }, + }, + }, + valid: true, + }, + { + desc: "duplicated campaign", + genState: &types.GenesisState{ + CampaignList: []types.Campaign{ + { + UID: dupplicateCampaign, + }, + { + UID: dupplicateCampaign, + }, + }, + }, + valid: false, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/reward/types/key_campaign.go b/x/reward/types/key_campaign.go new file mode 100644 index 00000000..01210b25 --- /dev/null +++ b/x/reward/types/key_campaign.go @@ -0,0 +1,17 @@ +package types + +import ( + "encoding/binary" + + "github.com/sge-network/sge/utils" +) + +var _ binary.ByteOrder + +// CampaignKeyPrefix is the prefix to retrieve all Campaign +var CampaignKeyPrefix = []byte{0x00} + +// GetCampaignKey returns the store key to retrieve a Campaign from the index fields +func GetCampaignKey(uid string) []byte { + return utils.StrBytes(uid) +} diff --git a/x/reward/types/keys.go b/x/reward/types/keys.go new file mode 100644 index 00000000..c7269f59 --- /dev/null +++ b/x/reward/types/keys.go @@ -0,0 +1,21 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "reward" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_reward" +) + +// module accounts constants +const ( + // rewardPool defines the account name for reward pool. + rewardPool = "reward_pool" +) diff --git a/x/reward/types/messages_campaign.go b/x/reward/types/messages_campaign.go new file mode 100644 index 00000000..0ac0bd9d --- /dev/null +++ b/x/reward/types/messages_campaign.go @@ -0,0 +1,117 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" +) + +const ( + TypeMsgCreateCampaign = "create_campaign" + TypeMsgUpdateCampaign = "update_campaign" +) + +var _ sdk.Msg = &MsgCreateCampaign{} + +func NewMsgCreateCampaign( + creator string, + uid string, + ticket string, +) *MsgCreateCampaign { + return &MsgCreateCampaign{ + Creator: creator, + Uid: uid, + Ticket: ticket, + } +} + +func (msg *MsgCreateCampaign) Route() string { + return RouterKey +} + +func (msg *MsgCreateCampaign) Type() string { + return TypeMsgCreateCampaign +} + +func (msg *MsgCreateCampaign) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgCreateCampaign) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgCreateCampaign) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if !utils.IsValidUID(msg.Uid) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid uid") + } + + if msg.Ticket == "" { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket") + } + + return nil +} + +var _ sdk.Msg = &MsgUpdateCampaign{} + +func NewMsgUpdateCampaign( + creator string, + uid string, + ticket string, +) *MsgUpdateCampaign { + return &MsgUpdateCampaign{ + Creator: creator, + Uid: uid, + Ticket: ticket, + } +} + +func (msg *MsgUpdateCampaign) Route() string { + return RouterKey +} + +func (msg *MsgUpdateCampaign) Type() string { + return TypeMsgUpdateCampaign +} + +func (msg *MsgUpdateCampaign) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgUpdateCampaign) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgUpdateCampaign) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if !utils.IsValidUID(msg.Uid) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid uid") + } + + if msg.Ticket == "" { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket") + } + + return nil +} diff --git a/x/reward/types/messages_campaign_test.go b/x/reward/types/messages_campaign_test.go new file mode 100644 index 00000000..bde35d9f --- /dev/null +++ b/x/reward/types/messages_campaign_test.go @@ -0,0 +1,121 @@ +package types_test + +import ( + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/testutil/sample" + + "github.com/sge-network/sge/x/reward/types" +) + +func TestMsgCreateCampaign_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgCreateCampaign + err error + }{ + { + name: "invalid address", + msg: types.MsgCreateCampaign{ + Creator: "invalid_address", + Uid: uuid.NewString(), + Ticket: "ticket", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "invalid uid", + msg: types.MsgCreateCampaign{ + Creator: sample.AccAddress(), + Uid: "invalid uid", + Ticket: "ticket", + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "invalid ticket", + msg: types.MsgCreateCampaign{ + Creator: sample.AccAddress(), + Uid: uuid.NewString(), + Ticket: "", + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "valid address", + msg: types.MsgCreateCampaign{ + Creator: sample.AccAddress(), + Uid: uuid.NewString(), + Ticket: "ticket", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} + +func TestMsgUpdateCampaign_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgUpdateCampaign + err error + }{ + { + name: "invalid address", + msg: types.MsgUpdateCampaign{ + Creator: "invalid_address", + Uid: uuid.NewString(), + Ticket: "ticket", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "invalid uid", + msg: types.MsgUpdateCampaign{ + Creator: sample.AccAddress(), + Uid: "invalid uid", + Ticket: "ticket", + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "invalid ticket", + msg: types.MsgUpdateCampaign{ + Creator: sample.AccAddress(), + Uid: uuid.NewString(), + Ticket: "", + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "valid address", + msg: types.MsgUpdateCampaign{ + Creator: sample.AccAddress(), + Uid: uuid.NewString(), + Ticket: "ticket", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/reward/types/messages_reward.go b/x/reward/types/messages_reward.go new file mode 100644 index 00000000..3ad89276 --- /dev/null +++ b/x/reward/types/messages_reward.go @@ -0,0 +1,65 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" +) + +const ( + TypeMsgApplyReward = "apply_reward" +) + +var _ sdk.Msg = &MsgApplyReward{} + +func NewMsgApplyReward( + creator string, + campaignUID string, + ticket string, +) *MsgApplyReward { + return &MsgApplyReward{ + Creator: creator, + CampaignUid: campaignUID, + Ticket: ticket, + } +} + +func (msg *MsgApplyReward) Route() string { + return RouterKey +} + +func (msg *MsgApplyReward) Type() string { + return TypeMsgApplyReward +} + +func (msg *MsgApplyReward) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgApplyReward) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgApplyReward) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if !utils.IsValidUID(msg.CampaignUid) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid campaign uid") + } + + if msg.Ticket == "" { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket") + } + + return nil +} diff --git a/x/reward/types/messages_reward_test.go b/x/reward/types/messages_reward_test.go new file mode 100644 index 00000000..88ce6d8c --- /dev/null +++ b/x/reward/types/messages_reward_test.go @@ -0,0 +1,62 @@ +package types_test + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/google/uuid" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/reward/types" + "github.com/stretchr/testify/require" +) + +func TestMsgApplyReward_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgApplyReward + err error + }{ + { + name: "invalid address", + msg: types.MsgApplyReward{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "invalid uid", + msg: types.MsgApplyReward{ + Creator: sample.AccAddress(), + CampaignUid: "bad uid", + Ticket: "ticket", + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "invalid ticket", + msg: types.MsgApplyReward{ + Creator: sample.AccAddress(), + CampaignUid: uuid.NewString(), + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "valid address", + msg: types.MsgApplyReward{ + Creator: sample.AccAddress(), + CampaignUid: uuid.NewString(), + Ticket: "ticket", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/reward/types/params.go b/x/reward/types/params.go new file mode 100644 index 00000000..3b80151b --- /dev/null +++ b/x/reward/types/params.go @@ -0,0 +1,40 @@ +package types + +import ( + yaml "gopkg.in/yaml.v2" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams() +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{} +} + +// Validate validates the set of params +func (p Params) Validate() error { + return nil +} + +// String implements the Stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} diff --git a/x/reward/types/params.pb.go b/x/reward/types/params.pb.go new file mode 100644 index 00000000..f8fbfd28 --- /dev/null +++ b/x/reward/types/params.pb.go @@ -0,0 +1,264 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/reward/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/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 + +// Params defines the parameters for the module. +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_13b61197a30d8929, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "sgenetwork.sge.reward.Params") +} + +func init() { proto.RegisterFile("sge/reward/params.proto", fileDescriptor_13b61197a30d8929) } + +var fileDescriptor_13b61197a30d8929 = []byte{ + // 157 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2f, 0x4e, 0x4f, 0xd5, + 0x2f, 0x4a, 0x2d, 0x4f, 0x2c, 0x4a, 0xd1, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, + 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x2d, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, + 0x2b, 0x4e, 0x4f, 0xd5, 0x83, 0xa8, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd0, 0x07, + 0xb1, 0x20, 0x8a, 0x95, 0xf8, 0xb8, 0xd8, 0x02, 0xc0, 0x9a, 0xad, 0x58, 0x66, 0x2c, 0x90, 0x67, + 0x70, 0x72, 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, 0xcd, 0xf4, 0xcc, + 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe2, 0xf4, 0x54, 0x5d, 0xa8, 0x15, 0x20, + 0xb6, 0x7e, 0x05, 0xcc, 0x21, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0xb3, 0x8d, 0x01, + 0x01, 0x00, 0x00, 0xff, 0xff, 0xd0, 0x57, 0xc4, 0x87, 0xa3, 0x00, 0x00, 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowParams + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/reward/types/pool.go b/x/reward/types/pool.go new file mode 100644 index 00000000..1aa2d09b --- /dev/null +++ b/x/reward/types/pool.go @@ -0,0 +1,21 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" +) + +func NewPool(total sdkmath.Int) Pool { + return Pool{ + Total: total, + Spent: sdkmath.ZeroInt(), + } +} + +func (p *Pool) CheckBalance(toSpend sdkmath.Int) error { + availablePool := p.Total.Sub(p.Spent) + if availablePool.LT(toSpend) { + return sdkerrors.Wrapf(ErrCampaignPoolBalance, "amount %s, available pool %s", toSpend, availablePool) + } + return nil +} diff --git a/x/reward/types/pool_test.go b/x/reward/types/pool_test.go new file mode 100644 index 00000000..bda9c811 --- /dev/null +++ b/x/reward/types/pool_test.go @@ -0,0 +1,41 @@ +package types_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + + "github.com/sge-network/sge/x/reward/types" +) + +func TestCheckBalance(t *testing.T) { + poolBalace := int64(10000000) + pool := types.NewPool(sdkmath.NewInt(poolBalace)) + tests := []struct { + name string + spent sdkmath.Int + err error + }{ + { + name: "not enough balance", + spent: sdkmath.NewInt(poolBalace + 1), + err: types.ErrCampaignPoolBalance, + }, + { + name: "valid", + spent: sdkmath.NewInt(poolBalace), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := pool.CheckBalance(tt.spent) + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/reward/types/query.pb.go b/x/reward/types/query.pb.go new file mode 100644 index 00000000..bf6d3920 --- /dev/null +++ b/x/reward/types/query.pb.go @@ -0,0 +1,1392 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/reward/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// QueryParamsRequest is request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// QueryCampaignRequest is request body of the query campaign endpoint. +type QueryCampaignRequest struct { + Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"` +} + +func (m *QueryCampaignRequest) Reset() { *m = QueryCampaignRequest{} } +func (m *QueryCampaignRequest) String() string { return proto.CompactTextString(m) } +func (*QueryCampaignRequest) ProtoMessage() {} +func (*QueryCampaignRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{2} +} +func (m *QueryCampaignRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCampaignRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCampaignRequest.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 *QueryCampaignRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCampaignRequest.Merge(m, src) +} +func (m *QueryCampaignRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryCampaignRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCampaignRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCampaignRequest proto.InternalMessageInfo + +func (m *QueryCampaignRequest) GetUid() string { + if m != nil { + return m.Uid + } + return "" +} + +// QueryCampaignRequest is response body of the query campaign endpoint. +type QueryCampaignResponse struct { + Campaign Campaign `protobuf:"bytes,1,opt,name=campaign,proto3" json:"campaign"` +} + +func (m *QueryCampaignResponse) Reset() { *m = QueryCampaignResponse{} } +func (m *QueryCampaignResponse) String() string { return proto.CompactTextString(m) } +func (*QueryCampaignResponse) ProtoMessage() {} +func (*QueryCampaignResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{3} +} +func (m *QueryCampaignResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCampaignResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCampaignResponse.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 *QueryCampaignResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCampaignResponse.Merge(m, src) +} +func (m *QueryCampaignResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryCampaignResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCampaignResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCampaignResponse proto.InternalMessageInfo + +func (m *QueryCampaignResponse) GetCampaign() Campaign { + if m != nil { + return m.Campaign + } + return Campaign{} +} + +// QueryCampaignAllRequest is request body of the query all campaigns endpoint. +type QueryCampaignAllRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryCampaignAllRequest) Reset() { *m = QueryCampaignAllRequest{} } +func (m *QueryCampaignAllRequest) String() string { return proto.CompactTextString(m) } +func (*QueryCampaignAllRequest) ProtoMessage() {} +func (*QueryCampaignAllRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{4} +} +func (m *QueryCampaignAllRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCampaignAllRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCampaignAllRequest.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 *QueryCampaignAllRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCampaignAllRequest.Merge(m, src) +} +func (m *QueryCampaignAllRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryCampaignAllRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCampaignAllRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCampaignAllRequest proto.InternalMessageInfo + +func (m *QueryCampaignAllRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryCampaignAllResponse is response body of the query all campaigns +// endpoint. +type QueryCampaignAllResponse struct { + Campaign []Campaign `protobuf:"bytes,1,rep,name=campaign,proto3" json:"campaign"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryCampaignAllResponse) Reset() { *m = QueryCampaignAllResponse{} } +func (m *QueryCampaignAllResponse) String() string { return proto.CompactTextString(m) } +func (*QueryCampaignAllResponse) ProtoMessage() {} +func (*QueryCampaignAllResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{5} +} +func (m *QueryCampaignAllResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCampaignAllResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCampaignAllResponse.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 *QueryCampaignAllResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCampaignAllResponse.Merge(m, src) +} +func (m *QueryCampaignAllResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryCampaignAllResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCampaignAllResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCampaignAllResponse proto.InternalMessageInfo + +func (m *QueryCampaignAllResponse) GetCampaign() []Campaign { + if m != nil { + return m.Campaign + } + return nil +} + +func (m *QueryCampaignAllResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "sgenetwork.sge.reward.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "sgenetwork.sge.reward.QueryParamsResponse") + proto.RegisterType((*QueryCampaignRequest)(nil), "sgenetwork.sge.reward.QueryCampaignRequest") + proto.RegisterType((*QueryCampaignResponse)(nil), "sgenetwork.sge.reward.QueryCampaignResponse") + proto.RegisterType((*QueryCampaignAllRequest)(nil), "sgenetwork.sge.reward.QueryCampaignAllRequest") + proto.RegisterType((*QueryCampaignAllResponse)(nil), "sgenetwork.sge.reward.QueryCampaignAllResponse") +} + +func init() { proto.RegisterFile("sge/reward/query.proto", fileDescriptor_324afa5f2186a8c0) } + +var fileDescriptor_324afa5f2186a8c0 = []byte{ + // 494 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x3d, 0x6f, 0x13, 0x31, + 0x18, 0xc7, 0xe3, 0x06, 0xa2, 0xf2, 0x74, 0x41, 0x26, 0xa5, 0xe5, 0x04, 0xd7, 0xc8, 0x43, 0x48, + 0x0b, 0xd8, 0x6a, 0x19, 0x99, 0xda, 0x4a, 0xb0, 0x96, 0x1b, 0xbb, 0x39, 0x89, 0x65, 0x4e, 0x24, + 0xe7, 0xeb, 0xd9, 0x47, 0xa9, 0x10, 0x0b, 0x0b, 0x2b, 0x12, 0x42, 0xe2, 0x13, 0xf0, 0x49, 0x18, + 0x3a, 0x56, 0x62, 0x61, 0x42, 0x28, 0xe1, 0x83, 0xa0, 0xd8, 0x3e, 0x7a, 0xe9, 0x35, 0xf4, 0xd4, + 0xed, 0x14, 0xff, 0x5f, 0x7e, 0x7e, 0xfc, 0x28, 0x70, 0x57, 0x4b, 0xc1, 0x32, 0x71, 0xcc, 0xb3, + 0x21, 0x3b, 0xca, 0x45, 0x76, 0x42, 0xd3, 0x4c, 0x19, 0x85, 0x57, 0xb5, 0x14, 0x89, 0x30, 0xc7, + 0x2a, 0x7b, 0x4d, 0xb5, 0x14, 0xd4, 0x49, 0x82, 0xb6, 0x54, 0x52, 0x59, 0x05, 0x9b, 0x7d, 0x39, + 0x71, 0x70, 0x5f, 0x2a, 0x25, 0x47, 0x82, 0xf1, 0x34, 0x66, 0x3c, 0x49, 0x94, 0xe1, 0x26, 0x56, + 0x89, 0xf6, 0xa7, 0x5b, 0x03, 0xa5, 0xc7, 0x4a, 0xb3, 0x3e, 0xd7, 0xc2, 0x75, 0xb0, 0x37, 0xdb, + 0x7d, 0x61, 0xf8, 0x36, 0x4b, 0xb9, 0x8c, 0x13, 0x2b, 0xf6, 0xda, 0xb5, 0x12, 0x4e, 0xca, 0x33, + 0x3e, 0x2e, 0x42, 0xee, 0x95, 0x0e, 0x06, 0x7c, 0x9c, 0xf2, 0x58, 0x7a, 0x0f, 0x69, 0x03, 0x7e, + 0x39, 0x4b, 0x3d, 0xb0, 0xfa, 0x48, 0x1c, 0xe5, 0x42, 0x1b, 0x12, 0xc1, 0x9d, 0xb9, 0x5f, 0x75, + 0xaa, 0x12, 0x2d, 0xf0, 0x33, 0x68, 0xb9, 0xdc, 0x75, 0xd4, 0x41, 0xbd, 0x95, 0x9d, 0x07, 0xf4, + 0xd2, 0x8b, 0x52, 0x67, 0xdb, 0xbb, 0x71, 0xfa, 0x6b, 0xa3, 0x11, 0x79, 0x0b, 0xe9, 0x41, 0xdb, + 0x66, 0xee, 0x7b, 0x00, 0xdf, 0x85, 0x6f, 0x43, 0x33, 0x8f, 0x87, 0x36, 0xf1, 0x56, 0x34, 0xfb, + 0x24, 0x87, 0xb0, 0x7a, 0x41, 0xe9, 0xfb, 0x77, 0x61, 0xb9, 0xc0, 0xf7, 0x04, 0x1b, 0x0b, 0x08, + 0x0a, 0xab, 0x67, 0xf8, 0x67, 0x23, 0x1c, 0xd6, 0xe6, 0xb2, 0x77, 0x47, 0xa3, 0x02, 0xe4, 0x39, + 0xc0, 0xf9, 0x48, 0x7d, 0x7e, 0x97, 0xba, 0xf9, 0xd3, 0xd9, 0xfc, 0xa9, 0x7b, 0x63, 0x3f, 0x7f, + 0x7a, 0xc0, 0xa5, 0xf0, 0xde, 0xa8, 0xe4, 0x24, 0xdf, 0x10, 0xac, 0x57, 0x3b, 0x2e, 0xbd, 0x42, + 0xf3, 0x1a, 0x57, 0xc0, 0x2f, 0xe6, 0x38, 0x97, 0x2c, 0xe7, 0xc3, 0x2b, 0x39, 0x5d, 0x7f, 0x19, + 0x74, 0xe7, 0x7b, 0x13, 0x6e, 0x5a, 0x50, 0xfc, 0x11, 0x41, 0xcb, 0x3d, 0x1a, 0xde, 0x5c, 0x80, + 0x53, 0xdd, 0x92, 0x60, 0xab, 0x8e, 0xd4, 0xf5, 0x92, 0xee, 0x87, 0x1f, 0x7f, 0x3e, 0x2f, 0x75, + 0x70, 0xc8, 0xb4, 0x14, 0x4f, 0xbc, 0x89, 0x55, 0x16, 0x16, 0x7f, 0x41, 0xb0, 0x5c, 0xdc, 0x1c, + 0x3f, 0xfa, 0x5f, 0xc1, 0x85, 0x3d, 0x0a, 0x1e, 0xd7, 0x13, 0x7b, 0x1e, 0x6a, 0x79, 0x7a, 0xb8, + 0xbb, 0x88, 0xa7, 0x18, 0x37, 0x7b, 0x97, 0xc7, 0xc3, 0xf7, 0xf8, 0x2b, 0x82, 0x95, 0xd2, 0x7b, + 0x62, 0x5a, 0xa7, 0xed, 0x7c, 0xb9, 0x02, 0x56, 0x5b, 0xef, 0x01, 0x7b, 0x16, 0x90, 0xe0, 0xce, + 0x55, 0x80, 0x7b, 0xfb, 0xa7, 0x93, 0x10, 0x9d, 0x4d, 0x42, 0xf4, 0x7b, 0x12, 0xa2, 0x4f, 0xd3, + 0xb0, 0x71, 0x36, 0x0d, 0x1b, 0x3f, 0xa7, 0x61, 0xe3, 0x70, 0x53, 0xc6, 0xe6, 0x55, 0xde, 0xa7, + 0x03, 0x35, 0xae, 0xa4, 0xbc, 0x2d, 0x72, 0xcc, 0x49, 0x2a, 0x74, 0xbf, 0x65, 0xff, 0x0e, 0x9e, + 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x7c, 0xb8, 0x74, 0xd3, 0x04, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // Queries an specific Campaign item. + Campaign(ctx context.Context, in *QueryCampaignRequest, opts ...grpc.CallOption) (*QueryCampaignResponse, error) + // Queries list of all Campaign items. + CampaignAll(ctx context.Context, in *QueryCampaignAllRequest, opts ...grpc.CallOption) (*QueryCampaignAllResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Campaign(ctx context.Context, in *QueryCampaignRequest, opts ...grpc.CallOption) (*QueryCampaignResponse, error) { + out := new(QueryCampaignResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Query/Campaign", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) CampaignAll(ctx context.Context, in *QueryCampaignAllRequest, opts ...grpc.CallOption) (*QueryCampaignAllResponse, error) { + out := new(QueryCampaignAllResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Query/CampaignAll", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // Queries an specific Campaign item. + Campaign(context.Context, *QueryCampaignRequest) (*QueryCampaignResponse, error) + // Queries list of all Campaign items. + CampaignAll(context.Context, *QueryCampaignAllRequest) (*QueryCampaignAllResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) Campaign(ctx context.Context, req *QueryCampaignRequest) (*QueryCampaignResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Campaign not implemented") +} +func (*UnimplementedQueryServer) CampaignAll(ctx context.Context, req *QueryCampaignAllRequest) (*QueryCampaignAllResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CampaignAll not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Campaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryCampaignRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Campaign(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Query/Campaign", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Campaign(ctx, req.(*QueryCampaignRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_CampaignAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryCampaignAllRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).CampaignAll(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Query/CampaignAll", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).CampaignAll(ctx, req.(*QueryCampaignAllRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "sgenetwork.sge.reward.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "Campaign", + Handler: _Query_Campaign_Handler, + }, + { + MethodName: "CampaignAll", + Handler: _Query_CampaignAll_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "sge/reward/query.proto", +} + +func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryCampaignRequest) 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 *QueryCampaignRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCampaignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Uid) > 0 { + i -= len(m.Uid) + copy(dAtA[i:], m.Uid) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Uid))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryCampaignResponse) 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 *QueryCampaignResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCampaignResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Campaign.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryCampaignAllRequest) 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 *QueryCampaignAllRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCampaignAllRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryCampaignAllResponse) 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 *QueryCampaignAllResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCampaignAllResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Campaign) > 0 { + for iNdEx := len(m.Campaign) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Campaign[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryCampaignRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Uid) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryCampaignResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Campaign.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryCampaignAllRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryCampaignAllResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Campaign) > 0 { + for _, e := range m.Campaign { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) 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 ErrIntOverflowQuery + } + 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: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) 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 ErrIntOverflowQuery + } + 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: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryCampaignRequest) 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 ErrIntOverflowQuery + } + 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: QueryCampaignRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCampaignRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Uid", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Uid = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryCampaignResponse) 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 ErrIntOverflowQuery + } + 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: QueryCampaignResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCampaignResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Campaign", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Campaign.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryCampaignAllRequest) 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 ErrIntOverflowQuery + } + 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: QueryCampaignAllRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCampaignAllRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryCampaignAllResponse) 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 ErrIntOverflowQuery + } + 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: QueryCampaignAllResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCampaignAllResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Campaign", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Campaign = append(m.Campaign, Campaign{}) + if err := m.Campaign[len(m.Campaign)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/reward/types/query.pb.gw.go b/x/reward/types/query.pb.gw.go new file mode 100644 index 00000000..a9bc1757 --- /dev/null +++ b/x/reward/types/query.pb.gw.go @@ -0,0 +1,337 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: sge/reward/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Campaign_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCampaignRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["uid"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "uid") + } + + protoReq.Uid, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "uid", err) + } + + msg, err := client.Campaign(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Campaign_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCampaignRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["uid"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "uid") + } + + protoReq.Uid, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "uid", err) + } + + msg, err := server.Campaign(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_CampaignAll_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_CampaignAll_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCampaignAllRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CampaignAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.CampaignAll(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_CampaignAll_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryCampaignAllRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_CampaignAll_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.CampaignAll(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Campaign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Campaign_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Campaign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_CampaignAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_CampaignAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CampaignAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Campaign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Campaign_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Campaign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_CampaignAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_CampaignAll_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_CampaignAll_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sge-network", "sge", "reward", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Campaign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge-network", "sge", "reward", "campaign", "uid"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_CampaignAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sge-network", "sge", "reward", "campaign"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_Campaign_0 = runtime.ForwardResponseMessage + + forward_Query_CampaignAll_0 = runtime.ForwardResponseMessage +) diff --git a/x/reward/types/reward.go b/x/reward/types/reward.go new file mode 100644 index 00000000..68410df2 --- /dev/null +++ b/x/reward/types/reward.go @@ -0,0 +1,53 @@ +package types + +import ( + context "context" + + sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type Definitions []Definition + +// RewardFactoryKeepers holds the keeper objectes usable by reward types methods. +type RewardFactoryKeepers struct { + OVMKeeper + BetKeeper +} + +// IRewardFactory defines the methods that should be implemented for all of reward types. +type IRewardFactory interface { + VaidateDefinitions(campaign Campaign) error + CalculateDistributions(goCtx context.Context, ctx sdk.Context, keepers RewardFactoryKeepers, + definitions Definitions, ticket string) ([]Distribution, error) +} + +// NewDistribution created new distribution object. +func NewDistribution(accAddr string, allocation Allocation) Distribution { + return Distribution{ + AccAddr: accAddr, + Allocation: allocation, + } +} + +// NewAllocation created allocation object. +func NewAllocation(amount sdkmath.Int, receiverAccType ReceiverAccType, unlockTS uint64) Allocation { + return Allocation{ + Amount: amount, + RecAccType: receiverAccType, + UnlockTS: unlockTS, + } +} + +// ValidateBasic validates the basic properties of a reward definition. +func (d *Definition) ValidateBasic(blockTime uint64) error { + if d.RecAccType != ReceiverAccType_RECEIVER_ACC_TYPE_SUB { + if d.UnlockTS != 0 { + return sdkerrors.Wrapf(ErrUnlockTSIsSubAccOnly, "%d", d.UnlockTS) + } + } else if d.UnlockTS <= blockTime { + return sdkerrors.Wrapf(ErrUnlockTSDefBeforeBlockTime, "%d", d.UnlockTS) + } + return nil +} diff --git a/x/reward/types/reward.pb.go b/x/reward/types/reward.pb.go new file mode 100644 index 00000000..a44d1ed4 --- /dev/null +++ b/x/reward/types/reward.pb.go @@ -0,0 +1,1487 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/reward/reward.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/gogoproto/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 + +// RewardType defines supported types of rewards of reward module. +type RewardType int32 + +const ( + // the invalid or unknown + RewardType_REWARD_TYPE_UNSPECIFIED RewardType = 0 + // signup reward + RewardType_REWARD_TYPE_SIGNUP RewardType = 1 + // referral reward + RewardType_REWARD_TYPE_REFERRAL RewardType = 2 + // affiliation reward + RewardType_REWARD_TYPE_AFFILIATION RewardType = 3 + // noloss bets reward + RewardType_REWARD_TYPE_NOLOSS_BETS RewardType = 4 +) + +var RewardType_name = map[int32]string{ + 0: "REWARD_TYPE_UNSPECIFIED", + 1: "REWARD_TYPE_SIGNUP", + 2: "REWARD_TYPE_REFERRAL", + 3: "REWARD_TYPE_AFFILIATION", + 4: "REWARD_TYPE_NOLOSS_BETS", +} + +var RewardType_value = map[string]int32{ + "REWARD_TYPE_UNSPECIFIED": 0, + "REWARD_TYPE_SIGNUP": 1, + "REWARD_TYPE_REFERRAL": 2, + "REWARD_TYPE_AFFILIATION": 3, + "REWARD_TYPE_NOLOSS_BETS": 4, +} + +func (x RewardType) String() string { + return proto.EnumName(RewardType_name, int32(x)) +} + +func (RewardType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_3412add70a4f177f, []int{0} +} + +// ReceiverAccType defines supported types account types for reward +// distribution. +type ReceiverAccType int32 + +const ( + // the invalid or unknown + ReceiverAccType_RECEIVER_ACC_TYPE_UNSPECIFIED ReceiverAccType = 0 + // main account + ReceiverAccType_RECEIVER_ACC_TYPE_MAIN ReceiverAccType = 1 + // sub account + ReceiverAccType_RECEIVER_ACC_TYPE_SUB ReceiverAccType = 2 +) + +var ReceiverAccType_name = map[int32]string{ + 0: "RECEIVER_ACC_TYPE_UNSPECIFIED", + 1: "RECEIVER_ACC_TYPE_MAIN", + 2: "RECEIVER_ACC_TYPE_SUB", +} + +var ReceiverAccType_value = map[string]int32{ + "RECEIVER_ACC_TYPE_UNSPECIFIED": 0, + "RECEIVER_ACC_TYPE_MAIN": 1, + "RECEIVER_ACC_TYPE_SUB": 2, +} + +func (x ReceiverAccType) String() string { + return proto.EnumName(ReceiverAccType_name, int32(x)) +} + +func (ReceiverAccType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_3412add70a4f177f, []int{1} +} + +// ReceiverType defines all of reward receiver types in the system. +type ReceiverType int32 + +const ( + // the invalid or unknown + ReceiverType_RECEIVER_TYPE_UNSPECIFIED ReceiverType = 0 + // single receiver account + ReceiverType_RECEIVER_TYPE_SINGLE ReceiverType = 1 + // referrer + ReceiverType_RECEIVER_TYPE_REFERRER ReceiverType = 2 + // referee + ReceiverType_RECEIVER_TYPE_REFEREE ReceiverType = 3 +) + +var ReceiverType_name = map[int32]string{ + 0: "RECEIVER_TYPE_UNSPECIFIED", + 1: "RECEIVER_TYPE_SINGLE", + 2: "RECEIVER_TYPE_REFERRER", + 3: "RECEIVER_TYPE_REFEREE", +} + +var ReceiverType_value = map[string]int32{ + "RECEIVER_TYPE_UNSPECIFIED": 0, + "RECEIVER_TYPE_SINGLE": 1, + "RECEIVER_TYPE_REFERRER": 2, + "RECEIVER_TYPE_REFEREE": 3, +} + +func (x ReceiverType) String() string { + return proto.EnumName(ReceiverType_name, int32(x)) +} + +func (ReceiverType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_3412add70a4f177f, []int{2} +} + +// RewardCommon is the type for common data of a reward. +type RewardCommon struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + CampaignUID string `protobuf:"bytes,2,opt,name=campaign_uid,proto3" json:"campaign_uid"` + TS uint64 `protobuf:"varint,3,opt,name=ts,proto3" json:"ts"` +} + +func (m *RewardCommon) Reset() { *m = RewardCommon{} } +func (m *RewardCommon) String() string { return proto.CompactTextString(m) } +func (*RewardCommon) ProtoMessage() {} +func (*RewardCommon) Descriptor() ([]byte, []int) { + return fileDescriptor_3412add70a4f177f, []int{0} +} +func (m *RewardCommon) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RewardCommon) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RewardCommon.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 *RewardCommon) XXX_Merge(src proto.Message) { + xxx_messageInfo_RewardCommon.Merge(m, src) +} +func (m *RewardCommon) XXX_Size() int { + return m.Size() +} +func (m *RewardCommon) XXX_DiscardUnknown() { + xxx_messageInfo_RewardCommon.DiscardUnknown(m) +} + +var xxx_messageInfo_RewardCommon proto.InternalMessageInfo + +func (m *RewardCommon) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *RewardCommon) GetCampaignUID() string { + if m != nil { + return m.CampaignUID + } + return "" +} + +func (m *RewardCommon) GetTS() uint64 { + if m != nil { + return m.TS + } + return 0 +} + +// Definition is the type for reward declaration for a campaign. +type Definition struct { + RecType ReceiverType `protobuf:"varint,1,opt,name=rec_type,json=recType,proto3,enum=sgenetwork.sge.reward.ReceiverType" json:"rec_type,omitempty"` + RecAccType ReceiverAccType `protobuf:"varint,2,opt,name=rec_acc_type,json=recAccType,proto3,enum=sgenetwork.sge.reward.ReceiverAccType" json:"rec_acc_type,omitempty"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount" yaml:"amount"` + UnlockTS uint64 `protobuf:"varint,4,opt,name=unlock_ts,proto3" json:"unlock_ts"` +} + +func (m *Definition) Reset() { *m = Definition{} } +func (m *Definition) String() string { return proto.CompactTextString(m) } +func (*Definition) ProtoMessage() {} +func (*Definition) Descriptor() ([]byte, []int) { + return fileDescriptor_3412add70a4f177f, []int{1} +} +func (m *Definition) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Definition) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Definition.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 *Definition) XXX_Merge(src proto.Message) { + xxx_messageInfo_Definition.Merge(m, src) +} +func (m *Definition) XXX_Size() int { + return m.Size() +} +func (m *Definition) XXX_DiscardUnknown() { + xxx_messageInfo_Definition.DiscardUnknown(m) +} + +var xxx_messageInfo_Definition proto.InternalMessageInfo + +func (m *Definition) GetRecType() ReceiverType { + if m != nil { + return m.RecType + } + return ReceiverType_RECEIVER_TYPE_UNSPECIFIED +} + +func (m *Definition) GetRecAccType() ReceiverAccType { + if m != nil { + return m.RecAccType + } + return ReceiverAccType_RECEIVER_ACC_TYPE_UNSPECIFIED +} + +func (m *Definition) GetUnlockTS() uint64 { + if m != nil { + return m.UnlockTS + } + return 0 +} + +// Distribution is the type for the distribution of a reward. +type Distribution struct { + AccAddr string `protobuf:"bytes,1,opt,name=acc_addr,json=accAddr,proto3" json:"acc_addr,omitempty"` + Allocation Allocation `protobuf:"bytes,2,opt,name=allocation,proto3" json:"allocation"` +} + +func (m *Distribution) Reset() { *m = Distribution{} } +func (m *Distribution) String() string { return proto.CompactTextString(m) } +func (*Distribution) ProtoMessage() {} +func (*Distribution) Descriptor() ([]byte, []int) { + return fileDescriptor_3412add70a4f177f, []int{2} +} +func (m *Distribution) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Distribution) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Distribution.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 *Distribution) XXX_Merge(src proto.Message) { + xxx_messageInfo_Distribution.Merge(m, src) +} +func (m *Distribution) XXX_Size() int { + return m.Size() +} +func (m *Distribution) XXX_DiscardUnknown() { + xxx_messageInfo_Distribution.DiscardUnknown(m) +} + +var xxx_messageInfo_Distribution proto.InternalMessageInfo + +func (m *Distribution) GetAccAddr() string { + if m != nil { + return m.AccAddr + } + return "" +} + +func (m *Distribution) GetAllocation() Allocation { + if m != nil { + return m.Allocation + } + return Allocation{} +} + +// Allocation is the distribution allocation of the rewards. +type Allocation struct { + Amount cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount" yaml:"amount"` + RecAccType ReceiverAccType `protobuf:"varint,2,opt,name=rec_acc_type,json=recAccType,proto3,enum=sgenetwork.sge.reward.ReceiverAccType" json:"rec_acc_type,omitempty"` + UnlockTS uint64 `protobuf:"varint,3,opt,name=unlock_ts,proto3" json:"unlock_ts"` +} + +func (m *Allocation) Reset() { *m = Allocation{} } +func (m *Allocation) String() string { return proto.CompactTextString(m) } +func (*Allocation) ProtoMessage() {} +func (*Allocation) Descriptor() ([]byte, []int) { + return fileDescriptor_3412add70a4f177f, []int{3} +} +func (m *Allocation) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Allocation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Allocation.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 *Allocation) XXX_Merge(src proto.Message) { + xxx_messageInfo_Allocation.Merge(m, src) +} +func (m *Allocation) XXX_Size() int { + return m.Size() +} +func (m *Allocation) XXX_DiscardUnknown() { + xxx_messageInfo_Allocation.DiscardUnknown(m) +} + +var xxx_messageInfo_Allocation proto.InternalMessageInfo + +func (m *Allocation) GetRecAccType() ReceiverAccType { + if m != nil { + return m.RecAccType + } + return ReceiverAccType_RECEIVER_ACC_TYPE_UNSPECIFIED +} + +func (m *Allocation) GetUnlockTS() uint64 { + if m != nil { + return m.UnlockTS + } + return 0 +} + +// Receiver is the type for reward receiver properties. +type Receiver struct { + RecType ReceiverType `protobuf:"varint,1,opt,name=rec_type,json=recType,proto3,enum=sgenetwork.sge.reward.ReceiverType" json:"rec_type,omitempty"` + Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` +} + +func (m *Receiver) Reset() { *m = Receiver{} } +func (m *Receiver) String() string { return proto.CompactTextString(m) } +func (*Receiver) ProtoMessage() {} +func (*Receiver) Descriptor() ([]byte, []int) { + return fileDescriptor_3412add70a4f177f, []int{4} +} +func (m *Receiver) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Receiver) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Receiver.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 *Receiver) XXX_Merge(src proto.Message) { + xxx_messageInfo_Receiver.Merge(m, src) +} +func (m *Receiver) XXX_Size() int { + return m.Size() +} +func (m *Receiver) XXX_DiscardUnknown() { + xxx_messageInfo_Receiver.DiscardUnknown(m) +} + +var xxx_messageInfo_Receiver proto.InternalMessageInfo + +func (m *Receiver) GetRecType() ReceiverType { + if m != nil { + return m.RecType + } + return ReceiverType_RECEIVER_TYPE_UNSPECIFIED +} + +func (m *Receiver) GetAddr() string { + if m != nil { + return m.Addr + } + return "" +} + +func init() { + proto.RegisterEnum("sgenetwork.sge.reward.RewardType", RewardType_name, RewardType_value) + proto.RegisterEnum("sgenetwork.sge.reward.ReceiverAccType", ReceiverAccType_name, ReceiverAccType_value) + proto.RegisterEnum("sgenetwork.sge.reward.ReceiverType", ReceiverType_name, ReceiverType_value) + proto.RegisterType((*RewardCommon)(nil), "sgenetwork.sge.reward.RewardCommon") + proto.RegisterType((*Definition)(nil), "sgenetwork.sge.reward.Definition") + proto.RegisterType((*Distribution)(nil), "sgenetwork.sge.reward.Distribution") + proto.RegisterType((*Allocation)(nil), "sgenetwork.sge.reward.Allocation") + proto.RegisterType((*Receiver)(nil), "sgenetwork.sge.reward.Receiver") +} + +func init() { proto.RegisterFile("sge/reward/reward.proto", fileDescriptor_3412add70a4f177f) } + +var fileDescriptor_3412add70a4f177f = []byte{ + // 675 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4d, 0x6f, 0xd3, 0x4a, + 0x14, 0x8d, 0x9d, 0xa8, 0x4d, 0x6f, 0xf3, 0xde, 0xb3, 0x46, 0xfd, 0x48, 0xfa, 0x68, 0xdc, 0x06, + 0x09, 0x95, 0x4a, 0x38, 0x52, 0x59, 0x20, 0xb1, 0x40, 0x72, 0x1c, 0xa7, 0x58, 0x0a, 0x69, 0x35, + 0x4e, 0x40, 0xb0, 0x20, 0x72, 0x27, 0x83, 0x6b, 0x25, 0xf6, 0x44, 0xf6, 0x84, 0xd2, 0x0d, 0x7f, + 0x80, 0x0d, 0x1b, 0xc4, 0x5f, 0xea, 0xb2, 0x3b, 0x10, 0x0b, 0x0b, 0xa5, 0xbb, 0x2e, 0xf9, 0x05, + 0xc8, 0x93, 0xb4, 0x49, 0xda, 0x22, 0x84, 0xca, 0xca, 0xd7, 0x73, 0xce, 0xbd, 0x33, 0xe7, 0xdc, + 0x99, 0x0b, 0xab, 0x91, 0x4b, 0xcb, 0x21, 0x3d, 0x72, 0xc2, 0xce, 0xf8, 0xa3, 0xf5, 0x43, 0xc6, + 0x19, 0x5a, 0x8e, 0x5c, 0x1a, 0x50, 0x7e, 0xc4, 0xc2, 0xae, 0x16, 0xb9, 0x54, 0x1b, 0x81, 0x6b, + 0x4b, 0x2e, 0x73, 0x99, 0x60, 0x94, 0x93, 0x68, 0x44, 0x2e, 0x7d, 0x90, 0x20, 0x87, 0x05, 0xc1, + 0x60, 0xbe, 0xcf, 0x02, 0x94, 0x87, 0x79, 0x12, 0x52, 0x87, 0xb3, 0x30, 0x2f, 0x6d, 0x48, 0x5b, + 0x0b, 0xf8, 0xe2, 0x17, 0x19, 0x90, 0x23, 0x8e, 0xdf, 0x77, 0x3c, 0x37, 0x68, 0x0f, 0xbc, 0x4e, + 0x5e, 0x4e, 0xe0, 0x8a, 0x3a, 0x8c, 0xd5, 0x45, 0x63, 0xbc, 0xde, 0xb2, 0xaa, 0xe7, 0xb1, 0x3a, + 0x43, 0xc3, 0x33, 0x7f, 0xe8, 0x0e, 0xc8, 0x3c, 0xca, 0xa7, 0x37, 0xa4, 0xad, 0x4c, 0x25, 0x37, + 0x8c, 0x55, 0xb9, 0x69, 0x9f, 0xc7, 0xaa, 0xcc, 0x23, 0x2c, 0xf3, 0xa8, 0xf4, 0x59, 0x06, 0xa8, + 0xd2, 0x37, 0x5e, 0xe0, 0x71, 0x8f, 0x05, 0xe8, 0x09, 0x64, 0x43, 0x4a, 0xda, 0xfc, 0xb8, 0x4f, + 0xc5, 0x61, 0xfe, 0xdd, 0xb9, 0xab, 0xdd, 0x28, 0x4e, 0xc3, 0x94, 0x50, 0xef, 0x2d, 0x0d, 0x9b, + 0xc7, 0x7d, 0x8a, 0xe7, 0x43, 0x4a, 0x92, 0x00, 0x3d, 0x85, 0x5c, 0x92, 0xef, 0x90, 0x71, 0x0d, + 0x59, 0xd4, 0xb8, 0xf7, 0x9b, 0x1a, 0x3a, 0x11, 0xd9, 0x18, 0x42, 0x4a, 0xc6, 0x31, 0xaa, 0xc1, + 0x9c, 0xe3, 0xb3, 0x41, 0xc0, 0xc5, 0xd1, 0x17, 0x2a, 0xda, 0x49, 0xac, 0xa6, 0xbe, 0xc5, 0xea, + 0x32, 0x61, 0x91, 0xcf, 0xa2, 0xa8, 0xd3, 0xd5, 0x3c, 0x56, 0xf6, 0x1d, 0x7e, 0xa8, 0x59, 0x01, + 0xff, 0x11, 0xab, 0xff, 0x1c, 0x3b, 0x7e, 0xef, 0x71, 0x69, 0x94, 0x54, 0xc2, 0xe3, 0x6c, 0xf4, + 0x08, 0x16, 0x06, 0x41, 0x8f, 0x91, 0x6e, 0x9b, 0x47, 0xf9, 0x8c, 0x70, 0xa1, 0x30, 0x8c, 0xd5, + 0x6c, 0x4b, 0x2c, 0x0a, 0x2f, 0x26, 0x04, 0x3c, 0x09, 0x4b, 0x21, 0xe4, 0xaa, 0x5e, 0xc4, 0x43, + 0xef, 0x60, 0x20, 0xac, 0x29, 0x40, 0x36, 0x91, 0xe5, 0x74, 0x3a, 0x97, 0x7d, 0x72, 0x08, 0xd1, + 0x3b, 0x9d, 0x10, 0xed, 0x02, 0x38, 0xbd, 0x1e, 0x23, 0x4e, 0x42, 0x14, 0x9a, 0x17, 0x77, 0x36, + 0x7f, 0xa1, 0x59, 0xbf, 0x24, 0x56, 0x32, 0x89, 0x24, 0x3c, 0x95, 0x5a, 0xfa, 0x22, 0x01, 0x4c, + 0x08, 0x53, 0x1e, 0x48, 0xb7, 0xf2, 0xe0, 0xef, 0x75, 0x65, 0xc6, 0xcd, 0xf4, 0x1f, 0xb8, 0xf9, + 0x1a, 0xb2, 0x17, 0x75, 0x6f, 0x7d, 0xc9, 0x10, 0x64, 0x44, 0x17, 0xc4, 0x73, 0xc0, 0x22, 0xde, + 0xfe, 0x24, 0x01, 0x8c, 0x5e, 0x95, 0xa0, 0xfc, 0x0f, 0xab, 0xd8, 0x7c, 0xa1, 0xe3, 0x6a, 0xbb, + 0xf9, 0x72, 0xdf, 0x6c, 0xb7, 0x1a, 0xf6, 0xbe, 0x69, 0x58, 0x35, 0xcb, 0xac, 0x2a, 0x29, 0xb4, + 0x02, 0x68, 0x1a, 0xb4, 0xad, 0xdd, 0x46, 0x6b, 0x5f, 0x91, 0x50, 0x1e, 0x96, 0xa6, 0xd7, 0xb1, + 0x59, 0x33, 0x31, 0xd6, 0xeb, 0x8a, 0x7c, 0xb5, 0x9c, 0x5e, 0xab, 0x59, 0x75, 0x4b, 0x6f, 0x5a, + 0x7b, 0x0d, 0x25, 0x7d, 0x15, 0x6c, 0xec, 0xd5, 0xf7, 0x6c, 0xbb, 0x5d, 0x31, 0x9b, 0xb6, 0x92, + 0xd9, 0xee, 0xc2, 0x7f, 0x57, 0xfc, 0x44, 0x9b, 0xb0, 0x8e, 0x4d, 0xc3, 0xb4, 0x9e, 0x9b, 0xb8, + 0xad, 0x1b, 0xc6, 0x4d, 0x27, 0x5c, 0x83, 0x95, 0xeb, 0x94, 0x67, 0xba, 0xd5, 0x50, 0x24, 0x54, + 0x80, 0xe5, 0xeb, 0x98, 0xdd, 0xaa, 0x28, 0xf2, 0xf6, 0xfb, 0x64, 0xb2, 0x4c, 0x1c, 0x43, 0xeb, + 0x50, 0xb8, 0xa4, 0xde, 0xb0, 0x8b, 0xd0, 0x3b, 0x0d, 0xdb, 0x56, 0x63, 0xb7, 0x6e, 0x2a, 0xd2, + 0xcc, 0xfe, 0x53, 0x5e, 0x98, 0x58, 0x91, 0x67, 0xf6, 0x9f, 0x60, 0xa6, 0xa9, 0xa4, 0x2b, 0xc6, + 0xc9, 0xb0, 0x28, 0x9d, 0x0e, 0x8b, 0xd2, 0xf7, 0x61, 0x51, 0xfa, 0x78, 0x56, 0x4c, 0x9d, 0x9e, + 0x15, 0x53, 0x5f, 0xcf, 0x8a, 0xa9, 0x57, 0xf7, 0x5d, 0x8f, 0x1f, 0x0e, 0x0e, 0x34, 0xc2, 0xfc, + 0x72, 0xe4, 0xd2, 0x07, 0xe3, 0x5e, 0x27, 0x71, 0xf9, 0xdd, 0xc5, 0x4c, 0x4d, 0x2e, 0x44, 0x74, + 0x30, 0x27, 0xc6, 0xe4, 0xc3, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x7a, 0xe8, 0x36, 0x6e, + 0x05, 0x00, 0x00, +} + +func (m *RewardCommon) 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 *RewardCommon) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RewardCommon) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TS != 0 { + i = encodeVarintReward(dAtA, i, uint64(m.TS)) + i-- + dAtA[i] = 0x18 + } + if len(m.CampaignUID) > 0 { + i -= len(m.CampaignUID) + copy(dAtA[i:], m.CampaignUID) + i = encodeVarintReward(dAtA, i, uint64(len(m.CampaignUID))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintReward(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Definition) 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 *Definition) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Definition) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.UnlockTS != 0 { + i = encodeVarintReward(dAtA, i, uint64(m.UnlockTS)) + i-- + dAtA[i] = 0x20 + } + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintReward(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.RecAccType != 0 { + i = encodeVarintReward(dAtA, i, uint64(m.RecAccType)) + i-- + dAtA[i] = 0x10 + } + if m.RecType != 0 { + i = encodeVarintReward(dAtA, i, uint64(m.RecType)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Distribution) 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 *Distribution) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Distribution) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Allocation.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintReward(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.AccAddr) > 0 { + i -= len(m.AccAddr) + copy(dAtA[i:], m.AccAddr) + i = encodeVarintReward(dAtA, i, uint64(len(m.AccAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Allocation) 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 *Allocation) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Allocation) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.UnlockTS != 0 { + i = encodeVarintReward(dAtA, i, uint64(m.UnlockTS)) + i-- + dAtA[i] = 0x18 + } + if m.RecAccType != 0 { + i = encodeVarintReward(dAtA, i, uint64(m.RecAccType)) + i-- + dAtA[i] = 0x10 + } + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintReward(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *Receiver) 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 *Receiver) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Receiver) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Addr) > 0 { + i -= len(m.Addr) + copy(dAtA[i:], m.Addr) + i = encodeVarintReward(dAtA, i, uint64(len(m.Addr))) + i-- + dAtA[i] = 0x12 + } + if m.RecType != 0 { + i = encodeVarintReward(dAtA, i, uint64(m.RecType)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintReward(dAtA []byte, offset int, v uint64) int { + offset -= sovReward(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *RewardCommon) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovReward(uint64(l)) + } + l = len(m.CampaignUID) + if l > 0 { + n += 1 + l + sovReward(uint64(l)) + } + if m.TS != 0 { + n += 1 + sovReward(uint64(m.TS)) + } + return n +} + +func (m *Definition) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.RecType != 0 { + n += 1 + sovReward(uint64(m.RecType)) + } + if m.RecAccType != 0 { + n += 1 + sovReward(uint64(m.RecAccType)) + } + l = m.Amount.Size() + n += 1 + l + sovReward(uint64(l)) + if m.UnlockTS != 0 { + n += 1 + sovReward(uint64(m.UnlockTS)) + } + return n +} + +func (m *Distribution) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.AccAddr) + if l > 0 { + n += 1 + l + sovReward(uint64(l)) + } + l = m.Allocation.Size() + n += 1 + l + sovReward(uint64(l)) + return n +} + +func (m *Allocation) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Amount.Size() + n += 1 + l + sovReward(uint64(l)) + if m.RecAccType != 0 { + n += 1 + sovReward(uint64(m.RecAccType)) + } + if m.UnlockTS != 0 { + n += 1 + sovReward(uint64(m.UnlockTS)) + } + return n +} + +func (m *Receiver) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.RecType != 0 { + n += 1 + sovReward(uint64(m.RecType)) + } + l = len(m.Addr) + if l > 0 { + n += 1 + l + sovReward(uint64(l)) + } + return n +} + +func sovReward(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozReward(x uint64) (n int) { + return sovReward(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *RewardCommon) 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 ErrIntOverflowReward + } + 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: RewardCommon: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RewardCommon: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + 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 ErrInvalidLengthReward + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReward + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CampaignUID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + 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 ErrInvalidLengthReward + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReward + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CampaignUID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TS", wireType) + } + m.TS = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TS |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipReward(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthReward + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Definition) 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 ErrIntOverflowReward + } + 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: Definition: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Definition: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RecType", wireType) + } + m.RecType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RecType |= ReceiverType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RecAccType", wireType) + } + m.RecAccType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RecAccType |= ReceiverAccType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + 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 ErrInvalidLengthReward + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReward + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UnlockTS", wireType) + } + m.UnlockTS = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UnlockTS |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipReward(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthReward + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Distribution) 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 ErrIntOverflowReward + } + 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: Distribution: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Distribution: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AccAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + 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 ErrInvalidLengthReward + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReward + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AccAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Allocation", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthReward + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthReward + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Allocation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipReward(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthReward + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Allocation) 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 ErrIntOverflowReward + } + 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: Allocation: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Allocation: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + 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 ErrInvalidLengthReward + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReward + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RecAccType", wireType) + } + m.RecAccType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RecAccType |= ReceiverAccType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UnlockTS", wireType) + } + m.UnlockTS = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UnlockTS |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipReward(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthReward + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Receiver) 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 ErrIntOverflowReward + } + 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: Receiver: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Receiver: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RecType", wireType) + } + m.RecType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RecType |= ReceiverType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReward + } + 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 ErrInvalidLengthReward + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthReward + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipReward(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthReward + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipReward(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, ErrIntOverflowReward + } + 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, ErrIntOverflowReward + } + 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, ErrIntOverflowReward + } + 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, ErrInvalidLengthReward + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupReward + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthReward + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthReward = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowReward = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupReward = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/reward/types/reward_affiliate.go b/x/reward/types/reward_affiliate.go new file mode 100644 index 00000000..904dfc3b --- /dev/null +++ b/x/reward/types/reward_affiliate.go @@ -0,0 +1,55 @@ +package types + +import ( + context "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// AffiliationReward is the type for affiliation rewards calculations +type AffiliationReward struct{} + +// NewAffiliationReward create new object of affiliation reward calculator type. +func NewAffiliationReward() AffiliationReward { return AffiliationReward{} } + +// VaidateDefinitions validates campaign definitions. +func (afr AffiliationReward) VaidateDefinitions(campaign Campaign) error { + if len(campaign.RewardDefs) != 1 { + return sdkerrors.Wrapf(ErrWrongDefinitionsCount, "affiliation rewards can only have single definition") + } + if campaign.RewardDefs[0].RecType != ReceiverType_RECEIVER_TYPE_SINGLE { + return sdkerrors.Wrapf(ErrInvalidReceiverType, "affiliation rewards can be defined for subaccount only") + } + if campaign.RewardDefs[0].RecAccType == ReceiverAccType_RECEIVER_ACC_TYPE_UNSPECIFIED { + return sdkerrors.Wrapf(ErrInvalidReceiverType, "bad account type for the receiver") + } + return nil +} + +// CalculateDistributions parses ticket payload and returns the distribution list of affiliation reward. +func (afr AffiliationReward) CalculateDistributions(goCtx context.Context, ctx sdk.Context, keepers RewardFactoryKeepers, + definitions Definitions, ticket string, +) ([]Distribution, error) { + var payload ApplyAffiliationRewardPayload + if err := keepers.OVMKeeper.VerifyTicketUnmarshal(goCtx, ticket, &payload); err != nil { + return nil, sdkerrors.Wrapf(ErrInTicketVerification, "%s", err) + } + + definition := definitions[0] + + if payload.Receiver.RecType != definition.RecType { + return nil, sdkerrors.Wrapf(ErrAccReceiverTypeNotFound, "%s", payload.Receiver.RecType) + } + + return []Distribution{ + NewDistribution( + payload.Receiver.Addr, + NewAllocation( + definition.Amount, + definition.RecAccType, + definition.UnlockTS, + ), + ), + }, nil +} diff --git a/x/reward/types/reward_noloss.go b/x/reward/types/reward_noloss.go new file mode 100644 index 00000000..b42f2592 --- /dev/null +++ b/x/reward/types/reward_noloss.go @@ -0,0 +1,72 @@ +package types + +import ( + context "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + bettypes "github.com/sge-network/sge/x/bet/types" +) + +// NoLossBetsReward is the type for no loss bets rewards calculations +type NoLossBetsReward struct{} + +// NewNoLossBetsReward create new object of no loss bets reward calculator type. +func NewNoLossBetsReward() NoLossBetsReward { return NoLossBetsReward{} } + +// VaidateDefinitions validates campaign definitions. +func (afr NoLossBetsReward) VaidateDefinitions(campaign Campaign) error { + if len(campaign.RewardDefs) != 1 { + return sdkerrors.Wrapf(ErrWrongDefinitionsCount, "noloss bets rewards can only have single definition") + } + if campaign.RewardDefs[0].RecType != ReceiverType_RECEIVER_TYPE_SINGLE { + return sdkerrors.Wrapf(ErrInvalidReceiverType, "noloss bets rewards can be defined for subaccount only") + } + if campaign.RewardDefs[0].RecAccType == ReceiverAccType_RECEIVER_ACC_TYPE_UNSPECIFIED { + return sdkerrors.Wrapf(ErrInvalidReceiverType, "bad account type for the receiver") + } + return nil +} + +// CalculateDistributions parses ticket payload and returns the distribution list of no loss bets reward. +func (afr NoLossBetsReward) CalculateDistributions(goCtx context.Context, ctx sdk.Context, keepers RewardFactoryKeepers, + definitions Definitions, ticket string, +) ([]Distribution, error) { + var payload ApplyNoLossBetsRewardPayload + if err := keepers.OVMKeeper.VerifyTicketUnmarshal(goCtx, ticket, &payload); err != nil { + return nil, sdkerrors.Wrapf(ErrInTicketVerification, "%s", err) + } + + definition := definitions[0] + + if payload.Receiver.RecType != definition.RecType { + return nil, sdkerrors.Wrapf(ErrAccReceiverTypeNotFound, "%s", payload.Receiver.RecType) + } + + bettorAddr := payload.Receiver.Addr + for _, betUID := range payload.BetUids { + uID2ID, found := keepers.BetKeeper.GetBetID(ctx, betUID) + if !found { + return nil, sdkerrors.Wrapf(ErrInvalidNoLossBetUID, "bet id not found %s", betUID) + } + bet, found := keepers.BetKeeper.GetBet(ctx, bettorAddr, uID2ID.ID) + if !found { + return nil, sdkerrors.Wrapf(ErrInvalidNoLossBetUID, "bet not found %s", betUID) + } + if bet.Result != bettypes.Bet_RESULT_LOST { + return nil, sdkerrors.Wrapf(ErrInvalidNoLossBetUID, "the bet result is not loss %s", betUID) + } + } + + return []Distribution{ + NewDistribution( + payload.Receiver.Addr, + NewAllocation( + definition.Amount, + definition.RecAccType, + definition.UnlockTS, + ), + ), + }, nil +} diff --git a/x/reward/types/reward_referral.go b/x/reward/types/reward_referral.go new file mode 100644 index 00000000..18f47eb6 --- /dev/null +++ b/x/reward/types/reward_referral.go @@ -0,0 +1,71 @@ +package types + +import ( + context "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// ReferralReward is the type for referral rewards calculations +type ReferralReward struct{} + +// NewReferralReward create new object of referral reward calculator type. +func NewReferralReward() ReferralReward { return ReferralReward{} } + +// VaidateDefinitions validates campaign definitions. +func (rfr ReferralReward) VaidateDefinitions(campaign Campaign) error { + hasReferrer := false + hasReferee := false + for _, d := range campaign.RewardDefs { + if d.RecAccType != ReceiverAccType_RECEIVER_ACC_TYPE_SUB { + return sdkerrors.Wrapf(ErrInvalidReceiverType, "referral rewards can be defined for subaccount only") + } + switch d.RecType { + case ReceiverType_RECEIVER_TYPE_REFEREE: + hasReferee = true + case ReceiverType_RECEIVER_TYPE_REFERRER: + hasReferrer = true + default: + return sdkerrors.Wrapf(ErrInvalidReceiverType, "%s", d.RecType) + } + } + + if !hasReferee || !hasReferrer { + return sdkerrors.Wrapf(ErrMissingDefinition, "referral rewards should have the referrer and the referee") + } + return nil +} + +// CalculateDistributions parses ticket payload and returns the distribution list of referral reward. +func (rfr ReferralReward) CalculateDistributions(goCtx context.Context, ctx sdk.Context, keepers RewardFactoryKeepers, + definitions Definitions, ticket string, +) ([]Distribution, error) { + var payload ApplyRerferralRewardPayload + if err := keepers.OVMKeeper.VerifyTicketUnmarshal(goCtx, ticket, &payload); err != nil { + return nil, sdkerrors.Wrapf(ErrInTicketVerification, "%s", err) + } + + distributions := []Distribution{} + for _, d := range definitions { + found := false + for _, r := range payload.Receivers { + if d.RecType == r.RecType { + found = true + distributions = append(distributions, NewDistribution( + r.Addr, + NewAllocation( + d.Amount, + d.RecAccType, + d.UnlockTS, + ), + )) + } + } + if !found { + return nil, sdkerrors.Wrapf(ErrAccReceiverTypeNotFound, "%s", d.RecType) + } + } + + return distributions, nil +} diff --git a/x/reward/types/reward_signup.go b/x/reward/types/reward_signup.go new file mode 100644 index 00000000..b6589412 --- /dev/null +++ b/x/reward/types/reward_signup.go @@ -0,0 +1,55 @@ +package types + +import ( + context "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// SignUpReward is the type for signup rewards calculations +type SignUpReward struct{} + +// NewSignUpReward create new object of signup reward calculator type. +func NewSignUpReward() SignUpReward { return SignUpReward{} } + +// VaidateDefinitions validates campaign definitions. +func (sur SignUpReward) VaidateDefinitions(campaign Campaign) error { + if len(campaign.RewardDefs) != 1 { + return sdkerrors.Wrapf(ErrWrongDefinitionsCount, "signup rewards can only have single definition") + } + if campaign.RewardDefs[0].RecType != ReceiverType_RECEIVER_TYPE_SINGLE { + return sdkerrors.Wrapf(ErrInvalidReceiverType, "signup rewards can be defined for single receiver only") + } + if campaign.RewardDefs[0].RecAccType != ReceiverAccType_RECEIVER_ACC_TYPE_SUB { + return sdkerrors.Wrapf(ErrInvalidReceiverType, "signup rewards can be defined for subaccount only") + } + return nil +} + +// CalculateDistributions parses ticket payload and returns the distribution list of signup reward. +func (sur SignUpReward) CalculateDistributions(goCtx context.Context, ctx sdk.Context, keepers RewardFactoryKeepers, + definitions Definitions, ticket string, +) ([]Distribution, error) { + var payload ApplySignupRewardPayload + if err := keepers.OVMKeeper.VerifyTicketUnmarshal(goCtx, ticket, &payload); err != nil { + return nil, sdkerrors.Wrapf(ErrInTicketVerification, "%s", err) + } + + definition := definitions[0] + + if payload.Receiver.RecType != definition.RecType { + return nil, sdkerrors.Wrapf(ErrAccReceiverTypeNotFound, "%s", payload.Receiver.RecType) + } + + return []Distribution{ + NewDistribution( + payload.Receiver.Addr, + NewAllocation( + definition.Amount, + definition.RecAccType, + definition.UnlockTS, + ), + ), + }, nil +} diff --git a/x/reward/types/ticket.go b/x/reward/types/ticket.go new file mode 100644 index 00000000..77034e9e --- /dev/null +++ b/x/reward/types/ticket.go @@ -0,0 +1,43 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" +) + +// Validate validates campaign creation ticket payload. +func (payload *CreateCampaignPayload) Validate(blockTime uint64) error { + _, err := sdk.AccAddressFromBech32(payload.FunderAddress) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if payload.StartTs >= payload.EndTs { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "start timestamp can not be after end time") + } + + if payload.EndTs <= blockTime { + return sdkerrors.Wrapf(ErrExpiredCampaign, "%d", payload.EndTs) + } + + if len(payload.RewardDefs) == 0 { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "at least one reward definition should be defined") + } + + if payload.PoolAmount.IsNil() || !payload.PoolAmount.GT(sdkmath.ZeroInt()) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "pool amount should be positive") + } + + return nil +} + +// Validate validates campaign update ticket payload. +func (payload *UpdateCampaignPayload) Validate(blockTime uint64) error { + if payload.EndTs < blockTime { + return sdkerrors.Wrapf(ErrExpiredCampaign, "%d", payload.EndTs) + } + + return nil +} diff --git a/x/reward/types/ticket.pb.go b/x/reward/types/ticket.pb.go new file mode 100644 index 00000000..cfabd21f --- /dev/null +++ b/x/reward/types/ticket.pb.go @@ -0,0 +1,1464 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/reward/ticket.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/gogoproto/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 + +// CreateCampaignPayload is the type for campaign creation payload. +type CreateCampaignPayload struct { + FunderAddress string `protobuf:"bytes,1,opt,name=funder_address,json=funderAddress,proto3" json:"funder_address,omitempty"` + StartTs uint64 `protobuf:"varint,2,opt,name=start_ts,json=startTs,proto3" json:"start_ts,omitempty"` + EndTs uint64 `protobuf:"varint,3,opt,name=end_ts,json=endTs,proto3" json:"end_ts,omitempty"` + Type RewardType `protobuf:"varint,4,opt,name=type,proto3,enum=sgenetwork.sge.reward.RewardType" json:"type,omitempty"` + RewardDefs []Definition `protobuf:"bytes,6,rep,name=reward_defs,json=rewardDefs,proto3" json:"reward_defs"` + PoolAmount cosmossdk_io_math.Int `protobuf:"bytes,7,opt,name=pool_amount,json=poolAmount,proto3,customtype=cosmossdk.io/math.Int" json:"pool_amount" yaml:"pool_amount"` +} + +func (m *CreateCampaignPayload) Reset() { *m = CreateCampaignPayload{} } +func (m *CreateCampaignPayload) String() string { return proto.CompactTextString(m) } +func (*CreateCampaignPayload) ProtoMessage() {} +func (*CreateCampaignPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{0} +} +func (m *CreateCampaignPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CreateCampaignPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CreateCampaignPayload.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 *CreateCampaignPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateCampaignPayload.Merge(m, src) +} +func (m *CreateCampaignPayload) XXX_Size() int { + return m.Size() +} +func (m *CreateCampaignPayload) XXX_DiscardUnknown() { + xxx_messageInfo_CreateCampaignPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateCampaignPayload proto.InternalMessageInfo + +func (m *CreateCampaignPayload) GetFunderAddress() string { + if m != nil { + return m.FunderAddress + } + return "" +} + +func (m *CreateCampaignPayload) GetStartTs() uint64 { + if m != nil { + return m.StartTs + } + return 0 +} + +func (m *CreateCampaignPayload) GetEndTs() uint64 { + if m != nil { + return m.EndTs + } + return 0 +} + +func (m *CreateCampaignPayload) GetType() RewardType { + if m != nil { + return m.Type + } + return RewardType_REWARD_TYPE_UNSPECIFIED +} + +func (m *CreateCampaignPayload) GetRewardDefs() []Definition { + if m != nil { + return m.RewardDefs + } + return nil +} + +// UpdateCampaignPayload is the type for campaign update payload. +type UpdateCampaignPayload struct { + EndTs uint64 `protobuf:"varint,1,opt,name=end_ts,json=endTs,proto3" json:"end_ts,omitempty"` +} + +func (m *UpdateCampaignPayload) Reset() { *m = UpdateCampaignPayload{} } +func (m *UpdateCampaignPayload) String() string { return proto.CompactTextString(m) } +func (*UpdateCampaignPayload) ProtoMessage() {} +func (*UpdateCampaignPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{1} +} +func (m *UpdateCampaignPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UpdateCampaignPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UpdateCampaignPayload.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 *UpdateCampaignPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateCampaignPayload.Merge(m, src) +} +func (m *UpdateCampaignPayload) XXX_Size() int { + return m.Size() +} +func (m *UpdateCampaignPayload) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateCampaignPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateCampaignPayload proto.InternalMessageInfo + +func (m *UpdateCampaignPayload) GetEndTs() uint64 { + if m != nil { + return m.EndTs + } + return 0 +} + +// ApplySignupRewardPayload is the signup reward ticket payload type. +type ApplySignupRewardPayload struct { + Receiver Receiver `protobuf:"bytes,1,opt,name=receiver,proto3" json:"receiver"` +} + +func (m *ApplySignupRewardPayload) Reset() { *m = ApplySignupRewardPayload{} } +func (m *ApplySignupRewardPayload) String() string { return proto.CompactTextString(m) } +func (*ApplySignupRewardPayload) ProtoMessage() {} +func (*ApplySignupRewardPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{2} +} +func (m *ApplySignupRewardPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ApplySignupRewardPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ApplySignupRewardPayload.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 *ApplySignupRewardPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_ApplySignupRewardPayload.Merge(m, src) +} +func (m *ApplySignupRewardPayload) XXX_Size() int { + return m.Size() +} +func (m *ApplySignupRewardPayload) XXX_DiscardUnknown() { + xxx_messageInfo_ApplySignupRewardPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_ApplySignupRewardPayload proto.InternalMessageInfo + +func (m *ApplySignupRewardPayload) GetReceiver() Receiver { + if m != nil { + return m.Receiver + } + return Receiver{} +} + +// ApplyRerferralRewardPayload is the referral reward ticket payload type. +type ApplyRerferralRewardPayload struct { + Receivers []Receiver `protobuf:"bytes,1,rep,name=receivers,proto3" json:"receivers"` +} + +func (m *ApplyRerferralRewardPayload) Reset() { *m = ApplyRerferralRewardPayload{} } +func (m *ApplyRerferralRewardPayload) String() string { return proto.CompactTextString(m) } +func (*ApplyRerferralRewardPayload) ProtoMessage() {} +func (*ApplyRerferralRewardPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{3} +} +func (m *ApplyRerferralRewardPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ApplyRerferralRewardPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ApplyRerferralRewardPayload.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 *ApplyRerferralRewardPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_ApplyRerferralRewardPayload.Merge(m, src) +} +func (m *ApplyRerferralRewardPayload) XXX_Size() int { + return m.Size() +} +func (m *ApplyRerferralRewardPayload) XXX_DiscardUnknown() { + xxx_messageInfo_ApplyRerferralRewardPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_ApplyRerferralRewardPayload proto.InternalMessageInfo + +func (m *ApplyRerferralRewardPayload) GetReceivers() []Receiver { + if m != nil { + return m.Receivers + } + return nil +} + +// ApplyAffiliationRewardPayload is the affiliation reward ticket payload type. +type ApplyAffiliationRewardPayload struct { + Receiver Receiver `protobuf:"bytes,1,opt,name=receiver,proto3" json:"receiver"` +} + +func (m *ApplyAffiliationRewardPayload) Reset() { *m = ApplyAffiliationRewardPayload{} } +func (m *ApplyAffiliationRewardPayload) String() string { return proto.CompactTextString(m) } +func (*ApplyAffiliationRewardPayload) ProtoMessage() {} +func (*ApplyAffiliationRewardPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{4} +} +func (m *ApplyAffiliationRewardPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ApplyAffiliationRewardPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ApplyAffiliationRewardPayload.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 *ApplyAffiliationRewardPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_ApplyAffiliationRewardPayload.Merge(m, src) +} +func (m *ApplyAffiliationRewardPayload) XXX_Size() int { + return m.Size() +} +func (m *ApplyAffiliationRewardPayload) XXX_DiscardUnknown() { + xxx_messageInfo_ApplyAffiliationRewardPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_ApplyAffiliationRewardPayload proto.InternalMessageInfo + +func (m *ApplyAffiliationRewardPayload) GetReceiver() Receiver { + if m != nil { + return m.Receiver + } + return Receiver{} +} + +// ApplyNoLossBetsRewardPayload is the noloss bets reward ticket payload type. +type ApplyNoLossBetsRewardPayload struct { + Receiver Receiver `protobuf:"bytes,1,opt,name=receiver,proto3" json:"receiver"` + BetUids []string `protobuf:"bytes,3,rep,name=bet_uids,json=betUids,proto3" json:"bet_uids,omitempty"` +} + +func (m *ApplyNoLossBetsRewardPayload) Reset() { *m = ApplyNoLossBetsRewardPayload{} } +func (m *ApplyNoLossBetsRewardPayload) String() string { return proto.CompactTextString(m) } +func (*ApplyNoLossBetsRewardPayload) ProtoMessage() {} +func (*ApplyNoLossBetsRewardPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{5} +} +func (m *ApplyNoLossBetsRewardPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ApplyNoLossBetsRewardPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ApplyNoLossBetsRewardPayload.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 *ApplyNoLossBetsRewardPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_ApplyNoLossBetsRewardPayload.Merge(m, src) +} +func (m *ApplyNoLossBetsRewardPayload) XXX_Size() int { + return m.Size() +} +func (m *ApplyNoLossBetsRewardPayload) XXX_DiscardUnknown() { + xxx_messageInfo_ApplyNoLossBetsRewardPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_ApplyNoLossBetsRewardPayload proto.InternalMessageInfo + +func (m *ApplyNoLossBetsRewardPayload) GetReceiver() Receiver { + if m != nil { + return m.Receiver + } + return Receiver{} +} + +func (m *ApplyNoLossBetsRewardPayload) GetBetUids() []string { + if m != nil { + return m.BetUids + } + return nil +} + +func init() { + proto.RegisterType((*CreateCampaignPayload)(nil), "sgenetwork.sge.reward.CreateCampaignPayload") + proto.RegisterType((*UpdateCampaignPayload)(nil), "sgenetwork.sge.reward.UpdateCampaignPayload") + proto.RegisterType((*ApplySignupRewardPayload)(nil), "sgenetwork.sge.reward.ApplySignupRewardPayload") + proto.RegisterType((*ApplyRerferralRewardPayload)(nil), "sgenetwork.sge.reward.ApplyRerferralRewardPayload") + proto.RegisterType((*ApplyAffiliationRewardPayload)(nil), "sgenetwork.sge.reward.ApplyAffiliationRewardPayload") + proto.RegisterType((*ApplyNoLossBetsRewardPayload)(nil), "sgenetwork.sge.reward.ApplyNoLossBetsRewardPayload") +} + +func init() { proto.RegisterFile("sge/reward/ticket.proto", fileDescriptor_5d710bc1249ca8ae) } + +var fileDescriptor_5d710bc1249ca8ae = []byte{ + // 504 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0x4f, 0x8b, 0xd3, 0x40, + 0x1c, 0x6d, 0xb6, 0xb5, 0xdd, 0x4e, 0x71, 0x0f, 0xc1, 0x62, 0x5c, 0x35, 0xad, 0x01, 0xa1, 0x1e, + 0x4c, 0x60, 0x17, 0x2f, 0xde, 0xda, 0xee, 0x41, 0x41, 0x44, 0x62, 0xf7, 0x22, 0x48, 0x99, 0x74, + 0x7e, 0xc9, 0x0e, 0x4d, 0x32, 0x61, 0x7e, 0x13, 0xd7, 0x80, 0x1f, 0xc2, 0x6f, 0xe5, 0x1e, 0xf7, + 0x28, 0x1e, 0x8a, 0xb4, 0xdf, 0xc0, 0x4f, 0x20, 0x99, 0xd9, 0x3f, 0x15, 0x76, 0xc1, 0xc3, 0x9e, + 0x32, 0xbf, 0x79, 0xef, 0xcd, 0xcb, 0x7b, 0xcc, 0x90, 0x87, 0x98, 0x40, 0x20, 0xe1, 0x94, 0x4a, + 0x16, 0x28, 0xbe, 0x58, 0x82, 0xf2, 0x0b, 0x29, 0x94, 0xb0, 0xfb, 0x98, 0x40, 0x0e, 0xea, 0x54, + 0xc8, 0xa5, 0x8f, 0x09, 0xf8, 0x86, 0xb3, 0xff, 0x20, 0x11, 0x89, 0xd0, 0x8c, 0xa0, 0x5e, 0x19, + 0xf2, 0xfe, 0xf6, 0x29, 0xe6, 0x63, 0x00, 0xef, 0xc7, 0x0e, 0xe9, 0x4f, 0x25, 0x50, 0x05, 0x53, + 0x9a, 0x15, 0x94, 0x27, 0xf9, 0x07, 0x5a, 0xa5, 0x82, 0x32, 0xfb, 0x39, 0xd9, 0x8b, 0xcb, 0x9c, + 0x81, 0x9c, 0x53, 0xc6, 0x24, 0x20, 0x3a, 0xd6, 0xd0, 0x1a, 0x75, 0xc3, 0xfb, 0x66, 0x77, 0x6c, + 0x36, 0xed, 0x47, 0x64, 0x17, 0x15, 0x95, 0x6a, 0xae, 0xd0, 0xd9, 0x19, 0x5a, 0xa3, 0x56, 0xd8, + 0xd1, 0xf3, 0x0c, 0xed, 0x3e, 0x69, 0x43, 0xce, 0x6a, 0xa0, 0xa9, 0x81, 0x7b, 0x90, 0xb3, 0x19, + 0xda, 0xaf, 0x48, 0x4b, 0x55, 0x05, 0x38, 0xad, 0xa1, 0x35, 0xda, 0x3b, 0x78, 0xe6, 0xdf, 0x98, + 0xc3, 0x0f, 0xf5, 0x67, 0x56, 0x15, 0x10, 0x6a, 0xba, 0xfd, 0x86, 0xf4, 0x0c, 0x34, 0x67, 0x10, + 0xa3, 0xd3, 0x1e, 0x36, 0x47, 0xbd, 0x5b, 0xd5, 0x47, 0x10, 0xf3, 0x9c, 0x2b, 0x2e, 0xf2, 0x49, + 0xeb, 0x6c, 0x35, 0x68, 0x84, 0xc4, 0x00, 0x47, 0x10, 0xa3, 0x3d, 0x23, 0xbd, 0x42, 0x88, 0x74, + 0x4e, 0x33, 0x51, 0xe6, 0xca, 0xe9, 0xd4, 0xb1, 0x26, 0x87, 0x35, 0xed, 0xd7, 0x6a, 0xd0, 0x5f, + 0x08, 0xcc, 0x04, 0x22, 0x5b, 0xfa, 0x5c, 0x04, 0x19, 0x55, 0x27, 0xfe, 0xdb, 0x5c, 0xfd, 0x59, + 0x0d, 0xec, 0x8a, 0x66, 0xe9, 0x6b, 0x6f, 0x4b, 0xe9, 0x85, 0xa4, 0x9e, 0xc6, 0x66, 0xf0, 0x49, + 0xff, 0xb8, 0x60, 0x37, 0x14, 0x79, 0x5d, 0x83, 0xb5, 0x55, 0x83, 0xf7, 0x99, 0x38, 0xe3, 0xa2, + 0x48, 0xab, 0x8f, 0x3c, 0xc9, 0xcb, 0xc2, 0xc4, 0xbd, 0x94, 0x8c, 0xc9, 0xae, 0x84, 0x05, 0xf0, + 0x2f, 0x20, 0xb5, 0xa8, 0x77, 0x30, 0xb8, 0xb5, 0x26, 0x43, 0xbb, 0x88, 0x79, 0x25, 0xf3, 0x22, + 0xf2, 0x58, 0x1f, 0x1f, 0x82, 0x8c, 0x41, 0x4a, 0x9a, 0xfe, 0xeb, 0x30, 0x25, 0xdd, 0x4b, 0x6a, + 0xfd, 0x5f, 0xcd, 0xff, 0xb7, 0xb8, 0xd6, 0x79, 0x11, 0x79, 0xaa, 0x3d, 0xc6, 0x71, 0xcc, 0x53, + 0x4e, 0xeb, 0xba, 0xef, 0x3c, 0xc7, 0x37, 0xf2, 0x44, 0x7b, 0xbc, 0x17, 0xef, 0x04, 0xe2, 0x04, + 0x14, 0xde, 0xb5, 0x45, 0x7d, 0x85, 0x23, 0x50, 0xf3, 0x92, 0xb3, 0xfa, 0xa6, 0x36, 0x47, 0xdd, + 0xb0, 0x13, 0x81, 0x3a, 0xe6, 0x0c, 0x27, 0xd3, 0xb3, 0xb5, 0x6b, 0x9d, 0xaf, 0x5d, 0xeb, 0xf7, + 0xda, 0xb5, 0xbe, 0x6f, 0xdc, 0xc6, 0xf9, 0xc6, 0x6d, 0xfc, 0xdc, 0xb8, 0x8d, 0x4f, 0x2f, 0x12, + 0xae, 0x4e, 0xca, 0xc8, 0x5f, 0x88, 0x2c, 0xc0, 0x04, 0x5e, 0x5e, 0x18, 0xd6, 0xeb, 0xe0, 0xeb, + 0xd5, 0x83, 0xad, 0x0a, 0xc0, 0xa8, 0xad, 0x9f, 0xda, 0xe1, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xfb, 0x46, 0x13, 0x5d, 0xcb, 0x03, 0x00, 0x00, +} + +func (m *CreateCampaignPayload) 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 *CreateCampaignPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CreateCampaignPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.PoolAmount.Size() + i -= size + if _, err := m.PoolAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + if len(m.RewardDefs) > 0 { + for iNdEx := len(m.RewardDefs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.RewardDefs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if m.Type != 0 { + i = encodeVarintTicket(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x20 + } + if m.EndTs != 0 { + i = encodeVarintTicket(dAtA, i, uint64(m.EndTs)) + i-- + dAtA[i] = 0x18 + } + if m.StartTs != 0 { + i = encodeVarintTicket(dAtA, i, uint64(m.StartTs)) + i-- + dAtA[i] = 0x10 + } + if len(m.FunderAddress) > 0 { + i -= len(m.FunderAddress) + copy(dAtA[i:], m.FunderAddress) + i = encodeVarintTicket(dAtA, i, uint64(len(m.FunderAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *UpdateCampaignPayload) 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 *UpdateCampaignPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UpdateCampaignPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.EndTs != 0 { + i = encodeVarintTicket(dAtA, i, uint64(m.EndTs)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ApplySignupRewardPayload) 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 *ApplySignupRewardPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ApplySignupRewardPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Receiver.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ApplyRerferralRewardPayload) 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 *ApplyRerferralRewardPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ApplyRerferralRewardPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Receivers) > 0 { + for iNdEx := len(m.Receivers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Receivers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ApplyAffiliationRewardPayload) 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 *ApplyAffiliationRewardPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ApplyAffiliationRewardPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Receiver.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ApplyNoLossBetsRewardPayload) 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 *ApplyNoLossBetsRewardPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ApplyNoLossBetsRewardPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BetUids) > 0 { + for iNdEx := len(m.BetUids) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.BetUids[iNdEx]) + copy(dAtA[i:], m.BetUids[iNdEx]) + i = encodeVarintTicket(dAtA, i, uint64(len(m.BetUids[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + { + size, err := m.Receiver.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintTicket(dAtA []byte, offset int, v uint64) int { + offset -= sovTicket(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *CreateCampaignPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FunderAddress) + if l > 0 { + n += 1 + l + sovTicket(uint64(l)) + } + if m.StartTs != 0 { + n += 1 + sovTicket(uint64(m.StartTs)) + } + if m.EndTs != 0 { + n += 1 + sovTicket(uint64(m.EndTs)) + } + if m.Type != 0 { + n += 1 + sovTicket(uint64(m.Type)) + } + if len(m.RewardDefs) > 0 { + for _, e := range m.RewardDefs { + l = e.Size() + n += 1 + l + sovTicket(uint64(l)) + } + } + l = m.PoolAmount.Size() + n += 1 + l + sovTicket(uint64(l)) + return n +} + +func (m *UpdateCampaignPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.EndTs != 0 { + n += 1 + sovTicket(uint64(m.EndTs)) + } + return n +} + +func (m *ApplySignupRewardPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Receiver.Size() + n += 1 + l + sovTicket(uint64(l)) + return n +} + +func (m *ApplyRerferralRewardPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Receivers) > 0 { + for _, e := range m.Receivers { + l = e.Size() + n += 1 + l + sovTicket(uint64(l)) + } + } + return n +} + +func (m *ApplyAffiliationRewardPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Receiver.Size() + n += 1 + l + sovTicket(uint64(l)) + return n +} + +func (m *ApplyNoLossBetsRewardPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Receiver.Size() + n += 1 + l + sovTicket(uint64(l)) + if len(m.BetUids) > 0 { + for _, s := range m.BetUids { + l = len(s) + n += 1 + l + sovTicket(uint64(l)) + } + } + return n +} + +func sovTicket(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTicket(x uint64) (n int) { + return sovTicket(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *CreateCampaignPayload) 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 ErrIntOverflowTicket + } + 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: CreateCampaignPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CreateCampaignPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FunderAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + 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 ErrInvalidLengthTicket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FunderAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTs", wireType) + } + m.StartTs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartTs |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTs", wireType) + } + m.EndTs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EndTs |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= RewardType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardDefs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTicket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RewardDefs = append(m.RewardDefs, Definition{}) + if err := m.RewardDefs[len(m.RewardDefs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + 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 ErrInvalidLengthTicket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PoolAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *UpdateCampaignPayload) 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 ErrIntOverflowTicket + } + 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: UpdateCampaignPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UpdateCampaignPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTs", wireType) + } + m.EndTs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EndTs |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ApplySignupRewardPayload) 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 ErrIntOverflowTicket + } + 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: ApplySignupRewardPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ApplySignupRewardPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTicket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Receiver.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ApplyRerferralRewardPayload) 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 ErrIntOverflowTicket + } + 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: ApplyRerferralRewardPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ApplyRerferralRewardPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receivers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTicket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Receivers = append(m.Receivers, Receiver{}) + if err := m.Receivers[len(m.Receivers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ApplyAffiliationRewardPayload) 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 ErrIntOverflowTicket + } + 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: ApplyAffiliationRewardPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ApplyAffiliationRewardPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTicket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Receiver.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ApplyNoLossBetsRewardPayload) 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 ErrIntOverflowTicket + } + 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: ApplyNoLossBetsRewardPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ApplyNoLossBetsRewardPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Receiver", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTicket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Receiver.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BetUids", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + 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 ErrInvalidLengthTicket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BetUids = append(m.BetUids, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTicket(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, ErrIntOverflowTicket + } + 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, ErrIntOverflowTicket + } + 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, ErrIntOverflowTicket + } + 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, ErrInvalidLengthTicket + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTicket + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTicket + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTicket = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTicket = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTicket = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/reward/types/ticket_test.go b/x/reward/types/ticket_test.go new file mode 100644 index 00000000..deecdb38 --- /dev/null +++ b/x/reward/types/ticket_test.go @@ -0,0 +1,156 @@ +package types_test + +import ( + "testing" + "time" + + sdkmath "cosmossdk.io/math" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/reward/types" +) + +func TestCreateCampaignPayloadValidation(t *testing.T) { + funderAddr := sample.AccAddress() + poolBalance := sdkmath.NewInt(1000) + blockTime := uint64(time.Now().Unix()) + + tests := []struct { + name string + payload types.CreateCampaignPayload + err error + }{ + { + name: "start after end", + payload: types.CreateCampaignPayload{ + FunderAddress: funderAddr, + StartTs: blockTime + 10, + EndTs: blockTime + 5, + }, + err: sdkerrtypes.ErrInvalidRequest, + }, + { + name: "expired", + payload: types.CreateCampaignPayload{ + FunderAddress: funderAddr, + StartTs: blockTime - 1, + EndTs: blockTime, + }, + err: types.ErrExpiredCampaign, + }, + { + name: "not enough defs", + payload: types.CreateCampaignPayload{ + FunderAddress: funderAddr, + StartTs: blockTime + 1, + EndTs: blockTime + 2, + }, + err: sdkerrtypes.ErrInvalidRequest, + }, + { + name: "nil pool amount", + payload: types.CreateCampaignPayload{ + FunderAddress: funderAddr, + StartTs: blockTime + 1, + EndTs: blockTime + 2, + RewardDefs: []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN, + Amount: sdkmath.NewInt(1000), + UnlockTS: 0, + }, + }, + }, + err: sdkerrtypes.ErrInvalidRequest, + }, + { + name: "invalid pool amount", + payload: types.CreateCampaignPayload{ + FunderAddress: funderAddr, + StartTs: blockTime + 1, + EndTs: blockTime + 2, + RewardDefs: []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN, + Amount: sdkmath.NewInt(1000), + UnlockTS: 0, + }, + }, + PoolAmount: sdkmath.NewInt(0), + }, + err: sdkerrtypes.ErrInvalidRequest, + }, + { + name: "valid", + payload: types.CreateCampaignPayload{ + FunderAddress: funderAddr, + StartTs: blockTime + 1, + EndTs: blockTime + 2, + Type: types.RewardType_REWARD_TYPE_SIGNUP, + RewardDefs: []types.Definition{ + { + RecType: types.ReceiverType_RECEIVER_TYPE_SINGLE, + RecAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_MAIN, + Amount: sdkmath.NewInt(1000), + UnlockTS: 0, + }, + }, + PoolAmount: poolBalance, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.payload.Validate(blockTime) + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} + +func TestUpdateCampaignPayloadValidation(t *testing.T) { + blockTime := uint64(time.Now().Unix()) + + tests := []struct { + name string + payload types.UpdateCampaignPayload + err error + }{ + { + name: "expired", + payload: types.UpdateCampaignPayload{ + EndTs: blockTime - 1, + }, + err: types.ErrExpiredCampaign, + }, + { + name: "valid now", + payload: types.UpdateCampaignPayload{ + EndTs: blockTime, + }, + }, + { + name: "valid", + payload: types.UpdateCampaignPayload{ + EndTs: blockTime + 1, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.payload.Validate(blockTime) + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/reward/types/tx.pb.go b/x/reward/types/tx.pb.go new file mode 100644 index 00000000..ad9f9fa4 --- /dev/null +++ b/x/reward/types/tx.pb.go @@ -0,0 +1,1506 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/reward/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// MsgCreateCampaign is campaign create message type. +type MsgCreateCampaign struct { + // creator is the address of creator account. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + // uid is the uinque identifier of the campaign. + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` + // ticket is the payload data. + Ticket string `protobuf:"bytes,3,opt,name=ticket,proto3" json:"ticket,omitempty"` +} + +func (m *MsgCreateCampaign) Reset() { *m = MsgCreateCampaign{} } +func (m *MsgCreateCampaign) String() string { return proto.CompactTextString(m) } +func (*MsgCreateCampaign) ProtoMessage() {} +func (*MsgCreateCampaign) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{0} +} +func (m *MsgCreateCampaign) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateCampaign) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateCampaign.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 *MsgCreateCampaign) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateCampaign.Merge(m, src) +} +func (m *MsgCreateCampaign) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateCampaign) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateCampaign.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateCampaign proto.InternalMessageInfo + +func (m *MsgCreateCampaign) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgCreateCampaign) GetUid() string { + if m != nil { + return m.Uid + } + return "" +} + +func (m *MsgCreateCampaign) GetTicket() string { + if m != nil { + return m.Ticket + } + return "" +} + +// MsgCreateCampaignResponse campaign create message response type. +type MsgCreateCampaignResponse struct { +} + +func (m *MsgCreateCampaignResponse) Reset() { *m = MsgCreateCampaignResponse{} } +func (m *MsgCreateCampaignResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateCampaignResponse) ProtoMessage() {} +func (*MsgCreateCampaignResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{1} +} +func (m *MsgCreateCampaignResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateCampaignResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateCampaignResponse.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 *MsgCreateCampaignResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateCampaignResponse.Merge(m, src) +} +func (m *MsgCreateCampaignResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateCampaignResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateCampaignResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateCampaignResponse proto.InternalMessageInfo + +// MsgUpdateCampaign is campaign update message type. +type MsgUpdateCampaign struct { + // creator is the address of creator account. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + // uid is the uinque identifier of the campaign. + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` + // ticket is the payload data. + Ticket string `protobuf:"bytes,3,opt,name=ticket,proto3" json:"ticket,omitempty"` +} + +func (m *MsgUpdateCampaign) Reset() { *m = MsgUpdateCampaign{} } +func (m *MsgUpdateCampaign) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateCampaign) ProtoMessage() {} +func (*MsgUpdateCampaign) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{2} +} +func (m *MsgUpdateCampaign) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateCampaign) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateCampaign.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 *MsgUpdateCampaign) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateCampaign.Merge(m, src) +} +func (m *MsgUpdateCampaign) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateCampaign) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateCampaign.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateCampaign proto.InternalMessageInfo + +func (m *MsgUpdateCampaign) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgUpdateCampaign) GetUid() string { + if m != nil { + return m.Uid + } + return "" +} + +func (m *MsgUpdateCampaign) GetTicket() string { + if m != nil { + return m.Ticket + } + return "" +} + +// MsgUpdateCampaignResponse campaign update message response type. +type MsgUpdateCampaignResponse struct { +} + +func (m *MsgUpdateCampaignResponse) Reset() { *m = MsgUpdateCampaignResponse{} } +func (m *MsgUpdateCampaignResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateCampaignResponse) ProtoMessage() {} +func (*MsgUpdateCampaignResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{3} +} +func (m *MsgUpdateCampaignResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateCampaignResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateCampaignResponse.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 *MsgUpdateCampaignResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateCampaignResponse.Merge(m, src) +} +func (m *MsgUpdateCampaignResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateCampaignResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateCampaignResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateCampaignResponse proto.InternalMessageInfo + +// MsgApplyReward is apply reward message type. +type MsgApplyReward struct { + // creator is the address of creator account. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + // campaign_uid is the uinque identifier of the campaign. + CampaignUid string `protobuf:"bytes,2,opt,name=campaign_uid,json=campaignUid,proto3" json:"campaign_uid,omitempty"` + // ticket is the payload data. + Ticket string `protobuf:"bytes,3,opt,name=ticket,proto3" json:"ticket,omitempty"` +} + +func (m *MsgApplyReward) Reset() { *m = MsgApplyReward{} } +func (m *MsgApplyReward) String() string { return proto.CompactTextString(m) } +func (*MsgApplyReward) ProtoMessage() {} +func (*MsgApplyReward) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{4} +} +func (m *MsgApplyReward) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgApplyReward) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgApplyReward.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 *MsgApplyReward) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgApplyReward.Merge(m, src) +} +func (m *MsgApplyReward) XXX_Size() int { + return m.Size() +} +func (m *MsgApplyReward) XXX_DiscardUnknown() { + xxx_messageInfo_MsgApplyReward.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgApplyReward proto.InternalMessageInfo + +func (m *MsgApplyReward) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgApplyReward) GetCampaignUid() string { + if m != nil { + return m.CampaignUid + } + return "" +} + +func (m *MsgApplyReward) GetTicket() string { + if m != nil { + return m.Ticket + } + return "" +} + +// MsgApplyRewardResponse apply reward message response type. +type MsgApplyRewardResponse struct { +} + +func (m *MsgApplyRewardResponse) Reset() { *m = MsgApplyRewardResponse{} } +func (m *MsgApplyRewardResponse) String() string { return proto.CompactTextString(m) } +func (*MsgApplyRewardResponse) ProtoMessage() {} +func (*MsgApplyRewardResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{5} +} +func (m *MsgApplyRewardResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgApplyRewardResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgApplyRewardResponse.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 *MsgApplyRewardResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgApplyRewardResponse.Merge(m, src) +} +func (m *MsgApplyRewardResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgApplyRewardResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgApplyRewardResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgApplyRewardResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgCreateCampaign)(nil), "sgenetwork.sge.reward.MsgCreateCampaign") + proto.RegisterType((*MsgCreateCampaignResponse)(nil), "sgenetwork.sge.reward.MsgCreateCampaignResponse") + proto.RegisterType((*MsgUpdateCampaign)(nil), "sgenetwork.sge.reward.MsgUpdateCampaign") + proto.RegisterType((*MsgUpdateCampaignResponse)(nil), "sgenetwork.sge.reward.MsgUpdateCampaignResponse") + proto.RegisterType((*MsgApplyReward)(nil), "sgenetwork.sge.reward.MsgApplyReward") + proto.RegisterType((*MsgApplyRewardResponse)(nil), "sgenetwork.sge.reward.MsgApplyRewardResponse") +} + +func init() { proto.RegisterFile("sge/reward/tx.proto", fileDescriptor_ad69e28332238e66) } + +var fileDescriptor_ad69e28332238e66 = []byte{ + // 321 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2e, 0x4e, 0x4f, 0xd5, + 0x2f, 0x4a, 0x2d, 0x4f, 0x2c, 0x4a, 0xd1, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x12, 0x2d, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0x2b, 0x4e, 0x4f, 0xd5, + 0x83, 0xc8, 0x2b, 0x85, 0x73, 0x09, 0xfa, 0x16, 0xa7, 0x3b, 0x17, 0xa5, 0x26, 0x96, 0xa4, 0x3a, + 0x27, 0xe6, 0x16, 0x24, 0x66, 0xa6, 0xe7, 0x09, 0x49, 0x70, 0xb1, 0x27, 0x83, 0x44, 0xf2, 0x8b, + 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x60, 0x5c, 0x21, 0x01, 0x2e, 0xe6, 0xd2, 0xcc, 0x14, + 0x09, 0x26, 0xb0, 0x28, 0x88, 0x29, 0x24, 0xc6, 0xc5, 0x56, 0x92, 0x99, 0x9c, 0x9d, 0x5a, 0x22, + 0xc1, 0x0c, 0x16, 0x84, 0xf2, 0x94, 0xa4, 0xb9, 0x24, 0x31, 0x0c, 0x0e, 0x4a, 0x2d, 0x2e, 0xc8, + 0xcf, 0x2b, 0x4e, 0x85, 0xda, 0x1a, 0x5a, 0x90, 0x42, 0x1b, 0x5b, 0x51, 0x0d, 0x86, 0xdb, 0x9a, + 0xca, 0xc5, 0xe7, 0x5b, 0x9c, 0xee, 0x58, 0x50, 0x90, 0x53, 0x19, 0x04, 0xf6, 0x3d, 0x1e, 0x2b, + 0x15, 0xb9, 0x78, 0x92, 0xa1, 0xfa, 0xe3, 0x11, 0x76, 0x73, 0xc3, 0xc4, 0x42, 0xf1, 0xb8, 0x41, + 0x82, 0x4b, 0x0c, 0xd5, 0x1a, 0x98, 0x03, 0x8c, 0x8e, 0x31, 0x71, 0x31, 0xfb, 0x16, 0xa7, 0x0b, + 0xe5, 0x70, 0xf1, 0xa1, 0x85, 0xb8, 0x86, 0x1e, 0xd6, 0xe8, 0xd1, 0xc3, 0x08, 0x42, 0x29, 0x03, + 0x62, 0x55, 0xc2, 0x6c, 0x05, 0xd9, 0x86, 0x16, 0xd2, 0x78, 0x6c, 0x43, 0x55, 0x89, 0xcf, 0x36, + 0xec, 0x81, 0x2c, 0x94, 0xcc, 0xc5, 0x8d, 0x1c, 0xc2, 0xaa, 0xb8, 0x0d, 0x40, 0x52, 0x26, 0xa5, + 0x4b, 0x94, 0x32, 0x98, 0x25, 0x4e, 0xce, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, + 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, + 0x10, 0xa5, 0x99, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x5f, 0x9c, 0x9e, + 0xaa, 0x0b, 0x35, 0x13, 0xc4, 0xd6, 0xaf, 0x80, 0x67, 0x8a, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, + 0x70, 0xc6, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xdc, 0x4c, 0x61, 0xd3, 0x2f, 0x03, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // CreateCampaign is campaign create message endpoint. + CreateCampaign(ctx context.Context, in *MsgCreateCampaign, opts ...grpc.CallOption) (*MsgCreateCampaignResponse, error) + // UpdateCampaign is campaign update message endpoint. + UpdateCampaign(ctx context.Context, in *MsgUpdateCampaign, opts ...grpc.CallOption) (*MsgUpdateCampaignResponse, error) + // ApplyReward is reward application message endpoint. + ApplyReward(ctx context.Context, in *MsgApplyReward, opts ...grpc.CallOption) (*MsgApplyRewardResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) CreateCampaign(ctx context.Context, in *MsgCreateCampaign, opts ...grpc.CallOption) (*MsgCreateCampaignResponse, error) { + out := new(MsgCreateCampaignResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Msg/CreateCampaign", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateCampaign(ctx context.Context, in *MsgUpdateCampaign, opts ...grpc.CallOption) (*MsgUpdateCampaignResponse, error) { + out := new(MsgUpdateCampaignResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Msg/UpdateCampaign", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) ApplyReward(ctx context.Context, in *MsgApplyReward, opts ...grpc.CallOption) (*MsgApplyRewardResponse, error) { + out := new(MsgApplyRewardResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Msg/ApplyReward", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // CreateCampaign is campaign create message endpoint. + CreateCampaign(context.Context, *MsgCreateCampaign) (*MsgCreateCampaignResponse, error) + // UpdateCampaign is campaign update message endpoint. + UpdateCampaign(context.Context, *MsgUpdateCampaign) (*MsgUpdateCampaignResponse, error) + // ApplyReward is reward application message endpoint. + ApplyReward(context.Context, *MsgApplyReward) (*MsgApplyRewardResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) CreateCampaign(ctx context.Context, req *MsgCreateCampaign) (*MsgCreateCampaignResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateCampaign not implemented") +} +func (*UnimplementedMsgServer) UpdateCampaign(ctx context.Context, req *MsgUpdateCampaign) (*MsgUpdateCampaignResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateCampaign not implemented") +} +func (*UnimplementedMsgServer) ApplyReward(ctx context.Context, req *MsgApplyReward) (*MsgApplyRewardResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ApplyReward not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_CreateCampaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateCampaign) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateCampaign(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Msg/CreateCampaign", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateCampaign(ctx, req.(*MsgCreateCampaign)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateCampaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateCampaign) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateCampaign(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Msg/UpdateCampaign", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateCampaign(ctx, req.(*MsgUpdateCampaign)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_ApplyReward_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgApplyReward) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ApplyReward(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Msg/ApplyReward", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ApplyReward(ctx, req.(*MsgApplyReward)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "sgenetwork.sge.reward.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateCampaign", + Handler: _Msg_CreateCampaign_Handler, + }, + { + MethodName: "UpdateCampaign", + Handler: _Msg_UpdateCampaign_Handler, + }, + { + MethodName: "ApplyReward", + Handler: _Msg_ApplyReward_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "sge/reward/tx.proto", +} + +func (m *MsgCreateCampaign) 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 *MsgCreateCampaign) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateCampaign) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Ticket) > 0 { + i -= len(m.Ticket) + copy(dAtA[i:], m.Ticket) + i = encodeVarintTx(dAtA, i, uint64(len(m.Ticket))) + i-- + dAtA[i] = 0x1a + } + if len(m.Uid) > 0 { + i -= len(m.Uid) + copy(dAtA[i:], m.Uid) + i = encodeVarintTx(dAtA, i, uint64(len(m.Uid))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateCampaignResponse) 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 *MsgCreateCampaignResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateCampaignResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateCampaign) 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 *MsgUpdateCampaign) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateCampaign) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Ticket) > 0 { + i -= len(m.Ticket) + copy(dAtA[i:], m.Ticket) + i = encodeVarintTx(dAtA, i, uint64(len(m.Ticket))) + i-- + dAtA[i] = 0x1a + } + if len(m.Uid) > 0 { + i -= len(m.Uid) + copy(dAtA[i:], m.Uid) + i = encodeVarintTx(dAtA, i, uint64(len(m.Uid))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateCampaignResponse) 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 *MsgUpdateCampaignResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateCampaignResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgApplyReward) 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 *MsgApplyReward) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgApplyReward) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Ticket) > 0 { + i -= len(m.Ticket) + copy(dAtA[i:], m.Ticket) + i = encodeVarintTx(dAtA, i, uint64(len(m.Ticket))) + i-- + dAtA[i] = 0x1a + } + if len(m.CampaignUid) > 0 { + i -= len(m.CampaignUid) + copy(dAtA[i:], m.CampaignUid) + i = encodeVarintTx(dAtA, i, uint64(len(m.CampaignUid))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgApplyRewardResponse) 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 *MsgApplyRewardResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgApplyRewardResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgCreateCampaign) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Uid) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Ticket) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateCampaignResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateCampaign) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Uid) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Ticket) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateCampaignResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgApplyReward) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.CampaignUid) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Ticket) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgApplyRewardResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgCreateCampaign) 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 ErrIntOverflowTx + } + 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: MsgCreateCampaign: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateCampaign: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Uid", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Uid = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ticket", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ticket = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateCampaignResponse) 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 ErrIntOverflowTx + } + 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: MsgCreateCampaignResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateCampaignResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateCampaign) 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 ErrIntOverflowTx + } + 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: MsgUpdateCampaign: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateCampaign: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Uid", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Uid = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ticket", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ticket = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateCampaignResponse) 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 ErrIntOverflowTx + } + 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: MsgUpdateCampaignResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateCampaignResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgApplyReward) 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 ErrIntOverflowTx + } + 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: MsgApplyReward: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgApplyReward: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CampaignUid", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CampaignUid = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ticket", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ticket = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgApplyRewardResponse) 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 ErrIntOverflowTx + } + 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: MsgApplyRewardResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgApplyRewardResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/subaccount/client/cli/query.go b/x/subaccount/client/cli/query.go new file mode 100644 index 00000000..6f0d998e --- /dev/null +++ b/x/subaccount/client/cli/query.go @@ -0,0 +1,62 @@ +package cli + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/subaccount/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd() *cobra.Command { + // Group bet queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf( + "Querying commands for the %s module", + types.ModuleName, + ), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(QuerySubaccount()) + + return cmd +} + +func QuerySubaccount() *cobra.Command { + cmd := &cobra.Command{ + Use: "subaccount [owner-address]", + Short: "queries the subaccount of an owner", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + _, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + res, err := queryClient.Subaccount(context.Background(), &types.QuerySubaccountRequest{SubaccountOwner: args[0]}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/subaccount/client/cli/tx.go b/x/subaccount/client/cli/tx.go new file mode 100644 index 00000000..dba6198d --- /dev/null +++ b/x/subaccount/client/cli/tx.go @@ -0,0 +1,315 @@ +package cli + +import ( + "fmt" + "strings" + "time" + + "github.com/spf13/cast" + "github.com/spf13/cobra" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" + + bettypes "github.com/sge-network/sge/x/bet/types" + housetypes "github.com/sge-network/sge/x/house/types" + "github.com/sge-network/sge/x/subaccount/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + TxCreate(), + TxTopupSubaccount(), + TxWager(), + TxHouseDeposit(), + TxHouseWithdraw(), + TxWithdraw(), + ) + + return cmd +} + +func TxCreate() *cobra.Command { + const ( + flagFunds = "funds" + flagLockDuration = "lock-duration" + ) + + cmd := &cobra.Command{ + Use: "create [subaccount-owner]", + Short: "Create a new subaccount", + Long: `Create a new subaccount.`, + Example: fmt.Sprintf(`$ %s tx subaccount create sge123456 --funds 1000000000 --lock-duration 8760h --from subaccount-funder-key`, version.AppName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + subaccountOwner, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + fundsStr, err := cmd.Flags().GetString(flagFunds) + if err != nil { + return err + } + funds, ok := sdkmath.NewIntFromString(fundsStr) + if !ok { + return fmt.Errorf("invalid funds amount: %s", fundsStr) + } + unlocksAfter, err := cmd.Flags().GetDuration(flagLockDuration) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgCreate{ + Creator: clientCtx.From, + SubAccountOwner: subaccountOwner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: uint64(time.Now().Add(unlocksAfter).Unix()), + Amount: funds, + }, + }, + }) + }, + } + cmd.Flags().String(flagFunds, "", "Funds to lock in the subaccount") + cmd.Flags().Duration(flagLockDuration, 12*30*24*time.Hour, "duration for which the funds will be locked") + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +func TxTopupSubaccount() *cobra.Command { + const ( + flagFunds = "funds" + flagLockDuration = "lock-duration" + ) + cmd := &cobra.Command{ + Use: "topup [subaccount-owner]", + Short: "Topup a subaccount", + Long: `Topup a subaccount.`, + Example: fmt.Sprintf(`$ %s tx subaccount topup sge123456 --funds 1000000000 --lock-duration 8760h --from funder-address-key`, version.AppName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + subaccountAddress, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + fundsStr, err := cmd.Flags().GetString(flagFunds) + if err != nil { + return err + } + funds, ok := sdkmath.NewIntFromString(fundsStr) + if !ok { + return fmt.Errorf("invalid funds amount: %s", fundsStr) + } + unlocksAfter, err := cmd.Flags().GetDuration(flagLockDuration) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgTopUp{ + Creator: clientCtx.From, + SubAccount: subaccountAddress.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: uint64(time.Now().Add(unlocksAfter).Unix()), + Amount: funds, + }, + }, + }) + }, + } + + cmd.Flags().String(flagFunds, "", "Funds to lock in the subaccount") + cmd.Flags().Duration(flagLockDuration, 12*30*24*time.Hour, "duration for which the funds will be locked") + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +func TxWithdraw() *cobra.Command { + cmd := &cobra.Command{ + Use: "withdraw --from subaccount-owner-key", + Short: "Withdraw unlocked funds from a subaccount", + Long: `Withdraw unlocked funds from a subaccount.`, + Example: fmt.Sprintf(`$ %s tx subaccount withdraw --from subaccount-owner-key`, version.AppName), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgWithdrawUnlockedBalances{ + Creator: clientCtx.From, + }) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +// TxWager implements a command to place and store a single bet +func TxWager() *cobra.Command { + cmd := &cobra.Command{ + Use: "wager [uid] [amount] [ticket] --from subaccount-owner-key", + Short: "Wager on an odds", + Long: "Wager on an odds. the uuid, amount and ticket required.", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Get value arguments + uid := args[0] + argAmount := args[1] + argTicket := args[2] + + argAmountCosmosInt, ok := sdkmath.NewIntFromString(argAmount) + if !ok { + return fmt.Errorf("invalid amount: %s", argAmount) + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := bettypes.NewMsgWager( + clientCtx.GetFromAddress().String(), + bettypes.WagerProps{ + UID: uid, + Amount: argAmountCosmosInt, + Ticket: argTicket, + }, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgWager{Msg: msg}) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func TxHouseDeposit() *cobra.Command { + cmd := &cobra.Command{ + Use: "house-deposit [market_uid] [amount] [ticket] --from subaccount-owner-key", + Args: cobra.ExactArgs(3), + Short: "Deposit tokens in a market order book to be the house", + Long: strings.TrimSpace( + fmt.Sprintf(`Deposit tokens in a market order book to be the house. + + Example: + $ %s tx subaccount deposit bc79a72c-ad7e-4cf5-91a2-98af2751e812 1000usge {ticket string} --from mykey + `, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + argMarketUID := args[0] + + argAmountCosmosInt, ok := sdkmath.NewIntFromString(args[1]) + if !ok { + return fmt.Errorf("invalid amount: %s", args[1]) + } + + argTicket := args[2] + + depAddr := clientCtx.GetFromAddress() + + msg := &types.MsgHouseDeposit{Msg: housetypes.NewMsgDeposit(depAddr.String(), argMarketUID, argAmountCosmosInt, argTicket)} + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func TxHouseWithdraw() *cobra.Command { + cmd := &cobra.Command{ + Use: "house-withdraw [market_uid] [participation_index] [ticket] [mode] [amount]", + Args: cobra.RangeArgs(4, 5), + Short: "Withdraw tokens from a deposit", + Long: strings.TrimSpace( + fmt.Sprintf(`Withdraw coins of unused amount corresponding to a deposit. + + Example: + $ %s tx subaccount withdraw bc79a72c-ad7e-4cf5-91a2-98af2751e812 1 {ticket string} 1 1000 --from mykey + `, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + argMarketUID := args[0] + + particiapntIndex, err := cast.ToUint64E(args[1]) + if err != nil || particiapntIndex < 1 { + return fmt.Errorf("participant number should be a positive number") + } + + argTicket := args[2] + + mode, err := cast.ToInt64E(args[3]) + if err != nil { + return fmt.Errorf("mode provided must be a non-negative-integer: %v", mode) + } + + var argAmountCosmosInt sdkmath.Int + if mode == int64(housetypes.WithdrawalMode_WITHDRAWAL_MODE_PARTIAL) { + if len(args) != 5 { + return fmt.Errorf("amount is mandatory for partial mode") + } + + var ok bool + argAmountCosmosInt, ok = sdkmath.NewIntFromString(args[4]) + if !ok { + return fmt.Errorf("invalid amount: %s", args[4]) + } + } + + depAddr := clientCtx.GetFromAddress() + + msg := housetypes.NewMsgWithdraw(depAddr.String(), argMarketUID, argAmountCosmosInt, + particiapntIndex, housetypes.WithdrawalMode(mode), argTicket) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgHouseWithdraw{Msg: msg}) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/subaccount/genesis.go b/x/subaccount/genesis.go new file mode 100644 index 00000000..86d470c4 --- /dev/null +++ b/x/subaccount/genesis.go @@ -0,0 +1,33 @@ +package subaccount + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/subaccount/keeper" + "github.com/sge-network/sge/x/subaccount/types" +) + +// InitGenesis initializes the module's state from a provided genesis +// state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + k.SetParams(ctx, genState.Params) + if genState.SubaccountId != 0 { + k.SetID(ctx, genState.SubaccountId) + } + for _, acc := range genState.Subaccounts { + owner := sdk.MustAccAddressFromBech32(acc.Owner) + addr := sdk.MustAccAddressFromBech32(acc.Address) + k.SetSubAccountOwner(ctx, addr, owner) + k.SetLockedBalances(ctx, addr, acc.LockedBalances) + k.SetBalance(ctx, addr, acc.Balance) + } +} + +// ExportGenesis returns the module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + return &types.GenesisState{ + Params: k.GetParams(ctx), + SubaccountId: k.Peek(ctx), + Subaccounts: k.GetAllSubaccounts(ctx), + } +} diff --git a/x/subaccount/genesis_test.go b/x/subaccount/genesis_test.go new file mode 100644 index 00000000..8854c932 --- /dev/null +++ b/x/subaccount/genesis_test.go @@ -0,0 +1,63 @@ +package subaccount_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/subaccount" + "github.com/sge-network/sge/x/subaccount/types" +) + +var ( + subAccOwner = sample.NativeAccAddress() + micro = sdkmath.NewInt(1_000_000) + subAccFunds = sdkmath.NewInt(10_000).Mul(micro) + subAccAddr = types.NewAddressFromSubaccount(1) +) + +func TestGenesis(t *testing.T) { + app, ctx, err := simapp.GetTestObjects() + require.NoError(t, err) + + k := app.SubaccountKeeper + + wantGenesis := types.GenesisState{ + Params: types.DefaultParams(), + Subaccounts: []types.GenesisSubaccount{ + { + Address: subAccAddr.String(), + Owner: subAccOwner.String(), + Balance: types.Balance{ + DepositedAmount: subAccFunds, + SpentAmount: sdk.ZeroInt(), + WithdrawmAmount: sdk.ZeroInt(), + LostAmount: sdk.ZeroInt(), + }, + LockedBalances: []types.LockedBalance{ + { + UnlockTS: uint64(time.Now().Add(24 * time.Hour).Unix()), + Amount: subAccFunds, + }, + }, + }, + }, + SubaccountId: 2, // next subaccount id + } + + subaccount.InitGenesis(ctx, *k, wantGenesis) + + require.Equal(t, wantGenesis.SubaccountId, k.Peek(ctx)) + require.Equal(t, wantGenesis.Params, k.GetParams(ctx)) + require.Len(t, wantGenesis.Subaccounts, 1) + require.Equal(t, wantGenesis.Subaccounts[0], k.GetAllSubaccounts(ctx)[0]) + + exportedGenesis := subaccount.ExportGenesis(ctx, *k) + require.Equal(t, wantGenesis, *exportedGenesis) +} diff --git a/x/subaccount/handler.go b/x/subaccount/handler.go new file mode 100644 index 00000000..b224477f --- /dev/null +++ b/x/subaccount/handler.go @@ -0,0 +1,43 @@ +package subaccount + +import ( + "fmt" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/x/subaccount/keeper" + "github.com/sge-network/sge/x/subaccount/types" +) + +// NewHandler initialize a new sdk.handler instance for registered messages +func NewHandler(k keeper.Keeper) sdk.Handler { + msgServer := keeper.NewMsgServerImpl(&k) + + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { + ctx = ctx.WithEventManager(sdk.NewEventManager()) + _ = ctx + + switch msg := msg.(type) { + case *types.MsgCreate: + res, err := msgServer.Create(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgTopUp: + res, err := msgServer.TopUp(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgWithdrawUnlockedBalances: + res, err := msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgHouseDeposit: + res, err := msgServer.HouseDeposit(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgHouseWithdraw: + res, err := msgServer.HouseWithdraw(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) + default: + errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) + return nil, sdkerrors.Wrap(sdkerrtypes.ErrUnknownRequest, errMsg) + } + } +} diff --git a/x/subaccount/keeper/balance.go b/x/subaccount/keeper/balance.go new file mode 100644 index 00000000..1cb5f643 --- /dev/null +++ b/x/subaccount/keeper/balance.go @@ -0,0 +1,138 @@ +package keeper + +import ( + "fmt" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/utils" + "github.com/sge-network/sge/x/subaccount/types" +) + +// SetLockedBalances saves the locked balances of an account. +func (k Keeper) SetLockedBalances(ctx sdk.Context, subAccountAddress sdk.AccAddress, lockedBalances []types.LockedBalance) { + store := ctx.KVStore(k.storeKey) + + for _, lockedBalance := range lockedBalances { + amountBytes, err := lockedBalance.Amount.Marshal() + if err != nil { + panic(err) + } + store.Set( + types.LockedBalanceKey(subAccountAddress, lockedBalance.UnlockTS), + amountBytes, + ) + } +} + +// GetLockedBalances returns the locked balances of an account. +func (k Keeper) GetLockedBalances(ctx sdk.Context, subAccountAddress sdk.AccAddress) []types.LockedBalance { + iterator := prefix.NewStore(ctx.KVStore(k.storeKey), types.LockedBalancePrefixKey(subAccountAddress)).Iterator(nil, nil) + defer iterator.Close() + + var lockedBalances []types.LockedBalance + for ; iterator.Valid(); iterator.Next() { + unlockTime := utils.Uint64FromBytes(iterator.Key()) + + amount := new(sdkmath.Int) + err := amount.Unmarshal(iterator.Value()) + if err != nil { + panic(err) + } + lockedBalances = append(lockedBalances, types.LockedBalance{ + UnlockTS: unlockTime, + Amount: *amount, + }) + } + + return lockedBalances +} + +// GetUnlockedBalance returns the unlocked balance of an account. +func (k Keeper) GetUnlockedBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress) sdkmath.Int { + iterator := prefix.NewStore(ctx.KVStore(k.storeKey), types.LockedBalancePrefixKey(subAccountAddress)). + Iterator(nil, utils.Int64ToBytes(ctx.BlockTime().Unix())) + + unlockedBalance := sdk.ZeroInt() + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + amount := new(sdkmath.Int) + err := amount.Unmarshal(iterator.Value()) + if err != nil { + panic(err) + } + unlockedBalance = unlockedBalance.Add(*amount) + } + + return unlockedBalance +} + +// SetBalance saves the balance of an account. +func (k Keeper) SetBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress, balance types.Balance) { + store := ctx.KVStore(k.storeKey) + + bz := k.cdc.MustMarshal(&balance) + store.Set(types.BalanceKey(subAccountAddress), bz) +} + +// GetBalance returns the balance of an account. +func (k Keeper) GetBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress) (types.Balance, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.BalanceKey(subAccountAddress)) + if bz == nil { + return types.Balance{}, false + } + + balance := types.Balance{} + k.cdc.MustUnmarshal(bz, &balance) + + return balance, true +} + +// TopUp tops up the subbacount balance. +func (k Keeper) TopUp(ctx sdk.Context, creator, subAccOwnerAddr string, + lockedBalance []types.LockedBalance, +) (string, error) { + moneyToAdd, err := sumBalanceUnlocks(ctx, lockedBalance) + if err != nil { + return "", err + } + + creatorAddr := sdk.MustAccAddressFromBech32(creator) + subaccountOwner := sdk.MustAccAddressFromBech32(subAccOwnerAddr) + + subAccAddr, exists := k.GetSubAccountByOwner(ctx, subaccountOwner) + if !exists { + return "", types.ErrSubaccountDoesNotExist + } + balance, exists := k.GetBalance(ctx, subAccAddr) + if !exists { + panic("data corruption: subaccount exists but balance does not") + } + + balance.DepositedAmount = balance.DepositedAmount.Add(moneyToAdd) + k.SetBalance(ctx, subAccAddr, balance) + k.SetLockedBalances(ctx, subAccAddr, lockedBalance) + + err = k.sendCoinsToSubaccount(ctx, creatorAddr, subAccAddr, moneyToAdd) + if err != nil { + return "", fmt.Errorf("unable to send coins: %w", err) + } + return subAccAddr.String(), nil +} + +// getBalances returns the balance, unlocked balance and bank balance of a subaccount +func (k Keeper) getBalances(sdkContext sdk.Context, subaccountAddr sdk.AccAddress) (types.Balance, sdkmath.Int, sdk.Coin) { + balance, exists := k.GetBalance(sdkContext, subaccountAddr) + if !exists { + panic("data corruption: subaccount exists but balance does not") + } + unlockedBalance := k.GetUnlockedBalance(sdkContext, subaccountAddr) + bankBalance := k.bankKeeper.GetBalance(sdkContext, subaccountAddr, params.DefaultBondDenom) + + return balance, unlockedBalance, bankBalance +} diff --git a/x/subaccount/keeper/hooks.go b/x/subaccount/keeper/hooks.go new file mode 100644 index 00000000..9b10477b --- /dev/null +++ b/x/subaccount/keeper/hooks.go @@ -0,0 +1,147 @@ +package keeper + +import ( + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/app/params" + orderbooktypes "github.com/sge-network/sge/x/orderbook/types" +) + +// Hooks wrapper struct for slashing keeper +type Hooks struct { + k Keeper +} + +// subaccount module shoule implement the orderbook module hooks. +var _ orderbooktypes.OrderBookHooks = Hooks{} + +// Create new distribution hooks +func (k Keeper) Hooks() Hooks { return Hooks{k} } + +// AfterBettorWin is subaccount module hook for subaccount bettor winning. +func (h Hooks) AfterBettorWin(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, profit sdkmath.Int) { + balance, exists := h.k.GetBalance(ctx, bettor) + if !exists { + return + } + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + // send profits to subaccount owner + owner, exists := h.k.GetSubAccountOwner(ctx, bettor) + if !exists { + panic("subaccount owner not found") + } + err = h.k.bankKeeper.SendCoins(ctx, bettor, owner, sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, profit))) + if err != nil { + panic(err) + } + h.k.SetBalance(ctx, bettor, balance) +} + +// AfterBettorLoss is subaccount module hook for subaccount bettor loss. +func (h Hooks) AfterBettorLoss(ctx sdk.Context, bettor sdk.AccAddress, originalAmount sdkmath.Int) { + balance, exists := h.k.GetBalance(ctx, bettor) + if !exists { + return + } + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + err = balance.AddLoss(originalAmount) + if err != nil { + panic(err) + } + h.k.SetBalance(ctx, bettor, balance) +} + +// AfterBettorRefund is subaccount module hook for subaccount bettor refund. +func (h Hooks) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, fee sdkmath.Int) { + balance, exists := h.k.GetBalance(ctx, bettor) + if !exists { + return + } + totalUnspent := originalAmount.Add(fee) + err := balance.Unspend(totalUnspent) + if err != nil { + panic(err) + } + h.k.SetBalance(ctx, bettor, balance) +} + +// AfterHouseWin is subaccount module hook for house winning over subbacount. +func (h Hooks) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdkmath.Int) { + // update balance + balance, exists := h.k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + h.k.SetBalance(ctx, house, balance) + + // send profits + subAccountOwner, exists := h.k.GetSubAccountOwner(ctx, house) + if !exists { + panic("data corruption: subaccount owner not found") + } + err = h.k.bankKeeper.SendCoins(ctx, house, subAccountOwner, sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, profit))) + if err != nil { + panic(err) + } +} + +// AfterHouseLoss is subaccount module hook for house loss for subbacount. +func (h Hooks) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount, lostAmt sdkmath.Int) { + balance, exists := h.k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + err = balance.AddLoss(lostAmt) + if err != nil { + panic(err) + } + + h.k.SetBalance(ctx, house, balance) +} + +// AfterHouseRefund is subaccount module hook for house refund in subaccount deposit. +func (h Hooks) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount sdkmath.Int) { + balance, exists := h.k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(originalAmount) + if err != nil { + panic(err) + } + + h.k.SetBalance(ctx, house, balance) +} + +// AfterHouseFeeRefund is subaccount module hook for house fee refund in subaccount deposit. +func (h Hooks) AfterHouseFeeRefund(ctx sdk.Context, house sdk.AccAddress, fee sdkmath.Int) { + balance, exists := h.k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(fee) + if err != nil { + panic(err) + } + + h.k.SetBalance(ctx, house, balance) +} diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go new file mode 100644 index 00000000..b1ba60e2 --- /dev/null +++ b/x/subaccount/keeper/keeper.go @@ -0,0 +1,53 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + bettypes "github.com/sge-network/sge/x/bet/types" + "github.com/sge-network/sge/x/subaccount/types" +) + +type Keeper struct { + cdc codec.Codec + storeKey storetypes.StoreKey + paramstore paramtypes.Subspace + + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + ovmKeeper bettypes.OVMKeeper + betKeeper types.BetKeeper + houseKeeper types.HouseKeeper + obKeeper types.OrderBookKeeper +} + +func NewKeeper( + cdc codec.Codec, + storeKey storetypes.StoreKey, + ps paramtypes.Subspace, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, + ovmKeeper bettypes.OVMKeeper, + betKeeper types.BetKeeper, + obKeeper types.OrderBookKeeper, + hk types.HouseKeeper, +) *Keeper { + // set KeyTable if it is not already set + if !ps.HasKeyTable() { + ps = ps.WithKeyTable(types.ParamKeyTable()) + } + + k := &Keeper{ + cdc: cdc, + storeKey: storeKey, + paramstore: ps, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + ovmKeeper: ovmKeeper, + betKeeper: betKeeper, + houseKeeper: hk, + obKeeper: obKeeper, + } + return k +} diff --git a/x/subaccount/keeper/keeper_test.go b/x/subaccount/keeper/keeper_test.go new file mode 100644 index 00000000..1a6f6b4a --- /dev/null +++ b/x/subaccount/keeper/keeper_test.go @@ -0,0 +1,20 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/simapp" + + "github.com/sge-network/sge/x/subaccount/keeper" +) + +func setupKeeperAndApp(t testing.TB) (*simapp.TestApp, *keeper.Keeper, sdk.Context) { + tApp, ctx, err := simapp.GetTestObjects() + require.NoError(t, err) + + return tApp, tApp.SubaccountKeeper, ctx.WithBlockTime(time.Now()) +} diff --git a/x/subaccount/keeper/msg_server.go b/x/subaccount/keeper/msg_server.go new file mode 100644 index 00000000..48699f9d --- /dev/null +++ b/x/subaccount/keeper/msg_server.go @@ -0,0 +1,19 @@ +package keeper + +import ( + "github.com/sge-network/sge/x/subaccount/types" +) + +type msgServer struct { + keeper *Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper *Keeper) types.MsgServer { + return &msgServer{ + keeper: keeper, + } +} + +var _ types.MsgServer = msgServer{} diff --git a/x/subaccount/keeper/msg_server_balance.go b/x/subaccount/keeper/msg_server_balance.go new file mode 100644 index 00000000..99c2355d --- /dev/null +++ b/x/subaccount/keeper/msg_server_balance.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/x/subaccount/types" +) + +// TopUp increases the balance of sub account according to the input data. +func (k msgServer) TopUp(goCtx context.Context, msg *types.MsgTopUp) (*types.MsgTopUpResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + subAccAddr, err := k.keeper.TopUp(ctx, msg.Creator, msg.SubAccount, msg.LockedBalances) + if err != nil { + return nil, err + } + + msg.EmitEvent(&ctx, subAccAddr) + + return &types.MsgTopUpResponse{}, nil +} + +// WithdrawUnlockedBalances withdraws the unlocked balance of sub account according to the input account. +func (k msgServer) WithdrawUnlockedBalances(goCtx context.Context, msg *types.MsgWithdrawUnlockedBalances) (*types.MsgWithdrawUnlockedBalancesResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + creatorAddr := sdk.MustAccAddressFromBech32(msg.Creator) + subAccAddr, exists := k.keeper.GetSubAccountByOwner(ctx, creatorAddr) + if !exists { + return nil, types.ErrSubaccountDoesNotExist + } + + balance, unlockedBalance, bankBalance := k.keeper.getBalances(ctx, subAccAddr) + + // calculate withdrawable balance, which is the minimum between the available balance, and + // what has been unlocked so far. Also, it cannot be greater than the bank balance. + // Available reports the deposited amount - spent amount - lost amount - withdrawn amount. + withdrawableBalance := sdk.MinInt(sdk.MinInt(balance.Available(), unlockedBalance), bankBalance.Amount) + if withdrawableBalance.IsZero() { + return nil, types.ErrNothingToWithdraw + } + + balance.WithdrawmAmount = balance.WithdrawmAmount.Add(withdrawableBalance) + k.keeper.SetBalance(ctx, subAccAddr, balance) + + err := k.keeper.bankKeeper.SendCoins(ctx, subAccAddr, creatorAddr, sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, withdrawableBalance))) + if err != nil { + return nil, err + } + + msg.EmitEvent(&ctx, subAccAddr.String()) + + return &types.MsgWithdrawUnlockedBalancesResponse{}, nil +} diff --git a/x/subaccount/keeper/msg_server_balance_test.go b/x/subaccount/keeper/msg_server_balance_test.go new file mode 100644 index 00000000..b16ab9b4 --- /dev/null +++ b/x/subaccount/keeper/msg_server_balance_test.go @@ -0,0 +1,293 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank/testutil" + + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/subaccount/keeper" + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestMsgServer_WithdrawUnlockedBalances(t *testing.T) { + creatorAddr := sample.NativeAccAddress() + subaccountOwner := sample.NativeAccAddress() + lockedTime := time.Now().Add(time.Hour * 24 * 365).UTC() + lockedTime2 := time.Now().Add(time.Hour * 24 * 365 * 2).UTC() + + app, _, msgServer, ctx := setupMsgServerAndApp(t) + + t.Log("funder account") + err := testutil.FundAccount(app.BankKeeper, ctx, creatorAddr, sdk.NewCoins(sdk.NewInt64Coin("usge", 1000))) + require.NoError(t, err) + + t.Log("Create sub account") + _, err = msgServer.Create(sdk.WrapSDKContext(ctx), &types.MsgCreate{ + Creator: creatorAddr.String(), + SubAccountOwner: subaccountOwner.String(), + LockedBalances: []types.LockedBalance{ + { + Amount: sdkmath.NewInt(100), + UnlockTS: uint64(lockedTime.Unix()), + }, + { + Amount: sdkmath.NewInt(200), + UnlockTS: uint64(lockedTime2.Unix()), + }, + }, + }) + require.NoError(t, err) + + t.Log("check balance of sub account") + subAccountAddr := types.NewAddressFromSubaccount(1) + balance := app.BankKeeper.GetBalance(ctx, subAccountAddr, "usge") + require.Equal(t, sdkmath.NewInt(300), balance.Amount) + + t.Log("check balance of subaccount owner") + balance = app.BankKeeper.GetBalance(ctx, subaccountOwner, "usge") + require.Equal(t, sdkmath.NewInt(0), balance.Amount) + + t.Log("Withdraw unlocked balances, with 0 expires") + _, err = msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), &types.MsgWithdrawUnlockedBalances{ + Creator: subaccountOwner.String(), + }) + require.ErrorContains(t, err, types.ErrNothingToWithdraw.Error()) + + t.Log("balance of subaccount owner should be zero") + balance = app.BankKeeper.GetBalance(ctx, subaccountOwner, "usge") + require.True(t, balance.IsZero()) + + t.Log("expire first locked balance") + ctx = ctx.WithBlockTime(lockedTime.Add(1 * time.Second)) + t.Log("Withdraw unlocked balances, with 1 expires") + _, err = msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), &types.MsgWithdrawUnlockedBalances{ + Creator: subaccountOwner.String(), + }) + require.NoError(t, err) + + t.Log("balance of subaccount owner should be the same as first locked balance") + balance = app.BankKeeper.GetBalance(ctx, subaccountOwner, "usge") + require.True(t, balance.Amount.Equal(sdkmath.NewInt(100)), balance.Amount.String()) + + t.Log("expire second locked balance, also force money to be spent") + // we force some money to be spent on the subaccount to correctly test + // that if the amount is unlocked but spent, it will not be withdrawable. + subAccountAddress := types.NewAddressFromSubaccount(1) + subaccountBalance, exists := app.SubaccountKeeper.GetBalance(ctx, subAccountAddress) + require.True(t, exists) + require.NoError(t, subaccountBalance.Spend(sdkmath.NewInt(100))) + app.SubaccountKeeper.SetBalance(ctx, subAccountAddr, subaccountBalance) + + ctx = ctx.WithBlockTime(lockedTime2.Add(1 * time.Second)) + t.Log("Withdraw unlocked balances, with 2 expires") + _, err = msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), &types.MsgWithdrawUnlockedBalances{ + Creator: subaccountOwner.String(), + }) + require.NoError(t, err) + + t.Log("balance of subaccount owner should be the same as both expired locked balances minus spent money") + balance = app.BankKeeper.GetBalance(ctx, subaccountOwner, "usge") + require.Equal(t, sdkmath.NewInt(200), balance.Amount) + + t.Log("check bank balance of sub account address") + balance = app.BankKeeper.GetBalance(ctx, subAccountAddr, "usge") + require.Equal(t, sdkmath.NewInt(100), balance.Amount) + + t.Log("after unspending the money of the subaccount, the owner will be able to get the money back when withdrawing") + subaccountBalance, exists = app.SubaccountKeeper.GetBalance(ctx, subAccountAddress) + require.True(t, exists) + require.NoError(t, subaccountBalance.Unspend(sdkmath.NewInt(100))) + app.SubaccountKeeper.SetBalance(ctx, subAccountAddr, subaccountBalance) + _, err = msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), &types.MsgWithdrawUnlockedBalances{ + Creator: subaccountOwner.String(), + }) + require.NoError(t, err) + + // check balances + balance = app.BankKeeper.GetBalance(ctx, subAccountAddr, "usge") + require.Equal(t, sdkmath.NewInt(0), balance.Amount) + subaccountBalance, exists = app.SubaccountKeeper.GetBalance(ctx, subAccountAddress) + require.True(t, exists) + require.Equal(t, sdkmath.NewInt(300), subaccountBalance.WithdrawmAmount) + + // check that the owner has received the last money + balance = app.BankKeeper.GetBalance(ctx, subaccountOwner, "usge") + require.Equal(t, sdkmath.NewInt(300), balance.Amount) + + // check that the owner can't withdraw again + _, err = msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), &types.MsgWithdrawUnlockedBalances{ + Creator: subaccountOwner.String(), + }) + require.ErrorContains(t, err, types.ErrNothingToWithdraw.Error()) +} + +func TestMsgServer_WithdrawUnlockedBalances_Errors(t *testing.T) { + creatorAddr := sample.AccAddress() + tests := []struct { + name string + msg types.MsgWithdrawUnlockedBalances + prepare func(ctx sdk.Context, keeper keeper.Keeper) + expectedErr string + }{ + { + name: "sub account does not exist", + msg: types.MsgWithdrawUnlockedBalances{ + Creator: creatorAddr, + }, + prepare: func(ctx sdk.Context, keeper keeper.Keeper) {}, + expectedErr: types.ErrSubaccountDoesNotExist.Error(), + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + _, k, msgServer, ctx := setupMsgServerAndApp(t) + + tt.prepare(ctx, *k) + + _, err := msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + }) + } +} + +func TestMsgServerTopUp_HappyPath(t *testing.T) { + afterTime := uint64(time.Now().Add(10 * time.Minute).Unix()) + creatirAddr := sample.NativeAccAddress() + subaccount := sample.AccAddress() + + app, k, msgServer, ctx := setupMsgServerAndApp(t) + + // Funder + err := testutil.FundAccount(app.BankKeeper, ctx, creatirAddr, sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdkmath.NewInt(100000000)))) + require.NoError(t, err) + + // Create subaccount + msg := &types.MsgCreate{ + Creator: creatirAddr.String(), + SubAccountOwner: subaccount, + LockedBalances: []types.LockedBalance{}, + } + _, err = msgServer.Create(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + subAccountAddr := types.NewAddressFromSubaccount(1) + + balance, exists := k.GetBalance(ctx, subAccountAddr) + require.True(t, exists) + require.Equal(t, sdkmath.NewInt(0), balance.DepositedAmount) + balances := k.GetLockedBalances(ctx, subAccountAddr) + require.Len(t, balances, 0) + + msgTopUp := &types.MsgTopUp{ + Creator: creatirAddr.String(), + SubAccount: subaccount, + LockedBalances: []types.LockedBalance{ + { + UnlockTS: afterTime, + Amount: sdkmath.NewInt(123), + }, + }, + } + _, err = msgServer.TopUp(sdk.WrapSDKContext(ctx), msgTopUp) + require.NoError(t, err) + + // Check balance + balance, exists = k.GetBalance(ctx, subAccountAddr) + require.True(t, exists) + require.Equal(t, sdkmath.NewInt(123), balance.DepositedAmount) + balances = k.GetLockedBalances(ctx, subAccountAddr) + require.Len(t, balances, 1) + require.True(t, afterTime == balances[0].UnlockTS) + require.Equal(t, sdkmath.NewInt(123), balances[0].Amount) +} + +func TestNewMsgServerTopUp_Errors(t *testing.T) { + beforeTime := uint64(time.Now().Add(-10 * time.Minute).Unix()) + afterTime := uint64(time.Now().Add(10 * time.Minute).Unix()) + + creatorAddr := sample.AccAddress() + subaccount := sample.AccAddress() + + tests := []struct { + name string + msg types.MsgTopUp + prepare func(ctx sdk.Context, msgServer types.MsgServer) + expectedErr string + }{ + { + name: "unlock time is expired", + msg: types.MsgTopUp{ + Creator: creatorAddr, + SubAccount: subaccount, + LockedBalances: []types.LockedBalance{ + { + UnlockTS: beforeTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + prepare: func(ctx sdk.Context, msgServer types.MsgServer) {}, + expectedErr: types.ErrUnlockTokenTimeExpired.Error(), + }, + { + name: "sub account does not exist", + msg: types.MsgTopUp{ + Creator: creatorAddr, + SubAccount: subaccount, + LockedBalances: []types.LockedBalance{ + { + UnlockTS: afterTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + prepare: func(ctx sdk.Context, msgServer types.MsgServer) {}, + expectedErr: types.ErrSubaccountDoesNotExist.Error(), + }, + { + name: "creator has not enough balance", + msg: types.MsgTopUp{ + Creator: creatorAddr, + SubAccount: subaccount, + LockedBalances: []types.LockedBalance{ + { + UnlockTS: afterTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + prepare: func(ctx sdk.Context, msgServer types.MsgServer) { + // Create subaccount + msg := &types.MsgCreate{ + Creator: creatorAddr, + SubAccountOwner: subaccount, + LockedBalances: []types.LockedBalance{}, + } + _, err := msgServer.Create(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + }, + expectedErr: "0usge is smaller than 123usge: insufficient funds", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + _, _, msgServer, ctx := setupMsgServerAndApp(t) + + tt.prepare(ctx, msgServer) + + _, err := msgServer.TopUp(sdk.WrapSDKContext(ctx), &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + }) + } +} diff --git a/x/subaccount/keeper/msg_server_bet.go b/x/subaccount/keeper/msg_server_bet.go new file mode 100644 index 00000000..e3e5db56 --- /dev/null +++ b/x/subaccount/keeper/msg_server_bet.go @@ -0,0 +1,56 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + bettypes "github.com/sge-network/sge/x/bet/types" + "github.com/sge-network/sge/x/subaccount/types" +) + +func (k msgServer) Wager(goCtx context.Context, msg *types.MsgWager) (*types.MsgWagerResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + subAccOwner := sdk.MustAccAddressFromBech32(msg.Msg.Creator) + // find subaccount + subAccAddr, exists := k.keeper.GetSubAccountByOwner(ctx, subAccOwner) + if !exists { + return nil, status.Error(codes.NotFound, "subaccount not found") + } + + bet, err := k.keeper.betKeeper.PrepareBetObject(ctx, msg.Msg.Creator, msg.Msg.Props) + if err != nil { + return nil, err + } + + // here we swap the original creator with the subaccount address + bet.Creator = subAccAddr.String() + + // make subaccount balance adjustments + balance, exists := k.keeper.GetBalance(ctx, subAccAddr) + if !exists { + panic("state corruption: subaccount balance not found") + } + + err = balance.Spend(bet.Amount) + if err != nil { + return nil, err + } + + if err := k.keeper.betKeeper.Wager(ctx, bet); err != nil { + return nil, sdkerrors.Wrapf(bettypes.ErrInWager, "%s", err) + } + + k.keeper.SetBalance(ctx, subAccAddr, balance) + + msg.EmitEvent(&ctx, subAccOwner.String()) + + return &types.MsgWagerResponse{ + Response: &bettypes.MsgWagerResponse{Props: msg.Msg.Props}, + }, nil +} diff --git a/x/subaccount/keeper/msg_server_bet_test.go b/x/subaccount/keeper/msg_server_bet_test.go new file mode 100644 index 00000000..36e7a87b --- /dev/null +++ b/x/subaccount/keeper/msg_server_bet_test.go @@ -0,0 +1,240 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/golang-jwt/jwt" + "github.com/google/uuid" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank/testutil" + + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/testutil/simapp" + sgetypes "github.com/sge-network/sge/types" + bettypes "github.com/sge-network/sge/x/bet/types" + marketkeeper "github.com/sge-network/sge/x/market/keeper" + markettypes "github.com/sge-network/sge/x/market/types" + "github.com/sge-network/sge/x/subaccount/types" +) + +var ( + testMarketUID = "5db09053-2901-4110-8fb5-c14e21f8d555" + testOddsUID1 = "6db09053-2901-4110-8fb5-c14e21f8d666" + testOddsUID2 = "5e31c60f-2025-48ce-ae79-1dc110f16358" + testOddsUID3 = "6e31c60f-2025-48ce-ae79-1dc110f16354" + testMarketOdds = []*markettypes.Odds{ + {UID: testOddsUID1, Meta: "Odds 1"}, + {UID: testOddsUID2, Meta: "Odds 2"}, + {UID: testOddsUID3, Meta: "Odds 3"}, + } + testSelectedBetOdds = &bettypes.BetOdds{ + UID: testOddsUID1, + MarketUID: testMarketUID, + Value: "4.20", + MaxLossMultiplier: sdk.MustNewDecFromStr("0.1"), + } + testCreator string +) + +var ( + subAccOwner = sample.NativeAccAddress() + subAccFunder = sample.NativeAccAddress() + micro = sdkmath.NewInt(1_000_000) + subAccFunds = sdkmath.NewInt(10_000).Mul(micro) + subAccAddr = types.NewAddressFromSubaccount(1) +) + +func TestMsgServer_Bet(t *testing.T) { + app, k, msgServer, ctx := setupMsgServerAndApp(t) + + // do subaccount creation + require.NoError( + t, + testutil.FundAccount( + app.BankKeeper, + ctx, + subAccFunder, + sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, subAccFunds)), + ), + ) + + _, err := msgServer.Create(sdk.WrapSDKContext(ctx), &types.MsgCreate{ + Creator: subAccFunder.String(), + SubAccountOwner: subAccOwner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: uint64(time.Now().Add(24 * time.Hour).Unix()), + Amount: subAccFunds, + }, + }, + }) + require.NoError(t, err) + + // add market + market := addTestMarket(t, app, ctx, true) + + // start betting using the subaccount + betAmt := sdkmath.NewInt(1000).Mul(micro) + _, err = msgServer.Wager( + sdk.WrapSDKContext(ctx), + &types.MsgWager{Msg: testBet(t, subAccOwner, betAmt)}, + ) + require.NoError(t, err) + + // check subaccount balance + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + betFees := sdkmath.NewInt(100) + + require.Equal(t, balance.SpentAmount, betAmt) + + t.Run("resolve market – better wins", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + // resolve the market – better wins + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + + // now we check the subaccount balance + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, sdk.ZeroInt().Add(betFees).String(), balance.SpentAmount.String()) + + // now we want the user to have some balance which is the payout + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, + sdk.NewCoins( + sdk.NewCoin( + params.DefaultBondDenom, + sdkmath.LegacyNewDecFromInt(betAmt.Sub(betFees)).Mul(sdkmath.LegacyMustNewDecFromStr("3.2")).TruncateInt(), // 4.2 - 1 = 3.2 + )), + ownerBalance, + ) + }) + // resolve the market – better loses + t.Run("resolve market – better loses", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + // resolve the market – better loses + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID2}, + Status: markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + + // now we check the subaccount balance + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, sdk.ZeroInt().Add(betFees).String(), balance.SpentAmount.String()) + require.Equal(t, betAmt.Sub(betFees), balance.LostAmount) + // the owner has no balances + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, sdk.NewCoins(), ownerBalance) + }) + t.Run("resolve market – refund", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + // resolve the market – refund + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_CANCELED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + + // now we check the subaccount balance + balance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, balance.SpentAmount, sdk.ZeroInt()) + + // the owner balance is zero + require.Equal(t, sdk.NewCoins(), app.BankKeeper.GetAllBalances(ctx, subAccOwner)) + }) +} + +func addTestMarket(t testing.TB, tApp *simapp.TestApp, ctx sdk.Context, prefund bool) *markettypes.Market { + testCreator = simapp.TestParamUsers["user1"].Address.String() + testAddMarketClaim := jwt.MapClaims{ + "uid": testMarketUID, + "start_ts": 1111111111, + "end_ts": uint64(ctx.BlockTime().Unix()) + 1000, + "odds": testMarketOdds, + "exp": 9999999999, + "iat": 7777777777, + "meta": "Winner of x:y", + "status": markettypes.MarketStatus_MARKET_STATUS_ACTIVE, + } + testAddMarketTicket, err := createJwtTicket(testAddMarketClaim) + require.Nil(t, err) + + testAddMarket := &markettypes.MsgAdd{ + Creator: testCreator, + Ticket: testAddMarketTicket, + } + wctx := sdk.WrapSDKContext(ctx) + marketSrv := marketkeeper.NewMsgServerImpl(*tApp.MarketKeeper) + resAddMarket, err := marketSrv.Add(wctx, testAddMarket) + require.Nil(t, err) + require.NotNil(t, resAddMarket) + + if prefund { + // add liquidity + err = testutil.FundAccount( + tApp.BankKeeper, + ctx, + simapp.TestParamUsers["user1"].Address, + sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdkmath.NewInt(1_000_000).Mul(micro))), + ) + require.NoError(t, err) + _, err = tApp.OrderbookKeeper.InitiateOrderBookParticipation( + ctx, + simapp.TestParamUsers["user1"].Address, + resAddMarket.Data.UID, + sdkmath.NewInt(1_000_000).Mul(micro), + sdkmath.NewInt(1), + ) + require.NoError(t, err) + } + return resAddMarket.Data +} + +func createJwtTicket(claim jwt.MapClaims) (string, error) { + token := jwt.NewWithClaims(jwt.SigningMethodEdDSA, claim) + return token.SignedString(simapp.TestOVMPrivateKeys[0]) +} + +func testBet(t testing.TB, better sdk.AccAddress, amount sdkmath.Int) *bettypes.MsgWager { + ticket, err := createJwtTicket(jwt.MapClaims{ + "exp": 9999999999, + "iat": 7777777777, + "selected_odds": testSelectedBetOdds, + "kyc_data": &sgetypes.KycDataPayload{ + Approved: true, + ID: better.String(), + }, + "odds_type": 1, + }) + require.NoError(t, err) + + return &bettypes.MsgWager{ + Creator: better.String(), + Props: &bettypes.WagerProps{ + UID: uuid.NewString(), + Amount: amount, + Ticket: ticket, + }, + } +} diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go new file mode 100644 index 00000000..ba377e88 --- /dev/null +++ b/x/subaccount/keeper/msg_server_house.go @@ -0,0 +1,104 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + housetypes "github.com/sge-network/sge/x/house/types" + "github.com/sge-network/sge/x/subaccount/types" +) + +func (k msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposit) (*types.MsgHouseDepositResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check if subaccount exists + subAccAddr, exists := k.keeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) + if !exists { + return nil, types.ErrSubaccountDoesNotExist + } + + // get subaccount balance, and check if it can spend + balance, exists := k.keeper.GetBalance(ctx, subAccAddr) + if !exists { + panic("data corruption: subaccount balance not found") + } + + // parse the ticket payload and create deposit, setting the authz allowed as false + _, err := k.keeper.houseKeeper.ParseDepositTicketAndValidate(goCtx, ctx, msg.Msg, false) + if err != nil { + return nil, sdkerrors.Wrap(err, "failed to deposit") + } + + if err := balance.Spend(msg.Msg.Amount); err != nil { + return nil, err + } + + // send house deposit from subaccount on behalf of the owner + participationIndex, err := k.keeper.houseKeeper.Deposit( + ctx, + msg.Msg.Creator, + subAccAddr.String(), + msg.Msg.MarketUID, + msg.Msg.Amount, + ) + if err != nil { + return nil, sdkerrors.Wrap(err, "failed to deposit") + } + + // update subaccount balance + k.keeper.SetBalance(ctx, subAccAddr, balance) + + // emit event + msg.EmitEvent(&ctx, subAccAddr.String(), participationIndex) + + return &types.MsgHouseDepositResponse{ + Response: &housetypes.MsgDepositResponse{ + MarketUID: msg.Msg.MarketUID, + ParticipationIndex: participationIndex, + }, + }, nil +} + +func (k msgServer) HouseWithdraw(goCtx context.Context, msg *types.MsgHouseWithdraw) (*types.MsgHouseWithdrawResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // check if subaccount exists + subAccAddr, exists := k.keeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(msg.Msg.Creator)) + if !exists { + return nil, types.ErrSubaccountDoesNotExist + } + + subAccountBalance, exists := k.keeper.GetBalance(ctx, subAccAddr) + if !exists { + panic("data corruption: subaccount balance not found") + } + + _, _, err := k.keeper.houseKeeper.ParseWithdrawTicketAndValidate(goCtx, ctx, msg.Msg, true) + if err != nil { + return nil, err + } + + id, err := k.keeper.houseKeeper.CalcAndWithdraw(ctx, msg.Msg, subAccAddr.String(), false) + if err != nil { + return nil, err + } + + err = subAccountBalance.Unspend(msg.Msg.Amount) + if err != nil { + panic("data corruption: it must be possible to unspend an house withdrawal") + } + + k.keeper.SetBalance(ctx, subAccAddr, subAccountBalance) + + msg.Msg.EmitEvent(&ctx, subAccAddr.String(), id) + + return &types.MsgHouseWithdrawResponse{ + Response: &housetypes.MsgWithdrawResponse{ + ID: id, + MarketUID: msg.Msg.MarketUID, + ParticipationIndex: msg.Msg.ParticipationIndex, + }, + }, nil +} diff --git a/x/subaccount/keeper/msg_server_house_test.go b/x/subaccount/keeper/msg_server_house_test.go new file mode 100644 index 00000000..cfca4c8a --- /dev/null +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -0,0 +1,336 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/golang-jwt/jwt" + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank/testutil" + + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/testutil/simapp" + sgetypes "github.com/sge-network/sge/types" + betmodulekeeper "github.com/sge-network/sge/x/bet/keeper" + housetypes "github.com/sge-network/sge/x/house/types" + markettypes "github.com/sge-network/sge/x/market/types" + "github.com/sge-network/sge/x/subaccount/types" +) + +var ( + bettor1 = sample.NativeAccAddress() + bettor1Funds = sdkmath.NewInt(10).Mul(micro) +) + +func TestMsgServer(t *testing.T) { + app, k, msgServer, ctx := setupMsgServerAndApp(t) + + // do subaccount creation + require.NoError( + t, + testutil.FundAccount( + app.BankKeeper, + ctx, + subAccFunder, + sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, subAccFunds)), + ), + ) + + _, err := msgServer.Create(sdk.WrapSDKContext(ctx), &types.MsgCreate{ + Creator: subAccFunder.String(), + SubAccountOwner: subAccOwner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: uint64(time.Now().Add(24 * time.Hour).Unix()), + Amount: subAccFunds, + }, + }, + }) + require.NoError(t, err) + + // fund a bettor + require.NoError( + t, + testutil.FundAccount( + app.BankKeeper, + ctx, + bettor1, + sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, subAccFunds)), + ), + ) + + // add market + market := addTestMarket(t, app, ctx, false) + + // do house deposit + deposit := sdkmath.NewInt(1000).Mul(micro) + depResp, err := msgServer.HouseDeposit(sdk.WrapSDKContext(ctx), houseDepositMsg(t, subAccOwner, market.UID, deposit)) + require.NoError(t, err) + // check spend + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, subBalance.SpentAmount, deposit) + + // place bet + betMsgServer := betmodulekeeper.NewMsgServerImpl(*app.BetKeeper) + _, err = betMsgServer.Wager(sdk.WrapSDKContext(ctx), testBet(t, bettor1, bettor1Funds)) + require.NoError(t, err) + + participateFee := app.HouseKeeper.GetHouseParticipationFee(ctx).Mul(sdk.NewDecFromInt(deposit)).TruncateInt() + bettorFee := sdkmath.NewInt(100) + + t.Run("house wins", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID2}, + Status: markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount.String(), sdk.ZeroInt().Add(participateFee).String()) + // check profits were forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, + ownerBalance.AmountOf(params.DefaultBondDenom).String(), + sdkmath.NewInt(10).Mul(micro).Sub(bettorFee).String()) + }) + + t.Run("house loses", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount.String(), sdk.ZeroInt().Add(participateFee).String()) + require.Equal(t, subBalance.LostAmount, sdk.NewDecFromInt(bettor1Funds.Sub(bettorFee)).Mul(sdk.MustNewDecFromStr("3.2")).TruncateInt()) + // check profits were forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(params.DefaultBondDenom), sdk.ZeroInt()) + }) + t.Run("house refund", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_CANCELED, + }) + err := app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount, sdk.ZeroInt()) + require.Equal(t, subBalance.LostAmount, sdk.ZeroInt()) + // check profits were forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(params.DefaultBondDenom), sdk.ZeroInt()) + }) + + // TODO: not participated in bet fulfillment. + + t.Run("withdrawal", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + _, err := msgServer.HouseWithdraw(sdk.WrapSDKContext(ctx), &types.MsgHouseWithdraw{Msg: houseWithdrawMsg(t, subAccOwner, deposit, depResp.Response.ParticipationIndex)}) + require.NoError(t, err) + + // do subaccount balance check + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + + require.Equal(t, subBalance.SpentAmount.String(), sdkmath.NewInt(131999680).String()) // NOTE: there was a match in the bet + participate fee + require.Equal(t, subBalance.LostAmount.String(), sdk.ZeroInt().String()) + }) + + t.Run("withdrawal and market refund with bet fulfillment", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + + _, err := msgServer.HouseWithdraw(sdk.WrapSDKContext(ctx), &types.MsgHouseWithdraw{Msg: houseWithdrawMsg(t, subAccOwner, deposit, depResp.Response.ParticipationIndex)}) + require.NoError(t, err) + + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_CANCELED, + }) + err = app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount, sdk.ZeroInt()) + require.Equal(t, subBalance.LostAmount, sdk.ZeroInt()) + // check profits were forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(params.DefaultBondDenom), sdk.ZeroInt()) + }) +} + +func TestHouseWithdrawal_MarketRefund(t *testing.T) { + app, k, msgServer, ctx := setupMsgServerAndApp(t) + + // do subaccount creation + require.NoError( + t, + testutil.FundAccount( + app.BankKeeper, + ctx, + subAccFunder, + sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, subAccFunds)), + ), + ) + + _, err := msgServer.Create(sdk.WrapSDKContext(ctx), &types.MsgCreate{ + Creator: subAccFunder.String(), + SubAccountOwner: subAccOwner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: uint64(time.Now().Add(24 * time.Hour).Unix()), + Amount: subAccFunds, + }, + }, + }) + require.NoError(t, err) + + // fund a bettor + require.NoError( + t, + testutil.FundAccount( + app.BankKeeper, + ctx, + bettor1, + sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, subAccFunds)), + ), + ) + + // add market + market := addTestMarket(t, app, ctx, false) + + // do house deposit + deposit := sdkmath.NewInt(1000).Mul(micro) + depResp, err := msgServer.HouseDeposit(sdk.WrapSDKContext(ctx), houseDepositMsg(t, subAccOwner, market.UID, deposit)) + require.NoError(t, err) + // check spend + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, subBalance.SpentAmount, deposit) + + // do house withdrawal + _, err = msgServer.HouseWithdraw(sdk.WrapSDKContext(ctx), &types.MsgHouseWithdraw{Msg: houseWithdrawMsg(t, subAccOwner, deposit, depResp.Response.ParticipationIndex)}) + require.NoError(t, err) + + // we expect the balance to be the original one minus participation fee + subBalance, exists = k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, subBalance.SpentAmount, sdkmath.NewInt(100).Mul(micro)) // all minus participation fee + require.Equal(t, subBalance.LostAmount, sdk.ZeroInt()) + require.Equal(t, subBalance.DepositedAmount, subAccFunds) + subBankBalance := app.BankKeeper.GetAllBalances(ctx, subAccAddr) + require.Equal(t, subBankBalance.AmountOf(params.DefaultBondDenom), subAccFunds.Sub(sdkmath.NewInt(100).Mul(micro))) // original funds - fee + + // resolve market with refund + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_CANCELED, + }) + err = app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists = k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount, sdk.ZeroInt()) + require.Equal(t, subBalance.LostAmount, sdk.ZeroInt()) + subBankBalance = app.BankKeeper.GetAllBalances(ctx, subAccAddr) + require.Equal(t, subBankBalance.AmountOf(params.DefaultBondDenom), subAccFunds) // original funds - fee was refunded + // check profits were not forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(params.DefaultBondDenom), sdk.ZeroInt()) +} + +func houseWithdrawMsg(t testing.TB, owner sdk.AccAddress, amt sdkmath.Int, partecipationIndex uint64) *housetypes.MsgWithdraw { + testKyc := &sgetypes.KycDataPayload{ + Approved: true, + ID: owner.String(), + } + ticketClaim := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "kyc_data": testKyc, + } + ticket, err := simapp.CreateJwtTicket(ticketClaim) + require.Nil(t, err) + + inputWithdraw := &housetypes.MsgWithdraw{ + Creator: owner.String(), + MarketUID: testMarketUID, + Amount: amt, + ParticipationIndex: partecipationIndex, + Mode: housetypes.WithdrawalMode_WITHDRAWAL_MODE_FULL, + Ticket: ticket, + } + return inputWithdraw +} + +func houseDepositMsg(t *testing.T, owner sdk.AccAddress, uid string, amt sdkmath.Int) *types.MsgHouseDeposit { + testKyc := &sgetypes.KycDataPayload{ + Approved: true, + ID: owner.String(), + } + ticketClaim := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "kyc_data": testKyc, + } + ticket, err := simapp.CreateJwtTicket(ticketClaim) + require.Nil(t, err) + + inputDeposit := &housetypes.MsgDeposit{ + Creator: owner.String(), + MarketUID: uid, + Amount: amt, + Ticket: ticket, + } + + return &types.MsgHouseDeposit{ + Msg: inputDeposit, + } +} diff --git a/x/subaccount/keeper/msg_server_subaccount.go b/x/subaccount/keeper/msg_server_subaccount.go new file mode 100644 index 00000000..b85ff230 --- /dev/null +++ b/x/subaccount/keeper/msg_server_subaccount.go @@ -0,0 +1,31 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/subaccount/types" +) + +// Create creates a sub account according to the input message data. +func (k msgServer) Create( + goCtx context.Context, + msg *types.MsgCreate, +) (*types.MsgCreateResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + err := msg.ValidateBasic() + if err != nil { + return nil, sdkerrors.Wrap(err, "invalid request") + } + + subAccAddr, err := k.keeper.CreateSubAccount(ctx, msg.Creator, msg.SubAccountOwner, msg.LockedBalances) + if err != nil { + return nil, err + } + + msg.EmitEvent(&ctx, subAccAddr) + + return &types.MsgCreateResponse{}, nil +} diff --git a/x/subaccount/keeper/msg_server_subaccount_test.go b/x/subaccount/keeper/msg_server_subaccount_test.go new file mode 100644 index 00000000..d5b1966d --- /dev/null +++ b/x/subaccount/keeper/msg_server_subaccount_test.go @@ -0,0 +1,145 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank/testutil" + + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/subaccount/keeper" + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestMsgServer_Create(t *testing.T) { + account := sample.NativeAccAddress() + creatorAddr := sample.NativeAccAddress() + + app, _, msgServer, ctx := setupMsgServerAndApp(t) + + err := testutil.FundAccount(app.BankKeeper, ctx, creatorAddr, sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, sdkmath.NewInt(100000000)))) + require.NoError(t, err) + + // Check that the account has been created + require.False(t, app.AccountKeeper.HasAccount(ctx, types.NewAddressFromSubaccount(1))) + + someTime := uint64(time.Now().Add(10 * time.Minute).Unix()) + msg := &types.MsgCreate{ + Creator: creatorAddr.String(), + SubAccountOwner: account.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: someTime, + Amount: sdkmath.NewInt(123), + }, + }, + } + + _, err = msgServer.Create(sdk.WrapSDKContext(ctx), msg) + require.NoError(t, err) + + // Check that the account has been created + require.True(t, app.AccountKeeper.HasAccount(ctx, types.NewAddressFromSubaccount(1))) + + // Check that the account has the correct balance + balance := app.BankKeeper.GetBalance(ctx, types.NewAddressFromSubaccount(1), params.DefaultBondDenom) + require.Equal(t, sdkmath.NewInt(123), balance.Amount) + + // Check that we can get the account by owner + owner, exists := app.SubaccountKeeper.GetSubAccountOwner(ctx, types.NewAddressFromSubaccount(1)) + require.True(t, exists) + require.Equal(t, account, owner) + + // check that balance unlocks are set correctly + lockedBalances := app.SubaccountKeeper.GetLockedBalances(ctx, types.NewAddressFromSubaccount(1)) + require.Len(t, lockedBalances, 1) + require.True(t, someTime == lockedBalances[0].UnlockTS) + require.Equal(t, sdkmath.NewInt(123), lockedBalances[0].Amount) + + // get the balance of the account + subaccountBalance, exists := app.SubaccountKeeper.GetBalance(ctx, types.NewAddressFromSubaccount(1)) + require.True(t, exists) + require.Equal(t, sdk.ZeroInt(), subaccountBalance.SpentAmount) + require.Equal(t, sdk.ZeroInt(), subaccountBalance.LostAmount) + require.Equal(t, sdk.ZeroInt(), subaccountBalance.WithdrawmAmount) + require.Equal(t, sdkmath.NewInt(123), subaccountBalance.DepositedAmount) +} + +func TestMsgServer_CreateSubAccount_Errors(t *testing.T) { + beforeTime := uint64(time.Now().Add(-10 * time.Minute).Unix()) + afterTime := uint64(time.Now().Add(10 * time.Minute).Unix()) + account := sample.NativeAccAddress() + creatorAddr := sample.NativeAccAddress() + + tests := []struct { + name string + msg types.MsgCreate + prepare func(ctx sdk.Context, keeper *keeper.Keeper) + expectedErr string + }{ + { + name: "unlock time is expired", + msg: types.MsgCreate{ + Creator: creatorAddr.String(), + SubAccountOwner: account.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: beforeTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + prepare: func(ctx sdk.Context, k *keeper.Keeper) {}, + expectedErr: types.ErrUnlockTokenTimeExpired.Error(), + }, + { + name: "account has already sub account", + msg: types.MsgCreate{ + Creator: creatorAddr.String(), + SubAccountOwner: account.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: afterTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + prepare: func(ctx sdk.Context, k *keeper.Keeper) { + k.SetSubAccountOwner(ctx, types.NewAddressFromSubaccount(1), account) + }, + expectedErr: types.ErrSubaccountAlreadyExist.Error(), + }, + { + name: "invalid request", + msg: types.MsgCreate{ + Creator: creatorAddr.String(), + SubAccountOwner: account.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: afterTime, + Amount: sdkmath.Int{}, + }, + }, + }, + prepare: func(ctx sdk.Context, k *keeper.Keeper) {}, + expectedErr: "invalid request", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + _, k, msgServer, ctx := setupMsgServerAndApp(t) + + tt.prepare(ctx, k) + + _, err := msgServer.Create(sdk.WrapSDKContext(ctx), &tt.msg) + require.ErrorContains(t, err, tt.expectedErr) + }) + } +} diff --git a/x/subaccount/keeper/msg_server_test.go b/x/subaccount/keeper/msg_server_test.go new file mode 100644 index 00000000..c778d977 --- /dev/null +++ b/x/subaccount/keeper/msg_server_test.go @@ -0,0 +1,18 @@ +package keeper_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/subaccount/keeper" + "github.com/sge-network/sge/x/subaccount/types" +) + +func setupMsgServerAndApp( + t testing.TB, +) (*simapp.TestApp, *keeper.Keeper, types.MsgServer, sdk.Context) { + tApp, k, ctx := setupKeeperAndApp(t) + return tApp, k, keeper.NewMsgServerImpl(k), ctx +} diff --git a/x/subaccount/keeper/params.go b/x/subaccount/keeper/params.go new file mode 100644 index 00000000..01e0b0f9 --- /dev/null +++ b/x/subaccount/keeper/params.go @@ -0,0 +1,18 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/subaccount/types" +) + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramstore.SetParamSet(ctx, ¶ms) +} + +// GetParams return parameters of the module +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + k.paramstore.GetParamSet(ctx, ¶ms) + return params +} diff --git a/x/subaccount/keeper/params_test.go b/x/subaccount/keeper/params_test.go new file mode 100644 index 00000000..77dc1ba6 --- /dev/null +++ b/x/subaccount/keeper/params_test.go @@ -0,0 +1,16 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestKeeper_GetParams(t *testing.T) { + _, k, ctx := setupKeeperAndApp(t) + + params := k.GetParams(ctx) + require.Equal(t, params, types.DefaultParams()) +} diff --git a/x/subaccount/keeper/query_server.go b/x/subaccount/keeper/query_server.go new file mode 100644 index 00000000..a3c6e224 --- /dev/null +++ b/x/subaccount/keeper/query_server.go @@ -0,0 +1,47 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/x/subaccount/types" +) + +func NewQueryServer(keeper Keeper) types.QueryServer { + return queryServer{keeper: keeper} +} + +type queryServer struct { + keeper Keeper +} + +func (q queryServer) Subaccount(goCtx context.Context, request *types.QuerySubaccountRequest) (*types.QuerySubaccountResponse, error) { + addr, err := sdk.AccAddressFromBech32(request.SubaccountOwner) + if err != nil { + return nil, err + } + + ctx := sdk.UnwrapSDKContext(goCtx) + subaccountAddr, exists := q.keeper.GetSubAccountByOwner(ctx, addr) + if !exists { + return nil, types.ErrSubaccountDoesNotExist + } + + balance, exists := q.keeper.GetBalance(ctx, subaccountAddr) + if !exists { + panic("subaccount exists but balance not found") + } + + balanceLocks := q.keeper.GetLockedBalances(ctx, subaccountAddr) + return &types.QuerySubaccountResponse{ + SubaccountAddress: subaccountAddr.String(), + Balance: balance, + LockedBalance: balanceLocks, + }, nil +} + +func (q queryServer) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + params := q.keeper.GetParams(sdk.UnwrapSDKContext(ctx)) + return &types.QueryParamsResponse{Params: ¶ms}, nil +} diff --git a/x/subaccount/keeper/query_server_test.go b/x/subaccount/keeper/query_server_test.go new file mode 100644 index 00000000..fdde1ef8 --- /dev/null +++ b/x/subaccount/keeper/query_server_test.go @@ -0,0 +1,69 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/cosmos-sdk/x/bank/testutil" + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/x/subaccount/keeper" + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestQueryServer(t *testing.T) { + app, k, msgServer, ctx := setupMsgServerAndApp(t) + queryServer := keeper.NewQueryServer(*k) + + // setup + wantParams := types.DefaultParams() + k.SetParams(ctx, wantParams) + + // do subaccount creation + require.NoError( + t, + testutil.FundAccount( + app.BankKeeper, + ctx, + subAccFunder, + sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, subAccFunds)), + ), + ) + + _, err := msgServer.Create(sdk.WrapSDKContext(ctx), &types.MsgCreate{ + Creator: subAccFunder.String(), + SubAccountOwner: subAccOwner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: uint64(time.Now().Add(24 * time.Hour).Unix()), + Amount: subAccFunds, + }, + }, + }) + require.NoError(t, err) + + t.Run("Params", func(t *testing.T) { + gotParams, err := queryServer.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) + require.NoError(t, err) + require.Equal(t, wantParams, *gotParams.Params) + }) + + t.Run("Subaccount", func(t *testing.T) { + gotSubaccount, err := queryServer.Subaccount(sdk.WrapSDKContext(ctx), &types.QuerySubaccountRequest{ + SubaccountOwner: subAccOwner.String(), + }) + require.NoError(t, err) + require.Equal(t, subAccAddr.String(), gotSubaccount.SubaccountAddress) + require.Equal(t, types.Balance{ + DepositedAmount: subAccFunds, + SpentAmount: sdk.ZeroInt(), + WithdrawmAmount: sdk.ZeroInt(), + LostAmount: sdk.ZeroInt(), + }, gotSubaccount.Balance) + require.Len(t, gotSubaccount.LockedBalance, 1) + require.Equal(t, subAccFunds, gotSubaccount.LockedBalance[0].Amount) + }) +} diff --git a/x/subaccount/keeper/subaccount.go b/x/subaccount/keeper/subaccount.go new file mode 100644 index 00000000..ac14374a --- /dev/null +++ b/x/subaccount/keeper/subaccount.go @@ -0,0 +1,150 @@ +package keeper + +import ( + sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/app/params" + "github.com/sge-network/sge/x/subaccount/types" +) + +// Peek returns the next value without advancing the subaccount ID. +func (k Keeper) Peek(ctx sdk.Context) uint64 { + key := ctx.KVStore(k.storeKey).Get(types.SubaccountIDPrefix) + if key == nil { + return 1 + } + + return sdk.BigEndianToUint64(key) +} + +// NextID returns the actual value, same as Peek, but also advances the subaccount ID. +func (k Keeper) NextID(ctx sdk.Context) uint64 { + actualID := k.Peek(ctx) + + ctx.KVStore(k.storeKey).Set(types.SubaccountIDPrefix, sdk.Uint64ToBigEndian(actualID+1)) + + return actualID +} + +// SetID sets the ID to a given value. +func (k Keeper) SetID(ctx sdk.Context, id uint64) { + ctx.KVStore(k.storeKey).Set(types.SubaccountIDPrefix, sdk.Uint64ToBigEndian(id)) +} + +// SetSubAccountOwner sets the owner of a subaccount. +func (k Keeper) SetSubAccountOwner(ctx sdk.Context, subAccountAddress, ownerAddress sdk.AccAddress) { + store := ctx.KVStore(k.storeKey) + store.Set(types.SubAccountOwnerKey(ownerAddress), subAccountAddress) + // and reverse mapping + store.Set(types.SubAccountKey(subAccountAddress), ownerAddress) +} + +// GetSubAccountByOwner returns the subaccount ID of an owner. +func (k Keeper) GetSubAccountByOwner(ctx sdk.Context, address sdk.AccAddress) (sdk.AccAddress, bool) { + store := ctx.KVStore(k.storeKey) + addr := store.Get(types.SubAccountOwnerKey(address)) + return addr, addr != nil +} + +// GetSubAccountOwner returns the owner of a subaccount given the subaccount address. +func (k Keeper) GetSubAccountOwner(ctx sdk.Context, subaccountAddr sdk.AccAddress) (sdk.AccAddress, bool) { + store := ctx.KVStore(k.storeKey) + addr := store.Get(types.SubAccountKey(subaccountAddr)) + return addr, addr != nil +} + +func (k Keeper) IterateSubaccounts(ctx sdk.Context, cb func(subAccountAddress, subaccountOwner sdk.AccAddress) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.SubAccountOwnerReversePrefix) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + if cb(iterator.Key()[len(types.SubAccountOwnerReversePrefix):], iterator.Value()) { + break + } + } +} + +func (k Keeper) GetAllSubaccounts(ctx sdk.Context) []types.GenesisSubaccount { + var subaccounts []types.GenesisSubaccount + k.IterateSubaccounts(ctx, func(subAccountAddress, ownerAddress sdk.AccAddress) (stop bool) { + balance, exists := k.GetBalance(ctx, subAccountAddress) + if !exists { + panic("subaccount balance does not exist") + } + lockedBalances := k.GetLockedBalances(ctx, subAccountAddress) + subaccounts = append(subaccounts, types.GenesisSubaccount{ + Address: subAccountAddress.String(), + Owner: ownerAddress.String(), + Balance: balance, + LockedBalances: lockedBalances, + }) + return false + }) + return subaccounts +} + +func (k Keeper) CreateSubAccount(ctx sdk.Context, creator, owner string, + lockedBalances []types.LockedBalance, +) (string, error) { + moneyToSend, err := sumBalanceUnlocks(ctx, lockedBalances) + if err != nil { + return "", err + } + + creatorAddr := sdk.MustAccAddressFromBech32(creator) + subAccOwnerAddr := sdk.MustAccAddressFromBech32(owner) + if _, exists := k.GetSubAccountByOwner(ctx, subAccOwnerAddr); exists { + return "", types.ErrSubaccountAlreadyExist + } + + subaccountID := k.NextID(ctx) + + // ALERT: If someone frontruns the account creation, will be overwritten here + subAccAddr := types.NewAddressFromSubaccount(subaccountID) + subaccountAccount := k.accountKeeper.NewAccountWithAddress(ctx, subAccAddr) + k.accountKeeper.SetAccount(ctx, subaccountAccount) + + err = k.sendCoinsToSubaccount(ctx, creatorAddr, subAccAddr, moneyToSend) + if err != nil { + return "", sdkerrors.Wrap(err, "unable to send coins") + } + + k.SetSubAccountOwner(ctx, subAccAddr, subAccOwnerAddr) + k.SetLockedBalances(ctx, subAccAddr, lockedBalances) + k.SetBalance(ctx, subAccAddr, types.Balance{ + DepositedAmount: moneyToSend, + SpentAmount: sdk.ZeroInt(), + WithdrawmAmount: sdk.ZeroInt(), + LostAmount: sdk.ZeroInt(), + }) + return subAccAddr.String(), nil +} + +// sendCoinsToSubaccount sends the coins to the subaccount. +func (k Keeper) sendCoinsToSubaccount(ctx sdk.Context, creatorAccount, subAccountAddress sdk.AccAddress, moneyToSend sdkmath.Int) error { + err := k.bankKeeper.SendCoins(ctx, creatorAccount, subAccountAddress, sdk.NewCoins(sdk.NewCoin(params.DefaultBondDenom, moneyToSend))) + if err != nil { + return sdkerrors.Wrap(err, "unable to send coins") + } + + return nil +} + +// sumBalanceUnlocks sums all the balances to unlock and returns the total amount. It +// returns an error if any of the unlock times is expired. +func sumBalanceUnlocks(ctx sdk.Context, balanceUnlocks []types.LockedBalance) (sdkmath.Int, error) { + moneyToSend := sdkmath.NewInt(0) + + for _, balanceUnlock := range balanceUnlocks { + if balanceUnlock.UnlockTS < uint64(ctx.BlockTime().Unix()) { + return sdkmath.Int{}, types.ErrUnlockTokenTimeExpired + } + + moneyToSend = moneyToSend.Add(balanceUnlock.Amount) + } + + return moneyToSend, nil +} diff --git a/x/subaccount/keeper/subaccount_test.go b/x/subaccount/keeper/subaccount_test.go new file mode 100644 index 00000000..0575b3ec --- /dev/null +++ b/x/subaccount/keeper/subaccount_test.go @@ -0,0 +1,146 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestSubaccountID(t *testing.T) { + _, k, ctx := setupKeeperAndApp(t) + + // Peek from beginning should return 1 + require.Equal(t, uint64(1), k.Peek(ctx)) + + // NextID returns the actual ID and increments the ID + require.Equal(t, uint64(1), k.NextID(ctx)) + require.Equal(t, uint64(2), k.Peek(ctx)) + + // We can set an arbitrary ID and continue from there + k.SetID(ctx, 100) + require.Equal(t, uint64(100), k.Peek(ctx)) +} + +func TestSubAccountOwner(t *testing.T) { + _, k, ctx := setupKeeperAndApp(t) + + owner := sample.NativeAccAddress() + + // Account should not have subaccount + _, exists := k.GetSubAccountOwner(ctx, owner) + require.False(t, exists) + + // Set subaccount owner + id := k.NextID(ctx) + k.SetSubAccountOwner(ctx, types.NewAddressFromSubaccount(id), owner) + + // Account should have subaccount + _, exists = k.GetSubAccountByOwner(ctx, owner) + require.True(t, exists) + + // Get subaccount ID + subAccountAddress, exists := k.GetSubAccountByOwner(ctx, owner) + require.True(t, exists) + require.Equal(t, types.NewAddressFromSubaccount(id), subAccountAddress) + + // Get owner of subaccount + gotOwner, exists := k.GetSubAccountOwner(ctx, subAccountAddress) + require.True(t, exists) + require.Equal(t, owner, gotOwner) + // Get account ID by owner + gotSubAccount, exists := k.GetSubAccountByOwner(ctx, owner) + require.True(t, exists) + require.Equal(t, types.NewAddressFromSubaccount(id), gotSubAccount) +} + +func TestSetLockedBalances(t *testing.T) { + _, k, ctx := setupKeeperAndApp(t) + + someUnlockTime := uint64(time.Now().Add(time.Hour * 24 * 365).Unix()) + otherUnlockTime := uint64(time.Now().Add(time.Hour * 24 * 365 * 2).Unix()) + + balanceUnlocks := []types.LockedBalance{ + { + Amount: sdkmath.NewInt(10000), + UnlockTS: someUnlockTime, + }, + { + Amount: sdkmath.NewInt(20000), + UnlockTS: otherUnlockTime, + }, + } + + addr := types.NewAddressFromSubaccount(1) + + k.SetLockedBalances(ctx, addr, balanceUnlocks) + + // Get locked balances + lockedBalances := k.GetLockedBalances(ctx, addr) + for i, lockedBalance := range lockedBalances { + require.Equal(t, lockedBalance.Amount, balanceUnlocks[i].Amount) + require.True(t, lockedBalance.UnlockTS == balanceUnlocks[i].UnlockTS) + } +} + +func TestSetBalances(t *testing.T) { + _, k, ctx := setupKeeperAndApp(t) + + balance := types.Balance{ + DepositedAmount: sdk.ZeroInt(), + SpentAmount: sdk.ZeroInt(), + WithdrawmAmount: sdk.ZeroInt(), + LostAmount: sdk.OneInt(), + } + + subAccAddr := types.NewAddressFromSubaccount(1) + k.SetBalance(ctx, subAccAddr, balance) + + // Get balance + gotBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, balance, gotBalance) +} + +func TestKeeper_GetLockedBalances(t *testing.T) { + _, k, ctx := setupKeeperAndApp(t) + + beforeUnlockTime1 := uint64(time.Now().Add(-time.Hour * 24 * 365).Unix()) + beforeUnlockTime2 := uint64(time.Now().Add(-time.Hour * 24 * 365 * 2).Unix()) + + afterUnlockTime1 := uint64(time.Now().Add(time.Hour * 24 * 365).Unix()) + afterUnlockTime2 := uint64(time.Now().Add(time.Hour * 24 * 365 * 2).Unix()) + + // I added them unordered to make sure they are sorted + balanceUnlocks := []types.LockedBalance{ + { + Amount: sdkmath.NewInt(10000), + UnlockTS: beforeUnlockTime1, + }, + { + Amount: sdkmath.NewInt(30000), + UnlockTS: afterUnlockTime1, + }, + { + Amount: sdkmath.NewInt(20000), + UnlockTS: beforeUnlockTime2, + }, + { + Amount: sdkmath.NewInt(40000), + UnlockTS: afterUnlockTime2, + }, + } + + addr := types.NewAddressFromSubaccount(1) + k.SetLockedBalances(ctx, addr, balanceUnlocks) + + // get unlocked balance + unlockedBalance := k.GetUnlockedBalance(ctx, addr) + require.True(t, unlockedBalance.Equal(sdkmath.NewInt(10000+20000))) +} diff --git a/x/subaccount/module.go b/x/subaccount/module.go new file mode 100644 index 00000000..8966ac99 --- /dev/null +++ b/x/subaccount/module.go @@ -0,0 +1,154 @@ +package subaccount + +import ( + "encoding/json" + "fmt" + + "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" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/sge-network/sge/x/subaccount/client/cli" + "github.com/sge-network/sge/x/subaccount/keeper" + "github.com/sge-network/sge/x/subaccount/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the module. +type AppModuleBasic struct{} + +// Name returns the module's name. +func (AppModuleBasic) Name() string { return types.ModuleName } + +// RegisterLegacyAminoCodec registers the legacy amino codec for the app module basic +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the module. +func (AppModuleBasic) ValidateGenesis( + cdc codec.JSONCodec, + _ client.TxEncodingConfig, + bz json.RawMessage, +) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {} + +// GetTxCmd returns the module's root tx command. +func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd() } + +// GetQueryCmd returns the module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +// NewAppModule creates new app module object +func NewAppModule(k keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{}, + keeper: k, + } +} + +// Name returns the module's name. +func (am AppModule) Name() string { return am.AppModuleBasic.Name() } + +// Route returns the module's message routing key. +func (am AppModule) Route() sdk.Route { + return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper)) +} + +// QuerierRoute returns the module's query routing key. +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler returns the module's Querier. +func (AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { return nil } + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) +} + +// RegisterInvariants registers the module's invariants. +func (AppModule) RegisterInvariants(sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis( + ctx sdk.Context, + cdc codec.JSONCodec, + gs json.RawMessage, +) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock executes all ABCI BeginBlock logic respective to the module. +func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the module. It +// returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/subaccount/types/address.go b/x/subaccount/types/address.go new file mode 100644 index 00000000..57adb77d --- /dev/null +++ b/x/subaccount/types/address.go @@ -0,0 +1,12 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// NewAddressFromSubaccount returns an account address for a subaccount +func NewAddressFromSubaccount(subaccountID uint64) sdk.AccAddress { + return address.Module(types.ModuleName, sdk.Uint64ToBigEndian(subaccountID)) +} diff --git a/x/subaccount/types/balance.go b/x/subaccount/types/balance.go new file mode 100644 index 00000000..9c6855f5 --- /dev/null +++ b/x/subaccount/types/balance.go @@ -0,0 +1,65 @@ +package types + +import ( + "fmt" + + sdkmath "cosmossdk.io/math" +) + +// Validate performs a basic validation of the LockedBalance fields. +func (lb *LockedBalance) Validate() error { + if lb.UnlockTS == 0 { + return fmt.Errorf("unlock time is zero %d", lb.UnlockTS) + } + + if lb.Amount.IsNil() { + return fmt.Errorf("amount is nil") + } + + if lb.Amount.IsNegative() { + return fmt.Errorf("amount is negative") + } + + return nil +} + +// Available reports the coins that are available in the subaccount. +func (m *Balance) Available() sdkmath.Int { + return m.DepositedAmount. + Sub(m.WithdrawmAmount). + Sub(m.SpentAmount). + Sub(m.LostAmount) +} + +// Spend modifies the spent amount of subaccount balance according to the spent value. +func (m *Balance) Spend(amt sdkmath.Int) error { + if amt.IsNegative() { + return fmt.Errorf("amount is not positive") + } + if amt.GT(m.Available()) { + return fmt.Errorf("amount is greater than available") + } + m.SpentAmount = m.SpentAmount.Add(amt) + return nil +} + +// Unspend modifies the spent amount of subaccount balance according to the undpent value. +func (m *Balance) Unspend(amt sdkmath.Int) error { + if amt.IsNegative() { + return fmt.Errorf("amount is not positive") + } + if amt.GT(m.SpentAmount) { + return fmt.Errorf("amount is greater than spent") + } + m.SpentAmount = m.SpentAmount.Sub(amt) + return nil +} + +// AddLoss adds to the lost amout of subaccount balance after losing the bet. +func (m *Balance) AddLoss(amt sdkmath.Int) error { + if amt.IsNegative() { + return fmt.Errorf("amount is not positive") + } + m.LostAmount = m.LostAmount.Add(amt) + return nil +} diff --git a/x/subaccount/types/balance.pb.go b/x/subaccount/types/balance.pb.go new file mode 100644 index 00000000..5f81584e --- /dev/null +++ b/x/subaccount/types/balance.pb.go @@ -0,0 +1,675 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/subaccount/balance.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/gogoproto/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 + +// Balance defines the balance of a subaccount. +type Balance struct { + // deposited_amount keeps track of how much was deposited so far in the + // subaccount. + DepositedAmount cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=deposited_amount,json=depositedAmount,proto3,customtype=cosmossdk.io/math.Int" json:"deposited_amount"` + // spent_amount keeps track of how much was spent in the account in betting, + // house, staking, etc. + SpentAmount cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=spent_amount,json=spentAmount,proto3,customtype=cosmossdk.io/math.Int" json:"spent_amount"` + // withdrawn_amount keeps track of how much was withdrawn in the account after + // locked coins become free. + WithdrawmAmount cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=withdrawm_amount,json=withdrawmAmount,proto3,customtype=cosmossdk.io/math.Int" json:"withdrawm_amount"` + // lost_amount keeps track of the amounts that were lost due to betting + // losses, slashing etc. + LostAmount cosmossdk_io_math.Int `protobuf:"bytes,4,opt,name=lost_amount,json=lostAmount,proto3,customtype=cosmossdk.io/math.Int" json:"lost_amount"` +} + +func (m *Balance) Reset() { *m = Balance{} } +func (m *Balance) String() string { return proto.CompactTextString(m) } +func (*Balance) ProtoMessage() {} +func (*Balance) Descriptor() ([]byte, []int) { + return fileDescriptor_19a80bd2939d53e2, []int{0} +} +func (m *Balance) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Balance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Balance.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 *Balance) XXX_Merge(src proto.Message) { + xxx_messageInfo_Balance.Merge(m, src) +} +func (m *Balance) XXX_Size() int { + return m.Size() +} +func (m *Balance) XXX_DiscardUnknown() { + xxx_messageInfo_Balance.DiscardUnknown(m) +} + +var xxx_messageInfo_Balance proto.InternalMessageInfo + +// LockedBalance defines a balance which is locked. +type LockedBalance struct { + UnlockTS uint64 `protobuf:"varint,1,opt,name=unlock_ts,proto3" json:"unlock_ts"` + Amount cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` +} + +func (m *LockedBalance) Reset() { *m = LockedBalance{} } +func (m *LockedBalance) String() string { return proto.CompactTextString(m) } +func (*LockedBalance) ProtoMessage() {} +func (*LockedBalance) Descriptor() ([]byte, []int) { + return fileDescriptor_19a80bd2939d53e2, []int{1} +} +func (m *LockedBalance) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LockedBalance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LockedBalance.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 *LockedBalance) XXX_Merge(src proto.Message) { + xxx_messageInfo_LockedBalance.Merge(m, src) +} +func (m *LockedBalance) XXX_Size() int { + return m.Size() +} +func (m *LockedBalance) XXX_DiscardUnknown() { + xxx_messageInfo_LockedBalance.DiscardUnknown(m) +} + +var xxx_messageInfo_LockedBalance proto.InternalMessageInfo + +func (m *LockedBalance) GetUnlockTS() uint64 { + if m != nil { + return m.UnlockTS + } + return 0 +} + +func init() { + proto.RegisterType((*Balance)(nil), "sgenetwork.sge.subaccount.Balance") + proto.RegisterType((*LockedBalance)(nil), "sgenetwork.sge.subaccount.LockedBalance") +} + +func init() { proto.RegisterFile("sge/subaccount/balance.proto", fileDescriptor_19a80bd2939d53e2) } + +var fileDescriptor_19a80bd2939d53e2 = []byte{ + // 333 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x31, 0x4b, 0xf3, 0x40, + 0x18, 0xc7, 0x93, 0xbe, 0xa5, 0xaf, 0xbd, 0x2a, 0x96, 0xa0, 0x60, 0x45, 0x13, 0xe9, 0xe4, 0xd2, + 0x64, 0x10, 0x71, 0x13, 0xcd, 0x62, 0x05, 0xa7, 0xaa, 0x8b, 0x4b, 0x49, 0x2e, 0xc7, 0x35, 0xa4, + 0xb9, 0x27, 0xf4, 0xb9, 0x50, 0x9d, 0xfc, 0x0a, 0x7e, 0x03, 0xbf, 0x4e, 0xc7, 0x8e, 0xe2, 0x10, + 0x24, 0xdd, 0xfc, 0x14, 0x92, 0x6b, 0xda, 0x3a, 0xc6, 0xed, 0xe1, 0xf8, 0xff, 0x7e, 0x3c, 0xfc, + 0x9f, 0x23, 0x47, 0xc8, 0x99, 0x83, 0xa9, 0xef, 0x51, 0x0a, 0xa9, 0x90, 0x8e, 0xef, 0x8d, 0x3d, + 0x41, 0x99, 0x9d, 0x4c, 0x40, 0x82, 0xd1, 0x41, 0xce, 0x04, 0x93, 0x53, 0x98, 0x44, 0x36, 0x72, + 0x66, 0x6f, 0x82, 0x87, 0x7b, 0x1c, 0x38, 0xa8, 0x94, 0x53, 0x4c, 0x4b, 0xa0, 0xfb, 0x5e, 0x23, + 0xff, 0xdd, 0xa5, 0xc2, 0xe8, 0x93, 0x76, 0xc0, 0x12, 0xc0, 0x50, 0xb2, 0x60, 0xe8, 0xc5, 0x05, + 0x75, 0xa0, 0x9f, 0xe8, 0xa7, 0x4d, 0xf7, 0x78, 0x96, 0x59, 0xda, 0x67, 0x66, 0xed, 0x53, 0xc0, + 0x18, 0x10, 0x83, 0xc8, 0x0e, 0xc1, 0x89, 0x3d, 0x39, 0xb2, 0x6f, 0x85, 0x1c, 0xec, 0xae, 0xb1, + 0x6b, 0x45, 0x19, 0x57, 0x64, 0x1b, 0x13, 0x26, 0xe4, 0xca, 0x52, 0xab, 0x62, 0x69, 0x29, 0xa4, + 0x34, 0xf4, 0x49, 0x7b, 0x1a, 0xca, 0x51, 0x30, 0xf1, 0xa6, 0xf1, 0xca, 0xf2, 0xaf, 0xd2, 0x2e, + 0x6b, 0xac, 0x34, 0x5d, 0x92, 0xd6, 0x18, 0x70, 0xbd, 0x4a, 0xbd, 0x8a, 0x84, 0x14, 0xc4, 0x92, + 0xef, 0xbe, 0x92, 0x9d, 0x3b, 0xa0, 0x11, 0x0b, 0x56, 0x35, 0x5d, 0x90, 0x66, 0x2a, 0xc6, 0x40, + 0xa3, 0xa1, 0x44, 0xd5, 0x4f, 0xdd, 0xed, 0xe4, 0x99, 0xb5, 0xf5, 0xa8, 0x1e, 0x1f, 0xee, 0xbf, + 0x33, 0x6b, 0x13, 0x18, 0x6c, 0x46, 0xe3, 0x9c, 0x34, 0xfe, 0xd2, 0x47, 0x19, 0x76, 0x6f, 0x66, + 0xb9, 0xa9, 0xcf, 0x73, 0x53, 0xff, 0xca, 0x4d, 0xfd, 0x6d, 0x61, 0x6a, 0xf3, 0x85, 0xa9, 0x7d, + 0x2c, 0x4c, 0xed, 0xa9, 0xc7, 0x43, 0x39, 0x4a, 0x7d, 0x9b, 0x42, 0xec, 0x20, 0x67, 0xbd, 0xf2, + 0xf2, 0xc5, 0xec, 0x3c, 0xff, 0xfe, 0x24, 0xf2, 0x25, 0x61, 0xe8, 0x37, 0xd4, 0xc9, 0xcf, 0x7e, + 0x02, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x2e, 0xd5, 0x37, 0x43, 0x02, 0x00, 0x00, +} + +func (m *Balance) 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 *Balance) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Balance) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.LostAmount.Size() + i -= size + if _, err := m.LostAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBalance(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.WithdrawmAmount.Size() + i -= size + if _, err := m.WithdrawmAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBalance(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size := m.SpentAmount.Size() + i -= size + if _, err := m.SpentAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBalance(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.DepositedAmount.Size() + i -= size + if _, err := m.DepositedAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBalance(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *LockedBalance) 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 *LockedBalance) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LockedBalance) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintBalance(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.UnlockTS != 0 { + i = encodeVarintBalance(dAtA, i, uint64(m.UnlockTS)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintBalance(dAtA []byte, offset int, v uint64) int { + offset -= sovBalance(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Balance) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.DepositedAmount.Size() + n += 1 + l + sovBalance(uint64(l)) + l = m.SpentAmount.Size() + n += 1 + l + sovBalance(uint64(l)) + l = m.WithdrawmAmount.Size() + n += 1 + l + sovBalance(uint64(l)) + l = m.LostAmount.Size() + n += 1 + l + sovBalance(uint64(l)) + return n +} + +func (m *LockedBalance) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.UnlockTS != 0 { + n += 1 + sovBalance(uint64(m.UnlockTS)) + } + l = m.Amount.Size() + n += 1 + l + sovBalance(uint64(l)) + return n +} + +func sovBalance(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozBalance(x uint64) (n int) { + return sovBalance(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Balance) 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 ErrIntOverflowBalance + } + 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: Balance: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Balance: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DepositedAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBalance + } + 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 ErrInvalidLengthBalance + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthBalance + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DepositedAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpentAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBalance + } + 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 ErrInvalidLengthBalance + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthBalance + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SpentAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawmAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBalance + } + 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 ErrInvalidLengthBalance + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthBalance + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.WithdrawmAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LostAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBalance + } + 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 ErrInvalidLengthBalance + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthBalance + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LostAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBalance(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBalance + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *LockedBalance) 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 ErrIntOverflowBalance + } + 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: LockedBalance: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LockedBalance: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UnlockTS", wireType) + } + m.UnlockTS = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBalance + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UnlockTS |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBalance + } + 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 ErrInvalidLengthBalance + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthBalance + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipBalance(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthBalance + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipBalance(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, ErrIntOverflowBalance + } + 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, ErrIntOverflowBalance + } + 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, ErrIntOverflowBalance + } + 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, ErrInvalidLengthBalance + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupBalance + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthBalance + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthBalance = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowBalance = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupBalance = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/subaccount/types/balance_test.go b/x/subaccount/types/balance_test.go new file mode 100644 index 00000000..3cb0101d --- /dev/null +++ b/x/subaccount/types/balance_test.go @@ -0,0 +1,53 @@ +package types_test + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestLockedBalanceValidate(t *testing.T) { + tests := []struct { + name string + lb types.LockedBalance + want error + }{ + { + name: "unlock time zero", + lb: types.LockedBalance{ + UnlockTS: 0, + Amount: sdkmath.Int{}, + }, + want: fmt.Errorf("unlock time is zero 0"), + }, + { + name: "negative amount", + lb: types.LockedBalance{ + UnlockTS: uint64(time.Now().Unix()), + Amount: sdkmath.NewInt(-1), + }, + want: fmt.Errorf("amount is negative"), + }, + { + name: "nil amount", + lb: types.LockedBalance{ + UnlockTS: uint64(time.Now().Unix()), + Amount: sdkmath.Int{}, + }, + want: fmt.Errorf("amount is nil"), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.lb.Validate() + require.Equal(t, tt.want, got) + }) + } +} diff --git a/x/subaccount/types/codec.go b/x/subaccount/types/codec.go new file mode 100644 index 00000000..4cfe3560 --- /dev/null +++ b/x/subaccount/types/codec.go @@ -0,0 +1,47 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterLegacyAminoCodec registers module codec to the app codec +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgCreate{}, "subaccount/Create") + legacy.RegisterAminoMsg(cdc, &MsgTopUp{}, "subaccount/TopUp") + legacy.RegisterAminoMsg(cdc, &MsgWithdrawUnlockedBalances{}, "subaccount/Withdraw") + legacy.RegisterAminoMsg(cdc, &MsgWager{}, "subaccount/BetWager") + legacy.RegisterAminoMsg(cdc, &MsgHouseDeposit{}, "subaccount/HouseDeposit") + legacy.RegisterAminoMsg(cdc, &MsgHouseWithdraw{}, "subaccount/HouseWithdraw") +} + +// RegisterInterfaces registers the module interface types +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgCreate{}, + &MsgTopUp{}, + &MsgWithdrawUnlockedBalances{}, + &MsgWager{}, + &MsgHouseDeposit{}, + &MsgHouseWithdraw{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + // amino is the legacy amino codec + amino = codec.NewLegacyAmino() + // ModuleCdc is the codec of the module + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) +} diff --git a/x/subaccount/types/errors.go b/x/subaccount/types/errors.go new file mode 100644 index 00000000..6eb7a47d --- /dev/null +++ b/x/subaccount/types/errors.go @@ -0,0 +1,15 @@ +package types + +// DONTCOVER + +import ( + sdkerrors "cosmossdk.io/errors" +) + +var ( + ErrUnlockTokenTimeExpired = sdkerrors.Register(ModuleName, 1, "unlock time is expired") + ErrSubaccountAlreadyExist = sdkerrors.Register(ModuleName, 2, "account has already sub account") + ErrSubaccountDoesNotExist = sdkerrors.Register(ModuleName, 3, "sub account does not exist") + ErrNothingToWithdraw = sdkerrors.Register(ModuleName, 4, "nothing to withdraw") + ErrInvalidLockedBalance = sdkerrors.Register(ModuleName, 5, "invalid locked balance") +) diff --git a/x/subaccount/types/events.go b/x/subaccount/types/events.go new file mode 100644 index 00000000..3c424452 --- /dev/null +++ b/x/subaccount/types/events.go @@ -0,0 +1,24 @@ +package types + +// DONTCOVER + +const ( + attributeValueCategory = ModuleName + + attributeKeyBetUID = "bet_uid" + attributeKeyBetCreator = "bet_creator" + attributeKeyBetCreatorOwner = "bet_creator_owner" +) + +const ( + attributeKeyDepositCreator = "creator" + attributeKeySubAccDepositor = "subacc_depositor" + attributeKeyWithdrawalID = "withdrawal_id" + attributeKeyDepositMarketUIDParticipantIndex = "deposit_market_index" + attributeKeyWithdrawMarketUIDParticipantIndex = "withdraw_market_index" +) + +const ( + attributeKeySubAccOwner = "subacc_owner" + attributeKeySubAcc = "subacc" +) diff --git a/x/subaccount/types/expected_keepers.go b/x/subaccount/types/expected_keepers.go new file mode 100644 index 00000000..9d4db116 --- /dev/null +++ b/x/subaccount/types/expected_keepers.go @@ -0,0 +1,52 @@ +package types + +import ( + context "context" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + bettypes "github.com/sge-network/sge/x/bet/types" + housetypes "github.com/sge-network/sge/x/house/types" +) + +// BetKeeper defines the expected interface needed to retrieve or set bets. +type BetKeeper interface { + PrepareBetObject(ctx sdk.Context, creator string, props *bettypes.WagerProps) (*bettypes.Bet, error) + Wager(ctx sdk.Context, bet *bettypes.Bet) error +} + +// AccountKeeper defines the expected account keeper used for simulations (noalias) +type AccountKeeper interface { + NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI + SetAccount(ctx sdk.Context, acc authtypes.AccountI) +} + +// BankKeeper defines the expected interface needed to retrieve account balances. +type BankKeeper interface { + SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin +} + +// HouseKeeper defines the expected interface needed to deposit or withdraw. +type HouseKeeper interface { + GetParams(ctx sdk.Context) housetypes.Params + ParseDepositTicketAndValidate(goCtx context.Context, ctx sdk.Context, msg *housetypes.MsgDeposit, authzAllowed bool) (string, error) + Deposit(ctx sdk.Context, creator, depositor, marketUID string, amount sdkmath.Int) (participationIndex uint64, err error) + ParseWithdrawTicketAndValidate(goCtx context.Context, ctx sdk.Context, msg *housetypes.MsgWithdraw, authzAllowed bool) (string, bool, error) + CalcAndWithdraw(ctx sdk.Context, msg *housetypes.MsgWithdraw, depositorAddr string, isOnBehalf bool) (uint64, error) +} + +// OrderbookKeeper defines the expected interface needed to initiate an order book for a market +type OrderBookKeeper interface { + CalcWithdrawalAmount( + ctx sdk.Context, + depositorAddress string, + marketUID string, + participationIndex uint64, + mode housetypes.WithdrawalMode, + totalWithdrawnAmount sdkmath.Int, + amount sdkmath.Int, + ) (sdkmath.Int, error) +} diff --git a/x/subaccount/types/genesis.go b/x/subaccount/types/genesis.go new file mode 100644 index 00000000..26819b59 --- /dev/null +++ b/x/subaccount/types/genesis.go @@ -0,0 +1,14 @@ +package types + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (*GenesisState) Validate() error { + return nil +} diff --git a/x/subaccount/types/genesis.pb.go b/x/subaccount/types/genesis.pb.go new file mode 100644 index 00000000..513415fa --- /dev/null +++ b/x/subaccount/types/genesis.pb.go @@ -0,0 +1,771 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/subaccount/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/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 + +// GenesisState defines the subaccount module's genesis state. +type GenesisState struct { + // params contains the subaccount parameters. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + SubaccountId uint64 `protobuf:"varint,2,opt,name=subaccount_id,json=subaccountId,proto3" json:"subaccount_id,omitempty"` + // subaccounts contains all the subaccounts. + Subaccounts []GenesisSubaccount `protobuf:"bytes,3,rep,name=subaccounts,proto3" json:"subaccounts"` +} + +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_021997686c533a34, []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) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetSubaccountId() uint64 { + if m != nil { + return m.SubaccountId + } + return 0 +} + +func (m *GenesisState) GetSubaccounts() []GenesisSubaccount { + if m != nil { + return m.Subaccounts + } + return nil +} + +// GenesisSubaccount defines the genesis subaccount containing owner, address +// and balance information. +type GenesisSubaccount struct { + // address is the address of the subaccount. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // owner is the owner of the subaccount. + Owner string `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,omitempty"` + // balance defines the balance status of a subaccount + Balance Balance `protobuf:"bytes,3,opt,name=balance,proto3" json:"balance"` + // locked_balances defines the lockup of balances history of a subaccount + LockedBalances []LockedBalance `protobuf:"bytes,4,rep,name=locked_balances,json=lockedBalances,proto3" json:"locked_balances"` +} + +func (m *GenesisSubaccount) Reset() { *m = GenesisSubaccount{} } +func (m *GenesisSubaccount) String() string { return proto.CompactTextString(m) } +func (*GenesisSubaccount) ProtoMessage() {} +func (*GenesisSubaccount) Descriptor() ([]byte, []int) { + return fileDescriptor_021997686c533a34, []int{1} +} +func (m *GenesisSubaccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisSubaccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisSubaccount.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 *GenesisSubaccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisSubaccount.Merge(m, src) +} +func (m *GenesisSubaccount) XXX_Size() int { + return m.Size() +} +func (m *GenesisSubaccount) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisSubaccount.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisSubaccount proto.InternalMessageInfo + +func (m *GenesisSubaccount) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *GenesisSubaccount) GetOwner() string { + if m != nil { + return m.Owner + } + return "" +} + +func (m *GenesisSubaccount) GetBalance() Balance { + if m != nil { + return m.Balance + } + return Balance{} +} + +func (m *GenesisSubaccount) GetLockedBalances() []LockedBalance { + if m != nil { + return m.LockedBalances + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "sgenetwork.sge.subaccount.GenesisState") + proto.RegisterType((*GenesisSubaccount)(nil), "sgenetwork.sge.subaccount.GenesisSubaccount") +} + +func init() { proto.RegisterFile("sge/subaccount/genesis.proto", fileDescriptor_021997686c533a34) } + +var fileDescriptor_021997686c533a34 = []byte{ + // 347 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xcf, 0x4e, 0xc2, 0x30, + 0x18, 0x5f, 0x05, 0x21, 0x14, 0xd4, 0xd8, 0x70, 0x98, 0x68, 0x26, 0xe2, 0x65, 0x07, 0xe9, 0x12, + 0x7c, 0x00, 0x93, 0x5d, 0x88, 0x89, 0x07, 0x33, 0x4d, 0x4c, 0xbc, 0x90, 0x6e, 0x6b, 0x2a, 0x01, + 0x56, 0xb2, 0x96, 0xa0, 0x6f, 0xe1, 0x63, 0x11, 0x4f, 0x1c, 0x3d, 0x19, 0x02, 0x2f, 0x62, 0x68, + 0x8b, 0x43, 0x8c, 0xbb, 0xf5, 0xfb, 0xed, 0xf7, 0xaf, 0xdf, 0x0a, 0xcf, 0x04, 0xa3, 0x9e, 0x98, + 0x84, 0x24, 0x8a, 0xf8, 0x24, 0x91, 0x1e, 0xa3, 0x09, 0x15, 0x7d, 0x81, 0xc7, 0x29, 0x97, 0x1c, + 0x9d, 0x88, 0xf5, 0x2c, 0xa7, 0x3c, 0x1d, 0x60, 0xc1, 0x28, 0xce, 0x88, 0x8d, 0x3a, 0xe3, 0x8c, + 0x2b, 0x96, 0xb7, 0x3e, 0x69, 0x41, 0xe3, 0x74, 0xc7, 0x6e, 0x4c, 0x52, 0x32, 0x32, 0x6e, 0x8d, + 0xdd, 0xac, 0x90, 0x0c, 0x49, 0x12, 0x51, 0xfd, 0xb5, 0xf5, 0x01, 0x60, 0xad, 0xab, 0xd3, 0x1f, + 0x24, 0x91, 0x14, 0xdd, 0xc0, 0x92, 0x96, 0xdb, 0xa0, 0x09, 0xdc, 0x6a, 0xe7, 0x02, 0xff, 0xdb, + 0x06, 0xdf, 0x2b, 0xa2, 0x5f, 0x9c, 0x7d, 0x9d, 0x5b, 0x81, 0x91, 0xa1, 0x4b, 0x78, 0x90, 0x51, + 0x7a, 0xfd, 0xd8, 0xde, 0x6b, 0x02, 0xb7, 0x18, 0xd4, 0x32, 0xf0, 0x36, 0x46, 0x8f, 0xb0, 0x9a, + 0xcd, 0xc2, 0x2e, 0x34, 0x0b, 0x6e, 0xb5, 0x73, 0x95, 0x13, 0xb5, 0xe9, 0xf8, 0x83, 0x98, 0xd4, + 0x6d, 0x9b, 0xd6, 0x02, 0xc0, 0xe3, 0x3f, 0x44, 0x64, 0xc3, 0x32, 0x89, 0xe3, 0x94, 0x0a, 0x7d, + 0xa5, 0x4a, 0xb0, 0x19, 0x51, 0x1d, 0xee, 0xf3, 0x69, 0x42, 0x53, 0x55, 0xb1, 0x12, 0xe8, 0x01, + 0xf9, 0xb0, 0x6c, 0x76, 0x64, 0x17, 0xd4, 0x0a, 0x5a, 0x39, 0xbd, 0x7c, 0xcd, 0x34, 0x6d, 0x36, + 0x42, 0xf4, 0x04, 0x8f, 0x86, 0x3c, 0x1a, 0xd0, 0xb8, 0x67, 0x10, 0x61, 0x17, 0xd5, 0x1d, 0xdd, + 0x1c, 0xaf, 0x3b, 0xa5, 0xf8, 0xed, 0x78, 0x38, 0xdc, 0x06, 0x85, 0xdf, 0x9d, 0x2d, 0x1d, 0x30, + 0x5f, 0x3a, 0x60, 0xb1, 0x74, 0xc0, 0xfb, 0xca, 0xb1, 0xe6, 0x2b, 0xc7, 0xfa, 0x5c, 0x39, 0xd6, + 0x73, 0x9b, 0xf5, 0xe5, 0xcb, 0x24, 0xc4, 0x11, 0x1f, 0x79, 0x82, 0xd1, 0xb6, 0x09, 0x59, 0x9f, + 0xbd, 0xd7, 0xed, 0x07, 0x20, 0xdf, 0xc6, 0x54, 0x84, 0x25, 0xf5, 0xff, 0xaf, 0xbf, 0x03, 0x00, + 0x00, 0xff, 0xff, 0x0a, 0xda, 0xf7, 0xe7, 0x8b, 0x02, 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.Subaccounts) > 0 { + for iNdEx := len(m.Subaccounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Subaccounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.SubaccountId != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.SubaccountId)) + i-- + dAtA[i] = 0x10 + } + { + size, err := m.Params.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 *GenesisSubaccount) 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 *GenesisSubaccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisSubaccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.LockedBalances) > 0 { + for iNdEx := len(m.LockedBalances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.LockedBalances[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + { + size, err := m.Balance.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Owner) > 0 { + i -= len(m.Owner) + copy(dAtA[i:], m.Owner) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Owner))) + 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 + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if m.SubaccountId != 0 { + n += 1 + sovGenesis(uint64(m.SubaccountId)) + } + if len(m.Subaccounts) > 0 { + for _, e := range m.Subaccounts { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *GenesisSubaccount) 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)) + } + l = len(m.Owner) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.Balance.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.LockedBalances) > 0 { + for _, e := range m.LockedBalances { + 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 Params", 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 + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SubaccountId", wireType) + } + m.SubaccountId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SubaccountId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Subaccounts", 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.Subaccounts = append(m.Subaccounts, GenesisSubaccount{}) + if err := m.Subaccounts[len(m.Subaccounts)-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 *GenesisSubaccount) 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: GenesisSubaccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisSubaccount: 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 Owner", 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.Owner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balance", 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 + } + if err := m.Balance.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LockedBalances", 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.LockedBalances = append(m.LockedBalances, LockedBalance{}) + if err := m.LockedBalances[len(m.LockedBalances)-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/x/subaccount/types/keys.go b/x/subaccount/types/keys.go new file mode 100644 index 00000000..251ce620 --- /dev/null +++ b/x/subaccount/types/keys.go @@ -0,0 +1,60 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + + "github.com/sge-network/sge/utils" +) + +// module constants +const ( + // ModuleName defines the module name + ModuleName = "subaccount" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey is the message route for slashing + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName +) + +var ( + // SubaccountIDPrefix is the key used to store the subaccount ID in the keeper KVStore + SubaccountIDPrefix = []byte{0x00} + + // SubAccountOwnerPrefix is the key used to store the subaccount owner in the keeper KVStore + SubAccountOwnerPrefix = []byte{0x01} + + // SubAccountOwnerReversePrefix is the key used to store the subaccount owner by ID in the keeper KVStore + SubAccountOwnerReversePrefix = []byte{0x02} + + // LockedBalancePrefix is the key used to store the locked balance in the keeper KVStore + LockedBalancePrefix = []byte{0x03} + + // BalancePrefix saves the balance of an account. + BalancePrefix = []byte{0x04} +) + +func SubAccountOwnerKey(address sdk.AccAddress) []byte { + return append(SubAccountOwnerPrefix, address...) +} + +func SubAccountKey(subAccountAddress sdk.AccAddress) []byte { + return append(SubAccountOwnerReversePrefix, subAccountAddress...) +} + +func LockedBalanceKey(subAccountAddress sdk.AccAddress, unlockTime uint64) []byte { + return append(LockedBalancePrefix, append(address.MustLengthPrefix(subAccountAddress), utils.Uint64ToBytes(unlockTime)...)...) +} + +func LockedBalancePrefixKey(subAccountAddress sdk.AccAddress) []byte { + return append(LockedBalancePrefix, address.MustLengthPrefix(subAccountAddress)...) +} + +func BalanceKey(address sdk.AccAddress) []byte { + return append(BalancePrefix, address.Bytes()...) +} diff --git a/x/subaccount/types/messages_balance.go b/x/subaccount/types/messages_balance.go new file mode 100644 index 00000000..73795c8a --- /dev/null +++ b/x/subaccount/types/messages_balance.go @@ -0,0 +1,96 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" +) + +const ( + // typeMsgTopUp is type of message MsgTopUp + typeMsgTopUp = "subacc_topup" + // typeMsgWithdrawUnlockedBalances is type of message MsgWithdrawUnlockedBalances + typeMsgWithdrawUnlockedBalances = "subacc_withdraw_unlocked" +) + +var ( + _ sdk.Msg = &MsgTopUp{} + _ sdk.Msg = &MsgWithdrawUnlockedBalances{} +) + +// Route returns the module's message router key. +func (*MsgTopUp) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgTopUp) Type() string { return typeMsgTopUp } + +func (msg *MsgTopUp) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +// EmitEvent emits the event for the message success. +func (msg *MsgTopUp) EmitEvent(ctx *sdk.Context, subAccAddr string) { + emitter := utils.NewEventEmitter(ctx, attributeValueCategory) + emitter.AddMsg(typeMsgTopUp, msg.Creator, + sdk.NewAttribute(attributeKeySubAcc, subAccAddr), + ) + emitter.Emit() +} + +func (msg *MsgTopUp) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return errors.ErrInvalidAddress + } + + _, err = sdk.AccAddressFromBech32(msg.SubAccount) + if err != nil { + return errors.ErrInvalidAddress + } + + for _, balanceUnlock := range msg.LockedBalances { + if err = balanceUnlock.Validate(); err != nil { + return sdkerrors.Wrapf(err, "invalid locked balance") + } + } + + return nil +} + +// Route returns the module's message router key. +func (*MsgWithdrawUnlockedBalances) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgWithdrawUnlockedBalances) Type() string { return typeMsgWithdrawUnlockedBalances } + +func (msg *MsgWithdrawUnlockedBalances) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (msg *MsgWithdrawUnlockedBalances) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return errors.ErrInvalidAddress + } + + return nil +} + +// EmitEvent emits the event for the message success. +func (msg *MsgWithdrawUnlockedBalances) EmitEvent(ctx *sdk.Context, subAccAddr string) { + emitter := utils.NewEventEmitter(ctx, attributeValueCategory) + emitter.AddMsg(typeMsgWithdrawUnlockedBalances, msg.Creator, + sdk.NewAttribute(attributeKeySubAcc, subAccAddr), + ) + emitter.Emit() +} diff --git a/x/subaccount/types/messages_balance_test.go b/x/subaccount/types/messages_balance_test.go new file mode 100644 index 00000000..bde19181 --- /dev/null +++ b/x/subaccount/types/messages_balance_test.go @@ -0,0 +1,77 @@ +package types_test + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestMsgTopUpValidateBasic(t *testing.T) { + creatorAddr := sample.NativeAccAddress() + owner := sample.NativeAccAddress() + + someTime := uint64(time.Now().Unix()) + tests := []struct { + name string + msg types.MsgTopUp + want error + }{ + { + name: "invalid creator", + msg: types.MsgTopUp{ + Creator: "someInvalidAddress", + SubAccount: owner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: someTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + want: errors.ErrInvalidAddress, + }, + { + name: "invalid sub account owner", + msg: types.MsgTopUp{ + Creator: creatorAddr.String(), + SubAccount: "someInvalidAddress", + LockedBalances: []types.LockedBalance{ + { + UnlockTS: someTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + want: errors.ErrInvalidAddress, + }, + { + name: "unlock time zero", + msg: types.MsgTopUp{ + Creator: creatorAddr.String(), + SubAccount: owner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: 0, + Amount: sdkmath.NewInt(123), + }, + }, + }, + want: fmt.Errorf("invalid locked balance: unlock time is zero"), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.msg.ValidateBasic() + require.ErrorContains(t, got, tt.want.Error()) + }) + } +} diff --git a/x/subaccount/types/messages_bet.go b/x/subaccount/types/messages_bet.go new file mode 100644 index 00000000..872f6287 --- /dev/null +++ b/x/subaccount/types/messages_bet.go @@ -0,0 +1,50 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" +) + +const ( + // typeMsgWager is type of message MsgWager + typeMsgWager = "subacc_wager" +) + +var _ sdk.Msg = &MsgWager{} + +// Route returns the module's message router key. +func (*MsgWager) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgWager) Type() string { return typeMsgWager } + +func (msg *MsgWager) GetSigners() []sdk.AccAddress { + return msg.Msg.GetSigners() +} + +// GetSignBytes returns sortJson form of its message +func (msg *MsgWager) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic validates basic constraints of original msgWager of bet module. +func (msg *MsgWager) ValidateBasic() error { + if msg.Msg == nil { + return errors.ErrInvalidRequest.Wrap("msg is nil") + } + return msg.Msg.ValidateBasic() +} + +// EmitEvent emits the event for the message success. +func (msg *MsgWager) EmitEvent(ctx *sdk.Context, accOwnerAddr string) { + emitter := utils.NewEventEmitter(ctx, attributeValueCategory) + emitter.AddMsg(typeMsgWager, msg.Msg.Creator, + sdk.NewAttribute(attributeKeyBetCreator, msg.Msg.Creator), + sdk.NewAttribute(attributeKeyBetCreatorOwner, accOwnerAddr), + sdk.NewAttribute(attributeKeyBetUID, msg.Msg.Props.UID), + ) + emitter.Emit() +} diff --git a/x/subaccount/types/messages_house.go b/x/subaccount/types/messages_house.go new file mode 100644 index 00000000..1924b808 --- /dev/null +++ b/x/subaccount/types/messages_house.go @@ -0,0 +1,97 @@ +package types + +import ( + "strings" + + "github.com/spf13/cast" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" +) + +const ( + // typeMsgHouseDeposit is type of message MsgHouseDeposit + typeMsgHouseDeposit = "subacc_house_deposit" + // typeHouseWithdraw is type of message MsgHouseWithdraw + typeHouseWithdraw = "subacc_house_withdraw" +) + +var ( + _ sdk.Msg = &MsgHouseDeposit{} + _ sdk.Msg = &MsgHouseWithdraw{} +) + +// Route returns the module's message router key. +func (*MsgHouseDeposit) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgHouseDeposit) Type() string { return typeMsgHouseDeposit } + +func (msg *MsgHouseDeposit) GetSigners() []sdk.AccAddress { + return msg.Msg.GetSigners() +} + +// GetSignBytes returns sortJson form of its message +func (msg *MsgHouseDeposit) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgHouseDeposit) ValidateBasic() error { + if msg.Msg == nil { + return errors.ErrInvalidRequest.Wrap("msg is nil") + } + return msg.Msg.ValidateBasic() +} + +// EmitEvent emits the event for the message success. +func (msg *MsgHouseDeposit) EmitEvent(ctx *sdk.Context, subAccAddr string, participationIndex uint64) { + emitter := utils.NewEventEmitter(ctx, attributeValueCategory) + emitter.AddMsg(typeMsgHouseDeposit, msg.Msg.Creator, + sdk.NewAttribute(attributeKeyDepositCreator, msg.Msg.Creator), + sdk.NewAttribute(attributeKeySubAccDepositor, subAccAddr), + sdk.NewAttribute(attributeKeyDepositMarketUIDParticipantIndex, + strings.Join([]string{msg.Msg.MarketUID, cast.ToString(participationIndex)}, "#"), + ), + ) + emitter.Emit() +} + +// Route returns the module's message router key. +func (*MsgHouseWithdraw) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgHouseWithdraw) Type() string { return typeHouseWithdraw } + +func (msg *MsgHouseWithdraw) GetSigners() []sdk.AccAddress { + return msg.Msg.GetSigners() +} + +// GetSignBytes returns sortJson form of its message +func (msg *MsgHouseWithdraw) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgHouseWithdraw) ValidateBasic() error { + if msg.Msg == nil { + return errors.ErrInvalidRequest.Wrap("msg is nil") + } + return msg.Msg.ValidateBasic() +} + +// EmitEvent emits the event for the message success. +func (msg *MsgHouseWithdraw) EmitEvent(ctx *sdk.Context, subAccAddr string, withdrawalID uint64) { + emitter := utils.NewEventEmitter(ctx, attributeValueCategory) + emitter.AddMsg(typeHouseWithdraw, msg.Msg.Creator, + sdk.NewAttribute(attributeKeyDepositCreator, msg.Msg.Creator), + sdk.NewAttribute(attributeKeySubAccDepositor, subAccAddr), + sdk.NewAttribute(attributeKeyWithdrawalID, cast.ToString(withdrawalID)), + sdk.NewAttribute(attributeKeyWithdrawMarketUIDParticipantIndex, + strings.Join([]string{msg.Msg.MarketUID, cast.ToString(msg.Msg.ParticipationIndex)}, "#"), + ), + ) + emitter.Emit() +} diff --git a/x/subaccount/types/messages_subaccount.go b/x/subaccount/types/messages_subaccount.go new file mode 100644 index 00000000..7097f884 --- /dev/null +++ b/x/subaccount/types/messages_subaccount.go @@ -0,0 +1,67 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" +) + +const ( + // typeMsgCreate is type of message MsgCreate + typeMsgCreate = "subacc_create" +) + +var _ sdk.Msg = &MsgCreate{} + +// Route returns the module's message router key. +func (*MsgCreate) Route() string { return RouterKey } + +// Type returns type of its message +func (*MsgCreate) Type() string { return typeMsgCreate } + +func (msg *MsgCreate) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +// GetSignBytes returns sortJson form of its message +func (msg *MsgCreate) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic performs a basic validation of the MsgCreate fields. +func (msg *MsgCreate) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) + } + + _, err = sdk.AccAddressFromBech32(msg.SubAccountOwner) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) + } + + for _, balanceUnlock := range msg.LockedBalances { + if err = balanceUnlock.Validate(); err != nil { + return sdkerrors.Wrapf(ErrInvalidLockedBalance, "%s", err) + } + } + + return nil +} + +// EmitEvent emits the event for the message success. +func (msg *MsgCreate) EmitEvent(ctx *sdk.Context, subAccAddr string) { + emitter := utils.NewEventEmitter(ctx, attributeValueCategory) + emitter.AddMsg(typeMsgCreate, msg.Creator, + sdk.NewAttribute(attributeKeySubAccOwner, msg.SubAccountOwner), + sdk.NewAttribute(attributeKeySubAcc, subAccAddr), + ) + emitter.Emit() +} diff --git a/x/subaccount/types/messages_subaccount_test.go b/x/subaccount/types/messages_subaccount_test.go new file mode 100644 index 00000000..918ab3de --- /dev/null +++ b/x/subaccount/types/messages_subaccount_test.go @@ -0,0 +1,76 @@ +package types_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/subaccount/types" +) + +func TestMsgCreateValidateBasic(t *testing.T) { + creatorAddr := sample.NativeAccAddress() + owner := sample.NativeAccAddress() + + someTime := uint64(time.Now().Unix()) + tests := []struct { + name string + msg types.MsgCreate + want error + }{ + { + name: "invalid creator", + msg: types.MsgCreate{ + Creator: "someInvalidAddress", + SubAccountOwner: owner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: someTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + want: errors.ErrInvalidAddress, + }, + { + name: "invalid sub account owner", + msg: types.MsgCreate{ + Creator: creatorAddr.String(), + SubAccountOwner: "someInvalidAddress", + LockedBalances: []types.LockedBalance{ + { + UnlockTS: someTime, + Amount: sdkmath.NewInt(123), + }, + }, + }, + want: errors.ErrInvalidAddress, + }, + { + name: "unlock time zero", + msg: types.MsgCreate{ + Creator: creatorAddr.String(), + SubAccountOwner: owner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTS: 0, + Amount: sdkmath.NewInt(123), + }, + }, + }, + want: types.ErrInvalidLockedBalance, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.msg.ValidateBasic() + require.ErrorContains(t, got, tt.want.Error()) + }) + } +} diff --git a/x/subaccount/types/params.go b/x/subaccount/types/params.go new file mode 100644 index 00000000..d7fda8a3 --- /dev/null +++ b/x/subaccount/types/params.go @@ -0,0 +1,34 @@ +package types + +import ( + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + yaml "gopkg.in/yaml.v2" +) + +// NewParams creates a new Params instance +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters. +func DefaultParams() Params { + return NewParams() +} + +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{} +} + +// String returns a human-readable string representation of the parameters. +func (p Params) String() string { + out, err := yaml.Marshal(p) + if err != nil { + panic(err) + } + return string(out) +} + +// ParamKeyTable for house module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} diff --git a/x/subaccount/types/params.pb.go b/x/subaccount/types/params.pb.go new file mode 100644 index 00000000..b1450d8d --- /dev/null +++ b/x/subaccount/types/params.pb.go @@ -0,0 +1,265 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/subaccount/params.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/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 + +// Params defines the parameters for the module. +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_13721530b9bd8795, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "sgenetwork.sge.subaccount.Params") +} + +func init() { proto.RegisterFile("sge/subaccount/params.proto", fileDescriptor_13721530b9bd8795) } + +var fileDescriptor_13721530b9bd8795 = []byte{ + // 161 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2e, 0x4e, 0x4f, 0xd5, + 0x2f, 0x2e, 0x4d, 0x4a, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0xd1, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, + 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x2c, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, + 0xcf, 0x2f, 0xca, 0xd6, 0x2b, 0x4e, 0x4f, 0xd5, 0x43, 0xa8, 0x93, 0x12, 0x49, 0xcf, 0x4f, 0xcf, + 0x07, 0xab, 0xd2, 0x07, 0xb1, 0x20, 0x1a, 0x94, 0xf8, 0xb8, 0xd8, 0x02, 0xc0, 0x06, 0x58, 0xb1, + 0xcc, 0x58, 0x20, 0xcf, 0xe0, 0xe4, 0x7e, 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, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xc5, 0xe9, 0xa9, + 0xba, 0x50, 0x6b, 0x40, 0x6c, 0xfd, 0x0a, 0x64, 0x07, 0x95, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, + 0x81, 0xcd, 0x37, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x12, 0x4a, 0x30, 0x1c, 0xaf, 0x00, 0x00, + 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowParams + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/subaccount/types/query.pb.go b/x/subaccount/types/query.pb.go new file mode 100644 index 00000000..4a74937f --- /dev/null +++ b/x/subaccount/types/query.pb.go @@ -0,0 +1,1046 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/subaccount/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// QueryParamsRequest is the request type for the Query/Params RPC method +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_e8576ea34550c199, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method +type QueryParamsResponse struct { + Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e8576ea34550c199, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() *Params { + if m != nil { + return m.Params + } + return nil +} + +// QuerySubaccountRequest is the request type for the Query/Subaccount RPC +type QuerySubaccountRequest struct { + SubaccountOwner string `protobuf:"bytes,1,opt,name=subaccount_owner,json=subaccountOwner,proto3" json:"subaccount_owner,omitempty"` +} + +func (m *QuerySubaccountRequest) Reset() { *m = QuerySubaccountRequest{} } +func (m *QuerySubaccountRequest) String() string { return proto.CompactTextString(m) } +func (*QuerySubaccountRequest) ProtoMessage() {} +func (*QuerySubaccountRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_e8576ea34550c199, []int{2} +} +func (m *QuerySubaccountRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySubaccountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySubaccountRequest.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 *QuerySubaccountRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySubaccountRequest.Merge(m, src) +} +func (m *QuerySubaccountRequest) XXX_Size() int { + return m.Size() +} +func (m *QuerySubaccountRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySubaccountRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySubaccountRequest proto.InternalMessageInfo + +func (m *QuerySubaccountRequest) GetSubaccountOwner() string { + if m != nil { + return m.SubaccountOwner + } + return "" +} + +// QuerySubaccountResponse is the response type for the Query/Subaccount RPC +type QuerySubaccountResponse struct { + SubaccountAddress string `protobuf:"bytes,1,opt,name=subaccount_address,json=subaccountAddress,proto3" json:"subaccount_address,omitempty"` + Balance Balance `protobuf:"bytes,2,opt,name=balance,proto3" json:"balance"` + LockedBalance []LockedBalance `protobuf:"bytes,3,rep,name=locked_balance,json=lockedBalance,proto3" json:"locked_balance"` +} + +func (m *QuerySubaccountResponse) Reset() { *m = QuerySubaccountResponse{} } +func (m *QuerySubaccountResponse) String() string { return proto.CompactTextString(m) } +func (*QuerySubaccountResponse) ProtoMessage() {} +func (*QuerySubaccountResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e8576ea34550c199, []int{3} +} +func (m *QuerySubaccountResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySubaccountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySubaccountResponse.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 *QuerySubaccountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySubaccountResponse.Merge(m, src) +} +func (m *QuerySubaccountResponse) XXX_Size() int { + return m.Size() +} +func (m *QuerySubaccountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySubaccountResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySubaccountResponse proto.InternalMessageInfo + +func (m *QuerySubaccountResponse) GetSubaccountAddress() string { + if m != nil { + return m.SubaccountAddress + } + return "" +} + +func (m *QuerySubaccountResponse) GetBalance() Balance { + if m != nil { + return m.Balance + } + return Balance{} +} + +func (m *QuerySubaccountResponse) GetLockedBalance() []LockedBalance { + if m != nil { + return m.LockedBalance + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "sgenetwork.sge.subaccount.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "sgenetwork.sge.subaccount.QueryParamsResponse") + proto.RegisterType((*QuerySubaccountRequest)(nil), "sgenetwork.sge.subaccount.QuerySubaccountRequest") + proto.RegisterType((*QuerySubaccountResponse)(nil), "sgenetwork.sge.subaccount.QuerySubaccountResponse") +} + +func init() { proto.RegisterFile("sge/subaccount/query.proto", fileDescriptor_e8576ea34550c199) } + +var fileDescriptor_e8576ea34550c199 = []byte{ + // 433 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x4f, 0xcf, 0xd2, 0x40, + 0x10, 0xc6, 0xbb, 0xa0, 0x18, 0x97, 0xf8, 0x6f, 0x25, 0x88, 0x95, 0x54, 0xec, 0x09, 0x0f, 0x6d, + 0x63, 0x3d, 0x79, 0xb4, 0x1e, 0xbc, 0x98, 0x88, 0x18, 0x2f, 0x5e, 0xc8, 0xb6, 0x6c, 0x56, 0x42, + 0xd9, 0x2d, 0xdd, 0x6d, 0x90, 0xab, 0x17, 0xaf, 0x26, 0x1e, 0xfc, 0x10, 0x7e, 0x11, 0x8e, 0x24, + 0x5e, 0x3c, 0x19, 0x43, 0xfd, 0x20, 0xa6, 0xdb, 0xc5, 0x02, 0xf2, 0xf2, 0xbe, 0xef, 0x6d, 0x33, + 0x33, 0xcf, 0x6f, 0xe6, 0x99, 0x4e, 0xa1, 0x29, 0x28, 0xf1, 0x44, 0x16, 0xe2, 0x28, 0xe2, 0x19, + 0x93, 0xde, 0x3c, 0x23, 0xe9, 0xd2, 0x4d, 0x52, 0x2e, 0x39, 0xba, 0x2f, 0x28, 0x61, 0x44, 0x2e, + 0x78, 0x3a, 0x75, 0x05, 0x25, 0x6e, 0x55, 0x66, 0xb6, 0x28, 0xa7, 0x5c, 0x55, 0x79, 0xc5, 0xab, + 0x14, 0x98, 0x5d, 0xca, 0x39, 0x8d, 0x89, 0x87, 0x93, 0x89, 0x87, 0x19, 0xe3, 0x12, 0xcb, 0x09, + 0x67, 0x62, 0x9b, 0x3d, 0x68, 0x15, 0xe2, 0x18, 0xb3, 0x88, 0xe8, 0xec, 0x83, 0x83, 0x6c, 0x82, + 0x53, 0x3c, 0xd3, 0x52, 0xbb, 0x05, 0xd1, 0x9b, 0x62, 0xb0, 0x81, 0x0a, 0x0e, 0xc9, 0x3c, 0x23, + 0x42, 0xda, 0x03, 0x78, 0x77, 0x2f, 0x2a, 0x12, 0xce, 0x04, 0x41, 0xcf, 0x60, 0xa3, 0x14, 0x77, + 0x40, 0x0f, 0xf4, 0x9b, 0xfe, 0x23, 0xf7, 0x4c, 0x1f, 0xae, 0x96, 0x6a, 0x81, 0xfd, 0x02, 0xb6, + 0x15, 0xf1, 0xed, 0xbf, 0x0a, 0xdd, 0x0b, 0x3d, 0x86, 0xb7, 0x2b, 0xd9, 0x88, 0x2f, 0x18, 0x49, + 0x15, 0xfe, 0xfa, 0xf0, 0x56, 0x15, 0x7f, 0x5d, 0x84, 0xed, 0x1c, 0xc0, 0x7b, 0xff, 0x51, 0xf4, + 0x6c, 0x0e, 0x44, 0x3b, 0x18, 0x3c, 0x1e, 0xa7, 0x44, 0x08, 0x0d, 0xba, 0x53, 0x65, 0x9e, 0x97, + 0x09, 0x14, 0xc0, 0x6b, 0x7a, 0x4b, 0x9d, 0x9a, 0xf2, 0x62, 0x9f, 0xf0, 0x12, 0x94, 0x95, 0xc1, + 0x95, 0xd5, 0xaf, 0x87, 0xc6, 0x70, 0x2b, 0x44, 0xef, 0xe0, 0xcd, 0x98, 0x47, 0x53, 0x32, 0x1e, + 0x6d, 0x51, 0xf5, 0x5e, 0xbd, 0xdf, 0xf4, 0xfb, 0x27, 0x50, 0xaf, 0x94, 0x60, 0x1f, 0x78, 0x23, + 0xde, 0x0d, 0xfa, 0xdf, 0x6b, 0xf0, 0xaa, 0x72, 0x89, 0xbe, 0x01, 0x08, 0x2b, 0xab, 0xe8, 0xc9, + 0x09, 0xee, 0xf1, 0xe5, 0x9a, 0xfe, 0x65, 0x24, 0xe5, 0x26, 0x6d, 0xfb, 0xd3, 0x8f, 0x3f, 0x5f, + 0x6b, 0x5d, 0x64, 0x7a, 0x07, 0x87, 0x53, 0x3d, 0xd1, 0x67, 0x00, 0x1b, 0xe5, 0x17, 0x46, 0xce, + 0x79, 0x2d, 0xf6, 0x4e, 0xcb, 0x74, 0x2f, 0x5a, 0xae, 0xa7, 0xb1, 0xd4, 0x34, 0x1d, 0xd4, 0xf6, + 0x8e, 0x9e, 0x71, 0xf0, 0x72, 0xb5, 0xb1, 0xc0, 0x7a, 0x63, 0x81, 0xdf, 0x1b, 0x0b, 0x7c, 0xc9, + 0x2d, 0x63, 0x9d, 0x5b, 0xc6, 0xcf, 0xdc, 0x32, 0xde, 0x3b, 0x74, 0x22, 0x3f, 0x64, 0xa1, 0x1b, + 0xf1, 0x59, 0xa1, 0x75, 0x74, 0x53, 0xc5, 0xf9, 0xb8, 0x4b, 0x92, 0xcb, 0x84, 0x88, 0xb0, 0xa1, + 0x7e, 0x88, 0xa7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x16, 0x0b, 0x3d, 0x2d, 0xb8, 0x03, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Subaccount fetches a subaccount given the owner. + Subaccount(ctx context.Context, in *QuerySubaccountRequest, opts ...grpc.CallOption) (*QuerySubaccountResponse, error) + // Params returns the subaccount module parameters. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Subaccount(ctx context.Context, in *QuerySubaccountRequest, opts ...grpc.CallOption) (*QuerySubaccountResponse, error) { + out := new(QuerySubaccountResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Query/Subaccount", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Subaccount fetches a subaccount given the owner. + Subaccount(context.Context, *QuerySubaccountRequest) (*QuerySubaccountResponse, error) + // Params returns the subaccount module parameters. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Subaccount(ctx context.Context, req *QuerySubaccountRequest) (*QuerySubaccountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Subaccount not implemented") +} +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Subaccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QuerySubaccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Subaccount(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Query/Subaccount", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Subaccount(ctx, req.(*QuerySubaccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "sgenetwork.sge.subaccount.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Subaccount", + Handler: _Query_Subaccount_Handler, + }, + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "sge/subaccount/query.proto", +} + +func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Params != nil { + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QuerySubaccountRequest) 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 *QuerySubaccountRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySubaccountRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SubaccountOwner) > 0 { + i -= len(m.SubaccountOwner) + copy(dAtA[i:], m.SubaccountOwner) + i = encodeVarintQuery(dAtA, i, uint64(len(m.SubaccountOwner))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QuerySubaccountResponse) 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 *QuerySubaccountResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySubaccountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.LockedBalance) > 0 { + for iNdEx := len(m.LockedBalance) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.LockedBalance[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + { + size, err := m.Balance.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.SubaccountAddress) > 0 { + i -= len(m.SubaccountAddress) + copy(dAtA[i:], m.SubaccountAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.SubaccountAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Params != nil { + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QuerySubaccountRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SubaccountOwner) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QuerySubaccountResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SubaccountAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = m.Balance.Size() + n += 1 + l + sovQuery(uint64(l)) + if len(m.LockedBalance) > 0 { + for _, e := range m.LockedBalance { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) 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 ErrIntOverflowQuery + } + 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: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) 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 ErrIntOverflowQuery + } + 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: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Params == nil { + m.Params = &Params{} + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySubaccountRequest) 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 ErrIntOverflowQuery + } + 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: QuerySubaccountRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySubaccountRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubaccountOwner", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubaccountOwner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySubaccountResponse) 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 ErrIntOverflowQuery + } + 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: QuerySubaccountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySubaccountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubaccountAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubaccountAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Balance.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LockedBalance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LockedBalance = append(m.LockedBalance, LockedBalance{}) + if err := m.LockedBalance[len(m.LockedBalance)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/subaccount/types/query.pb.gw.go b/x/subaccount/types/query.pb.gw.go new file mode 100644 index 00000000..bc73c33f --- /dev/null +++ b/x/subaccount/types/query.pb.gw.go @@ -0,0 +1,236 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: sge/subaccount/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +var ( + filter_Query_Subaccount_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Subaccount_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySubaccountRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Subaccount_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Subaccount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Subaccount_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySubaccountRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Subaccount_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Subaccount(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Subaccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Subaccount_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Subaccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Subaccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Subaccount_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Subaccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Subaccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 1}, []string{"sge", "subaccount"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "subaccount", "params"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Subaccount_0 = runtime.ForwardResponseMessage + + forward_Query_Params_0 = runtime.ForwardResponseMessage +) diff --git a/x/subaccount/types/tx.pb.go b/x/subaccount/types/tx.pb.go new file mode 100644 index 00000000..42e4898d --- /dev/null +++ b/x/subaccount/types/tx.pb.go @@ -0,0 +1,2650 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/subaccount/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + types "github.com/sge-network/sge/x/bet/types" + types1 "github.com/sge-network/sge/x/house/types" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// MsgCreate defines the Msg/Create request type. +type MsgCreate struct { + // creator is the msg signer. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + // sub_account_owner is the owner of the subaccount. + SubAccountOwner string `protobuf:"bytes,2,opt,name=sub_account_owner,json=subAccountOwner,proto3" json:"sub_account_owner,omitempty"` + // locked_balances is the list of balance locks. + LockedBalances []LockedBalance `protobuf:"bytes,3,rep,name=locked_balances,json=lockedBalances,proto3" json:"locked_balances"` +} + +func (m *MsgCreate) Reset() { *m = MsgCreate{} } +func (m *MsgCreate) String() string { return proto.CompactTextString(m) } +func (*MsgCreate) ProtoMessage() {} +func (*MsgCreate) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{0} +} +func (m *MsgCreate) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreate) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreate.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 *MsgCreate) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreate.Merge(m, src) +} +func (m *MsgCreate) XXX_Size() int { + return m.Size() +} +func (m *MsgCreate) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreate.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreate proto.InternalMessageInfo + +func (m *MsgCreate) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgCreate) GetSubAccountOwner() string { + if m != nil { + return m.SubAccountOwner + } + return "" +} + +func (m *MsgCreate) GetLockedBalances() []LockedBalance { + if m != nil { + return m.LockedBalances + } + return nil +} + +// MsgCreateAccountResponse defines the Msg/CreateAccount response type. +type MsgCreateResponse struct { +} + +func (m *MsgCreateResponse) Reset() { *m = MsgCreateResponse{} } +func (m *MsgCreateResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateResponse) ProtoMessage() {} +func (*MsgCreateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{1} +} +func (m *MsgCreateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateResponse.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 *MsgCreateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateResponse.Merge(m, src) +} +func (m *MsgCreateResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateResponse proto.InternalMessageInfo + +// MsgTopUp defines the Msg/TopUp request type. +type MsgTopUp struct { + // creator is the msg signer. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + // sub_account is the subaccount address. + SubAccount string `protobuf:"bytes,2,opt,name=sub_account,json=subAccount,proto3" json:"sub_account,omitempty"` + // locked_balances is the list of balance locks. + LockedBalances []LockedBalance `protobuf:"bytes,3,rep,name=locked_balances,json=lockedBalances,proto3" json:"locked_balances"` +} + +func (m *MsgTopUp) Reset() { *m = MsgTopUp{} } +func (m *MsgTopUp) String() string { return proto.CompactTextString(m) } +func (*MsgTopUp) ProtoMessage() {} +func (*MsgTopUp) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{2} +} +func (m *MsgTopUp) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgTopUp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgTopUp.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 *MsgTopUp) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgTopUp.Merge(m, src) +} +func (m *MsgTopUp) XXX_Size() int { + return m.Size() +} +func (m *MsgTopUp) XXX_DiscardUnknown() { + xxx_messageInfo_MsgTopUp.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgTopUp proto.InternalMessageInfo + +func (m *MsgTopUp) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgTopUp) GetSubAccount() string { + if m != nil { + return m.SubAccount + } + return "" +} + +func (m *MsgTopUp) GetLockedBalances() []LockedBalance { + if m != nil { + return m.LockedBalances + } + return nil +} + +// MsgTopUpResponse defines the Msg/TopUp response type. +type MsgTopUpResponse struct { +} + +func (m *MsgTopUpResponse) Reset() { *m = MsgTopUpResponse{} } +func (m *MsgTopUpResponse) String() string { return proto.CompactTextString(m) } +func (*MsgTopUpResponse) ProtoMessage() {} +func (*MsgTopUpResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{3} +} +func (m *MsgTopUpResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgTopUpResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgTopUpResponse.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 *MsgTopUpResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgTopUpResponse.Merge(m, src) +} +func (m *MsgTopUpResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgTopUpResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgTopUpResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgTopUpResponse proto.InternalMessageInfo + +// MsgWithdrawUnlockedBalances defines the Msg/WithdrawUnlockedBalances request +// type. +type MsgWithdrawUnlockedBalances struct { + // creator is the subaccount owner. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` +} + +func (m *MsgWithdrawUnlockedBalances) Reset() { *m = MsgWithdrawUnlockedBalances{} } +func (m *MsgWithdrawUnlockedBalances) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawUnlockedBalances) ProtoMessage() {} +func (*MsgWithdrawUnlockedBalances) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{4} +} +func (m *MsgWithdrawUnlockedBalances) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawUnlockedBalances) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawUnlockedBalances.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 *MsgWithdrawUnlockedBalances) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawUnlockedBalances.Merge(m, src) +} +func (m *MsgWithdrawUnlockedBalances) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawUnlockedBalances) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawUnlockedBalances.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawUnlockedBalances proto.InternalMessageInfo + +func (m *MsgWithdrawUnlockedBalances) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +// MsgWithdrawUnlockedBalancesResponse defines the Msg/WithdrawUnlockedBalances +// response type. +type MsgWithdrawUnlockedBalancesResponse struct { +} + +func (m *MsgWithdrawUnlockedBalancesResponse) Reset() { *m = MsgWithdrawUnlockedBalancesResponse{} } +func (m *MsgWithdrawUnlockedBalancesResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawUnlockedBalancesResponse) ProtoMessage() {} +func (*MsgWithdrawUnlockedBalancesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{5} +} +func (m *MsgWithdrawUnlockedBalancesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawUnlockedBalancesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawUnlockedBalancesResponse.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 *MsgWithdrawUnlockedBalancesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawUnlockedBalancesResponse.Merge(m, src) +} +func (m *MsgWithdrawUnlockedBalancesResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawUnlockedBalancesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawUnlockedBalancesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawUnlockedBalancesResponse proto.InternalMessageInfo + +// MsgPlaceBet wraps the MsgPlaceBet message. We need it in order not to have +// double interface registration conflicts. +type MsgWager struct { + Msg *types.MsgWager `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgWager) Reset() { *m = MsgWager{} } +func (m *MsgWager) String() string { return proto.CompactTextString(m) } +func (*MsgWager) ProtoMessage() {} +func (*MsgWager) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{6} +} +func (m *MsgWager) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWager) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWager.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 *MsgWager) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWager.Merge(m, src) +} +func (m *MsgWager) XXX_Size() int { + return m.Size() +} +func (m *MsgWager) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWager.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWager proto.InternalMessageInfo + +func (m *MsgWager) GetMsg() *types.MsgWager { + if m != nil { + return m.Msg + } + return nil +} + +// MsgBetResponse wraps the MsgPlaceBetResponse message. We need it in order not +// to have double interface registration conflicts. +type MsgWagerResponse struct { + Response *types.MsgWagerResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` +} + +func (m *MsgWagerResponse) Reset() { *m = MsgWagerResponse{} } +func (m *MsgWagerResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWagerResponse) ProtoMessage() {} +func (*MsgWagerResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{7} +} +func (m *MsgWagerResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWagerResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWagerResponse.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 *MsgWagerResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWagerResponse.Merge(m, src) +} +func (m *MsgWagerResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWagerResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWagerResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWagerResponse proto.InternalMessageInfo + +func (m *MsgWagerResponse) GetResponse() *types.MsgWagerResponse { + if m != nil { + return m.Response + } + return nil +} + +// MsgHouseDeposit wraps the MsgHouseDeposit message. We need it in order not to +// have double interface registration conflicts. +type MsgHouseDeposit struct { + Msg *types1.MsgDeposit `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgHouseDeposit) Reset() { *m = MsgHouseDeposit{} } +func (m *MsgHouseDeposit) String() string { return proto.CompactTextString(m) } +func (*MsgHouseDeposit) ProtoMessage() {} +func (*MsgHouseDeposit) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{8} +} +func (m *MsgHouseDeposit) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgHouseDeposit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgHouseDeposit.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 *MsgHouseDeposit) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgHouseDeposit.Merge(m, src) +} +func (m *MsgHouseDeposit) XXX_Size() int { + return m.Size() +} +func (m *MsgHouseDeposit) XXX_DiscardUnknown() { + xxx_messageInfo_MsgHouseDeposit.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgHouseDeposit proto.InternalMessageInfo + +func (m *MsgHouseDeposit) GetMsg() *types1.MsgDeposit { + if m != nil { + return m.Msg + } + return nil +} + +// MsgHouseDepositResponse wraps the MsgHouseDepositResponse message. We need it +// in order not to have double interface registration conflicts. +type MsgHouseDepositResponse struct { + Response *types1.MsgDepositResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` +} + +func (m *MsgHouseDepositResponse) Reset() { *m = MsgHouseDepositResponse{} } +func (m *MsgHouseDepositResponse) String() string { return proto.CompactTextString(m) } +func (*MsgHouseDepositResponse) ProtoMessage() {} +func (*MsgHouseDepositResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{9} +} +func (m *MsgHouseDepositResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgHouseDepositResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgHouseDepositResponse.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 *MsgHouseDepositResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgHouseDepositResponse.Merge(m, src) +} +func (m *MsgHouseDepositResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgHouseDepositResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgHouseDepositResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgHouseDepositResponse proto.InternalMessageInfo + +func (m *MsgHouseDepositResponse) GetResponse() *types1.MsgDepositResponse { + if m != nil { + return m.Response + } + return nil +} + +// MsgHouseWithdraw wraps the MsgHouseWithdraw message. We need it in order not +// to have double interface registration conflicts. +type MsgHouseWithdraw struct { + Msg *types1.MsgWithdraw `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` +} + +func (m *MsgHouseWithdraw) Reset() { *m = MsgHouseWithdraw{} } +func (m *MsgHouseWithdraw) String() string { return proto.CompactTextString(m) } +func (*MsgHouseWithdraw) ProtoMessage() {} +func (*MsgHouseWithdraw) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{10} +} +func (m *MsgHouseWithdraw) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgHouseWithdraw) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgHouseWithdraw.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 *MsgHouseWithdraw) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgHouseWithdraw.Merge(m, src) +} +func (m *MsgHouseWithdraw) XXX_Size() int { + return m.Size() +} +func (m *MsgHouseWithdraw) XXX_DiscardUnknown() { + xxx_messageInfo_MsgHouseWithdraw.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgHouseWithdraw proto.InternalMessageInfo + +func (m *MsgHouseWithdraw) GetMsg() *types1.MsgWithdraw { + if m != nil { + return m.Msg + } + return nil +} + +// MsgHouseWithdrawResponse wraps the MsgHouseWithdrawResponse message. We need +// it in order not to have double interface registration conflicts. +type MsgHouseWithdrawResponse struct { + Response *types1.MsgWithdrawResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` +} + +func (m *MsgHouseWithdrawResponse) Reset() { *m = MsgHouseWithdrawResponse{} } +func (m *MsgHouseWithdrawResponse) String() string { return proto.CompactTextString(m) } +func (*MsgHouseWithdrawResponse) ProtoMessage() {} +func (*MsgHouseWithdrawResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e042e836d366badb, []int{11} +} +func (m *MsgHouseWithdrawResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgHouseWithdrawResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgHouseWithdrawResponse.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 *MsgHouseWithdrawResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgHouseWithdrawResponse.Merge(m, src) +} +func (m *MsgHouseWithdrawResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgHouseWithdrawResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgHouseWithdrawResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgHouseWithdrawResponse proto.InternalMessageInfo + +func (m *MsgHouseWithdrawResponse) GetResponse() *types1.MsgWithdrawResponse { + if m != nil { + return m.Response + } + return nil +} + +func init() { + proto.RegisterType((*MsgCreate)(nil), "sgenetwork.sge.subaccount.MsgCreate") + proto.RegisterType((*MsgCreateResponse)(nil), "sgenetwork.sge.subaccount.MsgCreateResponse") + proto.RegisterType((*MsgTopUp)(nil), "sgenetwork.sge.subaccount.MsgTopUp") + proto.RegisterType((*MsgTopUpResponse)(nil), "sgenetwork.sge.subaccount.MsgTopUpResponse") + proto.RegisterType((*MsgWithdrawUnlockedBalances)(nil), "sgenetwork.sge.subaccount.MsgWithdrawUnlockedBalances") + proto.RegisterType((*MsgWithdrawUnlockedBalancesResponse)(nil), "sgenetwork.sge.subaccount.MsgWithdrawUnlockedBalancesResponse") + proto.RegisterType((*MsgWager)(nil), "sgenetwork.sge.subaccount.MsgWager") + proto.RegisterType((*MsgWagerResponse)(nil), "sgenetwork.sge.subaccount.MsgWagerResponse") + proto.RegisterType((*MsgHouseDeposit)(nil), "sgenetwork.sge.subaccount.MsgHouseDeposit") + proto.RegisterType((*MsgHouseDepositResponse)(nil), "sgenetwork.sge.subaccount.MsgHouseDepositResponse") + proto.RegisterType((*MsgHouseWithdraw)(nil), "sgenetwork.sge.subaccount.MsgHouseWithdraw") + proto.RegisterType((*MsgHouseWithdrawResponse)(nil), "sgenetwork.sge.subaccount.MsgHouseWithdrawResponse") +} + +func init() { proto.RegisterFile("sge/subaccount/tx.proto", fileDescriptor_e042e836d366badb) } + +var fileDescriptor_e042e836d366badb = []byte{ + // 594 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0x5f, 0x6b, 0xd3, 0x50, + 0x18, 0xc6, 0x1b, 0xeb, 0xe6, 0xf6, 0x56, 0xed, 0x76, 0x14, 0x16, 0xe3, 0xc8, 0x6a, 0x36, 0xa1, + 0x6e, 0x2e, 0x85, 0x16, 0x14, 0xbc, 0x10, 0xad, 0x1b, 0xf3, 0xc2, 0x22, 0x94, 0x8d, 0xa2, 0x08, + 0x25, 0xc9, 0x0e, 0xa7, 0x65, 0x5d, 0x4e, 0xcc, 0x9b, 0xd0, 0xf9, 0x2d, 0xd4, 0x0f, 0xe0, 0x07, + 0xf0, 0x93, 0xec, 0x72, 0x97, 0x5e, 0x89, 0xb4, 0x5f, 0x44, 0x72, 0xf2, 0xa7, 0x69, 0x4b, 0xd3, + 0x2a, 0xec, 0xee, 0xed, 0xdb, 0xe7, 0x79, 0xce, 0xef, 0x0d, 0xe7, 0xe5, 0xc0, 0x06, 0x32, 0x5a, + 0x41, 0xdf, 0x34, 0x2c, 0x8b, 0xfb, 0xb6, 0x57, 0xf1, 0x2e, 0x74, 0xc7, 0xe5, 0x1e, 0x27, 0x0f, + 0x90, 0x51, 0x9b, 0x7a, 0x7d, 0xee, 0x9e, 0xe9, 0xc8, 0xa8, 0x3e, 0xd2, 0x28, 0x9b, 0x13, 0x1e, + 0xd3, 0xe8, 0x19, 0xb6, 0x45, 0x43, 0xa3, 0xb2, 0x16, 0xfc, 0x6b, 0xd2, 0x51, 0x94, 0x42, 0x82, + 0x4e, 0x87, 0xfb, 0x48, 0x47, 0xbd, 0xfb, 0x8c, 0x33, 0x2e, 0xca, 0x4a, 0x50, 0x85, 0x5d, 0xed, + 0xa7, 0x04, 0xab, 0x0d, 0x64, 0x6f, 0x5c, 0x6a, 0x78, 0x94, 0xc8, 0x70, 0xcb, 0x0a, 0x2a, 0xee, + 0xca, 0x52, 0x49, 0x2a, 0xaf, 0x36, 0xe3, 0x9f, 0x64, 0x17, 0xd6, 0xd1, 0x37, 0xdb, 0x11, 0x40, + 0x9b, 0xf7, 0x6d, 0xea, 0xca, 0x37, 0x84, 0xa6, 0x88, 0xbe, 0xf9, 0x3a, 0xec, 0xbf, 0x0f, 0xda, + 0xa4, 0x05, 0xc5, 0x1e, 0xb7, 0xce, 0xe8, 0x69, 0x3b, 0xe2, 0x44, 0x39, 0x5f, 0xca, 0x97, 0x0b, + 0xd5, 0xb2, 0x3e, 0x73, 0x44, 0xfd, 0x9d, 0x70, 0xd4, 0x43, 0x43, 0xfd, 0xe6, 0xe5, 0xef, 0xad, + 0x5c, 0xf3, 0x6e, 0x2f, 0xdd, 0x44, 0xed, 0x1e, 0xac, 0x27, 0xac, 0x4d, 0x8a, 0x0e, 0xb7, 0x91, + 0x6a, 0x3f, 0x24, 0x58, 0x69, 0x20, 0x3b, 0xe6, 0xce, 0x89, 0x93, 0x31, 0xc0, 0x16, 0x14, 0x52, + 0x03, 0x44, 0xe8, 0x30, 0x42, 0xbf, 0x3e, 0x6a, 0x02, 0x6b, 0x31, 0x5f, 0x02, 0xfd, 0x1c, 0x1e, + 0x36, 0x90, 0xb5, 0xba, 0x5e, 0xe7, 0xd4, 0x35, 0xfa, 0x27, 0xf6, 0xb8, 0x65, 0xf6, 0x18, 0xda, + 0x63, 0xd8, 0xce, 0x30, 0x26, 0xf9, 0x2f, 0xc4, 0x37, 0x69, 0x19, 0x8c, 0xba, 0x44, 0x87, 0xfc, + 0x39, 0x32, 0x11, 0x54, 0xa8, 0x6e, 0x4e, 0x0e, 0x63, 0x52, 0x4f, 0x8f, 0xa5, 0xcd, 0x40, 0xa8, + 0x1d, 0x0b, 0xde, 0xb0, 0x11, 0xe5, 0x91, 0x57, 0xb0, 0xe2, 0x46, 0x75, 0x14, 0xb4, 0x93, 0x19, + 0x14, 0x69, 0x9b, 0x89, 0x4b, 0x3b, 0x84, 0x62, 0x03, 0xd9, 0xdb, 0xe0, 0x4e, 0x1e, 0x50, 0x87, + 0x63, 0xd7, 0x23, 0xd5, 0x34, 0x58, 0x69, 0x32, 0x4f, 0x5c, 0xdf, 0x20, 0x31, 0x92, 0x87, 0x70, + 0x6d, 0xd8, 0x98, 0x88, 0x49, 0x18, 0x0f, 0xa6, 0x18, 0xcb, 0x73, 0x33, 0xa7, 0x39, 0x8f, 0xc4, + 0xf4, 0xe2, 0x80, 0xf8, 0x2b, 0x93, 0x5a, 0x1a, 0xf4, 0xd1, 0xcc, 0xd0, 0x58, 0x1f, 0x92, 0x1a, + 0x20, 0x4f, 0x06, 0x25, 0xa8, 0x87, 0x53, 0xa8, 0x4f, 0xe6, 0xa7, 0x4e, 0xb1, 0x56, 0xbf, 0x2d, + 0x41, 0xbe, 0x81, 0x8c, 0x7c, 0x82, 0xe5, 0x68, 0x81, 0x77, 0x32, 0xee, 0x6a, 0xb2, 0x3a, 0xca, + 0xd3, 0x45, 0x54, 0x09, 0xec, 0x07, 0x58, 0x0a, 0x97, 0x6b, 0x3b, 0xdb, 0x26, 0x44, 0xca, 0xde, + 0x02, 0xa2, 0x24, 0xfa, 0xbb, 0x04, 0xf2, 0xcc, 0x25, 0x78, 0x96, 0x9d, 0x34, 0xcb, 0xa7, 0xbc, + 0xfc, 0x3f, 0x5f, 0x7a, 0xde, 0x70, 0x71, 0xe6, 0xcc, 0x2b, 0x44, 0xf3, 0xe6, 0x1d, 0x5f, 0x23, + 0x1b, 0x6e, 0x8f, 0x6d, 0xc0, 0x6e, 0xb6, 0x39, 0xad, 0x55, 0xaa, 0x8b, 0x6b, 0x93, 0xf3, 0x3e, + 0xc3, 0x9d, 0xf1, 0x9b, 0xbc, 0xb7, 0x40, 0x48, 0x2c, 0x56, 0x6a, 0xff, 0x20, 0x8e, 0x8f, 0xac, + 0x1f, 0x5d, 0x0e, 0x54, 0xe9, 0x6a, 0xa0, 0x4a, 0x7f, 0x06, 0xaa, 0xf4, 0x75, 0xa8, 0xe6, 0xae, + 0x86, 0x6a, 0xee, 0xd7, 0x50, 0xcd, 0x7d, 0xdc, 0x67, 0x5d, 0xaf, 0xe3, 0x9b, 0xba, 0xc5, 0xcf, + 0x2b, 0xc8, 0xe8, 0x7e, 0x94, 0x1c, 0xd4, 0x95, 0x8b, 0xb1, 0x17, 0xf1, 0x8b, 0x43, 0xd1, 0x5c, + 0x16, 0x0f, 0x54, 0xed, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x02, 0x7f, 0x7f, 0x6c, 0x30, 0x07, + 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // Create defines a method for creating a subaccount. + Create(ctx context.Context, in *MsgCreate, opts ...grpc.CallOption) (*MsgCreateResponse, error) + // TopUp defines a method for topping up a subaccount. + TopUp(ctx context.Context, in *MsgTopUp, opts ...grpc.CallOption) (*MsgTopUpResponse, error) + // WithdrawUnlockedBalances defines a method for withdrawing unlocked + // balances. + WithdrawUnlockedBalances(ctx context.Context, in *MsgWithdrawUnlockedBalances, opts ...grpc.CallOption) (*MsgWithdrawUnlockedBalancesResponse, error) + // PlaceBet defines a method for placing a bet using a subaccount. + Wager(ctx context.Context, in *MsgWager, opts ...grpc.CallOption) (*MsgWagerResponse, error) + // HouseDeposit defines a method for depositing funds to provide liquidity to + // a market. + HouseDeposit(ctx context.Context, in *MsgHouseDeposit, opts ...grpc.CallOption) (*MsgHouseDepositResponse, error) + // HouseWithdraw defines a method for withdrawing funds from a market. + HouseWithdraw(ctx context.Context, in *MsgHouseWithdraw, opts ...grpc.CallOption) (*MsgHouseWithdrawResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) Create(ctx context.Context, in *MsgCreate, opts ...grpc.CallOption) (*MsgCreateResponse, error) { + out := new(MsgCreateResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) TopUp(ctx context.Context, in *MsgTopUp, opts ...grpc.CallOption) (*MsgTopUpResponse, error) { + out := new(MsgTopUpResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/TopUp", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) WithdrawUnlockedBalances(ctx context.Context, in *MsgWithdrawUnlockedBalances, opts ...grpc.CallOption) (*MsgWithdrawUnlockedBalancesResponse, error) { + out := new(MsgWithdrawUnlockedBalancesResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/WithdrawUnlockedBalances", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Wager(ctx context.Context, in *MsgWager, opts ...grpc.CallOption) (*MsgWagerResponse, error) { + out := new(MsgWagerResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/Wager", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) HouseDeposit(ctx context.Context, in *MsgHouseDeposit, opts ...grpc.CallOption) (*MsgHouseDepositResponse, error) { + out := new(MsgHouseDepositResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/HouseDeposit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) HouseWithdraw(ctx context.Context, in *MsgHouseWithdraw, opts ...grpc.CallOption) (*MsgHouseWithdrawResponse, error) { + out := new(MsgHouseWithdrawResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Msg/HouseWithdraw", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // Create defines a method for creating a subaccount. + Create(context.Context, *MsgCreate) (*MsgCreateResponse, error) + // TopUp defines a method for topping up a subaccount. + TopUp(context.Context, *MsgTopUp) (*MsgTopUpResponse, error) + // WithdrawUnlockedBalances defines a method for withdrawing unlocked + // balances. + WithdrawUnlockedBalances(context.Context, *MsgWithdrawUnlockedBalances) (*MsgWithdrawUnlockedBalancesResponse, error) + // PlaceBet defines a method for placing a bet using a subaccount. + Wager(context.Context, *MsgWager) (*MsgWagerResponse, error) + // HouseDeposit defines a method for depositing funds to provide liquidity to + // a market. + HouseDeposit(context.Context, *MsgHouseDeposit) (*MsgHouseDepositResponse, error) + // HouseWithdraw defines a method for withdrawing funds from a market. + HouseWithdraw(context.Context, *MsgHouseWithdraw) (*MsgHouseWithdrawResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) Create(ctx context.Context, req *MsgCreate) (*MsgCreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedMsgServer) TopUp(ctx context.Context, req *MsgTopUp) (*MsgTopUpResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TopUp not implemented") +} +func (*UnimplementedMsgServer) WithdrawUnlockedBalances(ctx context.Context, req *MsgWithdrawUnlockedBalances) (*MsgWithdrawUnlockedBalancesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WithdrawUnlockedBalances not implemented") +} +func (*UnimplementedMsgServer) Wager(ctx context.Context, req *MsgWager) (*MsgWagerResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Wager not implemented") +} +func (*UnimplementedMsgServer) HouseDeposit(ctx context.Context, req *MsgHouseDeposit) (*MsgHouseDepositResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HouseDeposit not implemented") +} +func (*UnimplementedMsgServer) HouseWithdraw(ctx context.Context, req *MsgHouseWithdraw) (*MsgHouseWithdrawResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HouseWithdraw not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreate) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Create(ctx, req.(*MsgCreate)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_TopUp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgTopUp) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).TopUp(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/TopUp", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).TopUp(ctx, req.(*MsgTopUp)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_WithdrawUnlockedBalances_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWithdrawUnlockedBalances) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).WithdrawUnlockedBalances(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/WithdrawUnlockedBalances", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).WithdrawUnlockedBalances(ctx, req.(*MsgWithdrawUnlockedBalances)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Wager_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWager) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Wager(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/Wager", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Wager(ctx, req.(*MsgWager)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_HouseDeposit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgHouseDeposit) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).HouseDeposit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/HouseDeposit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).HouseDeposit(ctx, req.(*MsgHouseDeposit)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_HouseWithdraw_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgHouseWithdraw) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).HouseWithdraw(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Msg/HouseWithdraw", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).HouseWithdraw(ctx, req.(*MsgHouseWithdraw)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "sgenetwork.sge.subaccount.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Msg_Create_Handler, + }, + { + MethodName: "TopUp", + Handler: _Msg_TopUp_Handler, + }, + { + MethodName: "WithdrawUnlockedBalances", + Handler: _Msg_WithdrawUnlockedBalances_Handler, + }, + { + MethodName: "Wager", + Handler: _Msg_Wager_Handler, + }, + { + MethodName: "HouseDeposit", + Handler: _Msg_HouseDeposit_Handler, + }, + { + MethodName: "HouseWithdraw", + Handler: _Msg_HouseWithdraw_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "sge/subaccount/tx.proto", +} + +func (m *MsgCreate) 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 *MsgCreate) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreate) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.LockedBalances) > 0 { + for iNdEx := len(m.LockedBalances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.LockedBalances[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.SubAccountOwner) > 0 { + i -= len(m.SubAccountOwner) + copy(dAtA[i:], m.SubAccountOwner) + i = encodeVarintTx(dAtA, i, uint64(len(m.SubAccountOwner))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateResponse) 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 *MsgCreateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgTopUp) 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 *MsgTopUp) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgTopUp) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.LockedBalances) > 0 { + for iNdEx := len(m.LockedBalances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.LockedBalances[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.SubAccount) > 0 { + i -= len(m.SubAccount) + copy(dAtA[i:], m.SubAccount) + i = encodeVarintTx(dAtA, i, uint64(len(m.SubAccount))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgTopUpResponse) 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 *MsgTopUpResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgTopUpResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawUnlockedBalances) 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 *MsgWithdrawUnlockedBalances) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawUnlockedBalances) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawUnlockedBalancesResponse) 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 *MsgWithdrawUnlockedBalancesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawUnlockedBalancesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgWager) 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 *MsgWager) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWager) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Msg != nil { + { + size, err := m.Msg.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgWagerResponse) 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 *MsgWagerResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWagerResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgHouseDeposit) 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 *MsgHouseDeposit) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgHouseDeposit) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Msg != nil { + { + size, err := m.Msg.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgHouseDepositResponse) 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 *MsgHouseDepositResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgHouseDepositResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgHouseWithdraw) 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 *MsgHouseWithdraw) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgHouseWithdraw) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Msg != nil { + { + size, err := m.Msg.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgHouseWithdrawResponse) 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 *MsgHouseWithdrawResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgHouseWithdrawResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Response != nil { + { + size, err := m.Response.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgCreate) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.SubAccountOwner) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.LockedBalances) > 0 { + for _, e := range m.LockedBalances { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgCreateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgTopUp) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.SubAccount) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.LockedBalances) > 0 { + for _, e := range m.LockedBalances { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgTopUpResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgWithdrawUnlockedBalances) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWithdrawUnlockedBalancesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgWager) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Msg != nil { + l = m.Msg.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWagerResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgHouseDeposit) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Msg != nil { + l = m.Msg.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgHouseDepositResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgHouseWithdraw) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Msg != nil { + l = m.Msg.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgHouseWithdrawResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Response != nil { + l = m.Response.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgCreate) 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 ErrIntOverflowTx + } + 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: MsgCreate: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreate: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubAccountOwner", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubAccountOwner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LockedBalances", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LockedBalances = append(m.LockedBalances, LockedBalance{}) + if err := m.LockedBalances[len(m.LockedBalances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateResponse) 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 ErrIntOverflowTx + } + 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: MsgCreateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgTopUp) 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 ErrIntOverflowTx + } + 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: MsgTopUp: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgTopUp: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubAccount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubAccount = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LockedBalances", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LockedBalances = append(m.LockedBalances, LockedBalance{}) + if err := m.LockedBalances[len(m.LockedBalances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgTopUpResponse) 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 ErrIntOverflowTx + } + 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: MsgTopUpResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgTopUpResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawUnlockedBalances) 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 ErrIntOverflowTx + } + 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: MsgWithdrawUnlockedBalances: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawUnlockedBalances: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawUnlockedBalancesResponse) 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 ErrIntOverflowTx + } + 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: MsgWithdrawUnlockedBalancesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawUnlockedBalancesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWager) 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 ErrIntOverflowTx + } + 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: MsgWager: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWager: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Msg == nil { + m.Msg = &types.MsgWager{} + } + if err := m.Msg.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWagerResponse) 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 ErrIntOverflowTx + } + 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: MsgWagerResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWagerResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types.MsgWagerResponse{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgHouseDeposit) 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 ErrIntOverflowTx + } + 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: MsgHouseDeposit: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgHouseDeposit: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Msg == nil { + m.Msg = &types1.MsgDeposit{} + } + if err := m.Msg.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgHouseDepositResponse) 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 ErrIntOverflowTx + } + 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: MsgHouseDepositResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgHouseDepositResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types1.MsgDepositResponse{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgHouseWithdraw) 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 ErrIntOverflowTx + } + 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: MsgHouseWithdraw: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgHouseWithdraw: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Msg == nil { + m.Msg = &types1.MsgWithdraw{} + } + if err := m.Msg.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgHouseWithdrawResponse) 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 ErrIntOverflowTx + } + 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: MsgHouseWithdrawResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgHouseWithdrawResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Response", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Response == nil { + m.Response = &types1.MsgWithdrawResponse{} + } + if err := m.Response.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +)