forked from TrueCloudLab/neoneo-go
*: switch from fixed8 to int64
Follow C# implementation, we have to marshall JSON Fixed8 fields without taking into account decimals.
This commit is contained in:
parent
8ad355b444
commit
73b630db9b
35 changed files with 146 additions and 155 deletions
|
@ -360,7 +360,7 @@ func transferNEP5(ctx *cli.Context) error {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := c.CreateNEP5TransferTx(acc, to, token.Hash, amount, gas)
|
tx, err := c.CreateNEP5TransferTx(acc, to, token.Hash, amount, int64(gas))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ func addSender(t *testing.T, txs ...*transaction.Transaction) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func signTx(t *testing.T, feePerByte util.Fixed8, txs ...*transaction.Transaction) {
|
func signTx(t *testing.T, feePerByte int64, txs ...*transaction.Transaction) {
|
||||||
validators := make([]*keys.PublicKey, 4)
|
validators := make([]*keys.PublicKey, 4)
|
||||||
privNetKeys := make([]*keys.PrivateKey, 4)
|
privNetKeys := make([]*keys.PrivateKey, 4)
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
|
@ -263,9 +263,9 @@ func signTx(t *testing.T, feePerByte util.Fixed8, txs ...*transaction.Transactio
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
size := io.GetVarSize(tx)
|
size := io.GetVarSize(tx)
|
||||||
netFee, sizeDelta := core.CalculateNetworkFee(rawScript)
|
netFee, sizeDelta := core.CalculateNetworkFee(rawScript)
|
||||||
tx.NetworkFee = tx.NetworkFee.Add(netFee)
|
tx.NetworkFee += +netFee
|
||||||
size += sizeDelta
|
size += sizeDelta
|
||||||
tx.NetworkFee = tx.NetworkFee.Add(util.Fixed8(int64(size) * int64(feePerByte)))
|
tx.NetworkFee += int64(size) * feePerByte
|
||||||
data := tx.GetSignedPart()
|
data := tx.GetSignedPart()
|
||||||
|
|
||||||
buf := io.NewBufBinWriter()
|
buf := io.NewBufBinWriter()
|
||||||
|
|
|
@ -788,23 +788,23 @@ func (bc *Blockchain) GetNEP5Balances(acc util.Uint160) *state.NEP5Balances {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUtilityTokenBalance returns utility token (GAS) balance for the acc.
|
// GetUtilityTokenBalance returns utility token (GAS) balance for the acc.
|
||||||
func (bc *Blockchain) GetUtilityTokenBalance(acc util.Uint160) util.Fixed8 {
|
func (bc *Blockchain) GetUtilityTokenBalance(acc util.Uint160) int64 {
|
||||||
bs, err := bc.dao.GetNEP5Balances(acc)
|
bs, err := bc.dao.GetNEP5Balances(acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return util.Fixed8(bs.Trackers[bc.contracts.GAS.Hash].Balance)
|
return bs.Trackers[bc.contracts.GAS.Hash].Balance
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGoverningTokenBalance returns governing token (NEO) balance and the height
|
// GetGoverningTokenBalance returns governing token (NEO) balance and the height
|
||||||
// of the last balance change for the account.
|
// of the last balance change for the account.
|
||||||
func (bc *Blockchain) GetGoverningTokenBalance(acc util.Uint160) (util.Fixed8, uint32) {
|
func (bc *Blockchain) GetGoverningTokenBalance(acc util.Uint160) (int64, uint32) {
|
||||||
bs, err := bc.dao.GetNEP5Balances(acc)
|
bs, err := bc.dao.GetNEP5Balances(acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
neo := bs.Trackers[bc.contracts.NEO.Hash]
|
neo := bs.Trackers[bc.contracts.NEO.Hash]
|
||||||
return util.Fixed8(neo.Balance), neo.LastUpdatedBlock
|
return neo.Balance, neo.LastUpdatedBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
// LastBatch returns last persisted storage batch.
|
// LastBatch returns last persisted storage batch.
|
||||||
|
@ -1092,8 +1092,8 @@ func (bc *Blockchain) CalculateClaimable(value int64, startHeight, endHeight uin
|
||||||
}
|
}
|
||||||
|
|
||||||
// FeePerByte returns transaction network fee per byte.
|
// FeePerByte returns transaction network fee per byte.
|
||||||
func (bc *Blockchain) FeePerByte() util.Fixed8 {
|
func (bc *Blockchain) FeePerByte() int64 {
|
||||||
return util.Fixed8(bc.contracts.Policy.GetFeePerByteInternal(bc.dao))
|
return bc.contracts.Policy.GetFeePerByteInternal(bc.dao)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMemPool returns the memory pool of the blockchain.
|
// GetMemPool returns the memory pool of the blockchain.
|
||||||
|
@ -1147,16 +1147,16 @@ func (bc *Blockchain) verifyTx(t *transaction.Transaction, block *block.Block) e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
balance := bc.GetUtilityTokenBalance(t.Sender)
|
balance := bc.GetUtilityTokenBalance(t.Sender)
|
||||||
need := t.SystemFee.Add(t.NetworkFee)
|
need := t.SystemFee + t.NetworkFee
|
||||||
if balance.LessThan(need) {
|
if balance < need {
|
||||||
return errors.Errorf("insufficient funds: balance is %v, need: %v", balance, need)
|
return errors.Errorf("insufficient funds: balance is %v, need: %v", balance, need)
|
||||||
}
|
}
|
||||||
size := io.GetVarSize(t)
|
size := io.GetVarSize(t)
|
||||||
if size > transaction.MaxTransactionSize {
|
if size > transaction.MaxTransactionSize {
|
||||||
return errors.Errorf("invalid transaction size = %d. It shoud be less then MaxTransactionSize = %d", io.GetVarSize(t), transaction.MaxTransactionSize)
|
return errors.Errorf("invalid transaction size = %d. It shoud be less then MaxTransactionSize = %d", io.GetVarSize(t), transaction.MaxTransactionSize)
|
||||||
}
|
}
|
||||||
needNetworkFee := util.Fixed8(int64(size) * int64(bc.FeePerByte()))
|
needNetworkFee := int64(size) * bc.FeePerByte()
|
||||||
netFee := t.NetworkFee.Sub(needNetworkFee)
|
netFee := t.NetworkFee - needNetworkFee
|
||||||
if netFee < 0 {
|
if netFee < 0 {
|
||||||
return errors.Errorf("insufficient funds: net fee is %v, need %v", t.NetworkFee, needNetworkFee)
|
return errors.Errorf("insufficient funds: net fee is %v, need %v", t.NetworkFee, needNetworkFee)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ type Blockchainer interface {
|
||||||
GetBlock(hash util.Uint256) (*block.Block, error)
|
GetBlock(hash util.Uint256) (*block.Block, error)
|
||||||
GetContractState(hash util.Uint160) *state.Contract
|
GetContractState(hash util.Uint160) *state.Contract
|
||||||
GetEnrollments() ([]state.Validator, error)
|
GetEnrollments() ([]state.Validator, error)
|
||||||
GetGoverningTokenBalance(acc util.Uint160) (util.Fixed8, uint32)
|
GetGoverningTokenBalance(acc util.Uint160) (int64, uint32)
|
||||||
GetHeaderHash(int) util.Uint256
|
GetHeaderHash(int) util.Uint256
|
||||||
GetHeader(hash util.Uint256) (*block.Header, error)
|
GetHeader(hash util.Uint256) (*block.Header, error)
|
||||||
CurrentHeaderHash() util.Uint256
|
CurrentHeaderHash() util.Uint256
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
)
|
)
|
||||||
|
@ -11,12 +10,12 @@ const StoragePrice = 100000
|
||||||
|
|
||||||
// getPrice returns a price for executing op with the provided parameter.
|
// getPrice returns a price for executing op with the provided parameter.
|
||||||
// Some SYSCALLs have variable price depending on their arguments.
|
// Some SYSCALLs have variable price depending on their arguments.
|
||||||
func getPrice(v *vm.VM, op opcode.Opcode, parameter []byte) util.Fixed8 {
|
func getPrice(v *vm.VM, op opcode.Opcode, parameter []byte) int64 {
|
||||||
if op == opcode.SYSCALL {
|
if op == opcode.SYSCALL {
|
||||||
interopID := vm.GetInteropID(parameter)
|
interopID := vm.GetInteropID(parameter)
|
||||||
ifunc := v.GetInteropByID(interopID)
|
ifunc := v.GetInteropByID(interopID)
|
||||||
if ifunc != nil && ifunc.Price > 0 {
|
if ifunc != nil && ifunc.Price > 0 {
|
||||||
return util.Fixed8(ifunc.Price)
|
return ifunc.Price
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return opcodePrice(op)
|
return opcodePrice(op)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
|
@ -180,7 +181,7 @@ func TestCreateBasicChain(t *testing.T) {
|
||||||
priv0 := testchain.PrivateKeyByID(0)
|
priv0 := testchain.PrivateKeyByID(0)
|
||||||
priv0ScriptHash := priv0.GetScriptHash()
|
priv0ScriptHash := priv0.GetScriptHash()
|
||||||
|
|
||||||
require.Equal(t, util.Fixed8FromInt64(0), bc.GetUtilityTokenBalance(priv0ScriptHash))
|
require.Equal(t, int64(0), bc.GetUtilityTokenBalance(priv0ScriptHash))
|
||||||
// Move some NEO to one simple account.
|
// Move some NEO to one simple account.
|
||||||
txMoveNeo := newNEP5Transfer(neoHash, neoOwner, priv0ScriptHash, neoAmount)
|
txMoveNeo := newNEP5Transfer(neoHash, neoOwner, priv0ScriptHash, neoAmount)
|
||||||
txMoveNeo.ValidUntilBlock = validUntilBlock
|
txMoveNeo.ValidUntilBlock = validUntilBlock
|
||||||
|
@ -210,7 +211,7 @@ func TestCreateBasicChain(t *testing.T) {
|
||||||
t.Logf("txMoveNeo: %s", txMoveNeo.Hash().StringLE())
|
t.Logf("txMoveNeo: %s", txMoveNeo.Hash().StringLE())
|
||||||
t.Logf("txMoveGas: %s", txMoveGas.Hash().StringLE())
|
t.Logf("txMoveGas: %s", txMoveGas.Hash().StringLE())
|
||||||
|
|
||||||
require.True(t, util.Fixed8FromInt64(1000).CompareTo(bc.GetUtilityTokenBalance(priv0ScriptHash)) <= 0)
|
require.True(t, bc.GetUtilityTokenBalance(priv0ScriptHash) >= 1000*native.GASFactor)
|
||||||
// info for getblockheader rpc tests
|
// info for getblockheader rpc tests
|
||||||
t.Logf("header hash: %s", b.Hash().StringLE())
|
t.Logf("header hash: %s", b.Hash().StringLE())
|
||||||
buf := io.NewBufBinWriter()
|
buf := io.NewBufBinWriter()
|
||||||
|
@ -241,8 +242,7 @@ func TestCreateBasicChain(t *testing.T) {
|
||||||
emit.Syscall(script.BinWriter, "System.Contract.Create")
|
emit.Syscall(script.BinWriter, "System.Contract.Create")
|
||||||
txScript := script.Bytes()
|
txScript := script.Bytes()
|
||||||
|
|
||||||
invFee := util.Fixed8FromFloat(100)
|
txDeploy := transaction.New(testchain.Network(), txScript, 100*native.GASFactor)
|
||||||
txDeploy := transaction.New(testchain.Network(), txScript, invFee)
|
|
||||||
txDeploy.Nonce = getNextNonce()
|
txDeploy.Nonce = getNextNonce()
|
||||||
txDeploy.ValidUntilBlock = validUntilBlock
|
txDeploy.ValidUntilBlock = validUntilBlock
|
||||||
txDeploy.Sender = priv0ScriptHash
|
txDeploy.Sender = priv0ScriptHash
|
||||||
|
@ -407,9 +407,9 @@ func signTx(bc *Blockchain, txs ...*transaction.Transaction) error {
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
size := io.GetVarSize(tx)
|
size := io.GetVarSize(tx)
|
||||||
netFee, sizeDelta := CalculateNetworkFee(rawScript)
|
netFee, sizeDelta := CalculateNetworkFee(rawScript)
|
||||||
tx.NetworkFee = tx.NetworkFee.Add(netFee)
|
tx.NetworkFee += netFee
|
||||||
size += sizeDelta
|
size += sizeDelta
|
||||||
tx.NetworkFee = tx.NetworkFee.Add(util.Fixed8(int64(size) * int64(bc.FeePerByte())))
|
tx.NetworkFee += int64(size) * bc.FeePerByte()
|
||||||
data := tx.GetSignedPart()
|
data := tx.GetSignedPart()
|
||||||
tx.Scripts = []transaction.Witness{{
|
tx.Scripts = []transaction.Witness{{
|
||||||
InvocationScript: testchain.Sign(data),
|
InvocationScript: testchain.Sign(data),
|
||||||
|
@ -432,6 +432,6 @@ func addNetworkFee(bc *Blockchain, tx *transaction.Transaction, sender *wallet.A
|
||||||
size += sizeDelta
|
size += sizeDelta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.NetworkFee += util.Fixed8(int64(size) * int64(bc.FeePerByte()))
|
tx.NetworkFee += int64(size) * bc.FeePerByte()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ type Function struct {
|
||||||
ID uint32
|
ID uint32
|
||||||
Name string
|
Name string
|
||||||
Func func(*Context, *vm.VM) error
|
Func func(*Context, *vm.VM) error
|
||||||
Price int
|
Price int64
|
||||||
// AllowedTriggers is a set of triggers which are allowed to initiate invocation.
|
// AllowedTriggers is a set of triggers which are allowed to initiate invocation.
|
||||||
AllowedTriggers trigger.Type
|
AllowedTriggers trigger.Type
|
||||||
// RequiredFlags is a set of flags which must be set during script invocations.
|
// RequiredFlags is a set of flags which must be set during script invocations.
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto"
|
"github.com/nspcc-dev/neo-go/pkg/crypto"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
)
|
)
|
||||||
|
@ -39,7 +38,7 @@ func ECDSACheckMultisig(ic *interop.Context, v *vm.VM) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("wrong parameters: %s", err.Error())
|
return fmt.Errorf("wrong parameters: %s", err.Error())
|
||||||
}
|
}
|
||||||
if !v.AddGas(util.Fixed8(ECDSAVerifyPrice * len(pkeys))) {
|
if !v.AddGas(ECDSAVerifyPrice * int64(len(pkeys))) {
|
||||||
return errors.New("gas limit exceeded")
|
return errors.New("gas limit exceeded")
|
||||||
}
|
}
|
||||||
sigs, err := v.Estack().PopSigElements()
|
sigs, err := v.Estack().PopSigElements()
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
// GasLeft returns remaining amount of GAS.
|
// GasLeft returns remaining amount of GAS.
|
||||||
func GasLeft(_ *interop.Context, v *vm.VM) error {
|
func GasLeft(_ *interop.Context, v *vm.VM) error {
|
||||||
v.Estack().PushVal(int64(v.GasLimit - v.GasConsumed()))
|
v.Estack().PushVal(v.GasLimit - v.GasConsumed())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
)
|
)
|
||||||
|
@ -67,7 +66,7 @@ func createContractStateFromVM(ic *interop.Context, v *vm.VM) (*state.Contract,
|
||||||
if len(manifestBytes) > manifest.MaxManifestSize {
|
if len(manifestBytes) > manifest.MaxManifestSize {
|
||||||
return nil, errors.New("manifest is too big")
|
return nil, errors.New("manifest is too big")
|
||||||
}
|
}
|
||||||
if !v.AddGas(util.Fixed8(StoragePrice * (len(script) + len(manifestBytes)))) {
|
if !v.AddGas(int64(StoragePrice * (len(script) + len(manifestBytes)))) {
|
||||||
return nil, errGasLimitExceeded
|
return nil, errGasLimitExceeded
|
||||||
}
|
}
|
||||||
var m manifest.Manifest
|
var m manifest.Manifest
|
||||||
|
|
|
@ -346,7 +346,7 @@ func putWithContextAndFlags(ic *interop.Context, v *vm.VM, stc *StorageContext,
|
||||||
if len(value) > len(si.Value) {
|
if len(value) > len(si.Value) {
|
||||||
sizeInc = len(value) - len(si.Value)
|
sizeInc = len(value) - len(si.Value)
|
||||||
}
|
}
|
||||||
if !v.AddGas(util.Fixed8(sizeInc) * StoragePrice) {
|
if !v.AddGas(int64(sizeInc) * StoragePrice) {
|
||||||
return errGasLimitExceeded
|
return errGasLimitExceeded
|
||||||
}
|
}
|
||||||
si.Value = value
|
si.Value = value
|
||||||
|
|
|
@ -6,6 +6,6 @@ import (
|
||||||
|
|
||||||
// Feer is an interface that abstract the implementation of the fee calculation.
|
// Feer is an interface that abstract the implementation of the fee calculation.
|
||||||
type Feer interface {
|
type Feer interface {
|
||||||
FeePerByte() util.Fixed8
|
FeePerByte() int64
|
||||||
GetUtilityTokenBalance(util.Uint160) util.Fixed8
|
GetUtilityTokenBalance(util.Uint160) int64
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,8 @@ type items []*item
|
||||||
// utilityBalanceAndFees stores sender's balance and overall fees of
|
// utilityBalanceAndFees stores sender's balance and overall fees of
|
||||||
// sender's transactions which are currently in mempool
|
// sender's transactions which are currently in mempool
|
||||||
type utilityBalanceAndFees struct {
|
type utilityBalanceAndFees struct {
|
||||||
balance util.Fixed8
|
balance int64
|
||||||
feeSum util.Fixed8
|
feeSum int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pool stores the unconfirms transactions.
|
// Pool stores the unconfirms transactions.
|
||||||
|
@ -47,7 +47,7 @@ type Pool struct {
|
||||||
fees map[util.Uint160]utilityBalanceAndFees
|
fees map[util.Uint160]utilityBalanceAndFees
|
||||||
|
|
||||||
capacity int
|
capacity int
|
||||||
feePerByte util.Fixed8
|
feePerByte int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p items) Len() int { return len(p) }
|
func (p items) Len() int { return len(p) }
|
||||||
|
@ -64,11 +64,11 @@ func (p *item) CompareTo(otherP *item) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fees sorted ascending.
|
// Fees sorted ascending.
|
||||||
if ret := p.txn.FeePerByte().CompareTo(otherP.txn.FeePerByte()); ret != 0 {
|
if ret := int(p.txn.FeePerByte() - otherP.txn.FeePerByte()); ret != 0 {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
if ret := p.txn.NetworkFee.CompareTo(otherP.txn.NetworkFee); ret != 0 {
|
if ret := int(p.txn.NetworkFee - otherP.txn.NetworkFee); ret != 0 {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ func (mp *Pool) RemoveStale(isOK func(*transaction.Transaction) bool, feer Feer)
|
||||||
// changed.
|
// changed.
|
||||||
func (mp *Pool) loadPolicy(feer Feer) bool {
|
func (mp *Pool) loadPolicy(feer Feer) bool {
|
||||||
newFeePerByte := feer.FeePerByte()
|
newFeePerByte := feer.FeePerByte()
|
||||||
if newFeePerByte.GreaterThan(mp.feePerByte) {
|
if newFeePerByte > mp.feePerByte {
|
||||||
mp.feePerByte = newFeePerByte
|
mp.feePerByte = newFeePerByte
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type FeerStub struct {
|
type FeerStub struct {
|
||||||
feePerByte util.Fixed8
|
feePerByte int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FeerStub) FeePerByte() util.Fixed8 {
|
const balance = 10000000
|
||||||
|
|
||||||
|
func (fs *FeerStub) FeePerByte() int64 {
|
||||||
return fs.feePerByte
|
return fs.feePerByte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FeerStub) GetUtilityTokenBalance(uint160 util.Uint160) util.Fixed8 {
|
func (fs *FeerStub) GetUtilityTokenBalance(uint160 util.Uint160) int64 {
|
||||||
return util.Fixed8FromInt64(10000)
|
return balance
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) {
|
func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) {
|
||||||
|
@ -70,10 +72,10 @@ func TestOverCapacity(t *testing.T) {
|
||||||
Usage: transaction.Hash1,
|
Usage: transaction.Hash1,
|
||||||
Data: util.Uint256{1, 2, 3, 4}.BytesBE(),
|
Data: util.Uint256{1, 2, 3, 4}.BytesBE(),
|
||||||
})
|
})
|
||||||
tx.NetworkFee = util.Fixed8FromFloat(0.0001)
|
tx.NetworkFee = 10000
|
||||||
tx.Nonce = txcnt
|
tx.Nonce = txcnt
|
||||||
txcnt++
|
txcnt++
|
||||||
// size is 84, networkFee is 0.0001 => feePerByte is 0.00000119
|
// size is 84, networkFee is 10000 => feePerByte is 119
|
||||||
require.NoError(t, mp.Add(tx, fs))
|
require.NoError(t, mp.Add(tx, fs))
|
||||||
require.Equal(t, mempoolSize, mp.Count())
|
require.Equal(t, mempoolSize, mp.Count())
|
||||||
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
|
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
|
||||||
|
@ -84,7 +86,7 @@ func TestOverCapacity(t *testing.T) {
|
||||||
Usage: transaction.Hash1,
|
Usage: transaction.Hash1,
|
||||||
Data: util.Uint256{1, 2, 3, 4}.BytesBE(),
|
Data: util.Uint256{1, 2, 3, 4}.BytesBE(),
|
||||||
})
|
})
|
||||||
tx.NetworkFee = util.Fixed8FromFloat(0.000001)
|
tx.NetworkFee = 100
|
||||||
tx.Nonce = txcnt
|
tx.Nonce = txcnt
|
||||||
txcnt++
|
txcnt++
|
||||||
require.Error(t, mp.Add(tx, fs))
|
require.Error(t, mp.Add(tx, fs))
|
||||||
|
@ -94,10 +96,10 @@ func TestOverCapacity(t *testing.T) {
|
||||||
// Low net fee, but higher per-byte fee is still a better combination.
|
// Low net fee, but higher per-byte fee is still a better combination.
|
||||||
tx = transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
tx = transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
||||||
tx.Nonce = txcnt
|
tx.Nonce = txcnt
|
||||||
tx.NetworkFee = util.Fixed8FromFloat(0.00007)
|
tx.NetworkFee = 7000
|
||||||
txcnt++
|
txcnt++
|
||||||
// size is 51 (no attributes), networkFee is 0.00007 (<0.0001)
|
// size is 51 (no attributes), networkFee is 7000 (<10000)
|
||||||
// => feePerByte is 0.00000137 (>0.00000119)
|
// => feePerByte is 137 (>119)
|
||||||
require.NoError(t, mp.Add(tx, fs))
|
require.NoError(t, mp.Add(tx, fs))
|
||||||
require.Equal(t, mempoolSize, mp.Count())
|
require.Equal(t, mempoolSize, mp.Count())
|
||||||
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
|
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
|
||||||
|
@ -105,7 +107,7 @@ func TestOverCapacity(t *testing.T) {
|
||||||
// High priority always wins over low priority.
|
// High priority always wins over low priority.
|
||||||
for i := 0; i < mempoolSize; i++ {
|
for i := 0; i < mempoolSize; i++ {
|
||||||
tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
||||||
tx.NetworkFee = util.Fixed8FromFloat(0.00008)
|
tx.NetworkFee = 8000
|
||||||
tx.Nonce = txcnt
|
tx.Nonce = txcnt
|
||||||
txcnt++
|
txcnt++
|
||||||
require.NoError(t, mp.Add(tx, fs))
|
require.NoError(t, mp.Add(tx, fs))
|
||||||
|
@ -115,7 +117,7 @@ func TestOverCapacity(t *testing.T) {
|
||||||
// Good luck with low priority now.
|
// Good luck with low priority now.
|
||||||
tx = transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
tx = transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
||||||
tx.Nonce = txcnt
|
tx.Nonce = txcnt
|
||||||
tx.NetworkFee = util.Fixed8FromFloat(0.00007)
|
tx.NetworkFee = 7000
|
||||||
require.Error(t, mp.Add(tx, fs))
|
require.Error(t, mp.Add(tx, fs))
|
||||||
require.Equal(t, mempoolSize, mp.Count())
|
require.Equal(t, mempoolSize, mp.Count())
|
||||||
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
|
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
|
||||||
|
@ -182,50 +184,50 @@ func TestMemPoolFees(t *testing.T) {
|
||||||
mp := NewMemPool(10)
|
mp := NewMemPool(10)
|
||||||
sender0 := util.Uint160{1, 2, 3}
|
sender0 := util.Uint160{1, 2, 3}
|
||||||
tx0 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
tx0 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
||||||
tx0.NetworkFee = util.Fixed8FromInt64(11000)
|
tx0.NetworkFee = balance + 1
|
||||||
tx0.Sender = sender0
|
tx0.Sender = sender0
|
||||||
// insufficient funds to add transaction, but balance should be stored
|
// insufficient funds to add transaction, but balance should be stored
|
||||||
require.Equal(t, false, mp.Verify(tx0, &FeerStub{}))
|
require.Equal(t, false, mp.Verify(tx0, &FeerStub{}))
|
||||||
require.Error(t, mp.Add(tx0, &FeerStub{}))
|
require.Error(t, mp.Add(tx0, &FeerStub{}))
|
||||||
require.Equal(t, 1, len(mp.fees))
|
require.Equal(t, 1, len(mp.fees))
|
||||||
require.Equal(t, utilityBalanceAndFees{
|
require.Equal(t, utilityBalanceAndFees{
|
||||||
balance: util.Fixed8FromInt64(10000),
|
balance: balance,
|
||||||
feeSum: 0,
|
feeSum: 0,
|
||||||
}, mp.fees[sender0])
|
}, mp.fees[sender0])
|
||||||
|
|
||||||
// no problems with adding another transaction with lower fee
|
// no problems with adding another transaction with lower fee
|
||||||
tx1 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
tx1 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
||||||
tx1.NetworkFee = util.Fixed8FromInt64(7000)
|
tx1.NetworkFee = balance * 0.7
|
||||||
tx1.Sender = sender0
|
tx1.Sender = sender0
|
||||||
require.NoError(t, mp.Add(tx1, &FeerStub{}))
|
require.NoError(t, mp.Add(tx1, &FeerStub{}))
|
||||||
require.Equal(t, 1, len(mp.fees))
|
require.Equal(t, 1, len(mp.fees))
|
||||||
require.Equal(t, utilityBalanceAndFees{
|
require.Equal(t, utilityBalanceAndFees{
|
||||||
balance: util.Fixed8FromInt64(10000),
|
balance: balance,
|
||||||
feeSum: util.Fixed8FromInt64(7000),
|
feeSum: tx1.NetworkFee,
|
||||||
}, mp.fees[sender0])
|
}, mp.fees[sender0])
|
||||||
|
|
||||||
// balance shouldn't change after adding one more transaction
|
// balance shouldn't change after adding one more transaction
|
||||||
tx2 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
tx2 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
||||||
tx2.NetworkFee = util.Fixed8FromFloat(3000)
|
tx2.NetworkFee = balance * 0.3
|
||||||
tx2.Sender = sender0
|
tx2.Sender = sender0
|
||||||
require.NoError(t, mp.Add(tx2, &FeerStub{}))
|
require.NoError(t, mp.Add(tx2, &FeerStub{}))
|
||||||
require.Equal(t, 2, len(mp.verifiedTxes))
|
require.Equal(t, 2, len(mp.verifiedTxes))
|
||||||
require.Equal(t, 1, len(mp.fees))
|
require.Equal(t, 1, len(mp.fees))
|
||||||
require.Equal(t, utilityBalanceAndFees{
|
require.Equal(t, utilityBalanceAndFees{
|
||||||
balance: util.Fixed8FromInt64(10000),
|
balance: balance,
|
||||||
feeSum: util.Fixed8FromInt64(10000),
|
feeSum: balance,
|
||||||
}, mp.fees[sender0])
|
}, mp.fees[sender0])
|
||||||
|
|
||||||
// can't add more transactions as we don't have enough GAS
|
// can't add more transactions as we don't have enough GAS
|
||||||
tx3 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
tx3 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
|
||||||
tx3.NetworkFee = util.Fixed8FromFloat(0.5)
|
tx3.NetworkFee = 1
|
||||||
tx3.Sender = sender0
|
tx3.Sender = sender0
|
||||||
require.Equal(t, false, mp.Verify(tx3, &FeerStub{}))
|
require.Equal(t, false, mp.Verify(tx3, &FeerStub{}))
|
||||||
require.Error(t, mp.Add(tx3, &FeerStub{}))
|
require.Error(t, mp.Add(tx3, &FeerStub{}))
|
||||||
require.Equal(t, 1, len(mp.fees))
|
require.Equal(t, 1, len(mp.fees))
|
||||||
require.Equal(t, utilityBalanceAndFees{
|
require.Equal(t, utilityBalanceAndFees{
|
||||||
balance: util.Fixed8FromInt64(10000),
|
balance: balance,
|
||||||
feeSum: util.Fixed8FromInt64(10000),
|
feeSum: balance,
|
||||||
}, mp.fees[sender0])
|
}, mp.fees[sender0])
|
||||||
|
|
||||||
// check whether sender's fee updates correctly
|
// check whether sender's fee updates correctly
|
||||||
|
@ -237,8 +239,8 @@ func TestMemPoolFees(t *testing.T) {
|
||||||
}, &FeerStub{})
|
}, &FeerStub{})
|
||||||
require.Equal(t, 1, len(mp.fees))
|
require.Equal(t, 1, len(mp.fees))
|
||||||
require.Equal(t, utilityBalanceAndFees{
|
require.Equal(t, utilityBalanceAndFees{
|
||||||
balance: util.Fixed8FromInt64(10000),
|
balance: balance,
|
||||||
feeSum: util.Fixed8FromFloat(3000),
|
feeSum: tx2.NetworkFee,
|
||||||
}, mp.fees[sender0])
|
}, mp.fees[sender0])
|
||||||
|
|
||||||
// there should be nothing left
|
// there should be nothing left
|
||||||
|
|
|
@ -108,7 +108,7 @@ func getNativeInterop(ic *interop.Context, c interop.Contract) func(v *vm.VM) er
|
||||||
if !v.Context().GetCallFlags().Has(m.RequiredFlags) {
|
if !v.Context().GetCallFlags().Has(m.RequiredFlags) {
|
||||||
return errors.New("missing call flags")
|
return errors.New("missing call flags")
|
||||||
}
|
}
|
||||||
if !v.AddGas(util.Fixed8(m.Price)) {
|
if !v.AddGas(m.Price) {
|
||||||
return errors.New("gas limit exceeded")
|
return errors.New("gas limit exceeded")
|
||||||
}
|
}
|
||||||
result := m.Func(ic, args)
|
result := m.Func(ic, args)
|
||||||
|
|
|
@ -88,7 +88,7 @@ func (g *GAS) OnPersist(ic *interop.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, tx := range ic.Block.Transactions {
|
for _, tx := range ic.Block.Transactions {
|
||||||
absAmount := big.NewInt(int64(tx.SystemFee + tx.NetworkFee))
|
absAmount := big.NewInt(tx.SystemFee + tx.NetworkFee)
|
||||||
g.burn(ic, tx.Sender, absAmount)
|
g.burn(ic, tx.Sender, absAmount)
|
||||||
}
|
}
|
||||||
validators, err := g.NEO.getNextBlockValidatorsInternal(ic.Chain, ic.DAO)
|
validators, err := g.NEO.getNextBlockValidatorsInternal(ic.Chain, ic.DAO)
|
||||||
|
@ -96,7 +96,7 @@ func (g *GAS) OnPersist(ic *interop.Context) error {
|
||||||
return fmt.Errorf("cannot get block validators: %v", err)
|
return fmt.Errorf("cannot get block validators: %v", err)
|
||||||
}
|
}
|
||||||
primary := validators[ic.Block.ConsensusData.PrimaryIndex].GetScriptHash()
|
primary := validators[ic.Block.ConsensusData.PrimaryIndex].GetScriptHash()
|
||||||
var netFee util.Fixed8
|
var netFee int64
|
||||||
for _, tx := range ic.Block.Transactions {
|
for _, tx := range ic.Block.Transactions {
|
||||||
netFee += tx.NetworkFee
|
netFee += tx.NetworkFee
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// opcodePrice returns the deployment prices of specified opcodes
|
// opcodePrice returns the deployment prices of specified opcodes
|
||||||
func opcodePrice(opcodes ...opcode.Opcode) util.Fixed8 {
|
func opcodePrice(opcodes ...opcode.Opcode) int64 {
|
||||||
var result util.Fixed8
|
var result int64
|
||||||
for _, op := range opcodes {
|
for _, op := range opcodes {
|
||||||
result += util.Fixed8(prices[op])
|
result += prices[op]
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
var prices = map[opcode.Opcode]int{
|
var prices = map[opcode.Opcode]int64{
|
||||||
opcode.PUSHINT8: 30,
|
opcode.PUSHINT8: 30,
|
||||||
opcode.PUSHINT32: 30,
|
opcode.PUSHINT32: 30,
|
||||||
opcode.PUSHINT64: 30,
|
opcode.PUSHINT64: 30,
|
||||||
|
|
|
@ -21,7 +21,7 @@ type AppExecResult struct {
|
||||||
TxHash util.Uint256
|
TxHash util.Uint256
|
||||||
Trigger trigger.Type
|
Trigger trigger.Type
|
||||||
VMState string
|
VMState string
|
||||||
GasConsumed util.Fixed8
|
GasConsumed int64
|
||||||
Stack []smartcontract.Parameter
|
Stack []smartcontract.Parameter
|
||||||
Events []NotificationEvent
|
Events []NotificationEvent
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func (aer *AppExecResult) EncodeBinary(w *io.BinWriter) {
|
||||||
w.WriteBytes(aer.TxHash[:])
|
w.WriteBytes(aer.TxHash[:])
|
||||||
w.WriteB(byte(aer.Trigger))
|
w.WriteB(byte(aer.Trigger))
|
||||||
w.WriteString(aer.VMState)
|
w.WriteString(aer.VMState)
|
||||||
aer.GasConsumed.EncodeBinary(w)
|
w.WriteU64LE(uint64(aer.GasConsumed))
|
||||||
w.WriteArray(aer.Stack)
|
w.WriteArray(aer.Stack)
|
||||||
w.WriteArray(aer.Events)
|
w.WriteArray(aer.Events)
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func (aer *AppExecResult) DecodeBinary(r *io.BinReader) {
|
||||||
r.ReadBytes(aer.TxHash[:])
|
r.ReadBytes(aer.TxHash[:])
|
||||||
aer.Trigger = trigger.Type(r.ReadB())
|
aer.Trigger = trigger.Type(r.ReadB())
|
||||||
aer.VMState = r.ReadString()
|
aer.VMState = r.ReadString()
|
||||||
aer.GasConsumed.DecodeBinary(r)
|
aer.GasConsumed = int64(r.ReadU64LE())
|
||||||
r.ReadArray(&aer.Stack)
|
r.ReadArray(&aer.Stack)
|
||||||
r.ReadArray(&aer.Events)
|
r.ReadArray(&aer.Events)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ type Transaction struct {
|
||||||
Sender util.Uint160
|
Sender util.Uint160
|
||||||
|
|
||||||
// Fee to be burned.
|
// Fee to be burned.
|
||||||
SystemFee util.Fixed8
|
SystemFee int64
|
||||||
|
|
||||||
// Fee to be distributed to consensus nodes.
|
// Fee to be distributed to consensus nodes.
|
||||||
NetworkFee util.Fixed8
|
NetworkFee int64
|
||||||
|
|
||||||
// Maximum blockchain height exceeding which
|
// Maximum blockchain height exceeding which
|
||||||
// transaction should fail verification.
|
// transaction should fail verification.
|
||||||
|
@ -86,7 +86,7 @@ func NewTrimmedTX(hash util.Uint256) *Transaction {
|
||||||
|
|
||||||
// New returns a new transaction to execute given script and pay given system
|
// New returns a new transaction to execute given script and pay given system
|
||||||
// fee.
|
// fee.
|
||||||
func New(network netmode.Magic, script []byte, gas util.Fixed8) *Transaction {
|
func New(network netmode.Magic, script []byte, gas int64) *Transaction {
|
||||||
return &Transaction{
|
return &Transaction{
|
||||||
Version: 0,
|
Version: 0,
|
||||||
Nonce: rand.Uint32(),
|
Nonce: rand.Uint32(),
|
||||||
|
@ -129,12 +129,12 @@ func (t *Transaction) decodeHashableFields(br *io.BinReader) {
|
||||||
}
|
}
|
||||||
t.Nonce = br.ReadU32LE()
|
t.Nonce = br.ReadU32LE()
|
||||||
t.Sender.DecodeBinary(br)
|
t.Sender.DecodeBinary(br)
|
||||||
t.SystemFee.DecodeBinary(br)
|
t.SystemFee = int64(br.ReadU64LE())
|
||||||
if t.SystemFee < 0 {
|
if t.SystemFee < 0 {
|
||||||
br.Err = errors.New("negative system fee")
|
br.Err = errors.New("negative system fee")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.NetworkFee.DecodeBinary(br)
|
t.NetworkFee = int64(br.ReadU64LE())
|
||||||
if t.NetworkFee < 0 {
|
if t.NetworkFee < 0 {
|
||||||
br.Err = errors.New("negative network fee")
|
br.Err = errors.New("negative network fee")
|
||||||
return
|
return
|
||||||
|
@ -195,8 +195,8 @@ func (t *Transaction) encodeHashableFields(bw *io.BinWriter) {
|
||||||
bw.WriteB(byte(t.Version))
|
bw.WriteB(byte(t.Version))
|
||||||
bw.WriteU32LE(t.Nonce)
|
bw.WriteU32LE(t.Nonce)
|
||||||
t.Sender.EncodeBinary(bw)
|
t.Sender.EncodeBinary(bw)
|
||||||
t.SystemFee.EncodeBinary(bw)
|
bw.WriteU64LE(uint64(t.SystemFee))
|
||||||
t.NetworkFee.EncodeBinary(bw)
|
bw.WriteU64LE(uint64(t.NetworkFee))
|
||||||
bw.WriteU32LE(t.ValidUntilBlock)
|
bw.WriteU32LE(t.ValidUntilBlock)
|
||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
|
@ -277,8 +277,8 @@ func NewTransactionFromBytes(network netmode.Magic, b []byte) (*Transaction, err
|
||||||
|
|
||||||
// FeePerByte returns NetworkFee of the transaction divided by
|
// FeePerByte returns NetworkFee of the transaction divided by
|
||||||
// its size
|
// its size
|
||||||
func (t *Transaction) FeePerByte() util.Fixed8 {
|
func (t *Transaction) FeePerByte() int64 {
|
||||||
return util.Fixed8(int64(t.NetworkFee) / int64(io.GetVarSize(t)))
|
return t.NetworkFee / int64(io.GetVarSize(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
// transactionJSON is a wrapper for Transaction and
|
// transactionJSON is a wrapper for Transaction and
|
||||||
|
@ -289,8 +289,8 @@ type transactionJSON struct {
|
||||||
Version uint8 `json:"version"`
|
Version uint8 `json:"version"`
|
||||||
Nonce uint32 `json:"nonce"`
|
Nonce uint32 `json:"nonce"`
|
||||||
Sender string `json:"sender"`
|
Sender string `json:"sender"`
|
||||||
SystemFee util.Fixed8 `json:"sys_fee"`
|
SystemFee int64 `json:"sys_fee,string"`
|
||||||
NetworkFee util.Fixed8 `json:"net_fee"`
|
NetworkFee int64 `json:"net_fee,string"`
|
||||||
ValidUntilBlock uint32 `json:"valid_until_block"`
|
ValidUntilBlock uint32 `json:"valid_until_block"`
|
||||||
Attributes []Attribute `json:"attributes"`
|
Attributes []Attribute `json:"attributes"`
|
||||||
Cosigners []Cosigner `json:"cosigners"`
|
Cosigners []Cosigner `json:"cosigners"`
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -65,7 +64,7 @@ func TestDecodeEncodeInvocationTX(t *testing.T) {
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
script := []byte{0x51}
|
script := []byte{0x51}
|
||||||
tx := New(netmode.UnitTestNet, script, 1)
|
tx := New(netmode.UnitTestNet, script, 1)
|
||||||
assert.Equal(t, util.Fixed8(1), tx.SystemFee)
|
assert.Equal(t, int64(1), tx.SystemFee)
|
||||||
assert.Equal(t, script, tx.Script)
|
assert.Equal(t, script, tx.Script)
|
||||||
// Update hash fields to match tx2 that is gonna autoupdate them on decode.
|
// Update hash fields to match tx2 that is gonna autoupdate them on decode.
|
||||||
_ = tx.Hash()
|
_ = tx.Hash()
|
||||||
|
|
|
@ -17,6 +17,10 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ecdsaVerifyInteropPrice returns the price of Neo.Crypto.ECDsaVerify
|
||||||
|
// syscall to calculate NetworkFee for transaction
|
||||||
|
const ecdsaVerifyInteropPrice = 100000
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// governingTokenTX represents transaction that is used to create
|
// governingTokenTX represents transaction that is used to create
|
||||||
// governing (NEO) token. It's a part of the genesis block.
|
// governing (NEO) token. It's a part of the genesis block.
|
||||||
|
@ -26,10 +30,6 @@ var (
|
||||||
// utility (GAS) token. It's a part of the genesis block. It's mostly
|
// utility (GAS) token. It's a part of the genesis block. It's mostly
|
||||||
// useful for its hash that represents GAS asset ID.
|
// useful for its hash that represents GAS asset ID.
|
||||||
utilityTokenTX transaction.Transaction
|
utilityTokenTX transaction.Transaction
|
||||||
|
|
||||||
// ecdsaVerifyInteropPrice returns the price of Neo.Crypto.ECDsaVerify
|
|
||||||
// syscall to calculate NetworkFee for transaction
|
|
||||||
ecdsaVerifyInteropPrice = util.Fixed8(100000)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// createGenesisBlock creates a genesis block based on the given configuration.
|
// createGenesisBlock creates a genesis block based on the given configuration.
|
||||||
|
@ -131,31 +131,31 @@ func headerSliceReverse(dest []*block.Header) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CalculateNetworkFee returns network fee for transaction
|
// CalculateNetworkFee returns network fee for transaction
|
||||||
func CalculateNetworkFee(script []byte) (util.Fixed8, int) {
|
func CalculateNetworkFee(script []byte) (int64, int) {
|
||||||
var (
|
var (
|
||||||
netFee util.Fixed8
|
netFee int64
|
||||||
size int
|
size int
|
||||||
)
|
)
|
||||||
if vm.IsSignatureContract(script) {
|
if vm.IsSignatureContract(script) {
|
||||||
size += 67 + io.GetVarSize(script)
|
size += 67 + io.GetVarSize(script)
|
||||||
netFee = netFee.Add(opcodePrice(opcode.PUSHDATA1, opcode.PUSHNULL).Add(ecdsaVerifyInteropPrice))
|
netFee += opcodePrice(opcode.PUSHDATA1, opcode.PUSHNULL) + ecdsaVerifyInteropPrice
|
||||||
} else if n, pubs, ok := vm.ParseMultiSigContract(script); ok {
|
} else if n, pubs, ok := vm.ParseMultiSigContract(script); ok {
|
||||||
m := len(pubs)
|
m := len(pubs)
|
||||||
sizeInv := 66 * m
|
sizeInv := 66 * m
|
||||||
size += io.GetVarSize(sizeInv) + sizeInv + io.GetVarSize(script)
|
size += io.GetVarSize(sizeInv) + sizeInv + io.GetVarSize(script)
|
||||||
netFee = netFee.Add(calculateMultisigFee(m)).Add(calculateMultisigFee(n))
|
netFee += calculateMultisigFee(m) + calculateMultisigFee(n)
|
||||||
netFee = netFee.Add(opcodePrice(opcode.PUSHNULL)).Add(util.Fixed8(int64(ecdsaVerifyInteropPrice) * int64(n)))
|
netFee += opcodePrice(opcode.PUSHNULL) + ecdsaVerifyInteropPrice*int64(n)
|
||||||
} else {
|
} else {
|
||||||
// We can support more contract types in the future.
|
// We can support more contract types in the future.
|
||||||
}
|
}
|
||||||
return netFee, size
|
return netFee, size
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateMultisigFee(n int) util.Fixed8 {
|
func calculateMultisigFee(n int) int64 {
|
||||||
result := util.Fixed8(int64(opcodePrice(opcode.PUSHDATA1)) * int64(n))
|
result := opcodePrice(opcode.PUSHDATA1) * int64(n)
|
||||||
bw := io.NewBufBinWriter()
|
bw := io.NewBufBinWriter()
|
||||||
emit.Int(bw.BinWriter, int64(n))
|
emit.Int(bw.BinWriter, int64(n))
|
||||||
// it's a hack because prices of small PUSH* opcodes are equal
|
// it's a hack because prices of small PUSH* opcodes are equal
|
||||||
result = result.Add(opcodePrice(opcode.Opcode(bw.Bytes()[0])))
|
result += opcodePrice(opcode.Opcode(bw.Bytes()[0]))
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (chain testChain) CalculateClaimable(int64, uint32, uint32) util.Fixed8 {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (chain testChain) FeePerByte() util.Fixed8 {
|
func (chain testChain) FeePerByte() int64 {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,11 +123,11 @@ func (chain testChain) GetMemPool() *mempool.Pool {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (chain testChain) GetGoverningTokenBalance(acc util.Uint160) (util.Fixed8, uint32) {
|
func (chain testChain) GetGoverningTokenBalance(acc util.Uint160) (int64, uint32) {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (chain testChain) GetUtilityTokenBalance(uint160 util.Uint160) util.Fixed8 {
|
func (chain testChain) GetUtilityTokenBalance(uint160 util.Uint160) int64 {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ func (c *Client) NEP5TokenInfo(tokenHash util.Uint160) (*wallet.Token, error) {
|
||||||
// method of a given contract (token) to move specified amount of NEP5 assets
|
// method of a given contract (token) to move specified amount of NEP5 assets
|
||||||
// (in FixedN format using contract's number of decimals) to given account and
|
// (in FixedN format using contract's number of decimals) to given account and
|
||||||
// returns it. The returned transaction is not signed.
|
// returns it. The returned transaction is not signed.
|
||||||
func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas util.Fixed8) (*transaction.Transaction, error) {
|
func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas int64) (*transaction.Transaction, error) {
|
||||||
from, err := address.StringToUint160(acc.Address)
|
from, err := address.StringToUint160(acc.Address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("bad account address: %v", err)
|
return nil, fmt.Errorf("bad account address: %v", err)
|
||||||
|
@ -136,12 +136,8 @@ func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, toke
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't add system fee to transaction: %v", err)
|
return nil, fmt.Errorf("can't add system fee to transaction: %v", err)
|
||||||
}
|
}
|
||||||
gasConsumed, err := util.Fixed8FromString(result.GasConsumed)
|
if result.GasConsumed > 0 {
|
||||||
if err != nil {
|
tx.SystemFee = result.GasConsumed
|
||||||
return nil, fmt.Errorf("can't add system fee to transaction: %v", err)
|
|
||||||
}
|
|
||||||
if gasConsumed > 0 {
|
|
||||||
tx.SystemFee = gasConsumed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.ValidUntilBlock, err = c.CalculateValidUntilBlock()
|
tx.ValidUntilBlock, err = c.CalculateValidUntilBlock()
|
||||||
|
@ -161,7 +157,7 @@ func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, toke
|
||||||
// on a given token to move specified amount of NEP5 assets (in FixedN format
|
// on a given token to move specified amount of NEP5 assets (in FixedN format
|
||||||
// using contract's number of decimals) to given account and sends it to the
|
// using contract's number of decimals) to given account and sends it to the
|
||||||
// network returning just a hash of it.
|
// network returning just a hash of it.
|
||||||
func (c *Client) TransferNEP5(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas util.Fixed8) (util.Uint256, error) {
|
func (c *Client) TransferNEP5(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas int64) (util.Uint256, error) {
|
||||||
tx, err := c.CreateNEP5TransferTx(acc, to, token, amount, gas)
|
tx, err := c.CreateNEP5TransferTx(acc, to, token, amount, gas)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.Uint256{}, err
|
return util.Uint256{}, err
|
||||||
|
|
|
@ -427,7 +427,7 @@ func (c *Client) SubmitBlock(b block.Block) error {
|
||||||
// SignAndPushInvocationTx signs and pushes given script as an invocation
|
// SignAndPushInvocationTx signs and pushes given script as an invocation
|
||||||
// transaction using given wif to sign it and spending the amount of gas
|
// transaction using given wif to sign it and spending the amount of gas
|
||||||
// specified. It returns a hash of the invocation transaction and an error.
|
// specified. It returns a hash of the invocation transaction and an error.
|
||||||
func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee util.Fixed8, netfee util.Fixed8) (util.Uint256, error) {
|
func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee int64, netfee util.Fixed8) (util.Uint256, error) {
|
||||||
var txHash util.Uint256
|
var txHash util.Uint256
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -537,6 +537,6 @@ func (c *Client) AddNetworkFee(tx *transaction.Transaction, acc *wallet.Account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tx.NetworkFee += util.Fixed8(int64(size) * fee)
|
tx.NetworkFee += int64(size) * fee
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,13 @@ const hexB1 = "000000008aaab19c43c4ca2870c3e616b123f1b689866f44b138ae4d6a5352e54
|
||||||
|
|
||||||
const hexTxMoveNeo = "0002000000abec5362f11e75b6e02e407bb98d63675d14384100000000000000003e5f0d0000000000b00400000001abec5362f11e75b6e02e407bb98d63675d14384101590218ddf5050c14316e851039019d39dfc2c37d6c3fee19fd5809870c14abec5362f11e75b6e02e407bb98d63675d14384113c00c087472616e736665720c14897720d8cd76f4f00abfa37c0edd889c208fde9b41627d5b523801fd08010c40ae6fc04fe4b6c22218ca9617c98d607d9ec9b1faf8cfdc3391bec485ae76b11adc6cc6abeb31a50b536ea8073e674d62a5566fce5e0a0ceb0718cb971c1ae3d00c40603071b725a58d052cad7afd88e99b27baab931afd5bb50d16e224335aab450170aabe251d3c0c6ad3f31dd7e9b89b209baabe5a1e2fa588bd8118f9e2a6960f0c40d72afcf39e663dba2d70fb8c36a09d1a6a6ad0d2fd38c857a8e7dc71e2b98711324e0d2ec641fe6896ba63ba80d3ea341c1aad11e082fb188ee07e215b4031b10c409afb2808b60286a56343b7ffcef28bb2ab0c595603e7323b5e5b0b9c1c10edfa5c40754d921865cb6fd71668a206b37a1eb10c0029a9fcd3a856aed07742cd3f94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b413073b3bb"
|
const hexTxMoveNeo = "0002000000abec5362f11e75b6e02e407bb98d63675d14384100000000000000003e5f0d0000000000b00400000001abec5362f11e75b6e02e407bb98d63675d14384101590218ddf5050c14316e851039019d39dfc2c37d6c3fee19fd5809870c14abec5362f11e75b6e02e407bb98d63675d14384113c00c087472616e736665720c14897720d8cd76f4f00abfa37c0edd889c208fde9b41627d5b523801fd08010c40ae6fc04fe4b6c22218ca9617c98d607d9ec9b1faf8cfdc3391bec485ae76b11adc6cc6abeb31a50b536ea8073e674d62a5566fce5e0a0ceb0718cb971c1ae3d00c40603071b725a58d052cad7afd88e99b27baab931afd5bb50d16e224335aab450170aabe251d3c0c6ad3f31dd7e9b89b209baabe5a1e2fa588bd8118f9e2a6960f0c40d72afcf39e663dba2d70fb8c36a09d1a6a6ad0d2fd38c857a8e7dc71e2b98711324e0d2ec641fe6896ba63ba80d3ea341c1aad11e082fb188ee07e215b4031b10c409afb2808b60286a56343b7ffcef28bb2ab0c595603e7323b5e5b0b9c1c10edfa5c40754d921865cb6fd71668a206b37a1eb10c0029a9fcd3a856aed07742cd3f94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b413073b3bb"
|
||||||
|
|
||||||
const b1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"size":1681,"nextblockhash":"0x45f62d72e37b074ecdc9f687222b0f91ec98d6d9af4429a2caa2e076a9196b0d","confirmations":6,"hash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","version":0,"previousblockhash":"0x56fd4244e552536a4dae38b1446f8689b6f123b116e6c37028cac4439cb1aa8a","merkleroot":"0xf9dce467385206ad220a8b85d238f77239766eaffffed19955e3e47d24071140","time":1592472500001,"index":1,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEAPAetjcaE1Un3bIFoNrh9p0tMkg3zOEovq2QMwkYg/nOIebXWaQPaQdGWSsCHTl/CI47e0F/zvc80b/cKAB2lSDECE965dn1igmqVu6y8oJ0SlmoLRfjvg6xx/VObo33liDiYIGRusVygKg22y7Cp3bQfkPxa8dsR9NIsPzQnVbHwyDEArlbTjnsNRYqZAeV/yI+kt7JU5CgcutFf2pDIwUvgHMVF+DfAp5KRXIE93f1JhxqSojUbUw6vexjWm7tWA1sd/DEC5c1dFsd15WiWMMdjm+ofVz8Lps6SJDWENM7z4M7ZMWLDFzqF/OnEo8QZe0ZPmNpcVkPGT8ovdHu67vB/m587l","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"consensus_data":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0x7fb05b593cf4b1eb2d9a283c5488ca1bfe61191b5775bafa43b8647e7b20f22c","size":575,"version":0,"nonce":2,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"0.0087635","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFDFuhRA5AZ0538LDfWw/7hn9WAmHDBSr7FNi8R51tuAuQHu5jWNnXRQ4QRPADAh0cmFuc2ZlcgwUiXcg2M129PAKv6N8Dt2InCCP3ptBYn1bUjg=","scripts":[{"invocation":"DECub8BP5LbCIhjKlhfJjWB9nsmx+vjP3DORvsSFrnaxGtxsxqvrMaULU26oBz5nTWKlVm/OXgoM6wcYy5ccGuPQDEBgMHG3JaWNBSytev2I6ZsnuquTGv1btQ0W4iQzWqtFAXCqviUdPAxq0/Md1+m4myCbqr5aHi+liL2BGPnippYPDEDXKvzznmY9ui1w+4w2oJ0aamrQ0v04yFeo59xx4rmHETJODS7GQf5olrpjuoDT6jQcGq0R4IL7GI7gfiFbQDGxDECa+ygItgKGpWNDt//O8ouyqwxZVgPnMjteWwucHBDt+lxAdU2SGGXLb9cWaKIGs3oesQwAKan806hWrtB3Qs0/","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]},{"hash":"0xb661d5e4d9e41c3059b068f8abb6f1566a47ec800879e34c0ebd2799781a2760","size":579,"version":0,"nonce":3,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"0.0088035","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"AwDodkgXAAAADBQxboUQOQGdOd/Cw31sP+4Z/VgJhwwUq+xTYvEedbbgLkB7uY1jZ10UOEETwAwIdHJhbnNmZXIMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1I4","scripts":[{"invocation":"DECHEOe12Kxs2NCdb7Nb8tzOX1+zhZXdttBKVwvJJbwsVac83188taH+sKzE8myLvKbEPfO0qYuMPCyAnC8JbrJaDEDBhsECy/cjE/2U31B3/Fu+/NMiJ+0hWaR6RllId/o58zDYIjtFqiSv8AW+u1skJ6UMjE3oYY59ewDXPYNsRJQuDECiQ7W1Zb1LwvC7ES92JPazUUwSQTxalSMIGfrOP3YPA/y5axiPmAOKPyUWhrU6iNaXRPTkqYXmKXADqAzbFp6ADEBKlR5hrJnV7jGDHREXVK23EbSpBgqVJP44OpB3GEPNsJY4JnQCeofyoVqDvXfesrKrH+iz3m5UYpPvPfmxEp4o","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]}]}}`
|
const b1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"size":1681,"nextblockhash":"0x45f62d72e37b074ecdc9f687222b0f91ec98d6d9af4429a2caa2e076a9196b0d","confirmations":6,"hash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","version":0,"previousblockhash":"0x56fd4244e552536a4dae38b1446f8689b6f123b116e6c37028cac4439cb1aa8a","merkleroot":"0xf9dce467385206ad220a8b85d238f77239766eaffffed19955e3e47d24071140","time":1592472500001,"index":1,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEAPAetjcaE1Un3bIFoNrh9p0tMkg3zOEovq2QMwkYg/nOIebXWaQPaQdGWSsCHTl/CI47e0F/zvc80b/cKAB2lSDECE965dn1igmqVu6y8oJ0SlmoLRfjvg6xx/VObo33liDiYIGRusVygKg22y7Cp3bQfkPxa8dsR9NIsPzQnVbHwyDEArlbTjnsNRYqZAeV/yI+kt7JU5CgcutFf2pDIwUvgHMVF+DfAp5KRXIE93f1JhxqSojUbUw6vexjWm7tWA1sd/DEC5c1dFsd15WiWMMdjm+ofVz8Lps6SJDWENM7z4M7ZMWLDFzqF/OnEo8QZe0ZPmNpcVkPGT8ovdHu67vB/m587l","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"consensus_data":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0x7fb05b593cf4b1eb2d9a283c5488ca1bfe61191b5775bafa43b8647e7b20f22c","size":575,"version":0,"nonce":2,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"876350","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFDFuhRA5AZ0538LDfWw/7hn9WAmHDBSr7FNi8R51tuAuQHu5jWNnXRQ4QRPADAh0cmFuc2ZlcgwUiXcg2M129PAKv6N8Dt2InCCP3ptBYn1bUjg=","scripts":[{"invocation":"DECub8BP5LbCIhjKlhfJjWB9nsmx+vjP3DORvsSFrnaxGtxsxqvrMaULU26oBz5nTWKlVm/OXgoM6wcYy5ccGuPQDEBgMHG3JaWNBSytev2I6ZsnuquTGv1btQ0W4iQzWqtFAXCqviUdPAxq0/Md1+m4myCbqr5aHi+liL2BGPnippYPDEDXKvzznmY9ui1w+4w2oJ0aamrQ0v04yFeo59xx4rmHETJODS7GQf5olrpjuoDT6jQcGq0R4IL7GI7gfiFbQDGxDECa+ygItgKGpWNDt//O8ouyqwxZVgPnMjteWwucHBDt+lxAdU2SGGXLb9cWaKIGs3oesQwAKan806hWrtB3Qs0/","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]},{"hash":"0xb661d5e4d9e41c3059b068f8abb6f1566a47ec800879e34c0ebd2799781a2760","size":579,"version":0,"nonce":3,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"880350","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"AwDodkgXAAAADBQxboUQOQGdOd/Cw31sP+4Z/VgJhwwUq+xTYvEedbbgLkB7uY1jZ10UOEETwAwIdHJhbnNmZXIMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1I4","scripts":[{"invocation":"DECHEOe12Kxs2NCdb7Nb8tzOX1+zhZXdttBKVwvJJbwsVac83188taH+sKzE8myLvKbEPfO0qYuMPCyAnC8JbrJaDEDBhsECy/cjE/2U31B3/Fu+/NMiJ+0hWaR6RllId/o58zDYIjtFqiSv8AW+u1skJ6UMjE3oYY59ewDXPYNsRJQuDECiQ7W1Zb1LwvC7ES92JPazUUwSQTxalSMIGfrOP3YPA/y5axiPmAOKPyUWhrU6iNaXRPTkqYXmKXADqAzbFp6ADEBKlR5hrJnV7jGDHREXVK23EbSpBgqVJP44OpB3GEPNsJY4JnQCeofyoVqDvXfesrKrH+iz3m5UYpPvPfmxEp4o","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]}]}}`
|
||||||
|
|
||||||
const hexHeader1 = "000000008aaab19c43c4ca2870c3e616b123f1b689866f44b138ae4d6a5352e54442fd56401107247de4e35599d1feffaf6e763972f738d2858b0a22ad06523867e4dcf921f7c1c67201000001000000abec5362f11e75b6e02e407bb98d63675d14384101fd08010c400f01eb6371a135527ddb205a0dae1f69d2d324837cce128bead9033091883f9ce21e6d759a40f690746592b021d397f088e3b7b417fcef73cd1bfdc2800769520c4084f7ae5d9f58a09aa56eeb2f282744a59a82d17e3be0eb1c7f54e6e8df79620e2608191bac57280a836db2ec2a776d07e43f16bc76c47d348b0fcd09d56c7c320c402b95b4e39ec35162a640795ff223e92dec95390a072eb457f6a4323052f80731517e0df029e4a457204f777f5261c6a4a88d46d4c3abdec635a6eed580d6c77f0c40b9735745b1dd795a258c31d8e6fa87d5cfc2e9b3a4890d610d33bcf833b64c58b0c5cea17f3a7128f1065ed193e636971590f193f28bdd1eeebbbc1fe6e7cee594130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b413073b3bb00"
|
const hexHeader1 = "000000008aaab19c43c4ca2870c3e616b123f1b689866f44b138ae4d6a5352e54442fd56401107247de4e35599d1feffaf6e763972f738d2858b0a22ad06523867e4dcf921f7c1c67201000001000000abec5362f11e75b6e02e407bb98d63675d14384101fd08010c400f01eb6371a135527ddb205a0dae1f69d2d324837cce128bead9033091883f9ce21e6d759a40f690746592b021d397f088e3b7b417fcef73cd1bfdc2800769520c4084f7ae5d9f58a09aa56eeb2f282744a59a82d17e3be0eb1c7f54e6e8df79620e2608191bac57280a836db2ec2a776d07e43f16bc76c47d348b0fcd09d56c7c320c402b95b4e39ec35162a640795ff223e92dec95390a072eb457f6a4323052f80731517e0df029e4a457204f777f5261c6a4a88d46d4c3abdec635a6eed580d6c77f0c40b9735745b1dd795a258c31d8e6fa87d5cfc2e9b3a4890d610d33bcf833b64c58b0c5cea17f3a7128f1065ed193e636971590f193f28bdd1eeebbbc1fe6e7cee594130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b413073b3bb00"
|
||||||
|
|
||||||
const header1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"hash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","size":518,"version":0,"previousblockhash":"0x56fd4244e552536a4dae38b1446f8689b6f123b116e6c37028cac4439cb1aa8a","merkleroot":"0xf9dce467385206ad220a8b85d238f77239766eaffffed19955e3e47d24071140","time":1592472500001,"index":1,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEAPAetjcaE1Un3bIFoNrh9p0tMkg3zOEovq2QMwkYg/nOIebXWaQPaQdGWSsCHTl/CI47e0F/zvc80b/cKAB2lSDECE965dn1igmqVu6y8oJ0SlmoLRfjvg6xx/VObo33liDiYIGRusVygKg22y7Cp3bQfkPxa8dsR9NIsPzQnVbHwyDEArlbTjnsNRYqZAeV/yI+kt7JU5CgcutFf2pDIwUvgHMVF+DfAp5KRXIE93f1JhxqSojUbUw6vexjWm7tWA1sd/DEC5c1dFsd15WiWMMdjm+ofVz8Lps6SJDWENM7z4M7ZMWLDFzqF/OnEo8QZe0ZPmNpcVkPGT8ovdHu67vB/m587l","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"confirmations":6,"nextblockhash":"0x45f62d72e37b074ecdc9f687222b0f91ec98d6d9af4429a2caa2e076a9196b0d"}}`
|
const header1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"hash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","size":518,"version":0,"previousblockhash":"0x56fd4244e552536a4dae38b1446f8689b6f123b116e6c37028cac4439cb1aa8a","merkleroot":"0xf9dce467385206ad220a8b85d238f77239766eaffffed19955e3e47d24071140","time":1592472500001,"index":1,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEAPAetjcaE1Un3bIFoNrh9p0tMkg3zOEovq2QMwkYg/nOIebXWaQPaQdGWSsCHTl/CI47e0F/zvc80b/cKAB2lSDECE965dn1igmqVu6y8oJ0SlmoLRfjvg6xx/VObo33liDiYIGRusVygKg22y7Cp3bQfkPxa8dsR9NIsPzQnVbHwyDEArlbTjnsNRYqZAeV/yI+kt7JU5CgcutFf2pDIwUvgHMVF+DfAp5KRXIE93f1JhxqSojUbUw6vexjWm7tWA1sd/DEC5c1dFsd15WiWMMdjm+ofVz8Lps6SJDWENM7z4M7ZMWLDFzqF/OnEo8QZe0ZPmNpcVkPGT8ovdHu67vB/m587l","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"confirmations":6,"nextblockhash":"0x45f62d72e37b074ecdc9f687222b0f91ec98d6d9af4429a2caa2e076a9196b0d"}}`
|
||||||
|
|
||||||
const txMoveNeoVerbose = `{"id":5,"jsonrpc":"2.0","result":{"blockhash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","confirmations":6,"blocktime":1592472500001,"hash":"0x7fb05b593cf4b1eb2d9a283c5488ca1bfe61191b5775bafa43b8647e7b20f22c","size":575,"version":0,"nonce":2,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"0.0087635","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFDFuhRA5AZ0538LDfWw/7hn9WAmHDBSr7FNi8R51tuAuQHu5jWNnXRQ4QRPADAh0cmFuc2ZlcgwUiXcg2M129PAKv6N8Dt2InCCP3ptBYn1bUjg=","scripts":[{"invocation":"DECub8BP5LbCIhjKlhfJjWB9nsmx+vjP3DORvsSFrnaxGtxsxqvrMaULU26oBz5nTWKlVm/OXgoM6wcYy5ccGuPQDEBgMHG3JaWNBSytev2I6ZsnuquTGv1btQ0W4iQzWqtFAXCqviUdPAxq0/Md1+m4myCbqr5aHi+liL2BGPnippYPDEDXKvzznmY9ui1w+4w2oJ0aamrQ0v04yFeo59xx4rmHETJODS7GQf5olrpjuoDT6jQcGq0R4IL7GI7gfiFbQDGxDECa+ygItgKGpWNDt//O8ouyqwxZVgPnMjteWwucHBDt+lxAdU2SGGXLb9cWaKIGs3oesQwAKan806hWrtB3Qs0/","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]}}`
|
const txMoveNeoVerbose = `{"id":5,"jsonrpc":"2.0","result":{"blockhash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","confirmations":6,"blocktime":1592472500001,"hash":"0x7fb05b593cf4b1eb2d9a283c5488ca1bfe61191b5775bafa43b8647e7b20f22c","size":575,"version":0,"nonce":2,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"876350","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFDFuhRA5AZ0538LDfWw/7hn9WAmHDBSr7FNi8R51tuAuQHu5jWNnXRQ4QRPADAh0cmFuc2ZlcgwUiXcg2M129PAKv6N8Dt2InCCP3ptBYn1bUjg=","scripts":[{"invocation":"DECub8BP5LbCIhjKlhfJjWB9nsmx+vjP3DORvsSFrnaxGtxsxqvrMaULU26oBz5nTWKlVm/OXgoM6wcYy5ccGuPQDEBgMHG3JaWNBSytev2I6ZsnuquTGv1btQ0W4iQzWqtFAXCqviUdPAxq0/Md1+m4myCbqr5aHi+liL2BGPnippYPDEDXKvzznmY9ui1w+4w2oJ0aamrQ0v04yFeo59xx4rmHETJODS7GQf5olrpjuoDT6jQcGq0R4IL7GI7gfiFbQDGxDECa+ygItgKGpWNDt//O8ouyqwxZVgPnMjteWwucHBDt+lxAdU2SGGXLb9cWaKIGs3oesQwAKan806hWrtB3Qs0/","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]}}`
|
||||||
|
|
||||||
// getResultBlock1 returns data for block number 1 which is used by several tests.
|
// getResultBlock1 returns data for block number 1 which is used by several tests.
|
||||||
func getResultBlock1() *result.Block {
|
func getResultBlock1() *result.Block {
|
||||||
|
@ -114,7 +114,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
TxHash: txHash,
|
TxHash: txHash,
|
||||||
Trigger: "Application",
|
Trigger: "Application",
|
||||||
VMState: "HALT",
|
VMState: "HALT",
|
||||||
GasConsumed: "1",
|
GasConsumed: 1,
|
||||||
Stack: []smartcontract.Parameter{{Type: smartcontract.IntegerType, Value: int64(1)}},
|
Stack: []smartcontract.Parameter{{Type: smartcontract.IntegerType, Value: int64(1)}},
|
||||||
Events: []result.NotificationEvent{},
|
Events: []result.NotificationEvent{},
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetFeePerByte()
|
return c.GetFeePerByte()
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"0.0200739","script":"10c00c0d676574466565506572427974650c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"1000"}]}}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"2007390","script":"10c00c0d676574466565506572427974650c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"1000"}]}}`,
|
||||||
result: func(c *Client) interface{} {
|
result: func(c *Client) interface{} {
|
||||||
return int64(1000)
|
return int64(1000)
|
||||||
},
|
},
|
||||||
|
@ -337,7 +337,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetMaxTransactionsPerBlock()
|
return c.GetMaxTransactionsPerBlock()
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"0.0200739","script":"10c00c1a6765744d61785472616e73616374696f6e73506572426c6f636b0c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"512"}]}}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"2007390","script":"10c00c1a6765744d61785472616e73616374696f6e73506572426c6f636b0c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"512"}]}}`,
|
||||||
result: func(c *Client) interface{} {
|
result: func(c *Client) interface{} {
|
||||||
return int64(512)
|
return int64(512)
|
||||||
},
|
},
|
||||||
|
@ -349,7 +349,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetMaxBlockSize()
|
return c.GetMaxBlockSize()
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"0.0200739","script":"10c00c0f6765744d6178426c6f636b53697a650c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"262144"}]}}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"2007390","script":"10c00c0f6765744d6178426c6f636b53697a650c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"262144"}]}}`,
|
||||||
result: func(c *Client) interface{} {
|
result: func(c *Client) interface{} {
|
||||||
return int64(262144)
|
return int64(262144)
|
||||||
},
|
},
|
||||||
|
@ -361,7 +361,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
invoke: func(c *Client) (interface{}, error) {
|
invoke: func(c *Client) (interface{}, error) {
|
||||||
return c.GetBlockedAccounts()
|
return c.GetBlockedAccounts()
|
||||||
},
|
},
|
||||||
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"0.0200739","script":"10c00c12676574426c6f636b65644163636f756e74730c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Array","value":[]}]}}`,
|
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"2007390","script":"10c00c12676574426c6f636b65644163636f756e74730c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Array","value":[]}]}}`,
|
||||||
result: func(c *Client) interface{} {
|
result: func(c *Client) interface{} {
|
||||||
return native.BlockedAccounts{}
|
return native.BlockedAccounts{}
|
||||||
},
|
},
|
||||||
|
@ -625,7 +625,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
Account: util.Uint160{1, 2, 3},
|
Account: util.Uint160{1, 2, 3},
|
||||||
}})
|
}})
|
||||||
},
|
},
|
||||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"1426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf","state":"HALT","gas_consumed":"0.311","stack":[{"type":"ByteArray","value":"JivsCEQy"}],"tx":"d101361426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf000000000000000000000000"}}`,
|
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"1426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf","state":"HALT","gas_consumed":"31100000","stack":[{"type":"ByteArray","value":"JivsCEQy"}],"tx":"d101361426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf000000000000000000000000"}}`,
|
||||||
result: func(c *Client) interface{} {
|
result: func(c *Client) interface{} {
|
||||||
bytes, err := hex.DecodeString("262bec084432")
|
bytes, err := hex.DecodeString("262bec084432")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -633,7 +633,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
}
|
}
|
||||||
return &result.Invoke{
|
return &result.Invoke{
|
||||||
State: "HALT",
|
State: "HALT",
|
||||||
GasConsumed: "0.311",
|
GasConsumed: 31100000,
|
||||||
Script: "1426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf",
|
Script: "1426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf",
|
||||||
Stack: []smartcontract.Parameter{
|
Stack: []smartcontract.Parameter{
|
||||||
{
|
{
|
||||||
|
@ -653,7 +653,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
Account: util.Uint160{1, 2, 3},
|
Account: util.Uint160{1, 2, 3},
|
||||||
}})
|
}})
|
||||||
},
|
},
|
||||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"00046e616d656724058e5e1b6008847cd662728549088a9ee82191","state":"HALT","gas_consumed":"0.161","stack":[{"type":"ByteArray","value":"TkVQNSBHQVM="}],"tx":"d1011b00046e616d656724058e5e1b6008847cd662728549088a9ee82191000000000000000000000000"}}`,
|
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"00046e616d656724058e5e1b6008847cd662728549088a9ee82191","state":"HALT","gas_consumed":"16100000","stack":[{"type":"ByteArray","value":"TkVQNSBHQVM="}],"tx":"d1011b00046e616d656724058e5e1b6008847cd662728549088a9ee82191000000000000000000000000"}}`,
|
||||||
result: func(c *Client) interface{} {
|
result: func(c *Client) interface{} {
|
||||||
bytes, err := hex.DecodeString("4e45503520474153")
|
bytes, err := hex.DecodeString("4e45503520474153")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -661,7 +661,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
||||||
}
|
}
|
||||||
return &result.Invoke{
|
return &result.Invoke{
|
||||||
State: "HALT",
|
State: "HALT",
|
||||||
GasConsumed: "0.161",
|
GasConsumed: 16100000,
|
||||||
Script: "00046e616d656724058e5e1b6008847cd662728549088a9ee82191",
|
Script: "00046e616d656724058e5e1b6008847cd662728549088a9ee82191",
|
||||||
Stack: []smartcontract.Parameter{
|
Stack: []smartcontract.Parameter{
|
||||||
{
|
{
|
||||||
|
|
|
@ -116,10 +116,10 @@ func TestWSClientEvents(t *testing.T) {
|
||||||
var ok bool
|
var ok bool
|
||||||
// Events from RPC server test chain.
|
// Events from RPC server test chain.
|
||||||
var events = []string{
|
var events = []string{
|
||||||
`{"jsonrpc":"2.0","method":"transaction_executed","params":[{"txid":"0xe1cd5e57e721d2a2e05fb1f08721b12057b25ab1dd7fd0f33ee1639932fdfad7","trigger":"Application","vmstate":"HALT","gas_consumed":"2.291","stack":[],"notifications":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}},{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}}]}]}`,
|
`{"jsonrpc":"2.0","method":"transaction_executed","params":[{"txid":"0xe1cd5e57e721d2a2e05fb1f08721b12057b25ab1dd7fd0f33ee1639932fdfad7","trigger":"Application","vmstate":"HALT","gas_consumed":"22910000","stack":[],"notifications":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}},{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}}]}]}`,
|
||||||
`{"jsonrpc":"2.0","method":"notification_from_execution","params":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}}]}`,
|
`{"jsonrpc":"2.0","method":"notification_from_execution","params":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}}]}`,
|
||||||
`{"jsonrpc":"2.0","method":"transaction_executed","params":[{"txid":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","trigger":"Application","vmstate":"HALT","gas_consumed":"0.0604261","stack":[],"notifications":[{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteArray","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}]}},{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","state":{"type":"Array","value":[{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteArray","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}}]}]}`,
|
`{"jsonrpc":"2.0","method":"transaction_executed","params":[{"txid":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","trigger":"Application","vmstate":"HALT","gas_consumed":"6042610","stack":[],"notifications":[{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteArray","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}]}},{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","state":{"type":"Array","value":[{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteArray","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}}]}]}`,
|
||||||
`{"jsonrpc":"2.0","method":"block_added","params":[{"hash":"0x2d312f6379ead13cf62634c703091b750e7903728df2a3cf5bd96ce80b84a849","version":0,"previousblockhash":"0xb8237d34c156cac6be7b01578decf8ac8c99a62f0b6f774d622aad7be0fe189d","merkleroot":"0xf89169e89361692b71e671f13c088e84c5325015c413e8f89e7ba38efdb41287","time":1592472500006,"index":6,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEDblVguNGXWbUswDvBfVJzBt76BJyJ0Ga6siquyjioGn4Dbr6zy1IvcLl3xN5akcejRy9e+Mr1qvpe/gkLgtW4QDEDRwPISZagMFjE/plXTnZ/gEU0IbBAAe23U29zVWteUmzRsPxF/MdzXvdffR9W0edkj17AmkWpn+5rqzH9aCOpLDECEvjgxZaRoAHEDNzp1REllLcGzMwrwSjudtzfgRglQL3g1BKerDx6cGHH73medRVkL9QVm4KzSxlywVtvhwBMrDEBuPKvzg5TtakFW2jr/bfmy1bn2FiLARlOySwaGdKRV93ozA5lVEIAvHbBlJtT4/5H8jHjbncXXMrP3OUHqebZz","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"consensus_data":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","size":265,"version":0,"nonce":9,"sender":"NQRLhCpAru9BjGsMwk67vdMwmzKMRgsnnN","sys_fee":"0","net_fee":"0.0036521","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x870958fd19ee3f6c7dc3c2df399d013910856e31","scopes":"CalledByEntry"}],"script":"AHsMFCBygnSvr8NvQ6Bx0yjPo+Yp2cuwDBQxboUQOQGdOd/Cw31sP+4Z/VgJhxPADAh0cmFuc2ZlcgwU2gHvYphOfQUnXEpYeyAtoLP3X+ZBYn1bUjg=","scripts":[{"invocation":"DECwklSj3liZOJbktRtkVdUCu8U2LQlrU6Dv8NtMgd0xXbk5lXjc2p68xv6xtJXbJ4aoFMJZ9lkcNpGoeUCcaCet","verification":"DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQQqQatQ="}]}]}]}`,
|
`{"jsonrpc":"2.0","method":"block_added","params":[{"hash":"0x2d312f6379ead13cf62634c703091b750e7903728df2a3cf5bd96ce80b84a849","version":0,"previousblockhash":"0xb8237d34c156cac6be7b01578decf8ac8c99a62f0b6f774d622aad7be0fe189d","merkleroot":"0xf89169e89361692b71e671f13c088e84c5325015c413e8f89e7ba38efdb41287","time":1592472500006,"index":6,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEDblVguNGXWbUswDvBfVJzBt76BJyJ0Ga6siquyjioGn4Dbr6zy1IvcLl3xN5akcejRy9e+Mr1qvpe/gkLgtW4QDEDRwPISZagMFjE/plXTnZ/gEU0IbBAAe23U29zVWteUmzRsPxF/MdzXvdffR9W0edkj17AmkWpn+5rqzH9aCOpLDECEvjgxZaRoAHEDNzp1REllLcGzMwrwSjudtzfgRglQL3g1BKerDx6cGHH73medRVkL9QVm4KzSxlywVtvhwBMrDEBuPKvzg5TtakFW2jr/bfmy1bn2FiLARlOySwaGdKRV93ozA5lVEIAvHbBlJtT4/5H8jHjbncXXMrP3OUHqebZz","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"consensus_data":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","size":265,"version":0,"nonce":9,"sender":"NQRLhCpAru9BjGsMwk67vdMwmzKMRgsnnN","sys_fee":"0","net_fee":"365210","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x870958fd19ee3f6c7dc3c2df399d013910856e31","scopes":"CalledByEntry"}],"script":"AHsMFCBygnSvr8NvQ6Bx0yjPo+Yp2cuwDBQxboUQOQGdOd/Cw31sP+4Z/VgJhxPADAh0cmFuc2ZlcgwU2gHvYphOfQUnXEpYeyAtoLP3X+ZBYn1bUjg=","scripts":[{"invocation":"DECwklSj3liZOJbktRtkVdUCu8U2LQlrU6Dv8NtMgd0xXbk5lXjc2p68xv6xtJXbJ4aoFMJZ9lkcNpGoeUCcaCet","verification":"DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQQqQatQ="}]}]}]}`,
|
||||||
`{"jsonrpc":"2.0","method":"event_missed","params":[]}`,
|
`{"jsonrpc":"2.0","method":"event_missed","params":[]}`,
|
||||||
}
|
}
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
// CreateDeploymentScript returns a script that deploys given smart contract
|
// CreateDeploymentScript returns a script that deploys given smart contract
|
||||||
// with its metadata and system fee require for this.
|
// with its metadata and system fee require for this.
|
||||||
func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, util.Fixed8, error) {
|
func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, int64, error) {
|
||||||
script := io.NewBufBinWriter()
|
script := io.NewBufBinWriter()
|
||||||
rawManifest, err := manif.MarshalJSON()
|
rawManifest, err := manif.MarshalJSON()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,7 +26,7 @@ func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, util.
|
||||||
emit.Bytes(script.BinWriter, rawManifest)
|
emit.Bytes(script.BinWriter, rawManifest)
|
||||||
emit.Bytes(script.BinWriter, avm)
|
emit.Bytes(script.BinWriter, avm)
|
||||||
emit.Syscall(script.BinWriter, "System.Contract.Create")
|
emit.Syscall(script.BinWriter, "System.Contract.Create")
|
||||||
sysfee := util.Fixed8(core.StoragePrice * (len(avm) + len(rawManifest)))
|
sysfee := int64(core.StoragePrice * (len(avm) + len(rawManifest)))
|
||||||
return script.Bytes(), sysfee, nil
|
return script.Bytes(), sysfee, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package result
|
package result
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -15,7 +13,7 @@ type ApplicationLog struct {
|
||||||
TxHash util.Uint256 `json:"txid"`
|
TxHash util.Uint256 `json:"txid"`
|
||||||
Trigger string `json:"trigger"`
|
Trigger string `json:"trigger"`
|
||||||
VMState string `json:"vmstate"`
|
VMState string `json:"vmstate"`
|
||||||
GasConsumed string `json:"gas_consumed"`
|
GasConsumed int64 `json:"gas_consumed,string"`
|
||||||
Stack []smartcontract.Parameter `json:"stack"`
|
Stack []smartcontract.Parameter `json:"stack"`
|
||||||
Events []NotificationEvent `json:"notifications"`
|
Events []NotificationEvent `json:"notifications"`
|
||||||
}
|
}
|
||||||
|
@ -48,7 +46,7 @@ func NewApplicationLog(appExecRes *state.AppExecResult) ApplicationLog {
|
||||||
TxHash: appExecRes.TxHash,
|
TxHash: appExecRes.TxHash,
|
||||||
Trigger: appExecRes.Trigger.String(),
|
Trigger: appExecRes.Trigger.String(),
|
||||||
VMState: appExecRes.VMState,
|
VMState: appExecRes.VMState,
|
||||||
GasConsumed: strconv.FormatInt(int64(appExecRes.GasConsumed), 10),
|
GasConsumed: appExecRes.GasConsumed,
|
||||||
Stack: appExecRes.Stack,
|
Stack: appExecRes.Stack,
|
||||||
Events: events,
|
Events: events,
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
// that invoke functions, scripts and generic bytecode.
|
// that invoke functions, scripts and generic bytecode.
|
||||||
type Invoke struct {
|
type Invoke struct {
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
GasConsumed string `json:"gas_consumed"`
|
GasConsumed int64 `json:"gas_consumed,string"`
|
||||||
Script string `json:"script"`
|
Script string `json:"script"`
|
||||||
Stack []smartcontract.Parameter `json:"stack"`
|
Stack []smartcontract.Parameter `json:"stack"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -741,7 +741,7 @@ func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *respons
|
||||||
return 0, response.NewRPCError(errBlock.Error(), "", nil)
|
return 0, response.NewRPCError(errBlock.Error(), "", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockSysFee util.Fixed8
|
var blockSysFee int64
|
||||||
for _, tx := range block.Transactions {
|
for _, tx := range block.Transactions {
|
||||||
blockSysFee += tx.SystemFee
|
blockSysFee += tx.SystemFee
|
||||||
}
|
}
|
||||||
|
@ -786,7 +786,7 @@ func (s *Server) getUnclaimedGas(ps request.Params) (interface{}, *response.Erro
|
||||||
if neo == 0 {
|
if neo == 0 {
|
||||||
return "0", nil
|
return "0", nil
|
||||||
}
|
}
|
||||||
gas := s.chain.CalculateClaimable(int64(neo), neoHeight, s.chain.BlockHeight()+1) // +1 as in C#, for the next block.
|
gas := s.chain.CalculateClaimable(neo, neoHeight, s.chain.BlockHeight()+1) // +1 as in C#, for the next block.
|
||||||
return strconv.FormatInt(int64(gas), 10), nil // It's not represented as Fixed8 in C#.
|
return strconv.FormatInt(int64(gas), 10), nil // It's not represented as Fixed8 in C#.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,12 +862,12 @@ func (s *Server) invokescript(reqParams request.Params) (interface{}, *response.
|
||||||
// result.
|
// result.
|
||||||
func (s *Server) runScriptInVM(script []byte, tx *transaction.Transaction) *result.Invoke {
|
func (s *Server) runScriptInVM(script []byte, tx *transaction.Transaction) *result.Invoke {
|
||||||
vm := s.chain.GetTestVM(tx)
|
vm := s.chain.GetTestVM(tx)
|
||||||
vm.GasLimit = s.config.MaxGasInvoke
|
vm.GasLimit = int64(s.config.MaxGasInvoke)
|
||||||
vm.LoadScriptWithFlags(script, smartcontract.All)
|
vm.LoadScriptWithFlags(script, smartcontract.All)
|
||||||
_ = vm.Run()
|
_ = vm.Run()
|
||||||
result := &result.Invoke{
|
result := &result.Invoke{
|
||||||
State: vm.State(),
|
State: vm.State(),
|
||||||
GasConsumed: vm.GasConsumed().String(),
|
GasConsumed: vm.GasConsumed(),
|
||||||
Script: hex.EncodeToString(script),
|
Script: hex.EncodeToString(script),
|
||||||
Stack: vm.Estack().ToContractParameters(),
|
Stack: vm.Estack().ToContractParameters(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network"
|
"github.com/nspcc-dev/neo-go/pkg/network"
|
||||||
|
@ -85,10 +86,10 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, *Server, *http
|
||||||
|
|
||||||
type FeerStub struct{}
|
type FeerStub struct{}
|
||||||
|
|
||||||
func (fs *FeerStub) FeePerByte() util.Fixed8 {
|
func (fs *FeerStub) FeePerByte() int64 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FeerStub) GetUtilityTokenBalance(acc util.Uint160) util.Fixed8 {
|
func (fs *FeerStub) GetUtilityTokenBalance(acc util.Uint160) int64 {
|
||||||
return util.Fixed8FromInt64(1000000)
|
return 1000000 * native.GASFactor
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
// take burned gas into account
|
// take burned gas into account
|
||||||
u := testchain.PrivateKeyByID(0).GetScriptHash()
|
u := testchain.PrivateKeyByID(0).GetScriptHash()
|
||||||
for i := 0; i <= int(e.chain.BlockHeight()); i++ {
|
for i := 0; i <= int(e.chain.BlockHeight()); i++ {
|
||||||
var netFee util.Fixed8
|
var netFee int64
|
||||||
h := e.chain.GetHeaderHash(i)
|
h := e.chain.GetHeaderHash(i)
|
||||||
b, err := e.chain.GetBlock(h)
|
b, err := e.chain.GetBlock(h)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -453,7 +453,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
result: func(e *executor) interface{} {
|
result: func(e *executor) interface{} {
|
||||||
block, _ := e.chain.GetBlock(e.chain.GetHeaderHash(1))
|
block, _ := e.chain.GetBlock(e.chain.GetHeaderHash(1))
|
||||||
|
|
||||||
var expectedBlockSysFee util.Fixed8
|
var expectedBlockSysFee int64
|
||||||
for _, tx := range block.Transactions {
|
for _, tx := range block.Transactions {
|
||||||
expectedBlockSysFee += tx.SystemFee
|
expectedBlockSysFee += tx.SystemFee
|
||||||
}
|
}
|
||||||
|
@ -862,7 +862,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
|
||||||
netFee, sizeDelta := core.CalculateNetworkFee(acc0.Contract.Script)
|
netFee, sizeDelta := core.CalculateNetworkFee(acc0.Contract.Script)
|
||||||
tx.NetworkFee += netFee
|
tx.NetworkFee += netFee
|
||||||
size += sizeDelta
|
size += sizeDelta
|
||||||
tx.NetworkFee = tx.NetworkFee.Add(util.Fixed8(int64(size) * int64(chain.FeePerByte())))
|
tx.NetworkFee += int64(size) * chain.FeePerByte()
|
||||||
}
|
}
|
||||||
|
|
||||||
newTx := func() *transaction.Transaction {
|
newTx := func() *transaction.Transaction {
|
||||||
|
|
|
@ -17,7 +17,7 @@ type InteropFunc func(vm *VM) error
|
||||||
// InteropFuncPrice represents an interop function with a price.
|
// InteropFuncPrice represents an interop function with a price.
|
||||||
type InteropFuncPrice struct {
|
type InteropFuncPrice struct {
|
||||||
Func InteropFunc
|
Func InteropFunc
|
||||||
Price int
|
Price int64
|
||||||
// AllowedTriggers is a mask representing triggers which should be allowed by an interop.
|
// AllowedTriggers is a mask representing triggers which should be allowed by an interop.
|
||||||
// 0 is interpreted as All.
|
// 0 is interpreted as All.
|
||||||
AllowedTriggers trigger.Type
|
AllowedTriggers trigger.Type
|
||||||
|
|
12
pkg/vm/vm.go
12
pkg/vm/vm.go
|
@ -64,7 +64,7 @@ type VM struct {
|
||||||
getInterop []InteropGetterFunc
|
getInterop []InteropGetterFunc
|
||||||
|
|
||||||
// callback to get interop price
|
// callback to get interop price
|
||||||
getPrice func(*VM, opcode.Opcode, []byte) util.Fixed8
|
getPrice func(*VM, opcode.Opcode, []byte) int64
|
||||||
|
|
||||||
istack *Stack // invocation stack.
|
istack *Stack // invocation stack.
|
||||||
estack *Stack // execution stack.
|
estack *Stack // execution stack.
|
||||||
|
@ -77,8 +77,8 @@ type VM struct {
|
||||||
|
|
||||||
refs *refCounter
|
refs *refCounter
|
||||||
|
|
||||||
gasConsumed util.Fixed8
|
gasConsumed int64
|
||||||
GasLimit util.Fixed8
|
GasLimit int64
|
||||||
|
|
||||||
trigger trigger.Type
|
trigger trigger.Type
|
||||||
|
|
||||||
|
@ -125,17 +125,17 @@ func (v *VM) RegisterInteropGetter(f InteropGetterFunc) {
|
||||||
|
|
||||||
// SetPriceGetter registers the given PriceGetterFunc in v.
|
// SetPriceGetter registers the given PriceGetterFunc in v.
|
||||||
// f accepts vm's Context, current instruction and instruction parameter.
|
// f accepts vm's Context, current instruction and instruction parameter.
|
||||||
func (v *VM) SetPriceGetter(f func(*VM, opcode.Opcode, []byte) util.Fixed8) {
|
func (v *VM) SetPriceGetter(f func(*VM, opcode.Opcode, []byte) int64) {
|
||||||
v.getPrice = f
|
v.getPrice = f
|
||||||
}
|
}
|
||||||
|
|
||||||
// GasConsumed returns the amount of GAS consumed during execution.
|
// GasConsumed returns the amount of GAS consumed during execution.
|
||||||
func (v *VM) GasConsumed() util.Fixed8 {
|
func (v *VM) GasConsumed() int64 {
|
||||||
return v.gasConsumed
|
return v.gasConsumed
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddGas consumes specified amount of gas. It returns true iff gas limit wasn't exceeded.
|
// AddGas consumes specified amount of gas. It returns true iff gas limit wasn't exceeded.
|
||||||
func (v *VM) AddGas(gas util.Fixed8) bool {
|
func (v *VM) AddGas(gas int64) bool {
|
||||||
v.gasConsumed += gas
|
v.gasConsumed += gas
|
||||||
return v.GasLimit == 0 || v.gasConsumed <= v.GasLimit
|
return v.GasLimit == 0 || v.gasConsumed <= v.GasLimit
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
@ -71,7 +70,7 @@ func TestVM_SetPriceGetter(t *testing.T) {
|
||||||
require.EqualValues(t, 0, v.GasConsumed())
|
require.EqualValues(t, 0, v.GasConsumed())
|
||||||
})
|
})
|
||||||
|
|
||||||
v.SetPriceGetter(func(_ *VM, op opcode.Opcode, p []byte) util.Fixed8 {
|
v.SetPriceGetter(func(_ *VM, op opcode.Opcode, p []byte) int64 {
|
||||||
if op == opcode.PUSH4 {
|
if op == opcode.PUSH4 {
|
||||||
return 1
|
return 1
|
||||||
} else if op == opcode.PUSHDATA1 && bytes.Equal(p, []byte{0xCA, 0xFE}) {
|
} else if op == opcode.PUSHDATA1 && bytes.Equal(p, []byte{0xCA, 0xFE}) {
|
||||||
|
|
Loading…
Reference in a new issue