interop: return struct pointers where needed

`Transaction`, `Block` and `Contract` are represented as
`Array`s in VM, so we must return pointers.

Revert a1f98f92.
This commit is contained in:
Evgenii Stratonikov 2020-09-08 13:41:47 +03:00
parent 25f8545cdf
commit 37f7363386
5 changed files with 71 additions and 80 deletions

View file

@ -1392,10 +1392,7 @@ func (c *codegen) convertSyscall(expr *ast.CallExpr, api, name string) {
c.prog.Err = fmt.Errorf("unknown VM syscall api: %s.%s", api, name) c.prog.Err = fmt.Errorf("unknown VM syscall api: %s.%s", api, name)
return return
} }
emit.Syscall(c.prog.BinWriter, syscall.API) emit.Syscall(c.prog.BinWriter, syscall)
if syscall.ConvertResultToStruct {
c.emitConvert(stackitem.StructT)
}
// This NOP instruction is basically not needed, but if we do, we have a // This NOP instruction is basically not needed, but if we do, we have a
// one to one matching avm file with neo-python which is very nice for debugging. // one to one matching avm file with neo-python which is very nice for debugging.

View file

@ -2,91 +2,85 @@ package compiler
import "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" import "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
// Syscall represents NEO or System syscall API with flag for proper AVM generation
type Syscall struct {
API string
ConvertResultToStruct bool
}
// All lists are sorted, keep 'em this way, please. // All lists are sorted, keep 'em this way, please.
var syscalls = map[string]map[string]Syscall{ var syscalls = map[string]map[string]string{
"binary": { "binary": {
"Base58Decode": {interopnames.SystemBinaryBase58Decode, false}, "Base58Decode": interopnames.SystemBinaryBase58Decode,
"Base58Encode": {interopnames.SystemBinaryBase58Encode, false}, "Base58Encode": interopnames.SystemBinaryBase58Encode,
"Base64Decode": {interopnames.SystemBinaryBase64Decode, false}, "Base64Decode": interopnames.SystemBinaryBase64Decode,
"Base64Encode": {interopnames.SystemBinaryBase64Encode, false}, "Base64Encode": interopnames.SystemBinaryBase64Encode,
"Deserialize": {interopnames.SystemBinaryDeserialize, false}, "Deserialize": interopnames.SystemBinaryDeserialize,
"Serialize": {interopnames.SystemBinarySerialize, false}, "Serialize": interopnames.SystemBinarySerialize,
}, },
"blockchain": { "blockchain": {
"GetBlock": {interopnames.SystemBlockchainGetBlock, true}, "GetBlock": interopnames.SystemBlockchainGetBlock,
"GetContract": {interopnames.SystemBlockchainGetContract, true}, "GetContract": interopnames.SystemBlockchainGetContract,
"GetHeight": {interopnames.SystemBlockchainGetHeight, false}, "GetHeight": interopnames.SystemBlockchainGetHeight,
"GetTransaction": {interopnames.SystemBlockchainGetTransaction, true}, "GetTransaction": interopnames.SystemBlockchainGetTransaction,
"GetTransactionFromBlock": {interopnames.SystemBlockchainGetTransactionFromBlock, false}, "GetTransactionFromBlock": interopnames.SystemBlockchainGetTransactionFromBlock,
"GetTransactionHeight": {interopnames.SystemBlockchainGetTransactionHeight, false}, "GetTransactionHeight": interopnames.SystemBlockchainGetTransactionHeight,
}, },
"contract": { "contract": {
"Create": {interopnames.SystemContractCreate, true}, "Create": interopnames.SystemContractCreate,
"CreateStandardAccount": {interopnames.SystemContractCreateStandardAccount, false}, "CreateStandardAccount": interopnames.SystemContractCreateStandardAccount,
"Destroy": {interopnames.SystemContractDestroy, false}, "Destroy": interopnames.SystemContractDestroy,
"IsStandard": {interopnames.SystemContractIsStandard, false}, "IsStandard": interopnames.SystemContractIsStandard,
"GetCallFlags": {interopnames.SystemContractGetCallFlags, false}, "GetCallFlags": interopnames.SystemContractGetCallFlags,
"Update": {interopnames.SystemContractUpdate, false}, "Update": interopnames.SystemContractUpdate,
}, },
"crypto": { "crypto": {
"ECDsaSecp256k1Verify": {interopnames.NeoCryptoVerifyWithECDsaSecp256k1, false}, "ECDsaSecp256k1Verify": interopnames.NeoCryptoVerifyWithECDsaSecp256k1,
"ECDSASecp256k1CheckMultisig": {interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1, false}, "ECDSASecp256k1CheckMultisig": interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1,
"ECDsaSecp256r1Verify": {interopnames.NeoCryptoVerifyWithECDsaSecp256r1, false}, "ECDsaSecp256r1Verify": interopnames.NeoCryptoVerifyWithECDsaSecp256r1,
"ECDSASecp256r1CheckMultisig": {interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1, false}, "ECDSASecp256r1CheckMultisig": interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1,
"RIPEMD160": {interopnames.NeoCryptoRIPEMD160, false}, "RIPEMD160": interopnames.NeoCryptoRIPEMD160,
"SHA256": {interopnames.NeoCryptoSHA256, false}, "SHA256": interopnames.NeoCryptoSHA256,
}, },
"enumerator": { "enumerator": {
"Concat": {interopnames.SystemEnumeratorConcat, false}, "Concat": interopnames.SystemEnumeratorConcat,
"Create": {interopnames.SystemEnumeratorCreate, false}, "Create": interopnames.SystemEnumeratorCreate,
"Next": {interopnames.SystemEnumeratorNext, false}, "Next": interopnames.SystemEnumeratorNext,
"Value": {interopnames.SystemEnumeratorValue, false}, "Value": interopnames.SystemEnumeratorValue,
}, },
"engine": { "engine": {
"AppCall": {interopnames.SystemContractCall, false}, "AppCall": interopnames.SystemContractCall,
}, },
"iterator": { "iterator": {
"Concat": {interopnames.SystemIteratorConcat, false}, "Concat": interopnames.SystemIteratorConcat,
"Create": {interopnames.SystemIteratorCreate, false}, "Create": interopnames.SystemIteratorCreate,
"Key": {interopnames.SystemIteratorKey, false}, "Key": interopnames.SystemIteratorKey,
"Keys": {interopnames.SystemIteratorKeys, false}, "Keys": interopnames.SystemIteratorKeys,
"Next": {interopnames.SystemEnumeratorNext, false}, "Next": interopnames.SystemEnumeratorNext,
"Value": {interopnames.SystemEnumeratorValue, false}, "Value": interopnames.SystemEnumeratorValue,
"Values": {interopnames.SystemIteratorValues, false}, "Values": interopnames.SystemIteratorValues,
}, },
"json": { "json": {
"Deserialize": {interopnames.SystemJSONDeserialize, false}, "Deserialize": interopnames.SystemJSONDeserialize,
"Serialize": {interopnames.SystemJSONSerialize, false}, "Serialize": interopnames.SystemJSONSerialize,
}, },
"runtime": { "runtime": {
"GasLeft": {interopnames.SystemRuntimeGasLeft, false}, "GasLeft": interopnames.SystemRuntimeGasLeft,
"GetInvocationCounter": {interopnames.SystemRuntimeGetInvocationCounter, false}, "GetInvocationCounter": interopnames.SystemRuntimeGetInvocationCounter,
"GetCallingScriptHash": {interopnames.SystemRuntimeGetCallingScriptHash, false}, "GetCallingScriptHash": interopnames.SystemRuntimeGetCallingScriptHash,
"GetEntryScriptHash": {interopnames.SystemRuntimeGetEntryScriptHash, false}, "GetEntryScriptHash": interopnames.SystemRuntimeGetEntryScriptHash,
"GetExecutingScriptHash": {interopnames.SystemRuntimeGetExecutingScriptHash, false}, "GetExecutingScriptHash": interopnames.SystemRuntimeGetExecutingScriptHash,
"GetNotifications": {interopnames.SystemRuntimeGetNotifications, false}, "GetNotifications": interopnames.SystemRuntimeGetNotifications,
"GetScriptContainer": {interopnames.SystemRuntimeGetScriptContainer, true}, "GetScriptContainer": interopnames.SystemRuntimeGetScriptContainer,
"GetTime": {interopnames.SystemRuntimeGetTime, false}, "GetTime": interopnames.SystemRuntimeGetTime,
"GetTrigger": {interopnames.SystemRuntimeGetTrigger, false}, "GetTrigger": interopnames.SystemRuntimeGetTrigger,
"CheckWitness": {interopnames.SystemRuntimeCheckWitness, false}, "CheckWitness": interopnames.SystemRuntimeCheckWitness,
"Log": {interopnames.SystemRuntimeLog, false}, "Log": interopnames.SystemRuntimeLog,
"Notify": {interopnames.SystemRuntimeNotify, false}, "Notify": interopnames.SystemRuntimeNotify,
"Platform": {interopnames.SystemRuntimePlatform, false}, "Platform": interopnames.SystemRuntimePlatform,
}, },
"storage": { "storage": {
"ConvertContextToReadOnly": {interopnames.SystemStorageAsReadOnly, false}, "ConvertContextToReadOnly": interopnames.SystemStorageAsReadOnly,
"Delete": {interopnames.SystemStorageDelete, false}, "Delete": interopnames.SystemStorageDelete,
"Find": {interopnames.SystemStorageFind, false}, "Find": interopnames.SystemStorageFind,
"Get": {interopnames.SystemStorageGet, false}, "Get": interopnames.SystemStorageGet,
"GetContext": {interopnames.SystemStorageGetContext, false}, "GetContext": interopnames.SystemStorageGetContext,
"GetReadOnlyContext": {interopnames.SystemStorageGetReadOnlyContext, false}, "GetReadOnlyContext": interopnames.SystemStorageGetReadOnlyContext,
"Put": {interopnames.SystemStoragePut, false}, "Put": interopnames.SystemStoragePut,
"PutEx": {interopnames.SystemStoragePutEx, false}, "PutEx": interopnames.SystemStoragePutEx,
}, },
} }

