From 1e649bc9a0f0e5f335cc71d0757015588fad19e1 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 23 Mar 2021 13:49:27 +0300 Subject: [PATCH] core: move NotaryVerificationPrice to a separate package It is needed to avoid `native` dependency in RPC client. --- pkg/core/blockchain_test.go | 3 ++- pkg/core/native/nativeprices/prices.go | 4 ++++ pkg/core/native/notary.go | 6 ++---- pkg/rpc/client/rpc.go | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 pkg/core/native/nativeprices/prices.go diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 132d763a2..f5d77bfcf 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -21,6 +21,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" "github.com/nspcc-dev/neo-go/pkg/core/mempool" "github.com/nspcc-dev/neo-go/pkg/core/native" + "github.com/nspcc-dev/neo-go/pkg/core/native/nativeprices" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/storage" @@ -1031,7 +1032,7 @@ func TestVerifyTx(t *testing.T) { fee.Opcode(bc.GetBaseExecFee(), // Notary verification script opcode.PUSHDATA1, opcode.RET, // invocation script opcode.PUSH0, opcode.SYSCALL, opcode.RET) + // Neo.Native.Call - native.NotaryVerificationPrice*bc.GetBaseExecFee() // Notary witness verification price + nativeprices.NotaryVerificationPrice*bc.GetBaseExecFee() // Notary witness verification price tx.Scripts = []transaction.Witness{ { InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64, 64)...), diff --git a/pkg/core/native/nativeprices/prices.go b/pkg/core/native/nativeprices/prices.go new file mode 100644 index 000000000..a722c5239 --- /dev/null +++ b/pkg/core/native/nativeprices/prices.go @@ -0,0 +1,4 @@ +package nativeprices + +// NotaryVerificationPrice is the price of `verify` native Notary method. +const NotaryVerificationPrice = 1 << 15 diff --git a/pkg/core/native/notary.go b/pkg/core/native/notary.go index 70ae4468d..34beafc4d 100644 --- a/pkg/core/native/notary.go +++ b/pkg/core/native/notary.go @@ -12,6 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop/contract" "github.com/nspcc-dev/neo-go/pkg/core/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" + "github.com/nspcc-dev/neo-go/pkg/core/native/nativeprices" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/storage" @@ -41,9 +42,6 @@ type Notary struct { const ( notaryContractID = reservedContractID - 1 - // NotaryVerificationPrice is the price of `verify` Notary method. - NotaryVerificationPrice = 1 << 15 - // prefixDeposit is a prefix for storing Notary deposits. prefixDeposit = 1 defaultDepositDeltaTill = 5760 @@ -88,7 +86,7 @@ func newNotary() *Notary { desc = newDescriptor("verify", smartcontract.BoolType, manifest.NewParameter("signature", smartcontract.SignatureType)) - md = newMethodAndPrice(n.verify, NotaryVerificationPrice, callflag.ReadStates) + md = newMethodAndPrice(n.verify, nativeprices.NotaryVerificationPrice, callflag.ReadStates) n.AddMethod(md, desc) desc = newDescriptor("getMaxNotValidBeforeDelta", smartcontract.IntegerType) diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index a70a10242..dcec9177c 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -8,8 +8,8 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/fee" - "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" + "github.com/nspcc-dev/neo-go/pkg/core/native/nativeprices" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -693,7 +693,7 @@ func (c *Client) CalculateNotaryFee(nKeys uint8) (int64, error) { fee.Opcode(baseExecFee, // Notary node witness opcode.PUSHDATA1, opcode.RET, // invocation script opcode.PUSH0, opcode.SYSCALL, opcode.RET) + // System.Contract.CallNative - native.NotaryVerificationPrice*baseExecFee + // Notary witness verification price + nativeprices.NotaryVerificationPrice*baseExecFee + // Notary witness verification price feePerByte*int64(io.GetVarSize(make([]byte, 66))) + // invocation script per-byte fee feePerByte*int64(io.GetVarSize([]byte{})), // verification script per-byte fee nil