Skip to content

Commit

Permalink
refactor: Changed function name that wraps vm.CallCallablePoint()
Browse files Browse the repository at this point in the history
In keeper.go both Execute and Query call vm.CallCallablePoint(). For this reason, it is now possible to distinguish whether vm.CallCallablePoint() is called with isReadOnly=false or true with the name of the upper function that wraps the vm function.
  • Loading branch information
Kynea0b committed Apr 10, 2023
1 parent 92300c2 commit 3c6f2e2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions x/wasm/keeper/contract_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type decoratedKeeper interface {
pinCode(ctx sdk.Context, codeID uint64) error
unpinCode(ctx sdk.Context, codeID uint64) error
execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error)
callCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddress, argsEv []byte, funcNameWithCallablePoint string) ([]byte, error)
executeCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddress, argsEv []byte, callablePointName string) ([]byte, error)
Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error)
setContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra types.ContractInfoExtension) error
setAccessConfig(ctx sdk.Context, codeID uint64, config types.AccessConfig) error
Expand Down Expand Up @@ -54,8 +54,8 @@ func (p PermissionedKeeper) Execute(ctx sdk.Context, contractAddress sdk.AccAddr
return p.nested.execute(ctx, contractAddress, caller, msg, coins)
}

func (p PermissionedKeeper) CallCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddress, argsEv []byte, funcNameWithCallablePoint string) ([]byte, error) {
return p.nested.callCallablePoint(ctx, contractAddress, argsEv, funcNameWithCallablePoint)
func (p PermissionedKeeper) ExecuteCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddress, argsEv []byte, callablePointName string) ([]byte, error) {
return p.nested.executeCallablePoint(ctx, contractAddress, argsEv, callablePointName)
}

func (p PermissionedKeeper) Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func (k Keeper) execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller
return data, nil
}

func (k Keeper) callCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddress, argsEv []byte, funcNameWithCallablePoint string) ([]byte, error) {
func (k Keeper) executeCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddress, argsEv []byte, callablePointName string) ([]byte, error) {
defer func(begin time.Time) { k.metrics.ExecuteElapsedTimes.Observe(time.Since(begin).Seconds()) }(time.Now())
contractInfo, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddress)
if err != nil {
Expand All @@ -471,7 +471,7 @@ func (k Keeper) callCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddres
gas := k.runtimeGasForContract(ctx)
wasmStore := types.NewWasmStore(prefixStore)

funcNameWithCallablePointBin, err := json.Marshal(funcNameWithCallablePoint)
funcNameWithCallablePointBin, err := json.Marshal(callablePointName)
if err != nil {
panic(fmt.Sprintf("failed to marshal JSON: %s", err))
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func TestCallCallablePoint(t *testing.T) {
argsEvBin, err := json.Marshal(argsEv)
require.NoError(t, err)

res, err := keepers.ContractKeeper.CallCallablePoint(ctx.WithEventManager(em), addr, argsEvBin, callableFuncName)
res, err := keepers.ContractKeeper.ExecuteCallablePoint(ctx.WithEventManager(em), addr, argsEvBin, callableFuncName)
diff := time.Now().Sub(start)
require.NoError(t, err)
require.NotNil(t, res)
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/types/exported_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ContractOpsKeeper interface {
// Execute executes the contract instance
Execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error)

CallCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddress, argsEv []byte, funcNameWithCallablePoint string) ([]byte, error)
ExecuteCallablePoint(ctx sdk.Context, contractAddress sdk.AccAddress, argsEv []byte, funcNameWithCallablePoint string) ([]byte, error)

// Migrate allows to upgrade a contract to a new code with data migration.
Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error)
Expand Down

0 comments on commit 3c6f2e2

Please sign in to comment.