core

package
v0.0.0-...-5fbb372 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: LGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Copyright (C) 2018 go-gamc authors

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-gamc library.

the go-gamc library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

the go-gamc library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the go-gamc library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	// AddressPaddingLength the length of headpadding in byte
	AddressPaddingLength = 1
	// AddressPaddingIndex the index of headpadding bytes
	AddressPaddingIndex = 0
	// AddressTypeLength the length of address type in byte
	AddressTypeLength = 1
	// AddressTypeIndex the index of address type bytes
	AddressTypeIndex = 1

	AddressVersionLength = 1
	// AddressVersionIndex the index of address version bytes
	AddressVersionIndex = 2

	// AddressDataLength the length of data of address in byte.
	AddressDataLength = 20

	// AddressChecksumLength the checksum of address in byte.
	AddressChecksumLength = 4

	AddressLength = AddressPaddingLength + AddressTypeLength + AddressVersionLength + AddressDataLength + AddressChecksumLength

	// AddressDataEnd the end of the address data
	AddressDataEnd = 23

	// AddressBase58Length length of base58(Address.address)
	AddressBase58Length = 37
	// PublicKeyDataLength length of public key
	PublicKeyDataLength = 32
)
View Source
const (
	// ChunkSize is the size of blocks in a chunk
	ChunkSize = 32
	// Tail Key in storage
	Tail = "blockchain_tail"
	// Fixed in storage
	FIXED = "blockchain_fixed"
)
View Source
const (
	MessageTypeNewBlock                   = "newblock"
	MessageTypeParentBlockDownloadRequest = "dlblock"
	MessageTypeBlockDownloadResponse      = "dlreply"
	MessageTypeNewTx                      = "newtx"
)

MessageType

View Source
const (
	AddressVersion = 0x80
)
View Source
const (
	DefaultGenesisPath = "conf/genesis.yaml"
)
View Source
const (
	NoSender = ""
)

constants

View Source
const (
	Padding byte = 0x68
)

const

Variables

View Source
var (
	ErrBalanceInsufficient     = errors.New("cannot subtract a value which is bigger than current balance")
	ErrFrozenFundInsufficient  = errors.New("cannot subtract a value which is bigger than frozen fund")
	ErrPledgeFundInsufficient  = errors.New("cannot subtract a value which is bigger than pledge fund")
	ErrAccountNotFound         = errors.New("cannot found account in storage")
	ErrContractAccountNotFound = errors.New("cannot found contract account in storage please check contract address is valid or deploy is success")
)

Errors

View Source
var (
	ErrUnknownAncestor = errors.New("unknown ancestor")
	ErrFutureBlock     = errors.New("block in the future")
	ErrInvalidNumber   = errors.New("invalid block number")
)
View Source
var (
	GenesisHash      = []byte{10, 107, 126, 98, 237, 120, 159, 139, 240, 67, 134, 227, 127, 108, 206, 197, 236, 51, 176, 26, 218, 146, 194, 126, 194, 149, 216, 63, 18, 108, 55, 102}
	GenesisTimestamp = int64(1561615240)
)

Genesis Block Hash

View Source
var (
	ErrInvalidAddress         = errors.New("address: invalid address")
	ErrInvalidAddressFormat   = errors.New("address: invalid address format")
	ErrInvalidAddressType     = errors.New("address: invalid address type")
	ErrInvalidAddressChecksum = errors.New("address: invalid address checksum")

	ErrInvalidArgument           = errors.New("invalid argument(s)")
	ErrNilArgument               = errors.New("argument(s) is nil")
	ErrInvalidAmount             = errors.New("invalid amount")
	ErrInvalidProtoToBlock       = errors.New("protobuf message cannot be converted into Block")
	ErrInvalidProtoToBlockHeader = errors.New("protobuf message cannot be converted into BlockHeader")
	ErrInvalidProtoToTransaction = errors.New("protobuf message cannot be converted into Transaction")
	ErrInvalidProtoToWitness     = errors.New("protobuf message cannot be converted into Witness")
	ErrInvalidProtoToPsecData    = errors.New("protobuf message cannot be converted into PsecData")

	ErrDuplicatedBlock           = errors.New("duplicated block")
	ErrInvalidChainID            = errors.New("invalid transaction chainID")
	ErrInvalidTransactionHash    = errors.New("invalid transaction hash")
	ErrInvalidBlockHeaderChainID = errors.New("invalid block header chainId")
	ErrInvalidBlockHash          = errors.New("invalid block hash")

	ErrInvalidTransactionSigner = errors.New("invalid transaction signer")
	ErrInvalidPublicKey         = errors.New("invalid public key")

	ErrMissingParentBlock                                = errors.New("cannot find the block's parent block in storage")
	ErrInvalidBlockCannotFindParentInLocalAndTrySync     = errors.New("invalid block received, sync its parent from others")
	ErrInvalidBlockCannotFindParentInLocalAndTryDownload = errors.New("invalid block received, download its parent from others")
	ErrLinkToWrongParentBlock                            = errors.New("link the block to a block who is not its parent")
	ErrCloneAccountState                                 = errors.New("failed to clone account state")

	ErrInvalidBlockStateRoot = errors.New("invalid block state root hash")
	ErrInvalidBlockTxsRoot   = errors.New("invalid block txs root hash")
)
View Source
var (
	BlockHashLength = 32
)
View Source
var (
	ErrTxPoolFull = errors.New("tx pool is full")
)