View file

@ -70,15 +70,15 @@ func GetHeight() int {
// GetBlock returns block found by the given hash or index (with the same // GetBlock returns block found by the given hash or index (with the same
// encoding as for GetHeader). This function uses `System.Blockchain.GetBlock` // encoding as for GetHeader). This function uses `System.Blockchain.GetBlock`
// syscall. // syscall.
func GetBlock(heightOrHash interface{}) Block { func GetBlock(heightOrHash interface{}) *Block {
return Block{} return &Block{}
} }
// GetTransaction returns transaction found by the given hash (256 bit in BE // GetTransaction returns transaction found by the given hash (256 bit in BE
// format represented as a slice of 32 bytes). This function uses // format represented as a slice of 32 bytes). This function uses
// `System.Blockchain.GetTransaction` syscall. // `System.Blockchain.GetTransaction` syscall.
func GetTransaction(hash interop.Hash256) Transaction { func GetTransaction(hash interop.Hash256) *Transaction {
return Transaction{} return &Transaction{}
} }
// GetTransactionFromBlock returns transaction hash (256 bit in BE format // GetTransactionFromBlock returns transaction hash (256 bit in BE format
@ -100,6 +100,6 @@ func GetTransactionHeight(hash interop.Hash256) int {
// format represented as a slice of 20 bytes). Refer to the `contract` package // format represented as a slice of 20 bytes). Refer to the `contract` package
// for details on how to use the returned structure. This function uses // for details on how to use the returned structure. This function uses
// `System.Blockchain.GetContract` syscall. // `System.Blockchain.GetContract` syscall.
func GetContract(scriptHash interop.Hash160) contract.Contract { func GetContract(scriptHash interop.Hash160) *contract.Contract {
return contract.Contract{} return &contract.Contract{}
} }

View file

@ -21,8 +21,8 @@ type Contract struct {
// manifest contract's manifest (limited in length by 2 KiB) // manifest contract's manifest (limited in length by 2 KiB)
// It returns this new created Contract when successful (and fails transaction // It returns this new created Contract when successful (and fails transaction
// if not). It uses `System.Contract.Create` syscall. // if not). It uses `System.Contract.Create` syscall.
func Create(script []byte, manifest []byte) Contract { func Create(script []byte, manifest []byte) *Contract {
return Contract{} return &Contract{}
} }
// Update updates script and manifest of the calling contract (that is the one that calls Update) // Update updates script and manifest of the calling contract (that is the one that calls Update)

View file

@ -9,8 +9,8 @@ import (
// execution context. It never changes in a single execution, no matter how deep // execution context. It never changes in a single execution, no matter how deep
// this execution goes. This function uses // this execution goes. This function uses
// `System.Runtime.GetScriptContainer` syscall. // `System.Runtime.GetScriptContainer` syscall.
func GetScriptContainer() blockchain.Transaction { func GetScriptContainer() *blockchain.Transaction {
return blockchain.Transaction{} return &blockchain.Transaction{}
} }
// GetExecutingScriptHash returns script hash (160 bit in BE form represented // GetExecutingScriptHash returns script hash (160 bit in BE form represented