Skip to content

Commit b6c5524

Browse files
authored
refactor(vm): use expected keeper interface (#3935)
The goal of this PR is to prepare making more usable the GnoVM by potentially other chains. This follow the pattern that exists in the Cosmos SDK (https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/x/gov/types/expected_keepers.go) and that is being used in this repo as well: https://github.com/julienrbrt/gno/blob/71fbdef783b5d72ca603ed45b8fb10434ca0ab11/tm2/pkg/sdk/auth/types.go#L23.
1 parent d677c2f commit b6c5524

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

gno.land/pkg/sdk/vm/builtins.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/gnolang/gno/tm2/pkg/crypto"
88
"github.com/gnolang/gno/tm2/pkg/sdk"
9-
"github.com/gnolang/gno/tm2/pkg/sdk/params"
109
"github.com/gnolang/gno/tm2/pkg/std"
1110
)
1211

@@ -69,11 +68,11 @@ func (bnk *SDKBanker) RemoveCoin(b32addr crypto.Bech32Address, denom string, amo
6968
// Users must write code to limit access as appropriate.
7069

7170
type SDKParams struct {
72-
pmk params.ParamsKeeper
71+
pmk ParamsKeeperI
7372
ctx sdk.Context
7473
}
7574

76-
func NewSDKParams(pmk params.ParamsKeeper, ctx sdk.Context) *SDKParams {
75+
func NewSDKParams(pmk ParamsKeeperI, ctx sdk.Context) *SDKParams {
7776
return &SDKParams{
7877
pmk: pmk,
7978
ctx: ctx,

gno.land/pkg/sdk/vm/keeper.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import (
2424
"github.com/gnolang/gno/tm2/pkg/errors"
2525
osm "github.com/gnolang/gno/tm2/pkg/os"
2626
"github.com/gnolang/gno/tm2/pkg/sdk"
27-
"github.com/gnolang/gno/tm2/pkg/sdk/auth"
28-
"github.com/gnolang/gno/tm2/pkg/sdk/bank"
29-
"github.com/gnolang/gno/tm2/pkg/sdk/params"
3027
"github.com/gnolang/gno/tm2/pkg/std"
3128
"github.com/gnolang/gno/tm2/pkg/store"
3229
"github.com/gnolang/gno/tm2/pkg/store/dbadapter"
@@ -66,9 +63,9 @@ type VMKeeper struct {
6663

6764
baseKey store.StoreKey
6865
iavlKey store.StoreKey
69-
acck auth.AccountKeeper
70-
bank bank.BankKeeper
71-
prmk params.ParamsKeeper
66+
acck AccountKeeperI
67+
bank BankKeeperI
68+
prmk ParamsKeeperI
7269

7370
// cached, the DeliverTx persistent state.
7471
gnoStore gno.Store
@@ -80,9 +77,9 @@ type VMKeeper struct {
8077
func NewVMKeeper(
8178
baseKey store.StoreKey,
8279
iavlKey store.StoreKey,
83-
acck auth.AccountKeeper,
84-
bank bank.BankKeeper,
85-
prmk params.ParamsKeeper,
80+
acck AccountKeeperI,
81+
bank BankKeeperI,
82+
prmk ParamsKeeperI,
8683
) *VMKeeper {
8784
vmk := &VMKeeper{
8885
baseKey: baseKey,

gno.land/pkg/sdk/vm/types.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
package vm
22

3-
import "github.com/gnolang/gno/tm2/pkg/amino"
3+
import (
4+
"github.com/gnolang/gno/tm2/pkg/amino"
5+
"github.com/gnolang/gno/tm2/pkg/crypto"
6+
"github.com/gnolang/gno/tm2/pkg/sdk"
7+
"github.com/gnolang/gno/tm2/pkg/sdk/params"
8+
"github.com/gnolang/gno/tm2/pkg/std"
9+
)
10+
11+
// AccountKeeperI is the limited interface only needed for VM.
12+
type AccountKeeperI interface {
13+
GetAccount(ctx sdk.Context, addr crypto.Address) std.Account
14+
}
15+
16+
// BankKeeperI is the limited interface only needed for VM.
17+
type BankKeeperI interface {
18+
GetCoins(ctx sdk.Context, addr crypto.Address) std.Coins
19+
SendCoins(ctx sdk.Context, fromAddr crypto.Address, toAddr crypto.Address, amt std.Coins) error
20+
SubtractCoins(ctx sdk.Context, addr crypto.Address, amt std.Coins) (std.Coins, error)
21+
AddCoins(ctx sdk.Context, addr crypto.Address, amt std.Coins) (std.Coins, error)
22+
}
23+
24+
// ParamsKeeperI is the limited interface only needed for VM.
25+
type ParamsKeeperI interface {
26+
params.ParamsKeeperI
27+
28+
IsRegistered(moduleName string) bool
29+
GetRegisteredKeeper(moduleName string) params.ParamfulKeeper
30+
}
431

532
// Public facing function signatures.
633
// See convertArgToGno() for supported types.

0 commit comments

Comments
 (0)