Functions

func HashPbBlock

func HashPbBlock(pbBlock *corepb.Block) (byteutils.Hash, error)

HashPbBlock return the hash of pb block.

Types

type Account

type Account interface {
	Address() byteutils.Hash
	Balance() *big.Int
	FrozenFund() *big.Int
	PledgeFund() *big.Int
	Nonce() uint64
	CreditIndex() *big.Int
	VarsHash() byteutils.Hash
	Clone() (Account, error)

	ToBytes() ([]byte, error)
	FromBytes(bytes []byte, storage cdb.Storage) error

	IncrNonce()
	AddBalance(value *big.Int) error
	SubBalance(value *big.Int) error
	AddFrozenFund(value *big.Int) error
	SubFrozenFund(value *big.Int) error
	AddPledgeFund(value *big.Int) error
	SubPledgeFund(value *big.Int) error
	AddCreditIndex(value *big.Int) error
	SubCreditIndex(value *big.Int) error
	Put(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	Del(key []byte) error
	Iterator(prefix []byte) (Iterator, error)
}

Account Interface

type AccountManager

type AccountManager interface {
	NewAccount(passphrase []byte) (*Address, string, error)
	UpdateAccount(address string, oldPassphrase, newPassphrase []byte) error
	Sign(address *Address, hash []byte) ([]byte, error)
	SignBlock(address *Address, block *Block) error
	Verify(pubKey []byte, message, sig []byte) bool
}

type AccountState

type AccountState interface {
	RootHash() byteutils.Hash

	Flush() error
	Abort() error

	DirtyAccounts() ([]Account, error)
	Accounts() ([]Account, error)

	Clone() (AccountState, error)
	Replay(AccountState) error

	GetOrCreateAccount(byteutils.Hash) (Account, error)
}

AccountState Interface

func NewAccountState

func NewAccountState(root byteutils.Hash, storage cdb.Storage) (AccountState, error)

NewAccountState create a new account state

type Address

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

func AddressParse

func AddressParse(addStr string) (*Address, error)

func AddressParseFromBytes

func AddressParseFromBytes(b []byte) (*Address, error)

func NewAddress

func NewAddress(addr byteutils.Hash) *Address

func NewAddressFromPublicKey

func NewAddressFromPublicKey(s []byte) (*Address, error)

NewAddressFromPublicKey return new address from publickey bytes

func (*Address) Bytes

func (a *Address) Bytes() []byte

func (*Address) Equals

func (a *Address) Equals(b *Address) bool

Equals compare two Address. True is equal, otherwise false.

func (*Address) String

func (a *Address) String() string

func (*Address) Type

func (a *Address) Type() AddressType

Type return the type of address.

type AddressType

type AddressType byte
const (
	AccountAddress AddressType = 0x63 + iota
	ContractAddress
)
const UndefinedAddressType AddressType = 0x00

UndefinedAddressType undefined

type Block

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

Block

func LoadBlockFromStorage

func LoadBlockFromStorage(hash byteutils.Hash, chain *BlockChain) (*Block, error)

LoadBlockFromStorage return a block from storage

func NewBlock

func NewBlock(header *BlockHeader, txs []*Transaction) *Block

NewBlock

func NewBlockWithHeader

func NewBlockWithHeader(header *BlockHeader) *Block

func NewGenesis

func NewGenesis(cfg *config.Config, chain *BlockChain) (*Block, error)

func (*Block) Begin

func (b *Block) Begin() error

Begin a batch task

func (*Block) CalcHash

func (b *Block) CalcHash() byteutils.Hash

CalcHash

func (*Block) Coinbase

func (b *Block) Coinbase() *Address

Coinbase return coinbase

func (*Block) Commit

func (b *Block) Commit()

Commit a batch task

func (*Block) FromProto

func (b *Block) FromProto(msg proto.Message) error

FromProto converts proto Block to domain Block

func (*Block) Hash

func (b *Block) Hash() byteutils.Hash

func (*Block) Header

func (b *Block) Header() *BlockHeader

func (*Block) Height

func (b *Block) Height() uint64

func (*Block) LinkParentBlock

func (b *Block) LinkParentBlock(chain *BlockChain, parentBlock *Block) error

LinkParentBlock link parent block, return true if hash is the same; false otherwise.

func (*Block) ParentHash

func (b *Block) ParentHash() byteutils.Hash

ParentHash return parent hash.

func (*Block) RollBack

func (b *Block) RollBack()

RollBack a batch task

func (*Block) SetHeight

func (b *Block) SetHeight(height uint64)

func (*Block) SetParent

func (b *Block) SetParent(hash byteutils.Hash)

func (*Block) SetTimestamp

func (b *Block) SetTimestamp(time int64)

func (*Block) SetWorldState

func (b *Block) SetWorldState(parent *Block)

func (*Block) Sign

func (b *Block) Sign(signature keystore.Signature) error

func (*Block) SignHash

func (b *Block) SignHash() byteutils.Hash

SignHash return block's sign hash

func (*Block) Signature

func (b *Block) Signature() *corepb.Signature

Signature return block's signature

func (*Block) StateRoot

func (b *Block) StateRoot() byteutils.Hash

StateRoot return state root hash.

func (*Block) Timestamp

func (b *Block) Timestamp() int64

func (*Block) ToProto

func (b *Block) ToProto() (proto.Message, error)

ToProto converts domain Block into proto Block

func (*Block) Transactions

func (b *Block) Transactions() Transactions

Transactions returns block transactions

func (*Block) TxsRoot

func (b *Block) TxsRoot() byteutils.Hash

TxsRoot return txs root hash.

func (*Block) VerifyExecution

func (b *Block) VerifyExecution() error

VerifyExecution execute the block and verify the execution result.

func (*Block) VerifyIntegrity

func (b *Block) VerifyIntegrity(chainId uint32, consensus Consensus) error

VerifyIntegrity verify block's hash, txs' integrity and consensus acceptable.

func (*Block) Witness

func (b *Block) Witness() []*Witness

func (*Block) WorldState

func (b *Block) WorldState() WorldState

WorldState return the world state of the block

type BlockChain

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

BlockChain

func NewBlockChain

func NewBlockChain(config *config.Config, net network.Service, db cdb.Storage) (*BlockChain, error)

NewBlockChain

func (*BlockChain) BlockPool

func (bc *BlockChain) BlockPool() *BlockPool

func (*BlockChain) ChainId

func (bc *BlockChain) ChainId() uint32

func (*BlockChain) Consensus

func (bc *BlockChain) Consensus() Consensus

func (*BlockChain) CurrentBlock

func (bc *BlockChain) CurrentBlock() *Block

func (*BlockChain) FixedBlock

func (bc *BlockChain) FixedBlock() *Block

func (*BlockChain) GenesisBlock

func (bc *BlockChain) GenesisBlock() *Block

func (*BlockChain) GetBlock

func (bc *BlockChain) GetBlock(hash byteutils.Hash) *Block

GetBlock return block of given hash from local storage and detachedBlocks.

func (*BlockChain) GetBlockOnCanonicalChainByHash

func (bc *BlockChain) GetBlockOnCanonicalChainByHash(blockHash byteutils.Hash) *Block

GetBlockOnCanonicalChainByHash check if a block is on canonical chain

func (*BlockChain) GetBlockOnCanonicalChainByHeight

func (bc *BlockChain) GetBlockOnCanonicalChainByHeight(height uint64) *Block

GetBlockOnCanonicalChainByHeight return block in given height

func (*BlockChain) IsActiveSyncing

func (bc *BlockChain) IsActiveSyncing() bool

IsActiveSyncing returns true if being syncing

func (*BlockChain) LoadBlockFromStorage

func (bc *BlockChain) LoadBlockFromStorage(blockHash byteutils.Hash) *Block

func (*BlockChain) LoadFixedFromStorage

func (bc *BlockChain) LoadFixedFromStorage() (*Block, error)

LoadFixedFromStorage load FIXED

func (*BlockChain) LoadGenesisFromStorage

func (bc *BlockChain) LoadGenesisFromStorage() (*Block, error)

LoadGenesisFromStorage load genesis

func (*BlockChain) LoadTailFromStorage

func (bc *BlockChain) LoadTailFromStorage() (*Block, error)

LoadTailFromStorage load tail block

func (*BlockChain) SetFixedBlock

func (bc *BlockChain) SetFixedBlock(block *Block)

func (*BlockChain) SetSyncEngine

func (bc *BlockChain) SetSyncEngine(syncEngine Synchronize)

SetSyncEngine set sync engine

func (*BlockChain) SetTailBlock

func (bc *BlockChain) SetTailBlock(newTail *Block) error

func (*BlockChain) Setup

func (bc *BlockChain) Setup(gamc gamc) error

func (*BlockChain) Start

func (bc *BlockChain) Start()

Start start loop.

func (*BlockChain) StartActiveSync

func (bc *BlockChain) StartActiveSync() bool

StartActiveSync start active sync task

func (*BlockChain) Stop

func (bc *BlockChain) Stop()

Stop stop loop.

func (*BlockChain) StoreBlockToStorage

func (bc *BlockChain) StoreBlockToStorage(block *Block) error

StoreBlockToStorage store block

func (*BlockChain) StoreFIXEDHashToStorage

func (bc *BlockChain) StoreFIXEDHashToStorage(block *Block) error

StoreFIXEDHashToStorage store FIXED block hash

func (*BlockChain) StoreTailHashToStorage

func (bc *BlockChain) StoreTailHashToStorage(block *Block) error

func (*BlockChain) TailBlock

func (bc *BlockChain) TailBlock() *Block

func (*BlockChain) TxPool

func (bc *BlockChain) TxPool() *TxPool

type BlockHeader

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

BlockHeader

func CopyHeader

func CopyHeader(h *BlockHeader) *BlockHeader

CopyHeader creates a deep copy of a block header to prevent side effects from modifying a header variable.

func (*BlockHeader) ChainId

func (h *BlockHeader) ChainId() uint32

func (*BlockHeader) Coinbase

func (h *BlockHeader) Coinbase() *Address

func (*BlockHeader) Extra

func (h *BlockHeader) Extra() []byte

func (*BlockHeader) FromProto

func (h *BlockHeader) FromProto(msg proto.Message) error

FromProto converts proto BlockHeader to domain BlockHeader

func (*BlockHeader) Hash

func (h *BlockHeader) Hash() []byte

func (*BlockHeader) Height

func (h *BlockHeader) Height() uint64

func (*BlockHeader) ParentHash

func (h *BlockHeader) ParentHash() []byte

func (*BlockHeader) PsecData

func (h *BlockHeader) PsecData() *PsecData

func (*BlockHeader) SetAccountsRoot

func (h *BlockHeader) SetAccountsRoot(hash byteutils.Hash)

func (*BlockHeader) SetChainId

func (h *BlockHeader) SetChainId(id uint32)

func (*BlockHeader) SetCoinbase

func (h *BlockHeader) SetCoinbase(addr Address)

func (*BlockHeader) SetHash

func (h *BlockHeader) SetHash(hash byteutils.Hash)

func (*BlockHeader) SetHeight

func (h *BlockHeader) SetHeight(height uint64)

func (*BlockHeader) SetParentHash

func (h *BlockHeader) SetParentHash(hash []byte)

func (*BlockHeader) SetPsecData

func (h *BlockHeader) SetPsecData(pd PsecData)

func (*BlockHeader) SetTimestamp

func (h *BlockHeader) SetTimestamp(t int64)

func (*BlockHeader) SetTxsRoot

func (h *BlockHeader) SetTxsRoot(hash byteutils.Hash)

func (*BlockHeader) SetWitnessReward

func (h *BlockHeader) SetWitnessReward(reward int64)

func (*BlockHeader) Sign

func (h *BlockHeader) Sign() *corepb.Signature

func (*BlockHeader) Timestamp

func (h *BlockHeader) Timestamp() int64

func (*BlockHeader) ToProto

func (h *BlockHeader) ToProto() (proto.Message, error)

ToProto converts domain BlockHeader to proto BlockHeader

func (*BlockHeader) TxsRoot

func (h *BlockHeader) TxsRoot() []byte

func (*BlockHeader) WitnessReward

func (h *BlockHeader) WitnessReward() *big.Int

func (*BlockHeader) Witnesses

func (h *BlockHeader) Witnesses() []*Witness

type BlockPool

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

func NewBlockPool

func NewBlockPool(size int) (*BlockPool, error)

NewBlockPool return new #BlockPool instance.

func (*BlockPool) Push

func (pool *BlockPool) Push(block *Block) error

Push block into block pool

func (*BlockPool) PushAndBroadcast

func (pool *BlockPool) PushAndBroadcast(block *Block) error

func (*BlockPool) PushAndRelay

func (pool *BlockPool) PushAndRelay(sender string, block *Block) error

PushAndRelay push block into block pool and relay it.

func (*BlockPool) RegisterInNetwork

func (pool *BlockPool) RegisterInNetwork(ns net.Service)

RegisterInNetwork register message subscriber in network.

func (*BlockPool) Start

func (pool *BlockPool) Start()

Start start loop.

func (*BlockPool) Stop

func (pool *BlockPool) Stop()

Stop stop loop.

type Consensus

type Consensus interface {
	Setup(gamc gamc)
	Start()
	Stop()

	EnableMining()  //
	DisableMining() //
	IsEnable() bool

	ResumeMining()
	SuspendMining()  //
	IsSuspend() bool //

	UpdateFixedBlock()
	VerifyBlock(block *Block) error
	AccumulateRewards(addr Address, reward *big.Int) error
}

ConsensusEngine

type ConsensusState

type ConsensusState interface {
	RootHash() *corepb.ConsensusRoot
	String() string
	Clone() (ConsensusState, error)
	Replay(ConsensusState) error
	Proposer() byteutils.Hash
	Timestamp() int64
	NextConsensusState(int64, WorldState) (ConsensusState, error)
	Term() ([]byteutils.Hash, error)
	TermRoot() byteutils.Hash
}

ConsensusState interface of consensus state

type ContractSet

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

ContractSet

func (*ContractSet) NormalContracts

func (cs *ContractSet) NormalContracts() uint64

func (*ContractSet) TemplateContracts

func (cs *ContractSet) TemplateContracts() uint64

func (*ContractSet) TemplateContractsRefs

func (cs *ContractSet) TemplateContractsRefs() uint64

func (*ContractSet) Value

func (cs *ContractSet) Value() *big.Int

type Genesis

type Genesis struct {
	ChainId                uint32   `yaml:"chain_id"`
	Token                  []Token  `yaml:"token"`
	Coinbase               string   `yaml:"coinbase"`
	StandbyNode            []string `yaml:"standby_node"`
	Foundation             Token    `yaml:"foundation"`
	FoundingTeam           Token    `yaml:"founding_team"`
	NodeDeployment         Token    `yaml:"node_deployment"`
	EcologicalConstruction Token    `yaml:"ecological_construction"`
	FoundingCommunity      Token    `yaml:"founding_community"`
}

func LoadGenesisConf

func LoadGenesisConf(filePath string) (*Genesis, error)

type HandledData

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

CreditScore

func (*HandledData) HandledContracts

func (hd *HandledData) HandledContracts() *ContractSet

func (*HandledData) HandledTxs

func (hd *HandledData) HandledTxs() *TransactionSet

func (*HandledData) PrevRoundProductions

func (hd *HandledData) PrevRoundProductions() int

func (*HandledData) Value

func (hd *HandledData) Value() *big.Int

func (*HandledData) WinningTimes

func (hd *HandledData) WinningTimes() uint64

type Iterator

type Iterator interface {
	Next() (bool, error)
	Value() []byte
}

Iterator Variables in Account Storage

type Synchronize

type Synchronize interface {
	Start()
	Stop()

	StartActiveSync() bool
	StopActiveSync()
	WaitingForFinish()
	IsActiveSyncing() bool
}

Synchronize interface of sync service

type Token

type Token struct {
	Address string `yaml:"address"`
	Value   string `yaml:"value"`
}

type Transaction

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

Transaction

func NewContractCreation

func NewContractCreation(nonce uint64, from *Address, amount *big.Int) *Transaction

NewContractCreation

func NewTransaction

func NewTransaction(nonce uint64, from, to *Address, amount *big.Int) *Transaction

NewTransaction

func (*Transaction) From

func (tx *Transaction) From() *Address

TxFrom

func (*Transaction) FromProto

func (tx *Transaction) FromProto(msg proto.Message) error

FromProto converts proto Tx to domain Tx

func (*Transaction) Hash

func (tx *Transaction) Hash() byteutils.Hash

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

func (*Transaction) Timestamp

func (tx *Transaction) Timestamp() int64

func (*Transaction) To

func (tx *Transaction) To() *Address

TxTo

func (*Transaction) ToProto

func (tx *Transaction) ToProto() (proto.Message, error)

ToProto converts domain Tx to proto Tx

func (*Transaction) VerifyIntegrity

func (tx *Transaction) VerifyIntegrity(chainId uint32) error

VerifyIntegrity return transaction verify result, including Hash and Signature.

type TransactionSet

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

TransactionSet

func (*TransactionSet) ContractTxs

func (ts *TransactionSet) ContractTxs() uint64

func (*TransactionSet) NormalTxs

func (ts *TransactionSet) NormalTxs() uint64

func (*TransactionSet) Value

func (ts *TransactionSet) Value() *big.Int

type Transactions

type Transactions []*Transaction

Transactions is an alias of Transaction array.

type TxPool

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

TxPool

func NewTxPool

func NewTxPool() *TxPool

func (*TxPool) AddLocal

func (pool *TxPool) AddLocal(txs []*Transaction) []error

AddLocal

func (*TxPool) AddRemote

func (pool *TxPool) AddRemote(txs []*Transaction) []error

AddRemote

func (*TxPool) Get

func (pool *TxPool) Get(size int) []*Transaction

Get

func (*TxPool) GetAccountTxAmount

func (pool *TxPool) GetAccountTxAmount(address Address) int

GetAccountTxAmount

func (*TxPool) Promote

func (pool *TxPool) Promote(size int)

Promote

func (*TxPool) Start

func (pool *TxPool) Start()

type TxWorldState

type TxWorldState interface {
	AccountsRoot() byteutils.Hash
	TxsRoot() byteutils.Hash

	CheckAndUpdate() ([]interface{}, error)
	Reset(addr byteutils.Hash, isResetChangeLog bool) error
	Close() error

	Accounts() ([]Account, error)
	GetOrCreateAccount(addr byteutils.Hash) (Account, error)

	GetTx(txHash byteutils.Hash) ([]byte, error)
	PutTx(txHash byteutils.Hash, txBytes []byte) error

	GetBlockHashByHeight(height uint64) ([]byte, error)
	GetBlock(txHash byteutils.Hash) ([]byte, error)
}

TxWorldState is the world state of a single transaction

type Voter

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

Voter

func (*Voter) Address

func (v *Voter) Address() Address

func (*Voter) HandledData

func (v *Voter) HandledData() *HandledData

func (*Voter) Index

func (v *Voter) Index() *big.Int

func (*Voter) Pledge

func (v *Voter) Pledge() *big.Int

type Witness

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

func (*Witness) AddFollower

func (w *Witness) AddFollower(follower *Address)

func (*Witness) FromProto

func (w *Witness) FromProto(msg proto.Message) error

func (*Witness) Master

func (w *Witness) Master() *Address

func (*Witness) SetMaster

func (w *Witness) SetMaster(master *Address)

func (*Witness) ToProto

func (w *Witness) ToProto() (proto.Message, error)

type WorldState

type WorldState interface {
	Begin() error
	Commit() error
	RollBack() error

	Prepare(interface{}) (TxWorldState, error)
	Reset(addr byteutils.Hash, isResetChangeLog bool) error
	Flush() error
	Abort() error

	NextConsensusState(int64) (ConsensusState, error)
	SetConsensusState(ConsensusState)

	LoadAccountsRoot(byteutils.Hash) error
	LoadTxsRoot(byteutils.Hash) error

	Clone() (WorldState, error)

	AccountsRoot() byteutils.Hash
	TxsRoot() byteutils.Hash

	Accounts() ([]Account, error)
	GetOrCreateAccount(addr byteutils.Hash) (Account, error)

	GetTx(txHash byteutils.Hash) ([]byte, error)
	PutTx(txHash byteutils.Hash, txBytes []byte) error

	GetBlockHashByHeight(height uint64) ([]byte, error)
	GetBlock(txHash byteutils.Hash) ([]byte, error)
}

WorldState interface of world state

func NewWorldState

func NewWorldState(storage cdb.Storage) (WorldState, error)

NewWorldState create a new empty WorldState

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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