-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
276a1d3
commit d2f719d
Showing
16 changed files
with
568 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
package agoric.vpurse; | ||
|
||
option go_package = "github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types"; | ||
|
||
service Msg { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package vpurse | ||
|
||
import ( | ||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/keeper" | ||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types" | ||
) | ||
|
||
const ( | ||
ModuleName = types.ModuleName | ||
RouterKey = types.RouterKey | ||
StoreKey = types.StoreKey | ||
) | ||
|
||
var ( | ||
NewKeeper = keeper.NewKeeper | ||
ModuleCdc = types.ModuleCdc | ||
RegisterCodec = types.RegisterCodec | ||
) | ||
|
||
type ( | ||
Keeper = keeper.Keeper | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package vpurse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// NewHandler returns a handler for "vpurse" type messages. | ||
func NewHandler(keeper Keeper) sdk.Handler { | ||
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { | ||
if swingset.IsSimulation(ctx) { | ||
// We don't support simulation. | ||
return &sdk.Result{}, nil | ||
} else { | ||
// The simulation was done, so now allow infinite gas. | ||
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) | ||
} | ||
|
||
switch msg := msg.(type) { | ||
default: | ||
errMsg := fmt.Sprintf("Unrecognized vpurse Msg type: %v", msg.Type()) | ||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
|
||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types" | ||
) | ||
|
||
// Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine | ||
type Keeper struct { | ||
storeKey sdk.StoreKey | ||
cdc codec.Marshaler | ||
|
||
bankKeeper bankkeeper.Keeper | ||
|
||
// CallToController dispatches a message to the controlling process | ||
CallToController func(ctx sdk.Context, str string) (string, error) | ||
} | ||
|
||
// NewKeeper creates a new vpurse Keeper instance | ||
func NewKeeper( | ||
cdc codec.Marshaler, key sdk.StoreKey, | ||
bankKeeper bankkeeper.Keeper, | ||
callToController func(ctx sdk.Context, str string) (string, error), | ||
) Keeper { | ||
|
||
return Keeper{ | ||
storeKey: key, | ||
cdc: cdc, | ||
bankKeeper: bankKeeper, | ||
CallToController: callToController, | ||
} | ||
} | ||
|
||
func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin { | ||
return k.bankKeeper.GetBalance(ctx, addr, denom) | ||
} | ||
|
||
func (k Keeper) SendCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) error { | ||
if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, amt); err != nil { | ||
return err | ||
} | ||
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, amt) | ||
} | ||
|
||
func (k Keeper) GrabCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) error { | ||
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, amt); err != nil { | ||
return err | ||
} | ||
return k.bankKeeper.BurnCoins(ctx, types.ModuleName, amt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package vpurse | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vpurse/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
cdctypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
) | ||
|
||
// type check to ensure the interface is properly implemented | ||
var ( | ||
_ module.AppModule = AppModule{} | ||
_ module.AppModuleBasic = AppModuleBasic{} | ||
) | ||
|
||
// app module Basics object | ||
type AppModuleBasic struct { | ||
cdc codec.Marshaler | ||
} | ||
|
||
func (AppModuleBasic) Name() string { | ||
return ModuleName | ||
} | ||
|
||
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { | ||
RegisterCodec(cdc) | ||
} | ||
|
||
// RegisterInterfaces registers the module's interface types | ||
func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { | ||
types.RegisterInterfaces(registry) | ||
} | ||
|
||
// DefaultGenesis returns default genesis state as raw bytes for the deployment | ||
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { | ||
return nil | ||
} | ||
|
||
// Validation check of the Genesis | ||
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxEncodingConfig, bz json.RawMessage) error { | ||
return nil | ||
} | ||
|
||
// Register rest routes | ||
func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) { | ||
} | ||
|
||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) { | ||
} | ||
|
||
// GetTxCmd implements AppModuleBasic interface | ||
func (AppModuleBasic) GetTxCmd() *cobra.Command { | ||
return nil | ||
} | ||
|
||
// GetQueryCmd implements AppModuleBasic interface | ||
func (AppModuleBasic) GetQueryCmd() *cobra.Command { | ||
return nil | ||
} | ||
|
||
type AppModule struct { | ||
AppModuleBasic | ||
keeper Keeper | ||
} | ||
|
||
// NewAppModule creates a new AppModule Object | ||
func NewAppModule(k Keeper) AppModule { | ||
am := AppModule{ | ||
AppModuleBasic: AppModuleBasic{}, | ||
keeper: k, | ||
} | ||
return am | ||
} | ||
|
||
func (AppModule) Name() string { | ||
return ModuleName | ||
} | ||
|
||
// BeginBlock implements the AppModule interface | ||
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { | ||
} | ||
|
||
// EndBlock implements the AppModule interface | ||
func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { | ||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
// RegisterInvariants implements the AppModule interface | ||
func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { | ||
// TODO | ||
} | ||
|
||
// Route implements the AppModule interface | ||
func (am AppModule) Route() sdk.Route { | ||
return sdk.NewRoute(RouterKey, NewHandler(am.keeper)) | ||
} | ||
|
||
// QuerierRoute implements the AppModule interface | ||
func (AppModule) QuerierRoute() string { | ||
return ModuleName | ||
} | ||
|
||
// LegacyQuerierHandler implements the AppModule interface | ||
func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { | ||
return nil | ||
} | ||
|
||
// RegisterServices registers module services. | ||
func (am AppModule) RegisterServices(cfg module.Configurator) { | ||
tx := &types.UnimplementedMsgServer{} | ||
types.RegisterMsgServer(cfg.MsgServer(), tx) | ||
} | ||
|
||
// InitGenesis performs genesis initialization for the ibc-transfer module. It returns | ||
// no validator updates. | ||
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { | ||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
// ExportGenesis returns the exported genesis state as raw bytes for the ibc-transfer | ||
// module. | ||
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { | ||
return nil | ||
} |
Oops, something went wrong.