mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
smartcontract: rewrite trigger types for NEO3
This commit is contained in:
parent
a3b876d55c
commit
b12add5a78
4 changed files with 32 additions and 51 deletions
|
@ -272,7 +272,7 @@ func checkStorageContext(ic *interop.Context, stc *StorageContext) error {
|
|||
|
||||
// storageDelete deletes stored key-value pair.
|
||||
func storageDelete(ic *interop.Context, v *vm.VM) error {
|
||||
if ic.Trigger != trigger.Application && ic.Trigger != trigger.ApplicationR {
|
||||
if ic.Trigger != trigger.Application {
|
||||
return errors.New("can't delete when the trigger is not application")
|
||||
}
|
||||
stcInterface := v.Estack().Pop().Value()
|
||||
|
@ -337,7 +337,7 @@ func storageGetReadOnlyContext(ic *interop.Context, v *vm.VM) error {
|
|||
}
|
||||
|
||||
func putWithContextAndFlags(ic *interop.Context, stc *StorageContext, key []byte, value []byte, isConst bool) error {
|
||||
if ic.Trigger != trigger.Application && ic.Trigger != trigger.ApplicationR {
|
||||
if ic.Trigger != trigger.Application {
|
||||
return errors.New("can't delete when the trigger is not application")
|
||||
}
|
||||
if len(key) > MaxStorageKeyLen {
|
||||
|
|
|
@ -1,41 +1,29 @@
|
|||
package trigger
|
||||
|
||||
//go:generate stringer -type=Type
|
||||
//go:generate stringer -type=Type -output=trigger_type_string.go
|
||||
|
||||
// Type represents trigger type used in C# reference node: https://github.com/neo-project/neo/blob/c64748ecbac3baeb8045b16af0d518398a6ced24/neo/SmartContract/TriggerType.cs#L3
|
||||
type Type byte
|
||||
|
||||
// Viable list of supported trigger type constants.
|
||||
const (
|
||||
// System is trigger type that indicates that script is being invoke internally by the system.
|
||||
System Type = 0x01
|
||||
|
||||
// The verification trigger indicates that the contract is being invoked as a verification function.
|
||||
// The verification function can accept multiple parameters, and should return a boolean value that indicates the validity of the transaction or block.
|
||||
// The entry point of the contract will be invoked if the contract is triggered by Verification:
|
||||
// main(...);
|
||||
// The entry point of the contract must be able to handle this type of invocation.
|
||||
Verification Type = 0x00
|
||||
|
||||
// The verificationR trigger indicates that the contract is being invoked as a verification function because it is specified as a target of an output of the transaction.
|
||||
// The verification function accepts no parameter, and should return a boolean value that indicates the validity of the transaction.
|
||||
// The entry point of the contract will be invoked if the contract is triggered by VerificationR:
|
||||
// main("receiving", new object[0]);
|
||||
// The receiving function should have the following signature:
|
||||
// public bool receiving()
|
||||
// The receiving function will be invoked automatically when a contract is receiving assets from a transfer.
|
||||
VerificationR Type = 0x01
|
||||
Verification Type = 0x20
|
||||
|
||||
// The application trigger indicates that the contract is being invoked as an application function.
|
||||
// The application function can accept multiple parameters, change the states of the blockchain, and return any type of value.
|
||||
// The contract can have any form of entry point, but we recommend that all contracts should have the following entry point:
|
||||
// public byte[] main(string operation, params object[] args)
|
||||
// The functions can be invoked by creating an InvocationTransaction.
|
||||
Application Type = 0x10
|
||||
Application Type = 0x40
|
||||
|
||||
// The ApplicationR trigger indicates that the default function received of the contract is being invoked because it is specified as a target of an output of the transaction.
|
||||
// The received function accepts no parameter, changes the states of the blockchain, and returns any type of value.
|
||||
// The entry point of the contract will be invoked if the contract is triggered by ApplicationR:
|
||||
// main("received", new object[0]);
|
||||
// The received function should have the following signature:
|
||||
// public byte[] received()
|
||||
// The received function will be invoked automatically when a contract is receiving assets from a transfer.
|
||||
ApplicationR Type = 0x11
|
||||
// All represents any trigger type.
|
||||
All = System | Verification | Application
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by "stringer -type=Type"; DO NOT EDIT.
|
||||
// Code generated by "stringer -type=Type -output=trigger_type_string.go"; DO NOT EDIT.
|
||||
|
||||
package trigger
|
||||
|
||||
|
@ -8,29 +8,25 @@ 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[Verification-0]
|
||||
_ = x[VerificationR-1]
|
||||
_ = x[Application-16]
|
||||
_ = x[ApplicationR-17]
|
||||
_ = x[System-1]
|
||||
_ = x[Verification-32]
|
||||
_ = x[Application-64]
|
||||
}
|
||||
|
||||
const (
|
||||
_Type_name_0 = "VerificationVerificationR"
|
||||
_Type_name_1 = "ApplicationApplicationR"
|
||||
)
|
||||
|
||||
var (
|
||||
_Type_index_0 = [...]uint8{0, 12, 25}
|
||||
_Type_index_1 = [...]uint8{0, 11, 23}
|
||||
_Type_name_0 = "System"
|
||||
_Type_name_1 = "Verification"
|
||||
_Type_name_2 = "Application"
|
||||
)
|
||||
|
||||
func (i Type) String() string {
|
||||
switch {
|
||||
case i <= 1:
|
||||
return _Type_name_0[_Type_index_0[i]:_Type_index_0[i+1]]
|
||||
case 16 <= i && i <= 17:
|
||||
i -= 16
|
||||
return _Type_name_1[_Type_index_1[i]:_Type_index_1[i+1]]
|
||||
case i == 1:
|
||||
return _Type_name_0
|
||||
case i == 32:
|
||||
return _Type_name_1
|
||||
case i == 64:
|
||||
return _Type_name_2
|
||||
default:
|
||||
return "Type(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
|
|
|
@ -8,10 +8,9 @@ import (
|
|||
|
||||
func TestStringer(t *testing.T) {
|
||||
tests := map[Type]string{
|
||||
System: "System",
|
||||
Application: "Application",
|
||||
ApplicationR: "ApplicationR",
|
||||
Verification: "Verification",
|
||||
VerificationR: "VerificationR",
|
||||
}
|
||||
for o, s := range tests {
|
||||
assert.Equal(t, s, o.String())
|
||||
|
@ -20,10 +19,9 @@ func TestStringer(t *testing.T) {
|
|||
|
||||
func TestEncodeBynary(t *testing.T) {
|
||||
tests := map[Type]byte{
|
||||
Verification: 0x00,
|
||||
VerificationR: 0x01,
|
||||
Application: 0x10,
|
||||
ApplicationR: 0x11,
|
||||
System: 0x01,
|
||||
Verification: 0x20,
|
||||
Application: 0x40,
|
||||
}
|
||||
for o, b := range tests {
|
||||
assert.Equal(t, b, byte(o))
|
||||
|
@ -32,10 +30,9 @@ func TestEncodeBynary(t *testing.T) {
|
|||
|
||||
func TestDecodeBynary(t *testing.T) {
|
||||
tests := map[Type]byte{
|
||||
Verification: 0x00,
|
||||
VerificationR: 0x01,
|
||||
Application: 0x10,
|
||||
ApplicationR: 0x11,
|
||||
System: 0x01,
|
||||
Verification: 0x20,
|
||||
Application: 0x40,
|
||||
}
|
||||
for o, b := range tests {
|
||||
assert.Equal(t, o, Type(b))
|
||||
|
|
Loading…
Reference in a new issue