Compiler interop APIs (CityOfZion/neo-storm#5)
* added draft of block and transaction interop api. * added header interop API * added attribute, transaction, input, output interop API * Added asset, attribute and account interop api. * added Runtime interop apis * added asset renew and create + contract and asset interop apis Imported from CityOfZion/neo-storm (b6810d58b98312a959980f344db24689839574c4).
This commit is contained in:
parent
e4c80a001c
commit
523789ee1c
12 changed files with 353 additions and 8 deletions
23
interop/account/account.go
Normal file
23
interop/account/account.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package account
|
||||
|
||||
// Package account provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Account stubs a NEO account type.
|
||||
type Account struct{}
|
||||
|
||||
// GetScripHash returns the script hash of the given account.
|
||||
func GetScriptHash(a Account) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVotes returns the votes of the given account which should be a slice of
|
||||
// public key raw bytes.
|
||||
func GetVotes(a Account) [][]byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBalance returns the balance of for the given account and asset id.
|
||||
func GetBalance(a Account, assetID []byte) int {
|
||||
return 0
|
||||
}
|
53
interop/asset/asset.go
Normal file
53
interop/asset/asset.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package asset
|
||||
|
||||
// Package asset provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Asset stubs a NEO asset type.
|
||||
type Asset struct{}
|
||||
|
||||
// GetAssetID returns the id of the given asset.
|
||||
func GetAssetID(a Asset) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAssetType returns the type of the given asset.
|
||||
func GetAssetType(a Asset) byte {
|
||||
return 0x00
|
||||
}
|
||||
|
||||
// GetAmount returns the amount of the given asset.
|
||||
func GetAmount(a Asset) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetAvailable returns the available of the given asset.
|
||||
func GetAvailable(a Asset) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetPrecision returns the precision of the given asset.
|
||||
func GetPrecision(a Asset) byte {
|
||||
return 0x00
|
||||
}
|
||||
|
||||
// GetOwner returns the owner of the given asset.
|
||||
func GetOwner(a Asset) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAdmin returns the admin of the given asset.
|
||||
func GetAdmin(a Asset) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetIssuer returns the issuer of the given asset.
|
||||
func GetIssuer(a Asset) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create registers a new asset on the blockchain.
|
||||
func Create(assetType byte, name string, amount int, precision byte, owner, admin, issuer []byte) {}
|
||||
|
||||
// Renew renews the existance of an asset by the given years.
|
||||
func Renew(asset Asset, years int) {}
|
17
interop/attribute/attribute.go
Normal file
17
interop/attribute/attribute.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package attribute
|
||||
|
||||
// Package attribute provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Attribute stubs a NEO transaction attribute type.
|
||||
type Attribute struct{}
|
||||
|
||||
// GetUsage returns the usage of the given attribute.
|
||||
func GetUsage(attr Attribute) byte {
|
||||
return 0x00
|
||||
}
|
||||
|
||||
// GetData returns the data of the given attribute.
|
||||
func GetData(attr Attribute) []byte {
|
||||
return nil
|
||||
}
|
25
interop/block/block.go
Normal file
25
interop/block/block.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package block
|
||||
|
||||
import "github.com/CityOfZion/neo-go-sc/interop/transaction"
|
||||
|
||||
// Package block provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Block stubs a NEO block type.
|
||||
type Block struct{}
|
||||
|
||||
// GetTransactionCount return the number of recorded transactions in the given block.
|
||||
func GetTransactionCount(b Block) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetTransactions returns a slice of transactions recorded in the given block.
|
||||
func GetTransactions(b Block) []transaction.Transaction {
|
||||
return []transaction.Transaction{}
|
||||
}
|
||||
|
||||
// GetTransaction returns a transaction from the given a block hash of the
|
||||
// transaction.
|
||||
func GetTransaction(b Block, hash []byte) transaction.Transaction {
|
||||
return transaction.Transaction{}
|
||||
}
|
53
interop/blockchain/blockchain.go
Normal file
53
interop/blockchain/blockchain.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package blockchain
|
||||
|
||||
import (
|
||||
"github.com/CityOfZion/neo-go-sc/interop/account"
|
||||
"github.com/CityOfZion/neo-go-sc/interop/asset"
|
||||
"github.com/CityOfZion/neo-go-sc/interop/block"
|
||||
"github.com/CityOfZion/neo-go-sc/interop/contract"
|
||||
"github.com/CityOfZion/neo-go-sc/interop/header"
|
||||
"github.com/CityOfZion/neo-go-sc/interop/transaction"
|
||||
)
|
||||
|
||||
// Package blockchain provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// GetHeight returns the height of te block recorded in the current execution scope.
|
||||
func GetHeight() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetHeader returns the header found by the given hash or index.
|
||||
func GetHeader(heightOrHash interface{}) header.Header {
|
||||
return header.Header{}
|
||||
}
|
||||
|
||||
// GetBlock returns the block found by the given hash or index.
|
||||
func GetBlock(heightOrHash interface{}) block.Block {
|
||||
return block.Block{}
|
||||
}
|
||||
|
||||
// GetTransaction returns the transaction found by the given hash.
|
||||
func GetTransaction(hash []byte) transaction.Transaction {
|
||||
return transaction.Transaction{}
|
||||
}
|
||||
|
||||
// GetContract returns the contract found by the given script hash.
|
||||
func GetContract(scriptHash []byte) contract.Contract {
|
||||
return contract.Contract{}
|
||||
}
|
||||
|
||||
// GetAccount returns the account found by the given script hash.
|
||||
func GetAccount(scriptHash []byte) account.Account {
|
||||
return account.Account{}
|
||||
}
|
||||
|
||||
// GetValidators returns a slice of validator addresses.
|
||||
func GetValidators() [][]byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAsset returns the asset found by the given asset id.
|
||||
func GetAsset(assetID []byte) asset.Asset {
|
||||
return asset.Asset{}
|
||||
}
|
17
interop/contract/contract.go
Normal file
17
interop/contract/contract.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package contract
|
||||
|
||||
// Package contract provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Contract stubs a NEO contract type.
|
||||
type Contract struct{}
|
||||
|
||||
// GetScript returns the script of the given contract.
|
||||
func GetScript(c Contract) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsPayable returns whether the given contract is payable.
|
||||
func IsPayable(c Contract) bool {
|
||||
return false
|
||||
}
|
47
interop/header/header.go
Normal file
47
interop/header/header.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package header
|
||||
|
||||
// Package header provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Header stubs a NEO block header type.
|
||||
type Header struct{}
|
||||
|
||||
// GetIndex returns the index of the given header.
|
||||
func GetIndex(h Header) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetHash returns the hash of the given header.
|
||||
func GetHash(h Header) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPrevHash returns the previous hash of the given header.
|
||||
func GetPrevHash(h Header) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTimestamp returns the timestamp of the given header.
|
||||
func GetTimestamp(h Header) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetVersion returns the version of the given header.
|
||||
func GetVersion(h Header) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetMerkleRoot returns the merkle root of the given header.
|
||||
func GetMerkleRoot(h Header) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetConsensusData returns the consensus data of the given header.
|
||||
func GetConsensusData(h Header) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetNextConsensus returns the next consensus of the given header.
|
||||
func GetNextConsensus(h Header) []byte {
|
||||
return nil
|
||||
}
|
17
interop/input/input.go
Normal file
17
interop/input/input.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package input
|
||||
|
||||
// Package input provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Input stubs the input of a NEO transaction.
|
||||
type Input struct{}
|
||||
|
||||
// GetHash returns the hash of the given input.
|
||||
func GetHash(in Input) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetIndex returns the index of the given input.
|
||||
func GetIndex(in Input) int {
|
||||
return 0
|
||||
}
|
22
interop/output/output.go
Normal file
22
interop/output/output.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package output
|
||||
|
||||
// Package output provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Output stubs the output of a NEO transaction.
|
||||
type Output struct{}
|
||||
|
||||
// GetAssetID returns the asset id of the given output.
|
||||
func GetAssetID(out Output) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns the value of the given output.
|
||||
func GetValue(out Output) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetScriptHash returns the script hash of the given output.
|
||||
func GetScriptHash(out Output) []byte {
|
||||
return nil
|
||||
}
|
|
@ -1,17 +1,31 @@
|
|||
package runtime
|
||||
|
||||
// CheckWitness verifies if the given hash is the invoker of the contract
|
||||
// Package runtime provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// CheckWitness verifies if the given hash is the invoker of the contract.
|
||||
func CheckWitness(hash []byte) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Notify passes data to the VM
|
||||
// Log instucts the VM to log the given message.
|
||||
func Log(message string) {}
|
||||
|
||||
// Notify an event to the VM.
|
||||
func Notify(arg interface{}) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Log passes a message to the VM
|
||||
func Log(message string) {}
|
||||
// GetTime returns the timestamp of the most recent block.
|
||||
func GetTime() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetTrigger returns the smart contract invoke trigger which can be either
|
||||
// verification or application.
|
||||
func GetTrigger() byte {
|
||||
return 0x00
|
||||
}
|
||||
|
||||
// Application returns the Application trigger type
|
||||
func Application() byte {
|
||||
|
@ -23,8 +37,12 @@ func Verification() byte {
|
|||
return 0x00
|
||||
}
|
||||
|
||||
// GetTrigger return the current trigger type. The return in this function
|
||||
// Doesn't really matter, this is just an interop placeholder
|
||||
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
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package storage
|
||||
|
||||
// Package storage provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Context represents the storage context
|
||||
type Context struct{}
|
||||
|
||||
|
|
50
interop/transaction/transaction.go
Normal file
50
interop/transaction/transaction.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package transaction
|
||||
|
||||
import (
|
||||
"github.com/CityOfZion/neo-go-sc/interop/attribute"
|
||||
"github.com/CityOfZion/neo-go-sc/interop/input"
|
||||
"github.com/CityOfZion/neo-go-sc/interop/output"
|
||||
)
|
||||
|
||||
// Package transaction provides function signatures that can be used inside
|
||||
// smart contracts that are written in the neo-go-sc framework.
|
||||
|
||||
// Transaction stubs a NEO transaction type.
|
||||
type Transaction struct{}
|
||||
|
||||
// GetHash returns the hash of the given transaction.
|
||||
func GetHash(t Transaction) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetType returns the type of the given transaction.
|
||||
func GetType(t Transaction) byte {
|
||||
return 0x00
|
||||
}
|
||||
|
||||
// GetAttributes returns a slice of attributes for the given transaction.
|
||||
func GetAttributes(t Transaction) []attribute.Attribute {
|
||||
return []attribute.Attribute{}
|
||||
}
|
||||
|
||||
// FIXME: What is the correct return type for this?
|
||||
// GetReferences returns a slice of references for the given transaction.
|
||||
func GetReferences(t Transaction) interface{} {
|
||||
return 0
|
||||
}
|
||||
|
||||
// FIXME: What is the correct return type for this?
|
||||
// GetUnspentCoins returns the unspent coins for the given transaction.
|
||||
func GetUnspentCoins(t Transaction) interface{} {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetInputs returns the inputs of the given transaction.
|
||||
func GetInputs(t Transaction) []input.Input {
|
||||
return []input.Input{}
|
||||
}
|
||||
|
||||
// GetOutputs returns the outputs of the given transaction.
|
||||
func GetOutputs(t Transaction) []output.Output {
|
||||
return []output.Output{}
|
||||
}
|
Loading…
Reference in a new issue