@@ -21,21 +21,18 @@ import (
21
21
"github.com/cosmos/ibc-go/v8/modules/core/exported"
22
22
)
23
23
24
- var (
25
- VMGasRegister = NewDefaultWasmGasRegister ()
26
- // wasmvmAPI is a wasmvm.GoAPI implementation that is passed to the wasmvm, it
27
- // doesn't implement any functionality, directly returning an error.
28
- wasmvmAPI = wasmvm.GoAPI {
29
- HumanAddress : humanAddress ,
30
- CanonicalAddress : canonicalAddress ,
31
- }
32
- )
24
+ // wasmvmAPI is a wasmvm.GoAPI implementation that is passed to the wasmvm, it
25
+ // doesn't implement any functionality, directly returning an error.
26
+ var wasmvmAPI = wasmvm.GoAPI {
27
+ HumanAddress : humanAddress ,
28
+ CanonicalAddress : canonicalAddress ,
29
+ }
33
30
34
31
// instantiateContract calls vm.Instantiate with appropriate arguments.
35
32
func instantiateContract (ctx sdk.Context , clientStore storetypes.KVStore , checksum Checksum , msg []byte ) (* wasmvmtypes.Response , error ) {
36
33
sdkGasMeter := ctx .GasMeter ()
37
- multipliedGasMeter := NewMultipliedGasMeter (sdkGasMeter , VMGasRegister )
38
- gasLimit := VMGasRegister .runtimeGasForContract (ctx )
34
+ multipliedGasMeter := ibcwasm . NewMultipliedGasMeter (sdkGasMeter , ibcwasm . VMGasRegister )
35
+ gasLimit := ibcwasm . VMGasRegister .RuntimeGasForContract (ctx )
39
36
40
37
clientID , err := getClientID (clientStore )
41
38
if err != nil {
@@ -48,59 +45,59 @@ func instantiateContract(ctx sdk.Context, clientStore storetypes.KVStore, checks
48
45
Funds : nil ,
49
46
}
50
47
51
- ctx .GasMeter ().ConsumeGas (VMGasRegister .NewContractInstanceCosts (true , len (msg )), "Loading CosmWasm module: instantiate" )
52
- response , gasUsed , err := ibcwasm .GetVM ().Instantiate (checksum , env , msgInfo , msg , newStoreAdapter (clientStore ), wasmvmAPI , ibcwasm .GetQuerier (), multipliedGasMeter , gasLimit , costJSONDeserialization )
53
- VMGasRegister .consumeRuntimeGas (ctx , gasUsed )
48
+ ctx .GasMeter ().ConsumeGas (ibcwasm . VMGasRegister .NewContractInstanceCosts (true , len (msg )), "Loading CosmWasm module: instantiate" )
49
+ response , gasUsed , err := ibcwasm .GetVM ().Instantiate (checksum , env , msgInfo , msg , newStoreAdapter (clientStore ), wasmvmAPI , ibcwasm .GetQuerier (), multipliedGasMeter , gasLimit , ibcwasm . CostJSONDeserialization )
50
+ ibcwasm . VMGasRegister .ConsumeRuntimeGas (ctx , gasUsed )
54
51
return response , err
55
52
}
56
53
57
54
// callContract calls vm.Sudo with internally constructed gas meter and environment.
58
55
func callContract (ctx sdk.Context , clientStore storetypes.KVStore , checksum Checksum , msg []byte ) (* wasmvmtypes.Response , error ) {
59
56
sdkGasMeter := ctx .GasMeter ()
60
- multipliedGasMeter := NewMultipliedGasMeter (sdkGasMeter , VMGasRegister )
61
- gasLimit := VMGasRegister .runtimeGasForContract (ctx )
57
+ multipliedGasMeter := ibcwasm . NewMultipliedGasMeter (sdkGasMeter , ibcwasm . VMGasRegister )
58
+ gasLimit := ibcwasm . VMGasRegister .RuntimeGasForContract (ctx )
62
59
63
60
clientID , err := getClientID (clientStore )
64
61
if err != nil {
65
62
return nil , errorsmod .Wrap (err , "failed to retrieve clientID for wasm contract call" )
66
63
}
67
64
env := getEnv (ctx , clientID )
68
65
69
- ctx .GasMeter ().ConsumeGas (VMGasRegister .InstantiateContractCosts (true , len (msg )), "Loading CosmWasm module: sudo" )
70
- resp , gasUsed , err := ibcwasm .GetVM ().Sudo (checksum , env , msg , newStoreAdapter (clientStore ), wasmvmAPI , ibcwasm .GetQuerier (), multipliedGasMeter , gasLimit , costJSONDeserialization )
71
- VMGasRegister .consumeRuntimeGas (ctx , gasUsed )
66
+ ctx .GasMeter ().ConsumeGas (ibcwasm . VMGasRegister .InstantiateContractCosts (true , len (msg )), "Loading CosmWasm module: sudo" )
67
+ resp , gasUsed , err := ibcwasm .GetVM ().Sudo (checksum , env , msg , newStoreAdapter (clientStore ), wasmvmAPI , ibcwasm .GetQuerier (), multipliedGasMeter , gasLimit , ibcwasm . CostJSONDeserialization )
68
+ ibcwasm . VMGasRegister .ConsumeRuntimeGas (ctx , gasUsed )
72
69
return resp , err
73
70
}
74
71
75
72
// migrateContract calls vm.Migrate with internally constructed gas meter and environment.
76
73
func migrateContract (ctx sdk.Context , clientID string , clientStore storetypes.KVStore , checksum Checksum , msg []byte ) (* wasmvmtypes.Response , error ) {
77
74
sdkGasMeter := ctx .GasMeter ()
78
- multipliedGasMeter := NewMultipliedGasMeter (sdkGasMeter , VMGasRegister )
79
- gasLimit := VMGasRegister .runtimeGasForContract (ctx )
75
+ multipliedGasMeter := ibcwasm . NewMultipliedGasMeter (sdkGasMeter , ibcwasm . VMGasRegister )
76
+ gasLimit := ibcwasm . VMGasRegister .RuntimeGasForContract (ctx )
80
77
81
78
env := getEnv (ctx , clientID )
82
79
83
- ctx .GasMeter ().ConsumeGas (VMGasRegister .InstantiateContractCosts (true , len (msg )), "Loading CosmWasm module: migrate" )
84
- resp , gasUsed , err := ibcwasm .GetVM ().Migrate (checksum , env , msg , newStoreAdapter (clientStore ), wasmvmAPI , ibcwasm .GetQuerier (), multipliedGasMeter , gasLimit , costJSONDeserialization )
85
- VMGasRegister .consumeRuntimeGas (ctx , gasUsed )
80
+ ctx .GasMeter ().ConsumeGas (ibcwasm . VMGasRegister .InstantiateContractCosts (true , len (msg )), "Loading CosmWasm module: migrate" )
81
+ resp , gasUsed , err := ibcwasm .GetVM ().Migrate (checksum , env , msg , newStoreAdapter (clientStore ), wasmvmAPI , ibcwasm .GetQuerier (), multipliedGasMeter , gasLimit , ibcwasm . CostJSONDeserialization )
82
+ ibcwasm . VMGasRegister .ConsumeRuntimeGas (ctx , gasUsed )
86
83
return resp , err
87
84
}
88
85
89
86
// queryContract calls vm.Query.
90
87
func queryContract (ctx sdk.Context , clientStore storetypes.KVStore , checksum Checksum , msg []byte ) ([]byte , error ) {
91
88
sdkGasMeter := ctx .GasMeter ()
92
- multipliedGasMeter := NewMultipliedGasMeter (sdkGasMeter , VMGasRegister )
93
- gasLimit := VMGasRegister .runtimeGasForContract (ctx )
89
+ multipliedGasMeter := ibcwasm . NewMultipliedGasMeter (sdkGasMeter , ibcwasm . VMGasRegister )
90
+ gasLimit := ibcwasm . VMGasRegister .RuntimeGasForContract (ctx )
94
91
95
92
clientID , err := getClientID (clientStore )
96
93
if err != nil {
97
94
return nil , errorsmod .Wrap (err , "failed to retrieve clientID for wasm contract query" )
98
95
}
99
96
env := getEnv (ctx , clientID )
100
97
101
- ctx .GasMeter ().ConsumeGas (VMGasRegister .InstantiateContractCosts (true , len (msg )), "Loading CosmWasm module: query" )
102
- resp , gasUsed , err := ibcwasm .GetVM ().Query (checksum , env , msg , newStoreAdapter (clientStore ), wasmvmAPI , ibcwasm .GetQuerier (), multipliedGasMeter , gasLimit , costJSONDeserialization )
103
- VMGasRegister .consumeRuntimeGas (ctx , gasUsed )
98
+ ctx .GasMeter ().ConsumeGas (ibcwasm . VMGasRegister .InstantiateContractCosts (true , len (msg )), "Loading CosmWasm module: query" )
99
+ resp , gasUsed , err := ibcwasm .GetVM ().Query (checksum , env , msg , newStoreAdapter (clientStore ), wasmvmAPI , ibcwasm .GetQuerier (), multipliedGasMeter , gasLimit , ibcwasm . CostJSONDeserialization )
100
+ ibcwasm . VMGasRegister .ConsumeRuntimeGas (ctx , gasUsed )
104
101
return resp , err
105
102
}
106
103
0 commit comments