Skip to content

Commit

Permalink
chore: add basic tx and queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed Apr 30, 2024
1 parent f1e6811 commit 427da10
Show file tree
Hide file tree
Showing 15 changed files with 608 additions and 262 deletions.
1 change: 1 addition & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
fswaptypes.ModuleName: {authtypes.Burner, authtypes.Minter},
}

// module accounts that are allowed to receive tokens
Expand Down
19 changes: 19 additions & 0 deletions x/fswap/keeper/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package keeper

import (
sdk "github.com/Finschia/finschia-sdk/types"
)

type (
AccountKeeper interface {
GetModuleAddress(name string) sdk.AccAddress
}

BankKeeper interface {
HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
}
)
109 changes: 0 additions & 109 deletions x/fswap/keeper/fswap.go

This file was deleted.

6 changes: 3 additions & 3 deletions x/fswap/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) error
return fmt.Errorf("cannot initialize genesis state, there are more than 1 swapped")
}
for _, fswapInit := range genState.GetFswapInit() {
if err := k.SetFswapInit(ctx, fswapInit); err != nil {
if err := k.setFswapInit(ctx, fswapInit); err != nil {
panic(err)
}
}
Expand All @@ -31,7 +31,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) error
// ExportGenesis returns the module's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return &types.GenesisState{
FswapInit: k.GetAllFswapInits(ctx),
Swapped: k.GetAllSwapped(ctx),
FswapInit: k.getAllFswapInits(ctx),
Swapped: k.getAllSwapped(ctx),
}
}
2 changes: 1 addition & 1 deletion x/fswap/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func (s *KeeperTestSuite) TestInitAndExportGenesis() {
ctx, _ := s.sdkCtx.CacheContext()
ctx, _ := s.ctx.CacheContext()
defaultGenesis := types.DefaultGenesis()
err := s.keeper.InitGenesis(ctx, defaultGenesis)
s.Require().NoError(err)
Expand Down
46 changes: 12 additions & 34 deletions x/fswap/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,6 @@ import (
"github.com/Finschia/finschia-sdk/x/fswap/types"
)

//var _ types.QueryServer = Keeper{}
//
//// todo this files is just for test
//// Swapped implements types.QueryServer.
//func (k Keeper) Swapped(ctx context.Context, req *types.QuerySwappedRequest) (*types.QuerySwappedResponse, error) {
// sdkCtx := sdk.UnwrapSDKContext(ctx)
// check := k.GetFswap(sdkCtx)
//
// return &types.QuerySwappedResponse{
// OldCoinAmount: sdk.NewCoin(check.FromDenom, sdk.ZeroInt()),
// NewCoinAmount: sdk.NewCoin(check.ToDenom, sdk.ZeroInt()),
// }, nil
//}
//
//// TotalSwappableAmount implements types.QueryServer.
//func (k Keeper) TotalSwappableAmount(context.Context, *types.QueryTotalSwappableAmountRequest) (*types.QueryTotalSwappableAmountResponse, error) {
// //TODO implement me
// panic("unimplemented")
// // sdkCtx := sdk.UnwrapSDKContext(ctx)
// // totalSwappableAmount := k.GetParams(sdkCtx).SwappableNewCoinAmount
// // swapped := k.GetSwapped(sdkCtx)
// // swappableNewCoin := sdk.NewCoin(k.config.NewCoinDenom, totalSwappableAmount.Sub(swapped.NewCoinAmount))
// // return &types.QueryTotalSwappableAmountResponse{
// // SwappableNewCoin: swappableNewCoin,
// // }, nil
//}

var _ types.QueryServer = QueryServer{}

type QueryServer struct {
Expand All @@ -48,18 +21,23 @@ func NewQueryServer(keeper Keeper) *QueryServer {

func (s QueryServer) Swapped(ctx context.Context, _ *types.QuerySwappedRequest) (*types.QuerySwappedResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
allSwapped := s.Keeper.GetAllSwapped(c)
if len(allSwapped) == 0 {
return nil, types.ErrSwappedNotFound
swapped, err := s.Keeper.getSwapped(c)
if err != nil {
return nil, err
}
swapped := allSwapped[0]
return &types.QuerySwappedResponse{
OldCoinAmount: swapped.GetOldCoinAmount(),
NewCoinAmount: swapped.GetNewCoinAmount(),
}, nil
}

func (s QueryServer) TotalSwappableAmount(_ context.Context, _ *types.QueryTotalSwappableAmountRequest) (*types.QueryTotalSwappableAmountResponse, error) {
// s.Keeper.GetSwappableNewCoinAmount()
return nil, nil
func (s QueryServer) TotalSwappableAmount(ctx context.Context, _ *types.QueryTotalSwappableAmountRequest) (*types.QueryTotalSwappableAmountResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
amount, err := s.Keeper.getSwappableNewCoinAmount(c)
if err != nil {
return &types.QueryTotalSwappableAmountResponse{}, err
}
return &types.QueryTotalSwappableAmountResponse{
SwappableNewCoin: amount,
}, nil
}
1 change: 0 additions & 1 deletion x/fswap/keeper/grpc_query_params_test.go

This file was deleted.

Loading

0 comments on commit 427da10

Please sign in to comment.