forked from TrueCloudLab/neoneo-go
CityOfZion/neo-storm#17 Implemented util.CompareBytes (CityOfZion/neo-storm#21)
Imported from CityOfZion/neo-storm (c0ee185a7cfd2c222fb7b4c8ca19885844d53855).
This commit is contained in:
parent
b997eeb051
commit
f14833893c
4 changed files with 12 additions and 28 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/CityOfZion/neo-storm/interop/engine"
|
||||
"github.com/CityOfZion/neo-storm/interop/runtime"
|
||||
"github.com/CityOfZion/neo-storm/interop/storage"
|
||||
"github.com/CityOfZion/neo-storm/interop/util"
|
||||
)
|
||||
|
||||
// Token holds all token info
|
||||
|
@ -81,35 +82,16 @@ func (t Token) CanTransfer(ctx storage.Context, from []byte, to []byte, amount i
|
|||
// IsUsableAddress checks if the sender is either the correct NEO address or SC address
|
||||
func IsUsableAddress(addr []byte) bool {
|
||||
if len(addr) == 20 {
|
||||
|
||||
if runtime.CheckWitness(addr) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if a smart contract is calling scripthash
|
||||
callingScriptHash := engine.GetCallingScriptHash()
|
||||
if EqualAddresses(callingScriptHash, addr) {
|
||||
if util.CompareBytes(callingScriptHash, addr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// EqualAddresses compares two addresses if they're equal
|
||||
// also returns false if one of the two - or both - aren't actual addresses
|
||||
func EqualAddresses(a []byte, b []byte) bool {
|
||||
aLen := len(a)
|
||||
bLen := len(b)
|
||||
if aLen != bLen || aLen != 20 || bLen != 20 {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < aLen; i++ {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -4,3 +4,9 @@ package util
|
|||
func FromAddress(address string) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CompareBytes compares a with b and will return true whether a and b
|
||||
// are equal.
|
||||
func CompareBytes(a, b []byte) bool {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -13,14 +13,8 @@ var (
|
|||
// Go language builtin functions and custom builtin utility functions.
|
||||
builtinFuncs = []string{
|
||||
"len", "append", "SHA256",
|
||||
"SHA1", "Hash256", "Hash160", "FromAddress",
|
||||
}
|
||||
|
||||
// VM system calls that have no return value.
|
||||
noRetSyscalls = []string{
|
||||
"Notify", "Log", "Put", "Register", "Delete",
|
||||
"SetVotes", "ContractDestroy", "MerkleRoot", "Hash",
|
||||
"PrevHash", "GetHeader",
|
||||
"SHA1", "Hash256", "Hash160",
|
||||
"FromAddress", "CompareBytes",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -571,6 +571,8 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
|||
emitOpcode(c.prog, vm.HASH256)
|
||||
case "Hash160":
|
||||
emitOpcode(c.prog, vm.HASH160)
|
||||
case "CompareBytes":
|
||||
emitOpcode(c.prog, vm.EQUAL)
|
||||
case "FromAddress":
|
||||
// We can be sure that this is a ast.BasicLit just containing a simple
|
||||
// address string. Note that the string returned from calling Value will
|
||||
|
|
Loading…
Reference in a new issue