chain

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const MaxExtraDataLen = 256

Variables

View Source
var (
	ErrNoGenesis                     = errors.New("can't get genesis block")
	ErrBlockNotExist                 = errors.New("block not exist in local")
	ErrSaveBlock                     = errors.New("save block to db error")
	ErrSaveAccount                   = errors.New("save account error")
	ErrVerifyHeaderFailed            = errors.New("verify block's header error")
	ErrVerifyBlockFailed             = errors.New("verify block error")
	ErrInvalidConfirmInfo            = errors.New("invalid confirm info")
	ErrInvalidSignedConfirmInfo      = errors.New("invalid signed data of confirm info")
	ErrSetConfirmInfoToDB            = errors.New("set confirm info to db error")
	ErrSetStableBlockToDB            = errors.New("set stable block to db error")
	ErrStableHeightLargerThanCurrent = errors.New("stable block's height is larger than current block")
)
View Source
var (
	// ErrInvalidSender is returned if the transaction contains an invalid signature.
	ErrInvalidSender = errors.New("invalid sender")

	// ErrInsufficientFunds is returned if the total cost of executing a transaction
	// is higher than the balance of the user's account.
	ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value")
)
View Source
var (
	ErrInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas")
	ErrInvalidTxInBlock          = errors.New("block contains invalid transaction")
)
View Source
var DefaultDeputyNodes = deputynode.DeputyNodes{
	&deputynode.DeputyNode{
		MinerAddress: decodeMinerAddress("Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"),
		NodeID:       common.FromHex("0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0"),
		IP:           net.ParseIP("149.28.68.93"),
		Port:         7003,
		Rank:         0,
		Votes:        50000,
	},
	&deputynode.DeputyNode{
		MinerAddress: decodeMinerAddress("Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY"),
		NodeID:       common.FromHex("0xddb5fc36c415799e4c0cf7046ddde04aad6de8395d777db4f46ebdf258e55ee1d698fdd6f81a950f00b78bb0ea562e4f7de38cb0adf475c5026bb885ce74afb0"),
		IP:           net.ParseIP("149.28.68.93"),
		Port:         7005,
		Rank:         1,
		Votes:        40000,
	},
	&deputynode.DeputyNode{
		MinerAddress: decodeMinerAddress("Lemo842BJZ4DKCC764C63Y6A943775JH6NQ3Z33Y"),
		NodeID:       common.FromHex("0x7739f34055d3c0808683dbd77a937f8e28f707d5b1e873bbe61f6f2d0347692f36ef736f342fb5ce4710f7e337f062cc2110d134b63a9575f78cb167bfae2f43"),
		IP:           net.ParseIP("149.28.25.8"),
		Port:         7003,
		Rank:         2,
		Votes:        30000,
	},
	&deputynode.DeputyNode{
		MinerAddress: decodeMinerAddress("Lemo837QGPS3YNTYNF53CD88WA5DR3ABNA95W2DG"),
		NodeID:       common.FromHex("0x34f0df789b46e9bc09f23d5315b951bc77bbfeda653ae6f5aab564c9b4619322fddb3b1f28d1c434250e9d4dd8f51aa8334573d7281e4d63baba913e9fa6908f"),
		IP:           net.ParseIP("45.77.121.107"),
		Port:         7003,
		Rank:         3,
		Votes:        20000,
	},
	&deputynode.DeputyNode{
		MinerAddress: decodeMinerAddress("Lemo83HKZK68JQZDRGS5PWT2ZBSKR5CRADCSJB9B"),
		NodeID:       common.FromHex("0x5b980ffb1b463fce4773a22ebf376c07c6207023b016b36ccfaba7be1cd1ab4a91737741cd43b7fcb10879e0fcf314d69fa953daec0f02be0f8f9cedb0cb3797"),
		IP:           net.ParseIP("63.211.111.245"),
		Port:         7003,
		Rank:         4,
		Votes:        10000,
	},
}

DefaultDeputyNodes

View Source
var TransactionTimeOut = int64(3600)

Functions

func CanTransfer

func CanTransfer(am vm.AccountManager, addr common.Address, amount *big.Int) bool

CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.

func GetHashFn

func GetHashFn(ref *types.Header, chain ChainContext) vm.GetHashFunc

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func IntrinsicGas

func IntrinsicGas(data []byte, contractCreation bool) (uint64, error)

