forked from TrueCloudLab/neoneo-go
Merge pull request #1299 from nspcc-dev/fix/1298
compiler: use constants in interops
This commit is contained in:
commit
547c58c00c
4 changed files with 13 additions and 24 deletions
|
@ -261,7 +261,7 @@ func Main(operation string, args []interface{}) bool {
|
||||||
token := newToken()
|
token := newToken()
|
||||||
trigger := runtime.GetTrigger()
|
trigger := runtime.GetTrigger()
|
||||||
|
|
||||||
if trigger == runtime.Verification() {
|
if trigger == runtime.Verification {
|
||||||
isOwner := runtime.CheckWitness(token.Owner)
|
isOwner := runtime.CheckWitness(token.Owner)
|
||||||
if isOwner {
|
if isOwner {
|
||||||
return true
|
return true
|
||||||
|
@ -269,7 +269,7 @@ func Main(operation string, args []interface{}) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if trigger == runtime.Application() {
|
if trigger == runtime.Application {
|
||||||
if operation == "mintTokens" {
|
if operation == "mintTokens" {
|
||||||
token.AddToCirculation(100)
|
token.AddToCirculation(100)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,12 @@ func Main(operation string, args []interface{}) bool {
|
||||||
trigger := runtime.GetTrigger()
|
trigger := runtime.GetTrigger()
|
||||||
|
|
||||||
// Log owner upon Verification trigger
|
// Log owner upon Verification trigger
|
||||||
if trigger == runtime.Verification() {
|
if trigger == runtime.Verification {
|
||||||
return CheckWitness()
|
return CheckWitness()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discerns between log and notify for this test
|
// Discerns between log and notify for this test
|
||||||
if trigger == runtime.Application() {
|
if trigger == runtime.Application {
|
||||||
return handleOperation(operation, args)
|
return handleOperation(operation, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ func Main(operation string, args []interface{}) interface{} {
|
||||||
|
|
||||||
// This is used to verify if a transfer of system assets (NEO and Gas)
|
// This is used to verify if a transfer of system assets (NEO and Gas)
|
||||||
// involving this contract's address can proceed.
|
// involving this contract's address can proceed.
|
||||||
if trigger == runtime.Verification() {
|
if trigger == runtime.Verification {
|
||||||
// Check if the invoker is the owner of the contract.
|
// Check if the invoker is the owner of the contract.
|
||||||
if runtime.CheckWitness(cfg.Owner) {
|
if runtime.CheckWitness(cfg.Owner) {
|
||||||
return true
|
return true
|
||||||
|
@ -120,7 +120,7 @@ func Main(operation string, args []interface{}) interface{} {
|
||||||
// Otherwise TODO
|
// Otherwise TODO
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if trigger == runtime.Application() {
|
if trigger == runtime.Application {
|
||||||
return handleOperation(operation, args, ctx, cfg)
|
return handleOperation(operation, args, ctx, cfg)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -4,6 +4,13 @@ It has similar function to Runtime class in .net framwork for Neo.
|
||||||
*/
|
*/
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
// Trigger values to compare with GetTrigger result.
|
||||||
|
const (
|
||||||
|
System byte = 0x01
|
||||||
|
Application byte = 0x40
|
||||||
|
Verification byte = 0x20
|
||||||
|
)
|
||||||
|
|
||||||
// CheckWitness verifies if the given script hash (160-bit BE value in a 20 byte
|
// CheckWitness verifies if the given script hash (160-bit BE value in a 20 byte
|
||||||
// slice) or key (compressed serialized 33-byte form) is one of the signers of
|
// slice) or key (compressed serialized 33-byte form) is one of the signers of
|
||||||
// this invocation. It uses `System.Runtime.CheckWitness` syscall.
|
// this invocation. It uses `System.Runtime.CheckWitness` syscall.
|
||||||
|
@ -43,24 +50,6 @@ func GetTrigger() byte {
|
||||||
return 0x00
|
return 0x00
|
||||||
}
|
}
|
||||||
|
|
||||||
// System returns the System trigger type value to compare with
|
|
||||||
// GetTrigger return value.
|
|
||||||
func System() byte {
|
|
||||||
return 0x01
|
|
||||||
}
|
|
||||||
|
|
||||||
// Application returns the Application trigger type value to compare with
|
|
||||||
// GetTrigger return value.
|
|
||||||
func Application() byte {
|
|
||||||
return 0x40
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verification returns the Verification trigger type value to compare with
|
|
||||||
// GetTrigger return value.
|
|
||||||
func Verification() byte {
|
|
||||||
return 0x20
|
|
||||||
}
|
|
||||||
|
|
||||||
// GasLeft returns the amount of gas available for the current execution.
|
// GasLeft returns the amount of gas available for the current execution.
|
||||||
// This function uses `System.Runtime.GasLeft` syscall.
|
// This function uses `System.Runtime.GasLeft` syscall.
|
||||||
func GasLeft() int64 {
|
func GasLeft() int64 {
|
||||||
|
|
Loading…
Reference in a new issue