Documentation ¶
Index ¶
- 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) 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) GetTransaction(hash util.Uint256) (*transaction.Transaction, uint32, error)
- func (bc *Blockchain) GetTransationResults(t *transaction.Transaction) []*transaction.Result
- 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) Persist(ctx context.Context) (err error)
- func (bc *Blockchain) References(t *transaction.Transaction) map[util.Uint256]*transaction.Output
- func (bc *Blockchain) Run(ctx context.Context)
- func (bc *Blockchain) SystemFee(t *transaction.Transaction) util.Fixed8
- func (bc *Blockchain) Verify(t *transaction.Transaction) error
- func (bc *Blockchain) VerifyWitnesses(t *transaction.Transaction) error
- type Blockchainer
- type Cache
- type CoinState
- type ContractState
- 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 UnspentCoinState
- type UnspentCoins
- type ValidatorState
- type Validators
Constants ¶
This section is empty.
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
type Blockchain ¶
type Blockchain struct { // Any object that satisfies the BlockchainStorer interface. storage.Store // 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 processes the given block and will add it to the cache so it can be persisted.
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) 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) 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) GetTransationResults ¶
func (bc *Blockchain) GetTransationResults(t *transaction.Transaction) []*transaction.Result
GetTransationResults 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) 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) Persist ¶
func (bc *Blockchain) Persist(ctx context.Context) (err error)
Persist starts persist loop.
func (*Blockchain) References ¶
func (bc *Blockchain) References(t *transaction.Transaction) map[util.Uint256]*transaction.Output
References returns a map with input prevHash as key (util.Uint256) 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) Verify ¶
func (bc *Blockchain) Verify(t *transaction.Transaction) error
Verify verifies whether a transaction is bonafide or not. Golang implementation of Verify method in C# (https://github.com/neo-project/neo/blob/master/neo/Network/P2P/Payloads/Transaction.cs#L270).
func (*Blockchain) VerifyWitnesses ¶
func (bc *Blockchain) VerifyWitnesses(t *transaction.Transaction) error
VerifyWitnesses verify the scripts (witnesses) that come with a transactions. Golang implementation of VerifyWitnesses method in C# (https://github.com/neo-project/neo/blob/master/neo/SmartContract/Helper.cs#L87). Unfortunately the IVerifiable interface could not be implemented because we can't move the References method in blockchain.go to the transaction.go file
type Blockchainer ¶
type Blockchainer interface { GetConfig() config.ProtocolConfiguration AddHeaders(...*Header) error AddBlock(*Block) error BlockHeight() uint32 HeaderHeight() uint32 GetBlock(hash util.Uint256) (*Block, error) 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 GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error) References(t *transaction.Transaction) map[util.Uint256]*transaction.Output Feer // fee interface Verify(t *transaction.Transaction) error GetMemPool() MemPool }
Blockchainer is an interface that abstract the implementation of the blockchain.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is data structure with fixed type key of Uint256, but has a generic value. Used for block, tx and header cache types.
func (*Cache) ReapStrangeBlocks ¶
ReapStrangeBlocks drops blocks from cache that don't fit into the blkHeight-headHeight interval. Cache should only contain blocks that we expect to get and store.
type ContractState ¶
type ContractState struct { Script []byte ParamList []smartcontract.ParamType ReturnType smartcontract.ParamType Properties []int Name string CodeVersion string Author string Email string Description string HasStorage bool HasDynamicInvoke bool // contains filtered or unexported fields }
ContractState holds information about a smart contract in the NEO blockchain.
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 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.