ledger

package
v0.5.3-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const BlockVersion uint32 = 0
View Source
const (
	GenesisBlockProposedHeight = 4
)
View Source
const GenesisNonce uint64 = 2083236893
View Source
const (
	// initial version is 0, current version is 1
	HeaderVersion = 1
)

Variables

This section is empty.

Functions

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, []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) (*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 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) 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"`
	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, 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)

	SaveName(registrant []byte, name string) error
	GetName(registrant []byte) (*string, error)
	GetRegistrant(name string) ([]byte, 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

	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 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 TransactionArray

type TransactionArray []*tx.Transaction

func (TransactionArray) Iterate

func (iterable TransactionArray) Iterate(handler func(item *tx.Transaction) ErrCode) ErrCode

type VBlock

type VBlock struct {
	Block       *Block
	ReceiveTime int64
}

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
)

Jump to

Keyboard shortcuts

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