forked from TrueCloudLab/neoneo-go
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) {
|
func parseCosigner(c string) (transaction.Cosigner, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
res = transaction.Cosigner{}
|
res = transaction.Cosigner{
|
||||||
|
Scopes: transaction.Global,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
data := strings.SplitN(c, ":", 2)
|
data := strings.SplitN(c, ":", 2)
|
||||||
s := data[0]
|
s := data[0]
|
||||||
|
|
|
@ -152,6 +152,10 @@ func (t *Transaction) decodeHashableFields(br *io.BinReader) {
|
||||||
|
|
||||||
br.ReadArray(&t.Cosigners, MaxCosigners)
|
br.ReadArray(&t.Cosigners, MaxCosigners)
|
||||||
for i := 0; i < len(t.Cosigners); i++ {
|
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++ {
|
for j := i + 1; j < len(t.Cosigners); j++ {
|
||||||
if t.Cosigners[i].Account.Equals(t.Cosigners[j].Account) {
|
if t.Cosigners[i].Account.Equals(t.Cosigners[j].Account) {
|
||||||
br.Err = errors.New("transaction cosigners should be unique")
|
br.Err = errors.New("transaction cosigners should be unique")
|
||||||
|
|
|
@ -11,9 +11,8 @@ import (
|
||||||
type WitnessScope byte
|
type WitnessScope byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Global allows this witness in all contexts (default Neo2 behavior).
|
// FeeOnly is only valid for a sender, it can't be used during the execution.
|
||||||
// This cannot be combined with other flags.
|
FeeOnly WitnessScope = 0
|
||||||
Global WitnessScope = 0x00
|
|
||||||
// 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
|
||||||
|
@ -23,6 +22,9 @@ const (
|
||||||
CustomContracts WitnessScope = 0x10
|
CustomContracts WitnessScope = 0x10
|
||||||
// CustomGroups define custom pubkey for group members.
|
// CustomGroups define custom pubkey for group members.
|
||||||
CustomGroups WitnessScope = 0x20
|
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
|
// 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,
|
CalledByEntry.String(): CalledByEntry,
|
||||||
CustomContracts.String(): CustomContracts,
|
CustomContracts.String(): CustomContracts,
|
||||||
CustomGroups.String(): CustomGroups,
|
CustomGroups.String(): CustomGroups,
|
||||||
|
FeeOnly.String(): FeeOnly,
|
||||||
}
|
}
|
||||||
var isGlobal bool
|
var isGlobal bool
|
||||||
for _, scopeStr := range scopes {
|
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
|
// 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 {
|
if scopes&Global != 0 || scopes == FeeOnly {
|
||||||
return "Global"
|
return scopes.String()
|
||||||
}
|
}
|
||||||
var res string
|
var res string
|
||||||
if scopes&CalledByEntry != 0 {
|
if scopes&CalledByEntry != 0 {
|
||||||
|
|
|
@ -8,20 +8,22 @@ 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[Global-0]
|
_ = x[FeeOnly-0]
|
||||||
_ = x[CalledByEntry-1]
|
_ = x[CalledByEntry-1]
|
||||||
_ = x[CustomContracts-16]
|
_ = x[CustomContracts-16]
|
||||||
_ = x[CustomGroups-32]
|
_ = x[CustomGroups-32]
|
||||||
|
_ = x[Global-128]
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_WitnessScope_name_0 = "GlobalCalledByEntry"
|
_WitnessScope_name_0 = "FeeOnlyCalledByEntry"
|
||||||
_WitnessScope_name_1 = "CustomContracts"
|
_WitnessScope_name_1 = "CustomContracts"
|
||||||
_WitnessScope_name_2 = "CustomGroups"
|
_WitnessScope_name_2 = "CustomGroups"
|
||||||
|
_WitnessScope_name_3 = "Global"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_WitnessScope_index_0 = [...]uint8{0, 6, 19}
|
_WitnessScope_index_0 = [...]uint8{0, 7, 20}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (i WitnessScope) String() string {
|
func (i WitnessScope) String() string {
|
||||||
|
@ -32,6 +34,8 @@ func (i WitnessScope) String() string {
|
||||||
return _WitnessScope_name_1
|
return _WitnessScope_name_1
|
||||||
case i == 32:
|
case i == 32:
|
||||||
return _WitnessScope_name_2
|
return _WitnessScope_name_2
|
||||||
|
case i == 128:
|
||||||
|
return _WitnessScope_name_3
|
||||||
default:
|
default:
|
||||||
return "WitnessScope(" + strconv.FormatInt(int64(i), 10) + ")"
|
return "WitnessScope(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
||||||
Type: Cosigner,
|
Type: Cosigner,
|
||||||
Value: transaction.Cosigner{
|
Value: transaction.Cosigner{
|
||||||
Account: accountHash,
|
Account: accountHash,
|
||||||
Scopes: transaction.Global,
|
Scopes: transaction.FeeOnly,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue