Documentation ¶
Index ¶
- Constants
- func CanVerifyHeight(height uint32) bool
- func GetNextMiningSigChainTxnHash(height uint32) (Uint256, WinnerType, error)
- func HeaderCheck(header *Header) error
- func NextBlockProposerCheck(block *Block) error
- func SignerCheck(header *Header) error
- func TimestampCheck(timestamp int64) error
- func TransactionCheck(block *Block) error
- type Block
- func (b *Block) Deserialize(r io.Reader) error
- func (b *Block) FromTrimmedData(r io.Reader) error
- func (b *Block) GetMessage() []byte
- func (b *Block) GetProgramHashes() ([]Uint160, error)
- func (b *Block) GetPrograms() []*program.Program
- func (b *Block) GetSigner() ([]byte, []byte, error)
- func (b *Block) Hash() Uint256
- func (bd *Block) MarshalJson() ([]byte, error)
- func (b *Block) RebuildMerkleRoot() error
- func (b *Block) Serialize(w io.Writer) error
- func (bd *Block) SerializeUnsigned(w io.Writer) error
- func (b *Block) SetPrograms(prog []*program.Program)
- func (b *Block) ToArray() []byte
- func (b *Block) Trim(w io.Writer) error
- func (b *Block) Type() InventoryType
- func (bd *Block) UnmarshalJson(data []byte) error
- func (b *Block) Verify() error
- type Blockchain
- func (bc *Blockchain) AddBlock(block *Block) error
- func (bc *Blockchain) AddBlockTime(hash Uint256, time int64)
- func (bc *Blockchain) ContainsTransaction(hash Uint256) bool
- func (bc *Blockchain) CurrentBlockHash() Uint256
- func (bc *Blockchain) GetBlockTime(hash Uint256) (int64, error)
- func (bc *Blockchain) GetHeader(hash Uint256) (*Header, error)
- func (bc *Blockchain) SaveBlock(block *Block) error
- type BlocksInfo
- type BuiltinMining
- type Header
- func (h *Header) Deserialize(r io.Reader) error
- func (h *Header) DeserializeUnsigned(r io.Reader) error
- func (h *Header) GetMessage() []byte
- func (h *Header) GetProgramHashes() ([]Uint160, error)
- func (h *Header) GetPrograms() []*program.Program
- func (h *Header) Hash() Uint256
- func (h *Header) MarshalJson() ([]byte, error)
- func (h *Header) Serialize(w io.Writer) error
- func (h *Header) SerializeUnsigned(w io.Writer) error
- func (h *Header) SetPrograms(programs []*program.Program)
- func (h *Header) ToArray() []byte
- func (h *Header) UnmarshalJson(data []byte) error
- type HeaderInfo
- type ILedgerStore
- type Ledger
- func (l *Ledger) BlockInLedger(hash Uint256) bool
- func (l *Ledger) GetAsset(assetId Uint256) (*asset.Asset, error)
- func (l *Ledger) GetBlockWithHash(hash Uint256) (*Block, error)
- func (l *Ledger) GetBlockWithHeight(height uint32) (*Block, error)
- func (l *Ledger) GetLocalBlockChainHeight() uint32
- func (l *Ledger) GetTransactionWithHash(hash Uint256) (*tx.Transaction, error)
- func (l *Ledger) IsDoubleSpend(Tx *tx.Transaction) bool
- type Mining
- type TransactionArray
- type VBlock
- type WinnerType
Constants ¶
View Source
const BlockVersion uint32 = 0
View Source
const GenesisNonce uint64 = 2083236893
View Source
const (
TimestampTolerance = 40 * time.Second
)
Variables ¶
This section is empty.
Functions ¶
func CanVerifyHeight ¶
func GetNextMiningSigChainTxnHash ¶
func GetNextMiningSigChainTxnHash(height uint32) (Uint256, WinnerType, error)
GetWinner returns the winner hash and winner type of a block height using sigchain from PoR server.
func HeaderCheck ¶
func NextBlockProposerCheck ¶
func SignerCheck ¶
func TimestampCheck ¶
func TransactionCheck ¶
Types ¶
type Block ¶
type Block struct { Header *Header Transactions []*tx.Transaction // contains filtered or unexported fields }
func GenesisBlockInit ¶
func (*Block) GetMessage ¶
func (*Block) GetProgramHashes ¶
func (*Block) GetPrograms ¶
func (*Block) MarshalJson ¶
func (*Block) RebuildMerkleRoot ¶
func (*Block) SetPrograms ¶
func (*Block) UnmarshalJson ¶
type Blockchain ¶
type Blockchain struct { BlockHeight uint32 AssetID Uint256 BlockPersistTime map[Uint256]int64 BCEvents *events.Event // contains filtered or unexported fields }
func NewBlockchain ¶
func NewBlockchain(height uint32, asset Uint256) *Blockchain
func NewBlockchainWithGenesisBlock ¶
func NewBlockchainWithGenesisBlock(store ILedgerStore) (*Blockchain, error)
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(block *Block) error
func (*Blockchain) AddBlockTime ¶
func (bc *Blockchain) AddBlockTime(hash Uint256, time int64)
func (*Blockchain) ContainsTransaction ¶
func (bc *Blockchain) ContainsTransaction(hash Uint256) bool
func (*Blockchain) CurrentBlockHash ¶
func (bc *Blockchain) CurrentBlockHash() Uint256
func (*Blockchain) GetBlockTime ¶
func (bc *Blockchain) GetBlockTime(hash Uint256) (int64, error)
func (*Blockchain) GetHeader ¶
func (bc *Blockchain) GetHeader(hash Uint256) (*Header, error)
func (*Blockchain) SaveBlock ¶
func (bc *Blockchain) SaveBlock(block *Block) error
type BlocksInfo ¶
type BlocksInfo struct { Hash string `json:"hash"` Header *HeaderInfo `json:"header"` Transactions []*transaction.TransactionInfo `json:"transactions"` }
type BuiltinMining ¶
type BuiltinMining struct {
// contains filtered or unexported fields
}
func NewBuiltinMining ¶
func NewBuiltinMining(account *vault.Account, txnCollector *transaction.TxnCollector) *BuiltinMining
func (*BuiltinMining) BuildBlock ¶
func (bm *BuiltinMining) BuildBlock(height uint32, chordID []byte, winningHash common.Uint256, winnerType WinnerType, timestamp int64) (*Block, error)
func (*BuiltinMining) CreateCoinbaseTransaction ¶
func (bm *BuiltinMining) CreateCoinbaseTransaction() *transaction.Transaction
type Header ¶
type Header struct { Version uint32 PrevBlockHash Uint256 TransactionsRoot Uint256 Timestamp int64 Height uint32 ConsensusData uint64 NextBookKeeper Uint160 WinnerHash Uint256 WinnerType WinnerType Signer []byte ChordID []byte Signature []byte Program *program.Program // contains filtered or unexported fields }
func (*Header) GetMessage ¶
func (*Header) GetProgramHashes ¶
func (*Header) GetPrograms ¶
func (*Header) MarshalJson ¶
func (*Header) SerializeUnsigned ¶
Serialize the blockheader data without program
func (*Header) SetPrograms ¶
func (*Header) UnmarshalJson ¶
type HeaderInfo ¶
type HeaderInfo struct { Version uint32 `json:"version"` PrevBlockHash string `json:"prevBlockHash"` TransactionsRoot string `json:"transactionsRoot"` Timestamp int64 `json:"timestamp"` Height uint32 `json:"height"` ConsensusData uint64 `json:"consensusData"` NextBookKeeper string `json:"nextBookKeeper"` WinnerHash string `json:"winningHash"` WinnerType byte `json:"winningHashType"` Signer string `json:"signer"` ChordID string `json:"chordID"` Signature string `json:"signature"` Program program.ProgramInfo `json:"program"` Hash string `json:"hash"` }
type ILedgerStore ¶
type ILedgerStore interface { SaveBlock(b *Block, ledger *Ledger) error GetBlock(hash Uint256) (*Block, error) GetBlockByHeight(height uint32) (*Block, error) BlockInCache(hash Uint256) bool GetBlockHash(height uint32) (Uint256, error) GetBlockHistory(startHeight, blockNum uint32) map[uint32]Uint256 CheckBlockHistory(history map[uint32]Uint256) (uint32, bool) GetVotingWeight(hash Uint160) (int, error) IsDoubleSpend(tx *tx.Transaction) bool AddHeaders(headers []*Header) error GetHeader(hash Uint256) (*Header, error) GetHeaderByHeight(height uint32) (*Header, error) GetTransaction(hash Uint256) (*tx.Transaction, error) SaveAsset(assetid Uint256, asset *Asset) error GetAsset(hash Uint256) (*Asset, error) SaveName(registrant []byte, name string) error GetName(registrant []byte) (*string, error) GetRegistrant(name string) ([]byte, error) IsSubscribed(subscriber []byte, identifier string, topic string, bucket uint32) (bool, error) GetSubscribers(topic string, bucket uint32) []string GetSubscribersCount(topic string, bucket uint32) int GetFirstAvailableTopicBucket(topic string) int GetTopicBucketsCount(topic string) uint32 GetContract(codeHash Uint160) ([]byte, error) GetStorage(key []byte) ([]byte, error) GetCurrentBlockHash() Uint256 GetCurrentHeaderHash() Uint256 GetHeaderHeight() uint32 GetHeight() uint32 GetHeightByBlockHash(hash Uint256) (uint32, error) GetHeaderHashByHeight(height uint32) Uint256 InitLedgerStoreWithGenesisBlock(genesisblock *Block) (uint32, error) GetQuantityIssued(assetid Uint256) (Fixed64, error) GetUnspent(txid Uint256, index uint16) (*tx.TxnOutput, error) ContainsUnspent(txid Uint256, index uint16) (bool, error) GetUnspentFromProgramHash(programHash Uint160, assetid Uint256) ([]*tx.UTXOUnspent, error) GetUnspentsFromProgramHash(programHash Uint160) (map[Uint256][]*tx.UTXOUnspent, error) GetPrepaidInfo(programHash Uint160) (*Fixed64, *Fixed64, error) GetAssets() map[Uint256]*Asset IsTxHashDuplicate(txhash Uint256) bool IsBlockInStore(hash Uint256) bool Rollback(b *Block) error Close() }
ILedgerStore provides func with store package.
type Ledger ¶
type Ledger struct { Blockchain *Blockchain Store ILedgerStore }
var DefaultLedger *Ledger
func (*Ledger) BlockInLedger ¶
BlockInLedger checks if the block existed in ledger
func (*Ledger) GetBlockWithHash ¶
Get block with block hash.
func (*Ledger) GetBlockWithHeight ¶
Get Block With Height.
func (*Ledger) GetLocalBlockChainHeight ¶
Get local block chain height.
func (*Ledger) GetTransactionWithHash ¶
func (l *Ledger) GetTransactionWithHash(hash Uint256) (*tx.Transaction, error)
Get transaction with hash.
func (*Ledger) IsDoubleSpend ¶
func (l *Ledger) IsDoubleSpend(Tx *tx.Transaction) bool
double spend checking for transaction
type TransactionArray ¶
type TransactionArray []*tx.Transaction
func (TransactionArray) Iterate ¶
func (iterable TransactionArray) Iterate(handler func(item *tx.Transaction) ErrCode) ErrCode
type WinnerType ¶
type WinnerType byte
const ( // The proof of Block proposer validity should exists in previous Block header. // GenesisHash means next Block proposer is GenesisBlockProposer. GenesisSigner WinnerType = 0 // WinningTxnHash means next Block proposer is a node on signature chain. TxnSigner WinnerType = 1 // WinningBlockHash means next Block proposer is signer of historical Block. BlockSigner WinnerType = 2 // Genesis block proposer will propose first 5 blocks NumGenesisBlocks = por.SigChainMiningHeightOffset + por.SigChainBlockHeightOffset - 1 // initial version is 0, current version is 1 HeaderVersion = 1 )
func GetNextBlockSigner ¶
GetNextBlockSigner gets the next block signer after block height at timestamp. Returns next signer's public key, chord ID, winner type, and error
Click to show internal directories.
Click to hide internal directories.