mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-16 21:16:30 +00:00
core: add FeeOnly witness scope
This commit is contained in:
parent
75f1c2d6f2
commit
8697582b23
5 changed files with 23 additions and 10 deletions
|
@ -690,7 +690,9 @@ func parseContractConfig(confFile string) (ProjectConfig, error) {
|
|||
func parseCosigner(c string) (transaction.Cosigner, error) {
|
||||
var (
|
||||
err error
|
||||
res = transaction.Cosigner{}
|
||||
res = transaction.Cosigner{
|
||||
Scopes: transaction.Global,
|
||||
}
|
||||
)
|
||||
data := strings.SplitN(c, ":", 2)
|
||||
s := data[0]
|
||||
|
|
|
@ -152,6 +152,10 @@ func (t *Transaction) decodeHashableFields(br *io.BinReader) {
|
|||
|
||||
br.ReadArray(&t.Cosigners, MaxCosigners)
|
||||
for i := 0; i < len(t.Cosigners); i++ {
|
||||
if t.Cosigners[i].Scopes == FeeOnly {
|
||||
br.Err = errors.New("FeeOnly scope can be used only for sender")
|
||||
return
|
||||
}
|
||||
for j := i + 1; j < len(t.Cosigners); j++ {
|
||||
if t.Cosigners[i].Account.Equals(t.Cosigners[j].Account) {
|
||||
br.Err = errors.New("transaction cosigners should be unique")
|
||||
|
|
|
@ -11,9 +11,8 @@ import (
|
|||
type WitnessScope byte
|
||||
|
||||
const (
|
||||
// Global allows this witness in all contexts (default Neo2 behavior).
|
||||
// This cannot be combined with other flags.
|
||||
Global WitnessScope = 0x00
|
||||
// FeeOnly is only valid for a sender, it can't be used during the execution.
|
||||
FeeOnly WitnessScope = 0
|
||||
// CalledByEntry means that this condition must hold: EntryScriptHash == CallingScriptHash.
|
||||
// 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
|
||||
|
@ -23,6 +22,9 @@ const (
|
|||
CustomContracts WitnessScope = 0x10
|
||||
// CustomGroups define custom pubkey for group members.
|
||||
CustomGroups WitnessScope = 0x20
|
||||
// Global allows this witness in all contexts (default Neo2 behavior).
|
||||
// This cannot be combined with other flags.
|
||||
Global WitnessScope = 0x80
|
||||
)
|
||||
|
||||
// ScopesFromString converts string of comma-separated scopes to a set of scopes
|
||||
|
@ -40,6 +42,7 @@ func ScopesFromString(s string) (WitnessScope, error) {
|
|||
CalledByEntry.String(): CalledByEntry,
|
||||
CustomContracts.String(): CustomContracts,
|
||||
CustomGroups.String(): CustomGroups,
|
||||
FeeOnly.String(): FeeOnly,
|
||||
}
|
||||
var isGlobal bool
|
||||
for _, scopeStr := range scopes {
|
||||
|
@ -61,8 +64,8 @@ func ScopesFromString(s string) (WitnessScope, error) {
|
|||
// scopesToString converts witness scope to it's string representation. It uses
|
||||
// `, ` to separate scope names.
|
||||
func scopesToString(scopes WitnessScope) string {
|
||||
if scopes == Global {
|
||||
return "Global"
|
||||
if scopes&Global != 0 || scopes == FeeOnly {
|
||||
return scopes.String()
|
||||
}
|
||||
var res string
|
||||
if scopes&CalledByEntry != 0 {
|
||||
|
|
|
@ -8,20 +8,22 @@ func _() {
|
|||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[Global-0]
|
||||
_ = x[FeeOnly-0]
|
||||
_ = x[CalledByEntry-1]
|
||||
_ = x[CustomContracts-16]
|
||||
_ = x[CustomGroups-32]
|
||||
_ = x[Global-128]
|
||||
}
|
||||
|
||||
const (
|
||||
_WitnessScope_name_0 = "GlobalCalledByEntry"
|
||||
_WitnessScope_name_0 = "FeeOnlyCalledByEntry"
|
||||
_WitnessScope_name_1 = "CustomContracts"
|
||||
_WitnessScope_name_2 = "CustomGroups"
|
||||
_WitnessScope_name_3 = "Global"
|
||||
)
|
||||
|
||||
var (
|
||||
_WitnessScope_index_0 = [...]uint8{0, 6, 19}
|
||||
_WitnessScope_index_0 = [...]uint8{0, 7, 20}
|
||||
)
|
||||
|
||||
func (i WitnessScope) String() string {
|
||||
|
@ -32,6 +34,8 @@ func (i WitnessScope) String() string {
|
|||
return _WitnessScope_name_1
|
||||
case i == 32:
|
||||
return _WitnessScope_name_2
|
||||
case i == 128:
|
||||
return _WitnessScope_name_3
|
||||
default:
|
||||
return "WitnessScope(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
|||
Type: Cosigner,
|
||||
Value: transaction.Cosigner{
|
||||
Account: accountHash,
|
||||
Scopes: transaction.Global,
|
||||
Scopes: transaction.FeeOnly,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue