Add missing compiler interop API functions (#93)

* added runtime serialize and deserialize functions

* removed getCurrentBlock from runtime functions

* Added block and header stdlib interop functions

* added transaction interop api

* added asset interop api

* bumped version

* Added missing storage.Find storage API function

* Fixed wrong example in the compiler README

* updated the compiler README to be more accurate on compiler features
This commit is contained in:
Anthony De Meulemeester 2018-08-19 20:47:10 +02:00 committed by GitHub
parent 34a37ff51d
commit d77354db66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 145 additions and 9 deletions

View file

@ -1 +1 @@
0.44.7
0.44.8

31
pkg/vm/api/asset/asset.go Normal file
View file

@ -0,0 +1,31 @@
package asset
import "github.com/CityOfZion/neo-go/pkg/core"
// GetAssetID returns the id of the given asset.
func GetAssetID(asset *core.AssetState) []byte { return nil }
// TODO: Verify if we need to return a uint8 here.
// GetAssetType returns the type of the given asset.
func GetAssetType(asset *core.AssetState) uint8 { return 0x00 }
// GetAmount returns the amount of the given asset.
func GetAmount(asset *core.AssetState) uint64 { return 0 }
// GetAvailable returns the available amount of the given asset.
func GetAvailable(asset *core.AssetState) uint64 { return 0 }
// GetPrecision returns the precision the given asset.
func GetPrecision(asset *core.AssetState) uint8 { return 0 }
// GetOwner returns the owner the given asset.
func GetOwner(asset *core.AssetState) []byte { return nil }
// GetIssuer returns the issuer the given asset.
func GetIssuer(asset *core.AssetState) []byte { return nil }
// Create a new asset specified by the given parameters.
func Create(typ uint8, name string, amount uint64, owner, admin, issuer []byte) {}
// Renew the given asset for the given x years.
func Renew(asset *core.AssetState, years uint32) {}

41
pkg/vm/api/block/block.go Normal file
View file

@ -0,0 +1,41 @@
package block
import (
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/core/transaction"
)
// GetTransactionCount returns the number of transactions that are recorded in
// the given block.
func GetTransactionCount(block *core.Block) int { return 0 }
// GetTransactions returns a list of transactions that are recorded in this block.
func GetTransactions(block *core.Block) []*transaction.Transaction { return nil }
// GetIndex returns the index of the given block.
func GetIndex(block *core.Block) uint32 { return 0 }
// GetHash returns the hash of the given block.
func GetHash(block *core.Block) []byte { return nil }
// GetHash returns the version of the given block.
func GetVersion(block *core.Block) uint32 { return 0 }
// GetHash returns the previous hash of the given block.
func GetPrevHash(block *core.Block) []byte { return nil }
// GetHash returns the merkle root of the given block.
func GetMerkleRoot(block *core.Block) []byte { return nil }
// GetHash returns the timestamp of the given block.
func GetTimestamp(block *core.Block) uint32 { return 0 }
// GetHash returns the next validator address of the given block.
func GetNextConsensus(block *core.Block) []byte { return nil }
// GetConsensusData returns the consensus data of the given block.
func GetConsensusData(block *core.Block) uint64 { return 0 }
// GetTransaction returns a specific transaction that is recorded in the given block
// by the given index.
func GetTransaction(block *core.Block, index int) *transaction.Transaction { return nil }

View file

@ -0,0 +1,24 @@
package header
import "github.com/CityOfZion/neo-go/pkg/core"
// GetIndex returns the index of the given header.
func GetIndex(header *core.Header) uint32 { return 0 }
// GetHash returns the hash of the given header.
func GetHash(header *core.Header) []byte { return nil }
// GetHash returns the version of the given header.
func GetVersion(header *core.Header) uint32 { return 0 }
// GetHash returns the previous hash of the given header.
func GetPrevHash(header *core.Header) []byte { return nil }
// GetHash returns the merkle root of the given header.
func GetMerkleRoot(header *core.Header) []byte { return nil }
// GetHash returns the timestamp of the given header.
func GetTimestamp(header *core.Header) uint32 { return 0 }
// GetHash returns the next validator address of the given header.
func GetNextConsensus(header *core.Header) []byte { return nil }

View file

@ -1,15 +1,10 @@
package runtime
import "github.com/CityOfZion/neo-go/pkg/vm/api/types"
// CheckWitness verifies if the invoker is the owner of the contract.
func CheckWitness(hash []byte) bool {
return true
}
// GetCurrentBlock returns the current block.
func GetCurrentBlock() types.Block { return types.Block{} }
// GetTime returns the timestamp of the most recent block.
func GetTime() int {
return 0
@ -38,3 +33,13 @@ func Verification() byte {
func GetTrigger() interface{} {
return 0
}
// Serialize serializes and item into a bytearray.
func Serialize(item interface{}) []byte {
return nil
}
// Deserializes an item from a bytearray.
func Deserialize(b []byte) interface{} {
return nil
}

View file

@ -14,3 +14,6 @@ func Get(ctx interface{}, key interface{}) interface{} { return 0 }
// Delete removes a stored key value pair.
func Delete(ctx interface{}, key interface{}) {}
// Find entrys somewhat matching the given key.
func Find(ctx interface{}, key interface{}) interface{} { return 0 }

View file

@ -0,0 +1,27 @@
package transaction
import "github.com/CityOfZion/neo-go/pkg/core/transaction"
// GetType returns the type of the given transaction.
// TODO: Double check if the type returned should be of type uint8.
func GetType(tx *transaction.Transaction) uint8 { return 0x00 }
// GetTXHash returns the hash of the given transaction.
func GetTXHash(tx *transaction.Transaction) []byte { return nil }
// GetAttributes returns the attributes of the given transaction.
func GetAttributes(tx *transaction.Transaction) []*transaction.Attribute { return nil }
// GetInputs returns the inputs of the given transaction.
func GetInputs(tx *transaction.Transaction) []*transaction.Input { return nil }
// GetOutputs returns the outputs of the given transaction.
func GetOutputs(tx *transaction.Transaction) []*transaction.Output { return nil }
// TODO: What does this return as data type?
// GetReferences returns the outputs of the given transaction.
// func GetReferences(tx *transaction.Transaction) { }
// TODO: What does this return as data type?
// GetUnspentCoins returns the unspent coins of the given transaction.
// func GetUnspentCoins(tx *transaction.Transaction) { }

View file

@ -25,19 +25,24 @@ The neo-go compiler compiles Go programs to bytecode that the NEO virtual machin
### VM API (interop layer)
- storage
- runtime
- block
- header
- transaction
- asset
- blockchain
### VM utility helper functions
- SHA1
- SHA256
- Hash256
- Hash160
- other..
### Custom utility functions
- `FromAddress(address string) []byte`
## Not yet implemented
- range
- some parts of the interop layer (VM API)
- very small part of the interop layer (VM API)
## Not supported
Due to the limitations of the NEO virtual machine, features listed below will not be supported.
@ -152,7 +157,7 @@ type Token struct {
func (t Token) AddToCirculation(amount int) bool {
ctx := storage.Context()
inCirc := storage.GetInt(ctx, "in_circ")
inCirc := storage.Get(ctx, "in_circ").(int)
inCirc += amount
storage.Put(ctx, "in_circ", inCirc)
return true