core

package
v0.50.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

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

func NewBlockFromTrimmedBytes(b []byte) (*Block, error)

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

func (b *Block) DecodeBinary(br *io.BinReader)

DecodeBinary decodes the block from the given BinReader, implementing Serializable interface.

func (*Block) EncodeBinary

func (b *Block) EncodeBinary(bw *io.BinWriter)

EncodeBinary encodes the block to the given BinWriter, implementing Serializable interface.

func (*Block) Header

func (b *Block) Header() *Header

Header returns the Header of the Block.

func (*Block) Trim

func (b *Block) Trim() ([]byte, error)

Trim returns a subset of the block data to save up space in storage. Notice that only the hashes of the transactions are stored.

func (*Block) Verify

func (b *Block) Verify(full bool) bool

Verify the integrity of the block.

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

func (b *BlockBase) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*BlockBase) EncodeBinary

func (b *BlockBase) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface

func (*BlockBase) Hash

func (b *BlockBase) Hash() util.Uint256

Hash return the hash of the block.

func (*BlockBase) Verify

func (b *BlockBase) Verify() bool

Verify verifies the integrity of the BlockBase.

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

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) Run

func (bc *Blockchain) Run(ctx context.Context)

Run runs chain loop.

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 NewCache

func NewCache() *Cache

NewCache returns a ready to use Cache object.

func (*Cache) Add

func (c *Cache) Add(h util.Uint256, v interface{})

Add adds the given hash along with its value to the cache.

func (*Cache) Delete

func (c *Cache) Delete(h util.Uint256)

Delete removes the item out of the cache.

func (*Cache) GetBlock

func (c *Cache) GetBlock(h util.Uint256) (block *Block, ok bool)

GetBlock will return a Block type from the cache.

func (*Cache) Has

func (c *Cache) Has(h util.Uint256) bool

Has returns whether the cache contains the given hash.

func (*Cache) Len

func (c *Cache) Len() int

Len return the number of items present in the cache.

func (*Cache) ReapStrangeBlocks

func (c *Cache) ReapStrangeBlocks(blkHeight, headHeight uint32)

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 CoinState

type CoinState uint8

CoinState represents the state of a coin.

const (
	CoinStateConfirmed CoinState = 0
	CoinStateSpent     CoinState = 1 << 1
	CoinStateClaimed   CoinState = 1 << 2
	CoinStateFrozen    CoinState = 1 << 5
)

Viable CoinState constants.

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 struct {
	// Base of the block.
	BlockBase
	// contains filtered or unexported fields
}

Header holds the head info of a block.

func (*Header) DecodeBinary

func (h *Header) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*Header) EncodeBinary

func (h *Header) EncodeBinary(w *io.BinWriter)

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.

func (*HeaderHashList) Slice

func (l *HeaderHashList) Slice(start, end int) []util.Uint256

Slice return a subslice of the underlying hashes. Subsliced from start to end. Example:

headers := headerList.Slice(0, 2000)

func (*HeaderHashList) Write

func (l *HeaderHashList) Write(bw *io.BinWriter, start, n int) error

WriteTo will write n underlying hashes to the given BinWriter starting from start.

type MemPool

type MemPool struct {
	// contains filtered or unexported fields
}

MemPool stores the unconfirms transactions.

func NewMemPool

func NewMemPool(capacity int) MemPool

NewMemPool returns a new MemPool struct.

func (MemPool) ContainsKey

func (mp MemPool) ContainsKey(hash util.Uint256) bool

ContainsKey checks if a transactions hash is in the MemPool.

func (MemPool) Count

func (mp MemPool) Count() int

Count returns the total number of uncofirm transactions.

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) TryAdd

func (mp MemPool) TryAdd(hash util.Uint256, pItem *PoolItem) bool

TryAdd try to add the PoolItem to 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.

func (PoolItem) CompareTo

func (p PoolItem) CompareTo(otherP *PoolItem) int

CompareTo returns the difference between two PoolItems. difference < 0 implies p < otherP. difference = 0 implies p = otherP. difference > 0 implies p > otherP.

type PoolItems

type PoolItems []*PoolItem

PoolItems slice of PoolItem

func (PoolItems) Len

func (p PoolItems) Len() int

func (PoolItems) Less

func (p PoolItems) Less(i, j int) bool

func (PoolItems) Swap

func (p PoolItems) Swap(i, j int)

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

type ValidatorState struct {
	PublicKey  *keys.PublicKey
	Registered bool
	Votes      util.Fixed8
}

ValidatorState holds the state of a validator.

type Validators

type Validators map[*keys.PublicKey]*ValidatorState

Validators is a mapping between public keys and ValidatorState.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL