ledger

package
v0.0.0-...-67b0b38 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const BlockVersion uint32 = 0
View Source
const GenesisNonce uint64 = 2083236893

Variables

View Source
var StandbyBookKeepers []*crypto.PubKey

Functions

func GetBookKeeperAddress

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

Types

type Block

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

func GenesisBlockInit

func GenesisBlockInit(defaultBookKeeper []*crypto.PubKey) (*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) Hash

func (b *Block) Hash() Uint256

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

func (b *Block) Verify() error

type Blockchain

type Blockchain struct {
	BlockHeight uint32
	BCEvents    *events.Event
	// contains filtered or unexported fields
}

func GenesisBlock

func GenesisBlock(defBookKeeper []*crypto.PubKey) (*Blockchain, error)

func NewBlockchain

func NewBlockchain(height uint32) *Blockchain

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(block *Block) error

func (*Blockchain) ContainsTransaction

func (bc *Blockchain) ContainsTransaction(hash Uint256) bool

func (*Blockchain) CurrentBlockHash

func (bc *Blockchain) CurrentBlockHash() Uint256

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 Blockdata

type Blockdata struct {
	Version          uint32
	PrevBlockHash    Uint256
	TransactionsRoot Uint256
	Timestamp        uint32
	Height           uint32
	ConsensusData    uint64
	NextBookKeeper   Uint160

	Program *program.Program
	// contains filtered or unexported fields
}

func (*Blockdata) Deserialize

func (bd *Blockdata) Deserialize(r io.Reader) error

func (*Blockdata) DeserializeUnsigned

func (bd *Blockdata) DeserializeUnsigned(r io.Reader) error

func (*Blockdata) GetMessage

func (bd *Blockdata) GetMessage() []byte

func (*Blockdata) GetProgramHashes

func (bd *Blockdata) GetProgramHashes() ([]Uint160, error)

func (*Blockdata) GetPrograms

func (bd *Blockdata) GetPrograms() []*program.Program

func (*Blockdata) Hash

func (bd *Blockdata) Hash() Uint256

func (*Blockdata) Serialize

func (bd *Blockdata) Serialize(w io.Writer) error

func (*Blockdata) SerializeUnsigned

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

don't write the hash and program to writer

func (*Blockdata) SetPrograms

func (bd *Blockdata) SetPrograms(programs []*program.Program)

func (*Blockdata) ToArray

func (bd *Blockdata) ToArray() []byte
type Header struct {
	Blockdata *Blockdata
}

func (*Header) Deserialize

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

func (*Header) Serialize

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

Serialize the blockheader

func (*Header) ToArray

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

type ILedgerStore

type ILedgerStore interface {
	//TODO: define the state store func
	SaveBlock(b *Block, ledger *Ledger) error
	GetBlock(hash Uint256) (*Block, error)
	BlockInCache(hash Uint256) bool
	GetBlockHash(height uint32) (Uint256, error)
	InitLedgerStore(ledger *Ledger) error
	IsDoubleSpend(tx *tx.Transaction) bool

	//SaveHeader(header *Header,ledger *Ledger) error
	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)
	GetAssetState(assetId Uint256) (*states.AssetState, error)

	GetCurrentBlockHash() Uint256
	GetCurrentHeaderHash() Uint256
	GetHeaderHeight() uint32
	GetHeight() uint32
	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.TxOutput, error)
	ContainsUnspent(txid Uint256, index uint16) (bool, error)
	GetUnspentFromProgramHash(programHash Uint160, assetid Uint256) ([]*tx.UTXOUnspent, error)
	GetUnspentsFromProgramHash(programHash Uint160) (map[Uint256][]*tx.UTXOUnspent, error)
	GetLockedFromProgramHash(programHash Uint160, assetid Uint256) ([]*LockAsset, error)
	GetAvailableAsset(programHash Uint160, assetid Uint256) (Fixed64, Fixed64, error)
	GetAssets() map[Uint256]*Asset

	SaveRecord(hash string, txhash Uint256) error
	GetRecord(filehash string) (Uint256, error)

	IsTxHashDuplicate(txhash Uint256) bool
	IsBlockInStore(hash Uint256) bool
	Close()
}

ILedgerStore provides func with store package.

type Ledger

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

func GetDefaultLedger

func GetDefaultLedger() (*Ledger, error)

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)

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)

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

type State

type State struct {
}

type StateStore

type StateStore interface {
	SaveState(*State) error
}

Jump to

Keyboard shortcuts

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