IntrinsicGas computes the 'intrinsic gas' for a message with the given data.

func NewEVMContext

func NewEVMContext(tx *types.Transaction, header *types.Header, txIndex uint, txHash common.Hash, blockHash common.Hash, chain ChainContext) vm.Context

NewEVMContext creates a new context for use in the EVM.

func SetupGenesisBlock

func SetupGenesisBlock(db protocol.ChainDB, genesis *Genesis) (common.Hash, error)

SetupGenesisBlock setup genesis block

func Transfer

func Transfer(am vm.AccountManager, sender, recipient common.Address, amount *big.Int)

Transfer subtracts amount from sender and adds amount to recipient using the given Db

Types

type ApplyTxsResult

type ApplyTxsResult struct {
	Txs     types.Transactions // The transactions executed indeed. These transactions will be packaged in a block
	Events  []*types.Event     // contract events
	Bloom   types.Bloom        // used to search contract events
	GasUsed uint64             // gas used by all transactions
}

type BlockChain

type BlockChain struct {
	BroadcastConfirmInfo broadcastConfirmInfoFn // callback of broadcast confirm info
	BroadcastStableBlock broadcastBlockFn       // callback of broadcast stable block

	MinedBlockFeed  subscribe.Feed
	RecvBlockFeed   subscribe.Feed
	StableBlockFeed subscribe.Feed
	// contains filtered or unexported fields
}

func NewBlockChain

func NewBlockChain(chainID uint16, engine Engine, db db.ChainDB, flags flag.CmdFlags) (bc *BlockChain, err error)

func NewBlockChainForTest

func NewBlockChainForTest() (*BlockChain, chan *types.Block, error)

func (*BlockChain) AccountManager

func (bc *BlockChain) AccountManager() *account.Manager

func (*BlockChain) ChainID

func (bc *BlockChain) ChainID() uint16

ChainID

func (*BlockChain) CurrentBlock

func (bc *BlockChain) CurrentBlock() *types.Block

CurrentBlock get latest current block

func (*BlockChain) Db

func (bc *BlockChain) Db() db.ChainDB

func (*BlockChain) Flags

func (bc *BlockChain) Flags() flag.CmdFlags

func (*BlockChain) Genesis

func (bc *BlockChain) Genesis() *types.Block

Genesis genesis block

func (*BlockChain) GetBlockByHash

func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block

func (*BlockChain) GetBlockByHeight

func (bc *BlockChain) GetBlockByHeight(height uint32) *types.Block

func (*BlockChain) GetConfirms

func (bc *BlockChain) GetConfirms(query *protocol.GetConfirmInfo) []types.SignData

GetConfirms get all confirm info of special block

func (*BlockChain) HasBlock

func (bc *BlockChain) HasBlock(hash common.Hash) bool

HasBlock has special block in local

func (*BlockChain) InsertChain

func (bc *BlockChain) InsertChain(block *types.Block, isSynchronising bool) (err error)

InsertChain insert block of non-self to chain

func (*BlockChain) ReceiveConfirm

func (bc *BlockChain) ReceiveConfirm(info *protocol.BlockConfirmData) (err error)

ReceiveConfirm

func (*BlockChain) ReceiveConfirms

func (bc *BlockChain) ReceiveConfirms(pack protocol.BlockConfirms)

ReceiveConfirms receive confirm package from net connection

func (*BlockChain) SetMinedBlock

func (bc *BlockChain) SetMinedBlock(block *types.Block) error

SetMinedBlock 挖到新块

func (*BlockChain) SetStableBlock

func (bc *BlockChain) SetStableBlock(hash common.Hash, height uint32, logLess bool) error

SetStableBlock

func (*BlockChain) StableBlock

func (bc *BlockChain) StableBlock() *types.Block

StableBlock get latest stable block

func (*BlockChain) Stop

func (bc *BlockChain) Stop()

Stop stop block chain

func (*BlockChain) TxProcessor

func (bc *BlockChain) TxProcessor() *TxProcessor

func (*BlockChain) Verify

func (bc *BlockChain) Verify(block *types.Block) error

Verify verify block

type ChainContext

type ChainContext interface {
	// GetBlockByHash returns the hash corresponding to their hash.
	GetBlockByHash(hash common.Hash) *types.Block
}

ChainContext supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.

type Dpovp

type Dpovp struct {
	// contains filtered or unexported fields
}

func NewDpovp

