Documentation ¶
Index ¶
- Constants
- Variables
- func GoverningTokenID() util.Uint256
- func ScriptFromWitness(hash util.Uint160, witness *transaction.Witness) ([]byte, error)
- func UtilityTokenID() util.Uint256
- type Blockchain
- func (bc *Blockchain) AddBlock(block *block.Block) error
- func (bc *Blockchain) AddHeaders(headers ...*block.Header) (err error)
- func (bc *Blockchain) ApplyPolicyToTxSet(txes []mempool.TxWithFee) []mempool.TxWithFee
- func (bc *Blockchain) BlockHeight() uint32
- func (bc *Blockchain) Close()
- func (bc *Blockchain) CurrentBlockHash() (hash util.Uint256)
- func (bc *Blockchain) CurrentHeaderHash() (hash util.Uint256)
- func (bc *Blockchain) FeePerByte(t *transaction.Transaction) util.Fixed8
- func (bc *Blockchain) GetAccountState(scriptHash util.Uint160) *state.Account
- func (bc *Blockchain) GetAssetState(assetID util.Uint256) *state.Asset
- func (bc *Blockchain) GetBlock(hash util.Uint256) (*block.Block, error)
- func (bc *Blockchain) GetConfig() config.ProtocolConfiguration
- func (bc *Blockchain) GetContractState(hash util.Uint160) *state.Contract
- func (bc *Blockchain) GetHeader(hash util.Uint256) (*block.Header, error)
- func (bc *Blockchain) GetHeaderHash(i int) (hash util.Uint256)
- func (bc *Blockchain) GetMemPool() *mempool.Pool
- func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([]util.Uint160, error)
- func (bc *Blockchain) GetScriptHashesForVerifyingClaim(t *transaction.Transaction) ([]util.Uint160, error)
- func (bc *Blockchain) GetStandByValidators() (keys.PublicKeys, error)
- func (bc *Blockchain) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem
- func (bc *Blockchain) GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error)
- func (bc *Blockchain) GetTestVM() (*vm.VM, storage.Store)
- func (bc *Blockchain) GetTransaction(hash util.Uint256) (*transaction.Transaction, uint32, error)
- func (bc *Blockchain) GetTransactionResults(t *transaction.Transaction) []*transaction.Result
- func (bc *Blockchain) GetUnspentCoinState(hash util.Uint256) *UnspentCoinState
- func (bc *Blockchain) GetValidators(txes ...*transaction.Transaction) ([]*keys.PublicKey, error)
- func (bc *Blockchain) HasBlock(hash util.Uint256) bool
- func (bc *Blockchain) HasTransaction(hash util.Uint256) bool
- func (bc *Blockchain) HeaderHeight() uint32
- func (bc *Blockchain) IsLowPriority(fee util.Fixed8) bool
- func (bc *Blockchain) LastBatch() *storage.MemBatch
- func (bc *Blockchain) NetworkFee(t *transaction.Transaction) util.Fixed8
- func (bc *Blockchain) PoolTx(t *transaction.Transaction) error
- func (bc *Blockchain) References(t *transaction.Transaction) map[transaction.Input]*transaction.Output
- func (bc *Blockchain) Run()
- func (bc *Blockchain) SystemFee(t *transaction.Transaction) util.Fixed8
- func (bc *Blockchain) VerifyBlock(block *block.Block) error
- func (bc *Blockchain) VerifyTx(t *transaction.Transaction, block *block.Block) error
- type Blockchainer
- type HeaderHashList
- func (l *HeaderHashList) Add(h ...util.Uint256)
- func (l *HeaderHashList) Get(i int) util.Uint256
- func (l *HeaderHashList) Last() util.Uint256
- func (l *HeaderHashList) Len() int
- func (l *HeaderHashList) Slice(start, end int) []util.Uint256
- func (l *HeaderHashList) Write(bw *io.BinWriter, start, n int) error
- type SpentCoinState
- type StorageContext
- type UnspentCoinState
Constants ¶
const ( // MaxContractScriptSize is the maximum script size for a contract. MaxContractScriptSize = 1024 * 1024 // MaxContractParametersNum is the maximum number of parameters for a contract. MaxContractParametersNum = 252 // MaxContractStringLen is the maximum length for contract metadata strings. MaxContractStringLen = 252 // MaxAssetNameLen is the maximum length of asset name. MaxAssetNameLen = 1024 // MaxAssetPrecision is the maximum precision of asset. MaxAssetPrecision = 8 // BlocksPerYear is a multiplier for asset renewal. BlocksPerYear = 2000000 // DefaultAssetLifetime is the default lifetime of an asset (which differs // from assets created by register tx). DefaultAssetLifetime = 1 + BlocksPerYear )
const (
// MaxStorageKeyLen is the maximum length of a key for storage items.
MaxStorageKeyLen = 1024
)
Variables ¶
var ( // ErrAlreadyExists is returned when trying to add some already existing // transaction into the pool (not specifying whether it exists in the // chain or mempool). ErrAlreadyExists = errors.New("already exists") // ErrOOM is returned when adding transaction to the memory pool because // it reached its full capacity. ErrOOM = errors.New("no space left in the memory pool") // ErrPolicy is returned on attempt to add transaction that doesn't // comply with node's configured policy into the mempool. ErrPolicy = errors.New("not allowed by policy") )
Functions ¶
func GoverningTokenID ¶ added in v0.73.0
GoverningTokenID returns the governing token (NEO) hash.
func ScriptFromWitness ¶ added in v0.71.0
ScriptFromWitness returns verification script for provided witness. If hash is not equal to the witness script hash, error is returned.
func UtilityTokenID ¶ added in v0.73.0
UtilityTokenID returns the utility token (GAS) hash.
Types ¶
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain represents the blockchain.
func NewBlockchain ¶
func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.Logger) (*Blockchain, error)
NewBlockchain returns a new blockchain object the will use the given Store as its underlying storage.
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(block *block.Block) error
AddBlock accepts successive block for the Blockchain, verifies it and stores internally. Eventually it will be persisted to the backing storage.
func (*Blockchain) AddHeaders ¶
func (bc *Blockchain) AddHeaders(headers ...*block.Header) (err error)
AddHeaders processes the given headers and add them to the HeaderHashList.
func (*Blockchain) ApplyPolicyToTxSet ¶ added in v0.73.0
func (bc *Blockchain) ApplyPolicyToTxSet(txes []mempool.TxWithFee) []mempool.TxWithFee
ApplyPolicyToTxSet applies configured policies to given transaction set. It expects slice to be ordered by fee and returns a subslice of it.
func (*Blockchain) BlockHeight ¶
func (bc *Blockchain) BlockHeight() uint32
BlockHeight returns the height/index of the highest block.
func (*Blockchain) Close ¶ added in v0.70.0
func (bc *Blockchain) Close()
Close stops Blockchain's internal loop, syncs changes to persistent storage and closes it. The Blockchain is no longer functional after the call to Close.
func (*Blockchain) CurrentBlockHash ¶
func (bc *Blockchain) CurrentBlockHash() (hash util.Uint256)
CurrentBlockHash returns the highest processed block hash.
func (*Blockchain) CurrentHeaderHash ¶
func (bc *Blockchain) CurrentHeaderHash() (hash util.Uint256)
CurrentHeaderHash returns the hash of the latest known header.
func (*Blockchain) FeePerByte ¶
func (bc *Blockchain) FeePerByte(t *transaction.Transaction) util.Fixed8
FeePerByte returns network fee divided by the size of the transaction.
func (*Blockchain) GetAccountState ¶
func (bc *Blockchain) GetAccountState(scriptHash util.Uint160) *state.Account
GetAccountState returns the account state from its script hash.
func (*Blockchain) GetAssetState ¶
func (bc *Blockchain) GetAssetState(assetID util.Uint256) *state.Asset
GetAssetState returns asset state from its assetID.
func (*Blockchain) GetConfig ¶
func (bc *Blockchain) GetConfig() config.ProtocolConfiguration
GetConfig returns the config stored in the blockchain.
func (*Blockchain) GetContractState ¶ added in v0.51.0
func (bc *Blockchain) GetContractState(hash util.Uint160) *state.Contract
GetContractState returns contract by its script hash.
func (*Blockchain) GetHeader ¶
GetHeader returns data block header identified with the given hash value.
func (*Blockchain) GetHeaderHash ¶
func (bc *Blockchain) GetHeaderHash(i int) (hash util.Uint256)
GetHeaderHash returns the hash from the headerList by its height/index.
func (*Blockchain) GetMemPool ¶
func (bc *Blockchain) GetMemPool() *mempool.Pool
GetMemPool returns the memory pool of the blockchain.
func (*Blockchain) GetScriptHashesForVerifying ¶
func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([]util.Uint160, error)
GetScriptHashesForVerifying returns all the ScriptHashes of a transaction which will be use to verify whether the transaction is bonafide or not. Golang implementation of GetScriptHashesForVerifying method in C# (https://github.com/neo-project/neo/blob/master/neo/Network/P2P/Payloads/Transaction.cs#L190)
func (*Blockchain) GetScriptHashesForVerifyingClaim ¶ added in v0.51.0
func (bc *Blockchain) GetScriptHashesForVerifyingClaim(t *transaction.Transaction) ([]util.Uint160, error)
GetScriptHashesForVerifyingClaim returns all ScriptHashes of Claim transaction which has a different implementation from generic GetScriptHashesForVerifying.
func (*Blockchain) GetStandByValidators ¶ added in v0.70.0
func (bc *Blockchain) GetStandByValidators() (keys.PublicKeys, error)
GetStandByValidators returns validators from the configuration.
func (*Blockchain) GetStorageItem ¶ added in v0.51.0
func (bc *Blockchain) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem
GetStorageItem returns an item from storage.
func (*Blockchain) GetStorageItems ¶ added in v0.51.0
func (bc *Blockchain) GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error)
GetStorageItems returns all storage items for a given scripthash.
func (*Blockchain) GetTestVM ¶ added in v0.61.0
func (bc *Blockchain) GetTestVM() (*vm.VM, storage.Store)
GetTestVM returns a VM and a Store setup for a test run of some sort of code.
func (*Blockchain) GetTransaction ¶
func (bc *Blockchain) GetTransaction(hash util.Uint256) (*transaction.Transaction, uint32, error)
GetTransaction returns a TX and its height by the given hash.
func (*Blockchain) GetTransactionResults ¶ added in v0.51.0
func (bc *Blockchain) GetTransactionResults(t *transaction.Transaction) []*transaction.Result
GetTransactionResults returns the transaction results aggregate by assetID. Golang of GetTransationResults method in C# (https://github.com/neo-project/neo/blob/master/neo/Network/P2P/Payloads/Transaction.cs#L207)
func (*Blockchain) GetUnspentCoinState ¶ added in v0.51.0
func (bc *Blockchain) GetUnspentCoinState(hash util.Uint256) *UnspentCoinState
GetUnspentCoinState returns unspent coin state for given tx hash.
func (*Blockchain) GetValidators ¶ added in v0.70.0
func (bc *Blockchain) GetValidators(txes ...*transaction.Transaction) ([]*keys.PublicKey, error)
GetValidators returns validators. Golang implementation of GetValidators method in C# (https://github.com/neo-project/neo/blob/c64748ecbac3baeb8045b16af0d518398a6ced24/neo/Persistence/Snapshot.cs#L182)
func (*Blockchain) HasBlock ¶
func (bc *Blockchain) HasBlock(hash util.Uint256) bool
HasBlock returns true if the blockchain contains the given block hash.
func (*Blockchain) HasTransaction ¶
func (bc *Blockchain) HasTransaction(hash util.Uint256) bool
HasTransaction returns true if the blockchain contains he given transaction hash.
func (*Blockchain) HeaderHeight ¶
func (bc *Blockchain) HeaderHeight() uint32
HeaderHeight returns the index/height of the highest header.
func (*Blockchain) IsLowPriority ¶
func (bc *Blockchain) IsLowPriority(fee util.Fixed8) bool
IsLowPriority checks given fee for being less than configured LowPriorityThreshold.
func (*Blockchain) LastBatch ¶ added in v0.73.0
func (bc *Blockchain) LastBatch() *storage.MemBatch
LastBatch returns last persisted storage batch.
func (*Blockchain) NetworkFee ¶
func (bc *Blockchain) NetworkFee(t *transaction.Transaction) util.Fixed8
NetworkFee returns network fee.
func (*Blockchain) PoolTx ¶ added in v0.72.0
func (bc *Blockchain) PoolTx(t *transaction.Transaction) error
PoolTx verifies and tries to add given transaction into the mempool.
func (*Blockchain) References ¶
func (bc *Blockchain) References(t *transaction.Transaction) map[transaction.Input]*transaction.Output
References returns a map with input coin reference (prevhash and index) as key and transaction output as value from a transaction t. @TODO: unfortunately we couldn't attach this method to the Transaction struct in the transaction package because of a import cycle problem. Perhaps we should think to re-design the code base to avoid this situation.
func (*Blockchain) SystemFee ¶
func (bc *Blockchain) SystemFee(t *transaction.Transaction) util.Fixed8
SystemFee returns system fee.
func (*Blockchain) VerifyBlock ¶ added in v0.51.0
func (bc *Blockchain) VerifyBlock(block *block.Block) error
VerifyBlock verifies block against its current state.
func (*Blockchain) VerifyTx ¶ added in v0.51.0
func (bc *Blockchain) VerifyTx(t *transaction.Transaction, block *block.Block) error
VerifyTx verifies whether a transaction is bonafide or not. Block parameter is used for easy interop access and can be omitted for transactions that are not yet added into any block. Golang implementation of Verify method in C# (https://github.com/neo-project/neo/blob/master/neo/Network/P2P/Payloads/Transaction.cs#L270).
type Blockchainer ¶
type Blockchainer interface { ApplyPolicyToTxSet([]mempool.TxWithFee) []mempool.TxWithFee GetConfig() config.ProtocolConfiguration AddHeaders(...*block.Header) error AddBlock(*block.Block) error BlockHeight() uint32 Close() HeaderHeight() uint32 GetBlock(hash util.Uint256) (*block.Block, error) GetContractState(hash util.Uint160) *state.Contract GetHeaderHash(int) util.Uint256 GetHeader(hash util.Uint256) (*block.Header, error) CurrentHeaderHash() util.Uint256 CurrentBlockHash() util.Uint256 HasBlock(util.Uint256) bool HasTransaction(util.Uint256) bool GetAssetState(util.Uint256) *state.Asset GetAccountState(util.Uint160) *state.Account GetValidators(txes ...*transaction.Transaction) ([]*keys.PublicKey, error) GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error) GetStorageItem(scripthash util.Uint160, key []byte) *state.StorageItem GetStorageItems(hash util.Uint160) (map[string]*state.StorageItem, error) GetTestVM() (*vm.VM, storage.Store) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) GetUnspentCoinState(util.Uint256) *UnspentCoinState References(t *transaction.Transaction) map[transaction.Input]*transaction.Output mempool.Feer // fee interface PoolTx(*transaction.Transaction) error VerifyTx(*transaction.Transaction, *block.Block) error GetMemPool() *mempool.Pool }
Blockchainer is an interface that abstract the implementation of the blockchain.
type HeaderHashList ¶
type HeaderHashList struct {
// contains filtered or unexported fields
}
A HeaderHashList represents a list of header hashes. This data structure in not routine safe and should be used under some kind of protection against race conditions.
func NewHeaderHashList ¶
func NewHeaderHashList(hashes ...util.Uint256) *HeaderHashList
NewHeaderHashList returns a new pointer to a HeaderHashList.
func NewHeaderHashListFromBytes ¶
func NewHeaderHashListFromBytes(b []byte) (*HeaderHashList, error)
NewHeaderHashListFromBytes returns a new hash list from the given bytes.
func (*HeaderHashList) Add ¶
func (l *HeaderHashList) Add(h ...util.Uint256)
Add appends the given hash to the list of hashes.
func (*HeaderHashList) Get ¶
func (l *HeaderHashList) Get(i int) util.Uint256
Get returns the hash by the given index.
func (*HeaderHashList) Last ¶
func (l *HeaderHashList) Last() util.Uint256
Last return the last hash in the HeaderHashList.
func (*HeaderHashList) Len ¶
func (l *HeaderHashList) Len() int
Len returns the length of the underlying hashes slice.
type SpentCoinState ¶
type SpentCoinState struct {
// contains filtered or unexported fields
}
SpentCoinState represents the state of a spent coin.
func NewSpentCoinState ¶
func NewSpentCoinState(hash util.Uint256, height uint32) *SpentCoinState
NewSpentCoinState returns a new SpentCoinState object.
func (*SpentCoinState) DecodeBinary ¶
func (s *SpentCoinState) DecodeBinary(br *io.BinReader)
DecodeBinary implements Serializable interface.
func (*SpentCoinState) EncodeBinary ¶
func (s *SpentCoinState) EncodeBinary(bw *io.BinWriter)
EncodeBinary implements Serializable interface.
type StorageContext ¶ added in v0.51.0
StorageContext contains storing script hash and read/write flag, it's used as a context for storage manipulation functions.
type UnspentCoinState ¶
type UnspentCoinState struct {
// contains filtered or unexported fields
}
UnspentCoinState hold the state of a unspent coin.
func NewUnspentCoinState ¶
func NewUnspentCoinState(n int) *UnspentCoinState
NewUnspentCoinState returns a new unspent coin state with N confirmed states.
func (*UnspentCoinState) DecodeBinary ¶
func (s *UnspentCoinState) DecodeBinary(br *io.BinReader)
DecodeBinary decodes UnspentCoinState from the given BinReader.
func (*UnspentCoinState) EncodeBinary ¶
func (s *UnspentCoinState) EncodeBinary(bw *io.BinWriter)
EncodeBinary encodes UnspentCoinState to the given BinWriter.