Documentation ¶
Index ¶
- Constants
- func IsDoubleSpend(s storage.Store, tx *transaction.Transaction) bool
- type AccountState
- type Accounts
- type AssetState
- type Assets
- type Block
- type BlockBase
- type Blockchain
- func (bc *Blockchain) AddBlock(block *Block) error
- func (bc *Blockchain) AddHeaders(headers ...*Header) (err error)
- func (bc *Blockchain) BlockHeight() uint32
- 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) *AccountState
- func (bc *Blockchain) GetAssetState(assetID util.Uint256) *AssetState
- func (bc *Blockchain) GetBlock(hash util.Uint256) (*Block, error)
- func (bc *Blockchain) GetConfig() config.ProtocolConfiguration
- func (bc *Blockchain) GetContractState(hash util.Uint160) *ContractState
- func (bc *Blockchain) GetHeader(hash util.Uint256) (*Header, error)
- func (bc *Blockchain) GetHeaderHash(i int) (hash util.Uint256)
- func (bc *Blockchain) GetMemPool() MemPool
- func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([]util.Uint160, error)
- func (bc *Blockchain) GetScriptHashesForVerifyingClaim(t *transaction.Transaction) ([]util.Uint160, error)
- func (bc *Blockchain) GetStorageItem(scripthash util.Uint160, key []byte) *StorageItem
- func (bc *Blockchain) GetStorageItems(hash util.Uint160) (map[string]*StorageItem, error)
- 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) HasBlock(hash util.Uint256) bool
- func (bc *Blockchain) HasTransaction(hash util.Uint256) bool
- func (bc *Blockchain) HeaderHeight() uint32
- func (bc *Blockchain) IsLowPriority(t *transaction.Transaction) bool
- func (bc *Blockchain) NetworkFee(t *transaction.Transaction) util.Fixed8
- func (bc *Blockchain) References(t *transaction.Transaction) map[transaction.Input]*transaction.Output
- func (bc *Blockchain) Run(ctx context.Context)
- func (bc *Blockchain) SystemFee(t *transaction.Transaction) util.Fixed8
- func (bc *Blockchain) VerifyBlock(block *Block) error
- func (bc *Blockchain) VerifyTx(t *transaction.Transaction, block *Block) error
- type Blockchainer
- type CoinState
- type ContractState
- type Contracts
- type Feer
- type Header
- 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 MemPool
- func (mp MemPool) ContainsKey(hash util.Uint256) bool
- func (mp MemPool) Count() int
- func (mp *MemPool) GetVerifiedTransactions() []*transaction.Transaction
- func (mp *MemPool) RemoveOverCapacity()
- func (mp MemPool) TryAdd(hash util.Uint256, pItem *PoolItem) bool
- func (mp MemPool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool)
- func (mp MemPool) Verify(tx *transaction.Transaction) bool
- type PoolItem
- type PoolItems
- type SpentCoinState
- type SpentCoins
- type StorageContext
- type StorageItem
- type UnspentCoinState
- type UnspentCoins
- type ValidatorState
- type Validators
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 ¶
This section is empty.
Functions ¶
func IsDoubleSpend ¶
func IsDoubleSpend(s storage.Store, tx *transaction.Transaction) bool
IsDoubleSpend verifies that the input transactions are not double spent.
Types ¶
type AccountState ¶
type AccountState struct { Version uint8 ScriptHash util.Uint160 IsFrozen bool Votes []*keys.PublicKey Balances map[util.Uint256]util.Fixed8 }
AccountState represents the state of a NEO account.
func NewAccountState ¶
func NewAccountState(scriptHash util.Uint160) *AccountState
NewAccountState returns a new AccountState object.
func (*AccountState) DecodeBinary ¶
func (s *AccountState) DecodeBinary(br *io.BinReader)
DecodeBinary decodes AccountState from the given BinReader.
func (*AccountState) EncodeBinary ¶
func (s *AccountState) EncodeBinary(bw *io.BinWriter)
EncodeBinary encodes AccountState to the given BinWriter.
type Accounts ¶
type Accounts map[util.Uint160]*AccountState
Accounts is mapping between a account address and AccountState.
type AssetState ¶
type AssetState struct { ID util.Uint256 AssetType transaction.AssetType Name string Amount util.Fixed8 Available util.Fixed8 Precision uint8 FeeMode uint8 FeeAddress util.Uint160 Owner *keys.PublicKey Admin util.Uint160 Issuer util.Uint160 Expiration uint32 IsFrozen bool }
AssetState represents the state of an NEO registered Asset.
func (*AssetState) DecodeBinary ¶
func (a *AssetState) DecodeBinary(br *io.BinReader)
DecodeBinary implements Serializable interface.
func (*AssetState) EncodeBinary ¶
func (a *AssetState) EncodeBinary(bw *io.BinWriter)
EncodeBinary implements Serializable interface.
func (*AssetState) GetName ¶
func (a *AssetState) GetName() string
GetName returns the asset name based on its type.
type Assets ¶
type Assets map[util.Uint256]*AssetState
Assets is mapping between AssetID and the AssetState.
type Block ¶
type Block struct { // The base of the block. BlockBase // Transaction list. Transactions []*transaction.Transaction `json:"tx"` // True if this block is created from trimmed data. Trimmed bool `json:"-"` }
Block represents one block in the chain.
func NewBlockFromTrimmedBytes ¶
NewBlockFromTrimmedBytes returns a new block from trimmed data. This is commonly used to create a block from stored data. Blocks created from trimmed data will have their Trimmed field set to true.
func (*Block) DecodeBinary ¶
DecodeBinary decodes the block from the given BinReader, implementing Serializable interface.
func (*Block) EncodeBinary ¶
EncodeBinary encodes the block to the given BinWriter, implementing Serializable interface.
type BlockBase ¶
type BlockBase struct { // Version of the block. Version uint32 `json:"version"` // hash of the previous block. PrevHash util.Uint256 `json:"previousblockhash"` // Root hash of a transaction list. MerkleRoot util.Uint256 `json:"merkleroot"` // The time stamp of each block must be later than previous block's time stamp. // Generally the difference of two block's time stamp is about 15 seconds and imprecision is allowed. // The height of the block must be exactly equal to the height of the previous block plus 1. Timestamp uint32 `json:"time"` // index/height of the block Index uint32 `json:"height"` // Random number also called nonce ConsensusData uint64 `json:"nonce"` // Contract address of the next miner NextConsensus util.Uint160 `json:"next_consensus"` // Script used to validate the block Script *transaction.Witness `json:"script"` // contains filtered or unexported fields }
BlockBase holds the base info of a block
func (*BlockBase) DecodeBinary ¶
DecodeBinary implements Serializable interface.
func (*BlockBase) EncodeBinary ¶
EncodeBinary implements Serializable interface
func (*BlockBase) VerificationHash ¶ added in v0.51.0
VerificationHash returns the hash of the block used to verify it.
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain represents the blockchain.
func NewBlockchain ¶
func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration) (*Blockchain, error)
NewBlockchain return a new blockchain object the will use the given Store as its underlying storage.
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(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 ...*Header) (err error)
AddHeaders will process the given headers and add them to the HeaderHashList.
func (*Blockchain) BlockHeight ¶
func (bc *Blockchain) BlockHeight() uint32
BlockHeight returns the height/index of the highest block.
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) *AccountState
GetAccountState returns the account state from its script hash
func (*Blockchain) GetAssetState ¶
func (bc *Blockchain) GetAssetState(assetID util.Uint256) *AssetState
GetAssetState returns asset state from its assetID
func (*Blockchain) GetBlock ¶
func (bc *Blockchain) GetBlock(hash util.Uint256) (*Block, error)
GetBlock returns a Block by the given hash.
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) *ContractState
GetContractState returns contract by its script hash.
func (*Blockchain) GetHeader ¶
func (bc *Blockchain) GetHeader(hash util.Uint256) (*Header, error)
GetHeader returns data block header identified with the given hash value.
func (*Blockchain) GetHeaderHash ¶
func (bc *Blockchain) GetHeaderHash(i int) (hash util.Uint256)
GetHeaderHash return the hash from the headerList by its height/index.
func (*Blockchain) GetMemPool ¶
func (bc *Blockchain) GetMemPool() MemPool
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) GetStorageItem ¶ added in v0.51.0
func (bc *Blockchain) GetStorageItem(scripthash util.Uint160, key []byte) *StorageItem
GetStorageItem returns an item from storage.
func (*Blockchain) GetStorageItems ¶ added in v0.51.0
func (bc *Blockchain) GetStorageItems(hash util.Uint160) (map[string]*StorageItem, error)
GetStorageItems returns all storage items for a given scripthash.
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) HasBlock ¶
func (bc *Blockchain) HasBlock(hash util.Uint256) bool
HasBlock return true if the blockchain contains the given block hash.
func (*Blockchain) HasTransaction ¶
func (bc *Blockchain) HasTransaction(hash util.Uint256) bool
HasTransaction return 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(t *transaction.Transaction) bool
IsLowPriority flags a trnsaction as low priority if the network fee is less than LowPriorityThreshold
func (*Blockchain) NetworkFee ¶
func (bc *Blockchain) NetworkFee(t *transaction.Transaction) util.Fixed8
NetworkFee returns network fee
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) 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) 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 { GetConfig() config.ProtocolConfiguration AddHeaders(...*Header) error AddBlock(*Block) error BlockHeight() uint32 HeaderHeight() uint32 GetBlock(hash util.Uint256) (*Block, error) GetContractState(hash util.Uint160) *ContractState GetHeaderHash(int) util.Uint256 GetHeader(hash util.Uint256) (*Header, error) CurrentHeaderHash() util.Uint256 CurrentBlockHash() util.Uint256 HasBlock(util.Uint256) bool HasTransaction(util.Uint256) bool GetAssetState(util.Uint256) *AssetState GetAccountState(util.Uint160) *AccountState GetScriptHashesForVerifying(*transaction.Transaction) ([]util.Uint160, error) GetStorageItem(scripthash util.Uint160, key []byte) *StorageItem GetStorageItems(hash util.Uint160) (map[string]*StorageItem, error) GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) GetUnspentCoinState(util.Uint256) *UnspentCoinState References(t *transaction.Transaction) map[transaction.Input]*transaction.Output Feer // fee interface VerifyTx(*transaction.Transaction, *Block) error GetMemPool() MemPool }
Blockchainer is an interface that abstract the implementation of the blockchain.
type ContractState ¶
type ContractState struct { Script []byte ParamList []smartcontract.ParamType ReturnType smartcontract.ParamType Properties smartcontract.PropertyState Name string CodeVersion string Author string Email string Description string // contains filtered or unexported fields }
ContractState holds information about a smart contract in the NEO blockchain.
func (*ContractState) DecodeBinary ¶ added in v0.51.0
func (cs *ContractState) DecodeBinary(br *io.BinReader)
DecodeBinary implements Serializable interface.
func (*ContractState) EncodeBinary ¶ added in v0.51.0
func (cs *ContractState) EncodeBinary(bw *io.BinWriter)
EncodeBinary implements Serializable interface.
func (*ContractState) HasDynamicInvoke ¶
func (cs *ContractState) HasDynamicInvoke() bool
HasDynamicInvoke checks whether the contract has dynamic invoke property set.
func (*ContractState) HasStorage ¶
func (cs *ContractState) HasStorage() bool
HasStorage checks whether the contract has storage property set.
func (*ContractState) IsPayable ¶ added in v0.51.0
func (cs *ContractState) IsPayable() bool
IsPayable checks whether the contract has payable property set.
func (*ContractState) ScriptHash ¶ added in v0.51.0
func (cs *ContractState) ScriptHash() util.Uint160
ScriptHash returns a contract script hash.
type Contracts ¶ added in v0.51.0
type Contracts map[util.Uint160]*ContractState
Contracts is a mapping between scripthash and ContractState.
type Feer ¶
type Feer interface { NetworkFee(t *transaction.Transaction) util.Fixed8 IsLowPriority(t *transaction.Transaction) bool FeePerByte(t *transaction.Transaction) util.Fixed8 SystemFee(t *transaction.Transaction) util.Fixed8 }
Feer is an interface that abstract the implementation of the fee calculation.
type Header ¶
type Header struct { // Base of the block. BlockBase // contains filtered or unexported fields }
Header holds the head info of a block.
func (*Header) DecodeBinary ¶
DecodeBinary implements Serializable interface.
func (*Header) EncodeBinary ¶
EncodeBinary implements Serializable interface.
type HeaderHashList ¶
type HeaderHashList struct {
// contains filtered or unexported fields
}
A HeaderHashList represents a list of header hashes. This datastructure 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 return a new pointer to a HeaderHashList.
func NewHeaderHashListFromBytes ¶
func NewHeaderHashListFromBytes(b []byte) (*HeaderHashList, error)
NewHeaderHashListFromBytes return 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 return the length of the underlying hashes slice.
type MemPool ¶
type MemPool struct {
// contains filtered or unexported fields
}
MemPool stores the unconfirms transactions.
func (MemPool) ContainsKey ¶
ContainsKey checks if a transactions hash is in the MemPool.
func (*MemPool) GetVerifiedTransactions ¶
func (mp *MemPool) GetVerifiedTransactions() []*transaction.Transaction
GetVerifiedTransactions returns a slice of Input from all the transactions in the memory pool whose hash is not included in excludedHashes.
func (*MemPool) RemoveOverCapacity ¶
func (mp *MemPool) RemoveOverCapacity()
RemoveOverCapacity removes transactions with lowest fees until the total number of transactions in the MemPool is within the capacity of the MemPool.
func (MemPool) TryGetValue ¶
func (mp MemPool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool)
TryGetValue returns a transactions if it esists in the memory pool.
func (MemPool) Verify ¶
func (mp MemPool) Verify(tx *transaction.Transaction) bool
Verify verifies if the inputs of a transaction tx are already used in any other transaction in the memory pool. If yes, the transaction tx is not a valid transaction and the function return false. If no, the transaction tx is a valid transaction and the function return true.
type PoolItem ¶
type PoolItem struct {
// contains filtered or unexported fields
}
PoolItem represents a transaction in the the Memory pool.
func NewPoolItem ¶
func NewPoolItem(t *transaction.Transaction, fee Feer) *PoolItem
NewPoolItem returns a new PoolItem.
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 SpentCoins ¶
type SpentCoins map[util.Uint256]*SpentCoinState
SpentCoins is mapping between transactions and their spent coin state.
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 StorageItem ¶ added in v0.51.0
StorageItem is the value to be stored with read-only flag.
func (*StorageItem) DecodeBinary ¶ added in v0.51.0
func (si *StorageItem) DecodeBinary(r *io.BinReader)
DecodeBinary implements Serializable interface.
func (*StorageItem) EncodeBinary ¶ added in v0.51.0
func (si *StorageItem) EncodeBinary(w *io.BinWriter)
EncodeBinary implements Serializable interface.
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.
type UnspentCoins ¶
type UnspentCoins map[util.Uint256]*UnspentCoinState
UnspentCoins is mapping between transactions and their unspent coin state.
type ValidatorState ¶
ValidatorState holds the state of a validator.
type Validators ¶
type Validators map[*keys.PublicKey]*ValidatorState
Validators is a mapping between public keys and ValidatorState.