ledger

package
v0.3.6-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2018 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const BlockVersion uint32 = 0
View Source
const (
	GenesisBlockProposedHeight = 4
)
View Source
const GenesisNonce uint64 = 2083236893

Variables

View Source
var StandbyBookKeepers []*crypto.PubKey

Functions

func GetBookKeeperAddress

func GetBookKeeperAddress(bookKeepers []*crypto.PubKey) (Uint160, error)

Calc the BookKeepers address by bookKeepers pubkey.

func HeaderCheck

func HeaderCheck(header *Header, receiveTime int64) error

func TransactionCheck

func TransactionCheck(block *Block) error

Types

type Block

type Block struct {
	Header       *Header
	Transactions []*tx.Transaction
	// contains filtered or unexported fields
}

func GenesisBlockInit

func GenesisBlockInit() (*Block, error)

func (*Block) Deserialize

func (b *Block) Deserialize(r io.Reader) error

func (*Block) FromTrimmedData

func (b *Block) FromTrimmedData(r io.Reader) error

func (*Block) GetMessage

func (b *Block) GetMessage() []byte

func (*Block) GetProgramHashes

func (b *Block) GetProgramHashes() ([]Uint160, error)

func (*Block) GetPrograms

func (b *Block) GetPrograms() []*program.Program

func (*Block) GetSigner

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

func (*Block) Hash

func (b *Block) Hash() Uint256

func (*Block) MarshalJson

func (bd *Block) MarshalJson() ([]byte, error)

func (*Block) RebuildMerkleRoot

func (b *Block) RebuildMerkleRoot() error

func (*Block) Serialize

func (b *Block) Serialize(w io.Writer) error

func (*Block) SerializeUnsigned

func (bd *Block) SerializeUnsigned(w io.Writer) error

func (*Block) SetPrograms

func (b *Block) SetPrograms(prog []*program.Program)

func (*Block) ToArray

func (b *Block) ToArray() []byte

func (*Block) Trim

func (b *Block) Trim(w io.Writer) error

func (*Block) Type

func (b *Block) Type() InventoryType

func (*Block) UnmarshalJson

func (bd *Block) UnmarshalJson(data []byte) error

func (*Block) Verify

func (b *Block) Verify() error

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, defaultBookKeeper []*crypto.PubKey) (*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) GetBookKeepers

func (bc *Blockchain) GetBookKeepers() []*crypto.PubKey

func (*Blockchain) GetBookKeepersByTXs

func (bc *Blockchain) GetBookKeepersByTXs(others []*tx.Transaction) []*crypto.PubKey

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 Header struct {
	Version          uint32
	PrevBlockHash    Uint256
	TransactionsRoot Uint256
	Timestamp        int64
	Height           uint32
	ConsensusData    uint64
	NextBookKeeper   Uint160
	WinningHash      Uint256
	WinningHashType  WinningHashType
	Signer           []byte
	Signature        []byte
	Program          *program.Program
	// contains filtered or unexported fields
}

func (*Header) Deserialize

func (h *Header) Deserialize(r io.Reader) error

func (*Header) DeserializeUnsigned

func (h *Header) DeserializeUnsigned(r io.Reader) error

func (*Header) GetMessage

func (h *Header) GetMessage() []byte

func (*Header) GetProgramHashes

func (h *Header) GetProgramHashes() ([]Uint160, error)

func (*Header) GetPrograms

func (h *Header) GetPrograms() []*program.Program

func (*Header) Hash

func (h *Header) Hash() Uint256

func (*Header) MarshalJson

func (h *Header) MarshalJson() ([]byte, error)

func (*Header) Serialize

func (h *Header) Serialize(w io.Writer) error

Serialize the blockheader

func (*Header) SerializeUnsigned

func (h *Header) SerializeUnsigned(w io.Writer) error

Serialize the blockheader data without program

func (*Header) SetPrograms

func (h *Header) SetPrograms(programs []*program.Program)

func (*Header) ToArray

func (h *Header) ToArray() []byte

func (*Header) UnmarshalJson

func (h *Header) UnmarshalJson(data []byte) error

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"`
	WinningHash      string              `json:"winningHash"`
	WinningHashType  byte                `json:"winningHashType"`
	Signer           string              `json:"signer"`
	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, ledger *Ledger) error
	GetHeader(hash Uint256) (*Header, error)

	GetTransaction(hash Uint256) (*tx.Transaction, error)

	SaveAsset(assetid Uint256, asset *Asset) error
	GetAsset(hash Uint256) (*Asset, error)

	GetContract(codeHash Uint160) ([]byte, error)
	GetStorage(key []byte) ([]byte, error)
	GetAccount(programHash Uint160) (*account.AccountState, error)

	GetCurrentBlockHash() Uint256
	GetCurrentHeaderHash() Uint256
	GetHeaderHeight() uint32
	GetHeight() uint32
	GetHeightByBlockHash(hash Uint256) (uint32, error)
	GetHeaderHashByHeight(height uint32) Uint256

	GetBookKeeperList() ([]*crypto.PubKey, []*crypto.PubKey, error)
	InitLedgerStoreWithGenesisBlock(genesisblock *Block, defaultBookKeeper []*crypto.PubKey) (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
	Close()
}

ILedgerStore provides func with store package.

type Ledger

type Ledger struct {
	Blockchain *Blockchain
	Store      ILedgerStore
}
var DefaultLedger *Ledger

func GetDefaultLedger

func GetDefaultLedger() (*Ledger, error)

get the default ledger

func (*Ledger) BlockInLedger

func (l *Ledger) BlockInLedger(hash Uint256) bool

BlockInLedger checks if the block existed in ledger

func (*Ledger) GetAsset

func (l *Ledger) GetAsset(assetId Uint256) (*asset.Asset, error)

Get the Asset from store.

func (*Ledger) GetBlockWithHash

func (l *Ledger) GetBlockWithHash(hash Uint256) (*Block, error)

Get block with block hash.

func (*Ledger) GetBlockWithHeight

func (l *Ledger) GetBlockWithHeight(height uint32) (*Block, error)

Get Block With Height.

func (*Ledger) GetLocalBlockChainHeight

func (l *Ledger) GetLocalBlockChainHeight() uint32

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 VBlock

type VBlock struct {
	Block       *Block
	ReceiveTime int64
}

type WinningHashType

type WinningHashType byte
const (
	// The proof of Block proposer validity should exists in previous Block header.
	// GenesisHash means next Block proposer is GenesisBlockProposer.
	GenesisHash WinningHashType = 0
	// WinningTxnHash means next Block proposer is a node on signature chain.
	WinningTxnHash WinningHashType = 1
	// WinningBlockHash means next Block proposer is signer of historical Block.
	WinningBlockHash WinningHashType = 2
)

Jump to

Keyboard shortcuts

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