-
Notifications
You must be signed in to change notification settings - Fork 0
/
gas.go
48 lines (37 loc) · 834 Bytes
/
gas.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package types
type HostFuncGasRule interface {
SetContext(ctx VMContext)
ConsumeGas(dataSize int64) error
}
type BaseGasRule struct {
ctx VMContext
}
func (r *BaseGasRule) SetContext(ctx VMContext) {
r.ctx = ctx
}
type StaticGasRule struct {
BaseGasRule
cost int64
}
func (s *StaticGasRule) ConsumeGas(_ int64) error {
return s.ctx.ConsumeWASMGas(s.cost)
}
func NewStaticGasRule(cost int64) *StaticGasRule {
return &StaticGasRule{
cost: cost,
}
}
type DynamicGasRule struct {
BaseGasRule
multiplier int64
fixedCost int64
}
func NewDynamicGasRule(fixedCost int64, multiplier int64) *DynamicGasRule {
return &DynamicGasRule{
multiplier: multiplier,
fixedCost: fixedCost,
}
}
func (d *DynamicGasRule) ConsumeGas(dataSize int64) error {
return d.ctx.ConsumeWASMGas(d.fixedCost + dataSize*d.multiplier)
}