core

package
v0.61.0-pre Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

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) Compare added in v0.51.0

func (b *Block) Compare(item queue.Item) int

Compare implements the queue Item interface.

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() error

Verify verifies 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 returns the hash of the block.

func (*BlockBase) VerificationHash added in v0.51.0

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

VerificationHash returns the hash of the block used to verify it.

func (*BlockBase) Verify

func (b *BlockBase) Verify() bool

Verify verifies the integrity of the BlockBase.

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 returns 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 processes 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 returns 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 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(t *transaction.Transaction) bool

IsLowPriority flags a transaction 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

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

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 writes 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) Remove added in v0.60.0

func (mp *MemPool) Remove(hash util.Uint256)

Remove removes an item from the mempool, if it exists there (and does nothing if it doesn't).

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 transaction if it exists 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 StorageContext added in v0.51.0

type StorageContext struct {
	ScriptHash util.Uint160
	ReadOnly   bool
}

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

type StorageItem struct {
	Value   []byte
	IsConst bool
}

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

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