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)
return
}
emit.Syscall(c.prog.BinWriter, syscall.API)
if syscall.ConvertResultToStruct {
c.emitConvert(stackitem.StructT)
}
emit.Syscall(c.prog.BinWriter, syscall)
// 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.

View file

@ -2,91 +2,85 @@ package compiler
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.
var syscalls = map[string]map[string]Syscall{
var syscalls = map[string]map[string]string{
"binary": {
"Base58Decode": {interopnames.SystemBinaryBase58Decode, false},
"Base58Encode": {interopnames.SystemBinaryBase58Encode, false},
"Base64Decode": {interopnames.SystemBinaryBase64Decode, false},
"Base64Encode": {interopnames.SystemBinaryBase64Encode, false},
"Deserialize": {interopnames.SystemBinaryDeserialize, false},
"Serialize": {interopnames.SystemBinarySerialize, false},
"Base58Decode": interopnames.SystemBinaryBase58Decode,
"Base58Encode": interopnames.SystemBinaryBase58Encode,
"Base64Decode": interopnames.SystemBinaryBase64Decode,
"Base64Encode": interopnames.SystemBinaryBase64Encode,
"Deserialize": interopnames.SystemBinaryDeserialize,
"Serialize": interopnames.SystemBinarySerialize,
},
"blockchain": {
"GetBlock": {interopnames.SystemBlockchainGetBlock, true},
"GetContract": {interopnames.SystemBlockchainGetContract, true},
"GetHeight": {interopnames.SystemBlockchainGetHeight, false},
"GetTransaction": {interopnames.SystemBlockchainGetTransaction, true},
"GetTransactionFromBlock": {interopnames.SystemBlockchainGetTransactionFromBlock, false},
"GetTransactionHeight": {interopnames.SystemBlockchainGetTransactionHeight, false},
"GetBlock": interopnames.SystemBlockchainGetBlock,
"GetContract": interopnames.SystemBlockchainGetContract,
"GetHeight": interopnames.SystemBlockchainGetHeight,
"GetTransaction": interopnames.SystemBlockchainGetTransaction,
"GetTransactionFromBlock": interopnames.SystemBlockchainGetTransactionFromBlock,
"GetTransactionHeight": interopnames.SystemBlockchainGetTransactionHeight,
},
"contract": {
"Create": {interopnames.SystemContractCreate, true},
"CreateStandardAccount": {interopnames.SystemContractCreateStandardAccount, false},
"Destroy": {interopnames.SystemContractDestroy, false},
"IsStandard": {interopnames.SystemContractIsStandard, false},
"GetCallFlags": {interopnames.SystemContractGetCallFlags, false},
"Update": {interopnames.SystemContractUpdate, false},
"Create": interopnames.SystemContractCreate,
"CreateStandardAccount": interopnames.SystemContractCreateStandardAccount,
"Destroy": interopnames.SystemContractDestroy,
"IsStandard": interopnames.SystemContractIsStandard,
"GetCallFlags": interopnames.SystemContractGetCallFlags,
"Update": interopnames.SystemContractUpdate,
},
"crypto": {
"ECDsaSecp256k1Verify": {interopnames.NeoCryptoVerifyWithECDsaSecp256k1, false},
"ECDSASecp256k1CheckMultisig": {interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1, false},
"ECDsaSecp256r1Verify": {interopnames.NeoCryptoVerifyWithECDsaSecp256r1, false},
"ECDSASecp256r1CheckMultisig": {interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1, false},
"RIPEMD160": {interopnames.NeoCryptoRIPEMD160, false},
"SHA256": {interopnames.NeoCryptoSHA256, false},
"ECDsaSecp256k1Verify": interopnames.NeoCryptoVerifyWithECDsaSecp256k1,
"ECDSASecp256k1CheckMultisig": interopnames.NeoCryptoCheckMultisigWithECDsaSecp256k1,
"ECDsaSecp256r1Verify": interopnames.NeoCryptoVerifyWithECDsaSecp256r1,
"ECDSASecp256r1CheckMultisig": interopnames.NeoCryptoCheckMultisigWithECDsaSecp256r1,
"RIPEMD160": interopnames.NeoCryptoRIPEMD160,
"SHA256": interopnames.NeoCryptoSHA256,
},
"enumerator": {
"Concat": {interopnames.SystemEnumeratorConcat, false},
"Create": {interopnames.SystemEnumeratorCreate, false},
"Next": {interopnames.SystemEnumeratorNext, false},
"Value": {interopnames.SystemEnumeratorValue, false},
"Concat": interopnames.SystemEnumeratorConcat,
"Create": interopnames.SystemEnumeratorCreate,
"Next": interopnames.SystemEnumeratorNext,
"Value": interopnames.SystemEnumeratorValue,
},
"engine": {
"AppCall": {interopnames.SystemContractCall, false},
"AppCall": interopnames.SystemContractCall,
},
"iterator": {
"Concat": {interopnames.SystemIteratorConcat, false},
"Create": {interopnames.SystemIteratorCreate, false},
"Key": {interopnames.SystemIteratorKey, false},
"Keys": {interopnames.SystemIteratorKeys, false},
"Next": {interopnames.SystemEnumeratorNext, false},
"Value": {interopnames.SystemEnumeratorValue, false},
"Values": {interopnames.SystemIteratorValues, false},
"Concat": interopnames.SystemIteratorConcat,
"Create": interopnames.SystemIteratorCreate,
"Key": interopnames.SystemIteratorKey,
"Keys": interopnames.SystemIteratorKeys,
"Next": interopnames.SystemEnumeratorNext,
"Value": interopnames.SystemEnumeratorValue,
"Values": interopnames.SystemIteratorValues,
},
"json": {
"Deserialize": {interopnames.SystemJSONDeserialize, false},
"Serialize": {interopnames.SystemJSONSerialize, false},
"Deserialize": interopnames.SystemJSONDeserialize,
"Serialize": interopnames.SystemJSONSerialize,
},
"runtime": {
"GasLeft": {interopnames.SystemRuntimeGasLeft, false},
"GetInvocationCounter": {interopnames.SystemRuntimeGetInvocationCounter, false},
"GetCallingScriptHash": {interopnames.SystemRuntimeGetCallingScriptHash, false},
"GetEntryScriptHash": {interopnames.SystemRuntimeGetEntryScriptHash, false},
"GetExecutingScriptHash": {interopnames.SystemRuntimeGetExecutingScriptHash, false},
"GetNotifications": {interopnames.SystemRuntimeGetNotifications, false},
"GetScriptContainer": {interopnames.SystemRuntimeGetScriptContainer, true},
"GetTime": {interopnames.SystemRuntimeGetTime, false},
"GetTrigger": {interopnames.SystemRuntimeGetTrigger, false},
"CheckWitness": {interopnames.SystemRuntimeCheckWitness, false},
"Log": {interopnames.SystemRuntimeLog, false},
"Notify": {interopnames.SystemRuntimeNotify, false},
"Platform": {interopnames.SystemRuntimePlatform, false},
"GasLeft": interopnames.SystemRuntimeGasLeft,
"GetInvocationCounter": interopnames.SystemRuntimeGetInvocationCounter,
"GetCallingScriptHash": interopnames.SystemRuntimeGetCallingScriptHash,
"GetEntryScriptHash": interopnames.SystemRuntimeGetEntryScriptHash,
"GetExecutingScriptHash": interopnames.SystemRuntimeGetExecutingScriptHash,
"GetNotifications": interopnames.SystemRuntimeGetNotifications,
"GetScriptContainer": interopnames.SystemRuntimeGetScriptContainer,
"GetTime": interopnames.SystemRuntimeGetTime,
"GetTrigger": interopnames.SystemRuntimeGetTrigger,
"CheckWitness": interopnames.SystemRuntimeCheckWitness,
"Log": interopnames.SystemRuntimeLog,
"Notify": interopnames.SystemRuntimeNotify,
"Platform": interopnames.SystemRuntimePlatform,
},
"storage": {
"ConvertContextToReadOnly": {interopnames.SystemStorageAsReadOnly, false},
"Delete": {interopnames.SystemStorageDelete, false},
"Find": {interopnames.SystemStorageFind, false},
"Get": {interopnames.SystemStorageGet, false},
"GetContext": {interopnames.SystemStorageGetContext, false},
"GetReadOnlyContext": {interopnames.SystemStorageGetReadOnlyContext, false},
"Put": {interopnames.SystemStoragePut, false},
"PutEx": {interopnames.SystemStoragePutEx, false},
"ConvertContextToReadOnly": interopnames.SystemStorageAsReadOnly,
"Delete": interopnames.SystemStorageDelete,
"Find": interopnames.SystemStorageFind,
"Get": interopnames.SystemStorageGet,
"GetContext": interopnames.SystemStorageGetContext,
"GetReadOnlyContext": interopnames.SystemStorageGetReadOnlyContext,
"Put": interopnames.SystemStoragePut,
"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
// encoding as for GetHeader). This function uses `System.Blockchain.GetBlock`
// syscall.
func GetBlock(heightOrHash interface{}) Block {
return Block{}
func GetBlock(heightOrHash interface{}) *Block {
return &Block{}
}
// GetTransaction returns transaction found by the given hash (256 bit in BE
// format represented as a slice of 32 bytes). This function uses
// `System.Blockchain.GetTransaction` syscall.
func GetTransaction(hash interop.Hash256) Transaction {
return Transaction{}
func GetTransaction(hash interop.Hash256) *Transaction {
return &Transaction{}
}
// 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
// for details on how to use the returned structure. This function uses
// `System.Blockchain.GetContract` syscall.
func GetContract(scriptHash interop.Hash160) contract.Contract {
return contract.Contract{}
func GetContract(scriptHash interop.Hash160) *contract.Contract {
return &contract.Contract{}
}

View file

@ -21,8 +21,8 @@ type Contract struct {
// manifest contract's manifest (limited in length by 2 KiB)
// It returns this new created Contract when successful (and fails transaction
// if not). It uses `System.Contract.Create` syscall.
func Create(script []byte, manifest []byte) Contract {
return Contract{}
func Create(script []byte, manifest []byte) *Contract {
return &Contract{}
}
// 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
// this execution goes. This function uses
// `System.Runtime.GetScriptContainer` syscall.
func GetScriptContainer() blockchain.Transaction {
return blockchain.Transaction{}
func GetScriptContainer() *blockchain.Transaction {
return &blockchain.Transaction{}
}
// GetExecutingScriptHash returns script hash (160 bit in BE form represented