transaction: rename FeeOnly to None

Follow missed change from neo-project/neo#1816 .
`None` may be used for any signer. Currently it is used
for sender to only pay fees, or to sign tx attributes.
This commit is contained in:
Evgenii Stratonikov 2020-10-01 15:26:51 +03:00
parent 230352d99f
commit fa09b9af7b
13 changed files with 24 additions and 34 deletions

View file

@ -159,7 +159,7 @@ func NewCommands() []cli.Command {
UsageText: "neo-go contract invokefunction -r endpoint -w wallet [-a address] [-g gas] scripthash [method] [arguments...] [--] [signers...]", UsageText: "neo-go contract invokefunction -r endpoint -w wallet [-a address] [-g gas] scripthash [method] [arguments...] [--] [signers...]",
Description: `Executes given (as a script hash) deployed script with the given method, Description: `Executes given (as a script hash) deployed script with the given method,
arguments and signers. Sender is included in the list of signers by default arguments and signers. Sender is included in the list of signers by default
with FeeOnly witness scope. If you'd like to change default sender's scope, with None witness scope. If you'd like to change default sender's scope,
specify it via signers parameter. See testinvokefunction documentation for specify it via signers parameter. See testinvokefunction documentation for
the details about parameters. It differs from testinvokefunction in that this the details about parameters. It differs from testinvokefunction in that this
command sends an invocation transaction to the network. command sends an invocation transaction to the network.
@ -247,9 +247,8 @@ func NewCommands() []cli.Command {
* 'signer' is hex-encoded 160 bit (20 byte) LE value of signer's address, * 'signer' is hex-encoded 160 bit (20 byte) LE value of signer's address,
which could have '0x' prefix. which could have '0x' prefix.
* 'scope' is a comma-separated set of cosigner's scopes, which could be: * 'scope' is a comma-separated set of cosigner's scopes, which could be:
- 'FeeOnly' - marks transaction's sender and can be used only for the - 'None' - default witness scope which may be used for the sender
sender. Signer with this scope can't be used during the to only pay fee for the transaction.
script execution and only pays fees for the transaction.
- 'Global' - allows this witness in all contexts. This cannot be combined - 'Global' - allows this witness in all contexts. This cannot be combined
with other flags. with other flags.
- 'CalledByEntry' - means that this condition must hold: EntryScriptHash - 'CalledByEntry' - means that this condition must hold: EntryScriptHash

View file

@ -97,9 +97,9 @@ func TestParseCosigner(t *testing.T) {
Account: acc, Account: acc,
Scopes: transaction.CalledByEntry, Scopes: transaction.CalledByEntry,
}, },
acc.StringLE() + ":FeeOnly": { acc.StringLE() + ":None": {
Account: acc, Account: acc,
Scopes: transaction.FeeOnly, Scopes: transaction.None,
}, },
acc.StringLE() + ":CalledByEntry,CustomContracts": { acc.StringLE() + ":CalledByEntry,CustomContracts": {
Account: acc, Account: acc,
@ -115,7 +115,7 @@ func TestParseCosigner(t *testing.T) {
acc.StringLE() + "0", acc.StringLE() + "0",
acc.StringLE() + ":Unknown", acc.StringLE() + ":Unknown",
acc.StringLE() + ":Global,CustomContracts", acc.StringLE() + ":Global,CustomContracts",
acc.StringLE() + ":Global,FeeOnly", acc.StringLE() + ":Global,None",
} }
for _, s := range errorCases { for _, s := range errorCases {
_, err := parseCosigner(s) _, err := parseCosigner(s)

View file

@ -1259,7 +1259,7 @@ func (bc *Blockchain) verifyTxAttributes(tx *transaction.Transaction) error {
} }
hasOracle := false hasOracle := false
for i := range tx.Signers { for i := range tx.Signers {
if tx.Signers[i].Scopes != transaction.FeeOnly { if tx.Signers[i].Scopes != transaction.None {
return fmt.Errorf("%w: oracle tx has invalid signer scope", ErrInvalidAttribute) return fmt.Errorf("%w: oracle tx has invalid signer scope", ErrInvalidAttribute)
} }
if tx.Signers[i].Account.Equals(h) { if tx.Signers[i].Account.Equals(h) {

View file

@ -127,7 +127,7 @@ func TestAddBadBlock(t *testing.T) {
tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0)
tx.Signers = []transaction.Signer{{ tx.Signers = []transaction.Signer{{
Account: testchain.MultisigScriptHash(), Account: testchain.MultisigScriptHash(),
Scopes: transaction.FeeOnly, Scopes: transaction.None,
}} }}
require.NoError(t, signTx(bc, tx)) require.NoError(t, signTx(bc, tx))
b1 := bc.newBlock(tx) b1 := bc.newBlock(tx)
@ -147,7 +147,7 @@ func TestAddBadBlock(t *testing.T) {
tx.ValidUntilBlock = 128 tx.ValidUntilBlock = 128
tx.Signers = []transaction.Signer{{ tx.Signers = []transaction.Signer{{
Account: testchain.MultisigScriptHash(), Account: testchain.MultisigScriptHash(),
Scopes: transaction.FeeOnly, Scopes: transaction.None,
}} }}
require.NoError(t, signTx(bc, tx)) require.NoError(t, signTx(bc, tx))
require.NoError(t, bc.PoolTx(tx)) require.NoError(t, bc.PoolTx(tx))
@ -378,7 +378,7 @@ func TestVerifyTx(t *testing.T) {
tx.NetworkFee += 4_000_000 // multisig check tx.NetworkFee += 4_000_000 // multisig check
tx.Signers = []transaction.Signer{{ tx.Signers = []transaction.Signer{{
Account: testchain.CommitteeScriptHash(), Account: testchain.CommitteeScriptHash(),
Scopes: transaction.FeeOnly, Scopes: transaction.None,
}} }}
rawScript := testchain.CommitteeVerificationScript() rawScript := testchain.CommitteeVerificationScript()
require.NoError(t, err) require.NoError(t, err)
@ -419,7 +419,7 @@ func TestVerifyTx(t *testing.T) {
tx.SystemFee = int64(req.GasForResponse - uint64(tx.NetworkFee)) tx.SystemFee = int64(req.GasForResponse - uint64(tx.NetworkFee))
tx.Signers = []transaction.Signer{{ tx.Signers = []transaction.Signer{{
Account: oracleHash, Account: oracleHash,
Scopes: transaction.FeeOnly, Scopes: transaction.None,
}} }}
size := io.GetVarSize(tx) size := io.GetVarSize(tx)
netFee, sizeDelta := CalculateNetworkFee(oracleScript) netFee, sizeDelta := CalculateNetworkFee(oracleScript)

View file

@ -35,7 +35,7 @@ func (c *Signer) EncodeBinary(bw *io.BinWriter) {
func (c *Signer) DecodeBinary(br *io.BinReader) { func (c *Signer) DecodeBinary(br *io.BinReader) {
br.ReadBytes(c.Account[:]) br.ReadBytes(c.Account[:])
c.Scopes = WitnessScope(br.ReadB()) c.Scopes = WitnessScope(br.ReadB())
if c.Scopes & ^(Global|CalledByEntry|CustomContracts|CustomGroups|FeeOnly) != 0 { if c.Scopes & ^(Global|CalledByEntry|CustomContracts|CustomGroups|None) != 0 {
br.Err = errors.New("unknown witness scope") br.Err = errors.New("unknown witness scope")
return return
} }

View file

@ -348,7 +348,6 @@ var (
ErrNegativeNetworkFee = errors.New("negative network fee") ErrNegativeNetworkFee = errors.New("negative network fee")
ErrTooBigFees = errors.New("too big fees: int64 overflow") ErrTooBigFees = errors.New("too big fees: int64 overflow")
ErrEmptySigners = errors.New("signers array should contain sender") ErrEmptySigners = errors.New("signers array should contain sender")
ErrInvalidScope = errors.New("FeeOnly scope can be used only for sender")
ErrNonUniqueSigners = errors.New("transaction signers should be unique") ErrNonUniqueSigners = errors.New("transaction signers should be unique")
ErrInvalidAttribute = errors.New("invalid attribute") ErrInvalidAttribute = errors.New("invalid attribute")
ErrEmptyScript = errors.New("no script") ErrEmptyScript = errors.New("no script")
@ -372,9 +371,6 @@ func (t *Transaction) isValid() error {
return ErrEmptySigners return ErrEmptySigners
} }
for i := 0; i < len(t.Signers); i++ { for i := 0; i < len(t.Signers); i++ {
if i > 0 && t.Signers[i].Scopes == FeeOnly {
return ErrInvalidScope
}
for j := i + 1; j < len(t.Signers); j++ { for j := i + 1; j < len(t.Signers); j++ {
if t.Signers[i].Account.Equals(t.Signers[j].Account) { if t.Signers[i].Account.Equals(t.Signers[j].Account) {
return ErrNonUniqueSigners return ErrNonUniqueSigners

View file

@ -188,11 +188,6 @@ func TestTransaction_isValid(t *testing.T) {
tx.Signers = tx.Signers[:0] tx.Signers = tx.Signers[:0]
require.True(t, errors.Is(tx.isValid(), ErrEmptySigners)) require.True(t, errors.Is(tx.isValid(), ErrEmptySigners))
}) })
t.Run("InvalidScope", func(t *testing.T) {
tx := newTx()
tx.Signers[1].Scopes = FeeOnly
require.True(t, errors.Is(tx.isValid(), ErrInvalidScope))
})
t.Run("NonUniqueSigners", func(t *testing.T) { t.Run("NonUniqueSigners", func(t *testing.T) {
tx := newTx() tx := newTx()
tx.Signers[1].Account = tx.Signers[0].Account tx.Signers[1].Account = tx.Signers[0].Account

View file

@ -11,8 +11,8 @@ import (
type WitnessScope byte type WitnessScope byte
const ( const (
// FeeOnly is only valid for a sender, it can't be used during the execution. // None specifies that no contract was witnessed. Only sign the transaction.
FeeOnly WitnessScope = 0 None WitnessScope = 0
// CalledByEntry means that this condition must hold: EntryScriptHash == CallingScriptHash. // CalledByEntry means that this condition must hold: EntryScriptHash == CallingScriptHash.
// No params is needed, as the witness/permission/signature given on first invocation will // No params is needed, as the witness/permission/signature given on first invocation will
// automatically expire if entering deeper internal invokes. This can be default safe // automatically expire if entering deeper internal invokes. This can be default safe
@ -42,7 +42,7 @@ func ScopesFromString(s string) (WitnessScope, error) {
CalledByEntry.String(): CalledByEntry, CalledByEntry.String(): CalledByEntry,
CustomContracts.String(): CustomContracts, CustomContracts.String(): CustomContracts,
CustomGroups.String(): CustomGroups, CustomGroups.String(): CustomGroups,
FeeOnly.String(): FeeOnly, None.String(): None,
} }
var isGlobal bool var isGlobal bool
for _, scopeStr := range scopes { for _, scopeStr := range scopes {
@ -64,7 +64,7 @@ func ScopesFromString(s string) (WitnessScope, error) {
// scopesToString converts witness scope to it's string representation. It uses // scopesToString converts witness scope to it's string representation. It uses
// `, ` to separate scope names. // `, ` to separate scope names.
func scopesToString(scopes WitnessScope) string { func scopesToString(scopes WitnessScope) string {
if scopes&Global != 0 || scopes == FeeOnly { if scopes&Global != 0 || scopes == None {
return scopes.String() return scopes.String()
} }
var res string var res string

View file

@ -8,7 +8,7 @@ func _() {
// An "invalid array index" compiler error signifies that the constant values have changed. // An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again. // Re-run the stringer command to generate them again.
var x [1]struct{} var x [1]struct{}
_ = x[FeeOnly-0] _ = x[None-0]
_ = x[CalledByEntry-1] _ = x[CalledByEntry-1]
_ = x[CustomContracts-16] _ = x[CustomContracts-16]
_ = x[CustomGroups-32] _ = x[CustomGroups-32]
@ -16,14 +16,14 @@ func _() {
} }
const ( const (
_WitnessScope_name_0 = "FeeOnlyCalledByEntry" _WitnessScope_name_0 = "NoneCalledByEntry"
_WitnessScope_name_1 = "CustomContracts" _WitnessScope_name_1 = "CustomContracts"
_WitnessScope_name_2 = "CustomGroups" _WitnessScope_name_2 = "CustomGroups"
_WitnessScope_name_3 = "Global" _WitnessScope_name_3 = "Global"
) )
var ( var (
_WitnessScope_index_0 = [...]uint8{0, 7, 20} _WitnessScope_index_0 = [...]uint8{0, 4, 17}
) )
func (i WitnessScope) String() string { func (i WitnessScope) String() string {

View file

@ -80,7 +80,7 @@ func deployNativeContracts(magic netmode.Magic) *transaction.Transaction {
tx.Signers = []transaction.Signer{ tx.Signers = []transaction.Signer{
{ {
Account: hash.Hash160([]byte{byte(opcode.PUSH1)}), Account: hash.Hash160([]byte{byte(opcode.PUSH1)}),
Scopes: transaction.FeeOnly, Scopes: transaction.None,
}, },
} }
tx.Scripts = []transaction.Witness{ tx.Scripts = []transaction.Witness{

View file

@ -469,7 +469,7 @@ func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sys
func getSigners(sender util.Uint160, cosigners []transaction.Signer) []transaction.Signer { func getSigners(sender util.Uint160, cosigners []transaction.Signer) []transaction.Signer {
s := transaction.Signer{ s := transaction.Signer{
Account: sender, Account: sender,
Scopes: transaction.FeeOnly, Scopes: transaction.None,
} }
for i, c := range cosigners { for i, c := range cosigners {
if c.Account == sender { if c.Account == sender {

View file

@ -107,7 +107,7 @@ func TestParam_UnmarshalJSON(t *testing.T) {
Type: Signer, Type: Signer,
Value: transaction.Signer{ Value: transaction.Signer{
Account: accountHash, Account: accountHash,
Scopes: transaction.FeeOnly, Scopes: transaction.None,
}, },
}, },
{ {

View file

@ -955,7 +955,7 @@ func (s *Server) invokeFunction(reqParams request.Params) (interface{}, *respons
checkWitnessHashesIndex-- checkWitnessHashesIndex--
} }
if len(tx.Signers) == 0 { if len(tx.Signers) == 0 {
tx.Signers = []transaction.Signer{{Account: util.Uint160{}, Scopes: transaction.FeeOnly}} tx.Signers = []transaction.Signer{{Account: util.Uint160{}, Scopes: transaction.None}}
} }
script, err := request.CreateFunctionInvocationScript(scriptHash, reqParams[1:checkWitnessHashesIndex]) script, err := request.CreateFunctionInvocationScript(scriptHash, reqParams[1:checkWitnessHashesIndex])
if err != nil { if err != nil {
@ -985,7 +985,7 @@ func (s *Server) invokescript(reqParams request.Params) (interface{}, *response.
tx.Signers = signers tx.Signers = signers
} }
if len(tx.Signers) == 0 { if len(tx.Signers) == 0 {
tx.Signers = []transaction.Signer{{Account: util.Uint160{}, Scopes: transaction.FeeOnly}} tx.Signers = []transaction.Signer{{Account: util.Uint160{}, Scopes: transaction.None}}
} }
tx.Script = script tx.Script = script
return s.runScriptInVM(script, tx), nil return s.runScriptInVM(script, tx), nil