2020-01-20 12:31:12 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
2020-01-20 12:31:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// interopGasRatio is a multiplier by which a number returned from price getter
|
|
|
|
// and Fixed8 amount of GAS differ. Numbers defined in syscall tables are a multiple
|
|
|
|
// of 0.001 GAS = Fixed8(10^5).
|
|
|
|
const interopGasRatio = 100000
|
|
|
|
|
2020-06-09 09:23:14 +00:00
|
|
|
// StoragePrice is a price for storing 1 byte of storage.
|
|
|
|
const StoragePrice = 100000
|
|
|
|
|
2020-01-20 12:31:12 +00:00
|
|
|
// getPrice returns a price for executing op with the provided parameter.
|
|
|
|
// Some SYSCALLs have variable price depending on their arguments.
|
|
|
|
func getPrice(v *vm.VM, op opcode.Opcode, parameter []byte) util.Fixed8 {
|
2020-06-15 08:32:45 +00:00
|
|
|
if op == opcode.SYSCALL {
|
2020-01-20 12:31:12 +00:00
|
|
|
interopID := vm.GetInteropID(parameter)
|
2020-06-15 08:39:15 +00:00
|
|
|
ifunc := v.GetInteropByID(interopID)
|
|
|
|
if ifunc != nil && ifunc.Price > 0 {
|
|
|
|
return toFixed8(int64(ifunc.Price))
|
|
|
|
}
|
2020-01-20 12:31:12 +00:00
|
|
|
}
|
2020-06-15 08:32:45 +00:00
|
|
|
return opcodePrice(op)
|
2020-01-20 12:31:12 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 15:15:13 +00:00
|
|
|
func toFixed8(n int64) util.Fixed8 {
|
|
|
|
return util.Fixed8(n * interopGasRatio)
|
|
|
|
}
|