func NewDpovp(timeout int64, db protocol.ChainDB) *Dpovp

func (*Dpovp) Finalize

func (d *Dpovp) Finalize(header *types.Header, am *account.Manager)

Finalize

func (*Dpovp) Seal

func (d *Dpovp) Seal(header *types.Header, txs []*types.Transaction, changeLog []*types.ChangeLog, events []*types.Event) (*types.Block, error)

Seal packaged into a block

func (*Dpovp) VerifyHeader

func (d *Dpovp) VerifyHeader(block *types.Block) error

VerifyHeader verify block header

type Engine

type Engine interface {
	VerifyHeader(block *types.Block) error

	Seal(header *types.Header, txs []*types.Transaction, changeLog []*types.ChangeLog, events []*types.Event) (*types.Block, error)

	Finalize(header *types.Header, am *account.Manager)
}

type EngineTestForChain

type EngineTestForChain struct{}

func (*EngineTestForChain) Finalize

func (engine *EngineTestForChain) Finalize(header *types.Header, am *account.Manager)

func (*EngineTestForChain) Seal

func (engine *EngineTestForChain) Seal(header *types.Header, txs []*types.Transaction, changeLog []*types.ChangeLog, events []*types.Event) (*types.Block, error)

func (*EngineTestForChain) VerifyHeader

func (engine *EngineTestForChain) VerifyHeader(block *types.Block) error

type Genesis

type Genesis struct {
	Time        uint32                 `json:"timestamp"     gencodec:"required"`
	ExtraData   []byte                 `json:"extraData"`
	GasLimit    uint64                 `json:"gasLimit"      gencodec:"required"`
	Founder     common.Address         `json:"founder"       gencodec:"required"`
	DeputyNodes deputynode.DeputyNodes `json:"deputyNodes"   gencodec:"required"`
}

func DefaultGenesisBlock

func DefaultGenesisBlock() *Genesis

DefaultGenesisBlock default genesis block

func (Genesis) MarshalJSON

func (g Genesis) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Genesis) ToBlock

func (g *Genesis) ToBlock() *types.Block

ToBlock

func (*Genesis) UnmarshalJSON

func (g *Genesis) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type TransactionWithTime

type TransactionWithTime struct {
	Tx      *types.Transaction
	RecTime int64
	DelFlg  bool
}

type TxPool

type TxPool struct {
	NewTxsFeed subscribe.Feed
	// contains filtered or unexported fields
}

func NewTxPool

func NewTxPool(am *account.Manager) *TxPool

func (*TxPool) AddKey

func (pool *TxPool) AddKey(hash common.Hash)

func (*TxPool) AddTx

func (pool *TxPool) AddTx(tx *types.Transaction) error

func (*TxPool) AddTxs

func (pool *TxPool) AddTxs(txs []*types.Transaction) error

func (*TxPool) Pending

func (pool *TxPool) Pending(size int) []*types.Transaction

func (*TxPool) Remove

func (pool *TxPool) Remove(keys []common.Hash)

type TxProcessor

type TxProcessor struct {
	// contains filtered or unexported fields
}

func NewTxProcessor

func NewTxProcessor(bc *BlockChain) *TxProcessor

func (*TxProcessor) ApplyTxs

ApplyTxs picks and processes transactions from miner's tx pool.

func (*TxProcessor) FillHeader

func (p *TxProcessor) FillHeader(header *types.Header, txs types.Transactions, gasUsed uint64) (*types.Header, error)

FillHeader creates a new header then fills it with the result of transactions process

func (*TxProcessor) Process

func (p *TxProcessor) Process(block *types.Block) (*types.Header, error)

Process processes all transactions in a block. Change accounts' data and execute contract codes.

type TxsRecent

type TxsRecent struct {
	// contains filtered or unexported fields
}

func NewRecent

func NewRecent() *TxsRecent

type TxsSort

type TxsSort interface {
	// contains filtered or unexported methods
}

func NewTxsSortByTime

func NewTxsSortByTime() TxsSort

type TxsSortByTime

type TxsSortByTime struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
vm
abi
Package abi implements the Lemochain ABI (Application Binary Interface).
Package abi implements the Lemochain ABI (Application Binary Interface).
runtime
Package runtime provides a basic execution model for executing EVM code.
Package runtime provides a basic execution model for executing EVM code.

Jump to

Keyboard shortcuts

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