mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 12:05:18 +00:00
[R4R] Enable bep3 claim txs from new addresses (#482)
* incoming swaps trigger acc registration * move supply increment after recipient acc validation * use expected keepers pattern * remove expected keepers from alias * update comment
This commit is contained in:
parent
b3fd840f79
commit
d56ad961c0
@ -311,6 +311,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
|
|||||||
app.cdc,
|
app.cdc,
|
||||||
keys[bep3.StoreKey],
|
keys[bep3.StoreKey],
|
||||||
app.supplyKeeper,
|
app.supplyKeeper,
|
||||||
|
app.accountKeeper,
|
||||||
bep3Subspace,
|
bep3Subspace,
|
||||||
)
|
)
|
||||||
app.kavadistKeeper = kavadist.NewKeeper(
|
app.kavadistKeeper = kavadist.NewKeeper(
|
||||||
|
@ -135,7 +135,6 @@ type (
|
|||||||
QueryAssetSupply = types.QueryAssetSupply
|
QueryAssetSupply = types.QueryAssetSupply
|
||||||
QueryAtomicSwapByID = types.QueryAtomicSwapByID
|
QueryAtomicSwapByID = types.QueryAtomicSwapByID
|
||||||
QueryAtomicSwaps = types.QueryAtomicSwaps
|
QueryAtomicSwaps = types.QueryAtomicSwaps
|
||||||
SupplyKeeper = types.SupplyKeeper
|
|
||||||
SwapDirection = types.SwapDirection
|
SwapDirection = types.SwapDirection
|
||||||
SwapStatus = types.SwapStatus
|
SwapStatus = types.SwapStatus
|
||||||
)
|
)
|
||||||
|
@ -4,10 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
|
"github.com/kava-labs/kava/x/bep3/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitGenesis initializes the store state from a genesis state.
|
// InitGenesis initializes the store state from a genesis state.
|
||||||
func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper SupplyKeeper, gs GenesisState) {
|
func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, gs GenesisState) {
|
||||||
if err := gs.Validate(); err != nil {
|
if err := gs.Validate(); err != nil {
|
||||||
panic(fmt.Sprintf("failed to validate %s genesis state: %s", ModuleName, err))
|
panic(fmt.Sprintf("failed to validate %s genesis state: %s", ModuleName, err))
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,14 @@ type Keeper struct {
|
|||||||
cdc *codec.Codec
|
cdc *codec.Codec
|
||||||
paramSubspace subspace.Subspace
|
paramSubspace subspace.Subspace
|
||||||
supplyKeeper types.SupplyKeeper
|
supplyKeeper types.SupplyKeeper
|
||||||
|
accountKeeper types.AccountKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKeeper creates a bep3 keeper
|
// NewKeeper creates a bep3 keeper
|
||||||
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.SupplyKeeper, paramstore subspace.Subspace) Keeper {
|
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey,
|
||||||
|
sk types.SupplyKeeper, ak types.AccountKeeper,
|
||||||
|
paramstore subspace.Subspace,
|
||||||
|
) Keeper {
|
||||||
if addr := sk.GetModuleAddress(types.ModuleName); addr == nil {
|
if addr := sk.GetModuleAddress(types.ModuleName); addr == nil {
|
||||||
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
|
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
|
||||||
}
|
}
|
||||||
@ -36,6 +40,7 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.SupplyKeeper, params
|
|||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
paramSubspace: paramstore,
|
paramSubspace: paramstore,
|
||||||
supplyKeeper: sk,
|
supplyKeeper: sk,
|
||||||
|
accountKeeper: ak,
|
||||||
}
|
}
|
||||||
return keeper
|
return keeper
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,13 @@ func (k Keeper) CreateAtomicSwap(ctx sdk.Context, randomNumberHash []byte, times
|
|||||||
|
|
||||||
switch direction {
|
switch direction {
|
||||||
case types.Incoming:
|
case types.Incoming:
|
||||||
|
// If recipient's account doesn't exist, register it in state so that the address can send
|
||||||
|
// a claim swap tx without needing to be registered in state by receiving a coin transfer.
|
||||||
|
recipientAcc := k.accountKeeper.GetAccount(ctx, recipient)
|
||||||
|
if recipientAcc == nil {
|
||||||
|
newAcc := k.accountKeeper.NewAccountWithAddress(ctx, recipient)
|
||||||
|
k.accountKeeper.SetAccount(ctx, newAcc)
|
||||||
|
}
|
||||||
err = k.IncrementIncomingAssetSupply(ctx, amount[0])
|
err = k.IncrementIncomingAssetSupply(ctx, amount[0])
|
||||||
case types.Outgoing:
|
case types.Outgoing:
|
||||||
err = k.IncrementOutgoingAssetSupply(ctx, amount[0])
|
err = k.IncrementOutgoingAssetSupply(ctx, amount[0])
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
||||||
sim "github.com/cosmos/cosmos-sdk/x/simulation"
|
sim "github.com/cosmos/cosmos-sdk/x/simulation"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
@ -19,6 +18,7 @@ import (
|
|||||||
"github.com/kava-labs/kava/x/bep3/client/cli"
|
"github.com/kava-labs/kava/x/bep3/client/cli"
|
||||||
"github.com/kava-labs/kava/x/bep3/client/rest"
|
"github.com/kava-labs/kava/x/bep3/client/rest"
|
||||||
"github.com/kava-labs/kava/x/bep3/simulation"
|
"github.com/kava-labs/kava/x/bep3/simulation"
|
||||||
|
"github.com/kava-labs/kava/x/bep3/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -78,12 +78,12 @@ type AppModule struct {
|
|||||||
AppModuleBasic
|
AppModuleBasic
|
||||||
|
|
||||||
keeper Keeper
|
keeper Keeper
|
||||||
accountKeeper auth.AccountKeeper
|
accountKeeper types.AccountKeeper
|
||||||
supplyKeeper SupplyKeeper
|
supplyKeeper types.SupplyKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAppModule creates a new AppModule object
|
// NewAppModule creates a new AppModule object
|
||||||
func NewAppModule(keeper Keeper, accountKeeper auth.AccountKeeper, supplyKeeper SupplyKeeper) AppModule {
|
func NewAppModule(keeper Keeper, accountKeeper types.AccountKeeper, supplyKeeper types.SupplyKeeper) AppModule {
|
||||||
return AppModule{
|
return AppModule{
|
||||||
AppModuleBasic: AppModuleBasic{},
|
AppModuleBasic: AppModuleBasic{},
|
||||||
keeper: keeper,
|
keeper: keeper,
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||||
|
|
||||||
appparams "github.com/kava-labs/kava/app/params"
|
appparams "github.com/kava-labs/kava/app/params"
|
||||||
@ -28,7 +27,7 @@ const (
|
|||||||
|
|
||||||
// WeightedOperations returns all the operations from the module with their respective weights
|
// WeightedOperations returns all the operations from the module with their respective weights
|
||||||
func WeightedOperations(
|
func WeightedOperations(
|
||||||
appParams simulation.AppParams, cdc *codec.Codec, ak auth.AccountKeeper, k keeper.Keeper,
|
appParams simulation.AppParams, cdc *codec.Codec, ak types.AccountKeeper, k keeper.Keeper,
|
||||||
) simulation.WeightedOperations {
|
) simulation.WeightedOperations {
|
||||||
var weightCreateAtomicSwap int
|
var weightCreateAtomicSwap int
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ func WeightedOperations(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SimulateMsgCreateAtomicSwap generates a MsgCreateAtomicSwap with random values
|
// SimulateMsgCreateAtomicSwap generates a MsgCreateAtomicSwap with random values
|
||||||
func SimulateMsgCreateAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper) simulation.Operation {
|
func SimulateMsgCreateAtomicSwap(ak types.AccountKeeper, k keeper.Keeper) simulation.Operation {
|
||||||
return func(
|
return func(
|
||||||
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string,
|
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string,
|
||||||
) (simulation.OperationMsg, []simulation.FutureOperation, error) {
|
) (simulation.OperationMsg, []simulation.FutureOperation, error) {
|
||||||
@ -143,7 +142,7 @@ func SimulateMsgCreateAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper) simulat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func operationClaimAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper, swapID []byte, randomNumber []byte) simulation.Operation {
|
func operationClaimAtomicSwap(ak types.AccountKeeper, k keeper.Keeper, swapID []byte, randomNumber []byte) simulation.Operation {
|
||||||
return func(
|
return func(
|
||||||
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string,
|
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string,
|
||||||
) (simulation.OperationMsg, []simulation.FutureOperation, error) {
|
) (simulation.OperationMsg, []simulation.FutureOperation, error) {
|
||||||
@ -176,7 +175,7 @@ func operationClaimAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper, swapID []b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func operationRefundAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper, swapID []byte) simulation.Operation {
|
func operationRefundAtomicSwap(ak types.AccountKeeper, k keeper.Keeper, swapID []byte) simulation.Operation {
|
||||||
return func(
|
return func(
|
||||||
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string,
|
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string,
|
||||||
) (simulation.OperationMsg, []simulation.FutureOperation, error) {
|
) (simulation.OperationMsg, []simulation.FutureOperation, error) {
|
||||||
|
@ -2,10 +2,11 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
||||||
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
|
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SupplyKeeper defines the expected supply Keeper
|
// SupplyKeeper defines the expected supply keeper (noalias)
|
||||||
type SupplyKeeper interface {
|
type SupplyKeeper interface {
|
||||||
GetModuleAddress(name string) sdk.AccAddress
|
GetModuleAddress(name string) sdk.AccAddress
|
||||||
GetModuleAccount(ctx sdk.Context, moduleName string) supplyexported.ModuleAccountI
|
GetModuleAccount(ctx sdk.Context, moduleName string) supplyexported.ModuleAccountI
|
||||||
@ -17,3 +18,10 @@ type SupplyKeeper interface {
|
|||||||
BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
|
BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
|
||||||
MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error
|
MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AccountKeeper defines the expected account keeper (noalias)
|
||||||
|
type AccountKeeper interface {
|
||||||
|
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account
|
||||||
|
NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authexported.Account
|
||||||
|
SetAccount(ctx sdk.Context, acc authexported.Account)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user