core

package
v0.0.0-...-03c5838 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: LGPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Copyright (C) 2018 go-cloudcard authors

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard library. If not, see <http://www.gnu.org/licenses/>.

This file is part of the go-cloudcard library.

the go-cloudcard 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-cloudcard 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-cloudcard 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 (
	MiningReward = int64(1000000000)

	WitnessNum = 4
	AllNum     = WitnessNum * 4
)
View Source
const (
	NoSender        = ""
	StandbyWaitTime = 21 * 5
)

constants

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"
	// Latest Propose in storage
	Propose = "consensus_propose"
	// standby nodes
	StandbyNodes = "standby_nodes"
	// transaction's block height
	TxBlockHeight = "height"
	//
	TermID = "term_id"
)
View Source
const (
	MessageTypeNewBlock                   = "newblock"
	MessageTypeParentBlockDownloadRequest = "dlblock"
	MessageTypeBlockDownloadResponse      = "dlreply"
	MessageTypeNewTx                      = "newtx"
)

MessageType

View Source
const (
	PledgeTx         = "PledgeTx"
	TransferTx       = "TransferTx"
	ComplexTx        = "ComplexTx"
	ContractDeployTx = "ContractDeployTx"
	ContractInvokeTx = "ContractInvokeTx"
	ContractClosedTx = "ContractClosedTx"

	PriorityNormal = 0
	PriorityHigh   = 255

	C = int64(100 * cC)

	UintPricePerByte  = 10 * uC
	ContractInvokeFee = 10 * mC

	Thousand = int64(1000)

	Decimals        = 8
	ZeroString      = "0"
	ZeroCUintString = "0.00000000"
	Minus           = "-"
	Dot             = "."
	Numerical       = "-[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?"
)
View Source
const (
	AddressVersion = 0x60
)
View Source
const (
	DefaultGenesisPath = "conf/genesis.yaml"
)
View Source
const (
	Padding byte = 0x51
)

const

Variables

View Source
var (
	ContractAddressIsNilError  = errors.New("contract address is nil")
	TxHashLengthNotMatchError  = errors.New("tx hash is not 64")
	TransactionNotFoundInBlock = errors.New("transaction not found in block")
)
View Source
var (
	GenesisHash        = []byte("990c9490a8fe664c1da047c9447da525c37b345bc5058b5d08d939b54a799882")
	GenesisTimestamp   = int64(1561615240)
	GenesisCoinbase, _ = NewAddressFromPublicKey(make([]byte, PublicKeyDataLength))
)

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")
	ErrTxPoolFull                = errors.New("tx pool is full")
	ErrInvalidArgument           = errors.New("invalid argument(s)")
	ErrNilArgument               = errors.New("argument(s) is nil")
	ErrInvalidAmount             = errors.New("invalid amount")
	ErrInsufficientBalance       = errors.New("insufficient balance")
	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")
	ErrInvalidTransfer           = errors.New("transfer error: overflow or insufficient balance")
	ErrDuplicatedTransaction     = errors.New("duplicated transaction")
	ErrSmallTransactionNonce     = errors.New("cannot accept a transaction with smaller nonce")
	ErrLargeTransactionNonce     = errors.New("cannot accept a transaction with too bigger nonce")

	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")
	ErrInvalidBlockSign          = errors.New("invalid block signature")

	ErrInvalidTransactionSigner = errors.New("invalid transaction signer")
	ErrInvalidTransactionSign   = errors.New("invalid transaction signature")
	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 (
	TxDataIsNilError          = errors.New("transaction data is nil")
	TxDataMsgIsNilError       = errors.New("transaction data msg is nil or length is 0")
	TransactionTypeNotSupport = errors.New("the transaction type is nonsupport")
	TransactionTypeMismatch   = errors.New("transaction type mismatch")
	IllegalAmountError        = errors.New("the amount must be greater than 0")
	IllegalAddressError       = errors.New("address is nil or length is not 37")
	ToAddressIsNilError       = errors.New("to address is nil")
	UnmarshalDataError        = errors.New("unmarshal data error")
	MarshalDataError          = errors.New("marshal data error")
	ComplexTxTypeError        = errors.New("complex transaction can not contain complex transaction")
	IllegalPriorityRangeError = errors.New("transaction priority out of rang")
	AmountNotEnoughError      = errors.New("amount not enough to create contract")
	TxFeeInvalidError         = errors.New("the transaction fee is not equal to the calculated transaction fee")

	ValueCanNotToBigIntError = errors.New("value string can not transfer to big int")
	ValueIsNotValid          = errors.New("the value must be greater than 0")
	IsNotNumericalValueError = errors.New("the value is not numerical value")
)
View Source
var (
	ErrNoData   = errors.New("the page size no data")
	ErrPoolFull = errors.New("tx pool is full")
)

Functions

func AcceptTransaction

func AcceptTransaction(tx *Transaction, ws WorldState) (bool, error)

AcceptTx accepts a tx in world state.

func CUintStringToNcUintBigInt

func CUintStringToNcUintBigInt(valueStr string) (*big.Int, error)

CUintStringToNcUintBigInt

func CheckGenesisBlock

func CheckGenesisBlock(block *Block) bool

func CheckGenesisTx

func CheckGenesisTx(coinbase *Address, tx *Transaction) bool

func CheckTransaction

func CheckTransaction(tx *Transaction, ws WorldState) (bool, error)

CheckTx checks if the tx in world state.

func CheckTxType

func CheckTxType(txType string) error

func HashPbBlock

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

HashPbBlock return the hash of pb block.

func LoadGenesisConf

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

func NcUnitToCUnitString

func NcUnitToCUnitString(value *big.Int) string

NcUnitToCUnitString

func VerifyExecution

func VerifyExecution(tx *Transaction, block *Block, ws WorldState) (bool, error)

VerifyExecution verifies tx in block and returns result.

Types

type AccountManager

type AccountManager interface {
	NewAccount(passphrase []byte) (*Address, string, error)
	UpdateAccount(address *Address, oldPassphrase, newPassphrase []byte) error
	GetAllAddress() []*Address
	AddressIsValid(address string) (*Address, error)
	UnLock(address *Address, passphrase []byte, duration time.Duration) error
	Lock(address *Address) error
	ImportAccount(priKey, passphrase []byte) (*Address, error)
	Sign(address *Address, hash []byte) ([]byte, error)
	SignBlock(address *Address, block *Block) error
	SignTx(addr *Address, tx *Transaction) error
	Verify(addr *Address, message, sig []byte) (bool, error)
}

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(chainID uint32, coinbase *Address, parent *Block) (*Block, error)

NewBlock

func NewGenesis

func NewGenesis(cfg *corepb.Genesis, chain *BlockChain) (*Block, error)

NewGenesis

func (*Block) Begin

func (block *Block) Begin() error

Begin a batch task

func (*Block) CalcHash

func (block *Block) CalcHash() error

CalcHash

func (*Block) CanElect

func (block *Block) CanElect() bool

func (*Block) Coinbase

func (block *Block) Coinbase() *Address

Coinbase return coinbase

func (*Block) Commit

func (block *Block) Commit()

Commit a batch task

func (*Block) ConsensusRoot

func (block *Block) ConsensusRoot() byteutils.Hash

ConsensusRoot returns block's consensus root.

func (*Block) ExecuteTransaction

func (block *Block) ExecuteTransaction(tx *Transaction, ws WorldState) (bool, error)

ExecuteTx

func (*Block) Extra

func (block *Block) Extra() byteutils.Hash

func (*Block) FromProto

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

FromProto converts proto Block to domain Block

func (*Block) Hash

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

func (*Block) Header

func (block *Block) Header() *BlockHeader

func (*Block) Height

func (block *Block) Height() uint64

func (*Block) LinkParentBlock

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

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

func (*Block) PackTransactions

func (block *Block) PackTransactions(deadline int64)

func (*Block) ParentHash

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

ParentHash return parent hash.

func (*Block) PutBackTxs

func (block *Block) PutBackTxs()

func (*Block) PutWitnesses

func (block *Block) PutWitnesses(wts *corepb.WitnessState) error

func (*Block) RollBack

func (block *Block) RollBack()

RollBack a batch task

func (*Block) Seal

func (block *Block) Seal() error

func (*Block) Sealed

func (block *Block) Sealed() bool

func (*Block) SetHeight

func (block *Block) SetHeight(height uint64)

func (*Block) SetParent

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

func (*Block) SetTermId

func (block *Block) SetTermId(id uint64)

func (*Block) SetTimestamp

func (block *Block) SetTimestamp(time int64)

func (*Block) SetWorldState

func (block *Block) SetWorldState(parent *Block)

func (*Block) Sign

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

func (*Block) SignHash

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

SignHash return block's sign hash

func (*Block) Signature

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

Signature return block's signature

func (*Block) StateRoot

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

StateRoot return state root hash.

func (*Block) TermId

func (block *Block) TermId() uint64

func (*Block) Timestamp

func (block *Block) Timestamp() int64

func (*Block) ToProto

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

ToProto converts domain Block into proto Block

func (*Block) Transactions

func (block *Block) Transactions() Transactions

Transactions returns block transactions

func (*Block) Txs

func (block *Block) Txs() []*Transaction

func (*Block) TxsRoot

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

TxsRoot return txs root hash.

func (*Block) VerifyExecution

func (block *Block) VerifyExecution() error

VerifyExecution execute the block and verify the execution result.

func (*Block) VerifyIntegrity

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

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

func (*Block) WitnessRoot

func (block *Block) WitnessRoot() byteutils.Hash

func (*Block) WorldState

func (block *Block) WorldState() state.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) DetachedTailBlocks

func (bc *BlockChain) DetachedTailBlocks() []*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) GetBlocksByHeight

func (bc *BlockChain) GetBlocksByHeight(height uint64) []*Block

func (*BlockChain) GetIndexAndHashesByHeight

func (bc *BlockChain) GetIndexAndHashesByHeight(height uint64) (int, []byteutils.Hash)

func (*BlockChain) GetTransactionByContractAddress

func (bc *BlockChain) GetTransactionByContractAddress(contrctAddress *Address) (*TransactionReceipt, error)

func (*BlockChain) GetTransactionByHash

func (bc *BlockChain) GetTransactionByHash(txHash string) (*TransactionReceipt, error)

func (*BlockChain) GetTransactionHeight

func (bc *BlockChain) GetTransactionHeight(hash byteutils.Hash) (uint64, error)

GetTransactionHeight return transaction's block height

func (*BlockChain) IsActiveSyncing

func (bc *BlockChain) IsActiveSyncing() bool

IsActiveSyncing returns true if being syncing

func (*BlockChain) LatestPropose

func (bc *BlockChain) LatestPropose() *corepb.Propose

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

func (bc *BlockChain) LoadLatestProposeFromStorage() (*corepb.Propose, error)

LoadLatestProposeFromStorage load latest propose

func (*BlockChain) LoadStandbyNodesFromStorage

func (bc *BlockChain) LoadStandbyNodesFromStorage() []string

func (*BlockChain) LoadTailFromStorage

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

LoadTailFromStorage load tail block

func (*BlockChain) LoadTermIdFromStorage

func (bc *BlockChain) LoadTermIdFromStorage() uint64

func (*BlockChain) SetFixedBlock

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

func (*BlockChain) SetLatestPropose

func (bc *BlockChain) SetLatestPropose(latestPropose *corepb.Propose)

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(cloudcard cloudcard) 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) Storage

func (bc *BlockChain) Storage() cdb.Storage

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

func (bc *BlockChain) StoreLatestProposeFromStorage(propose *corepb.Propose) error

StoreLatestProposeFromStorage store latest propose to Storage

func (*BlockChain) StoreTailHashToStorage

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

func (*BlockChain) StoreTermIdToStorage

func (bc *BlockChain) StoreTermIdToStorage(id uint64)

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 (*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) 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) 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

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

func (blkp *BlockPool) Add(block *Block) error

Add block into block pool

func (*BlockPool) AddAndBroadcast

func (blkp *BlockPool) AddAndBroadcast(block *Block) error

AddAndBroadcast adds block into block pool and broadcast it.

func (*BlockPool) AddAndRelay

func (blkp *BlockPool) AddAndRelay(sender string, block *Block) error

AddAndRelay adds block into block pool and relay it.

func (*BlockPool) ClearCacheForCreditIndex

func (blkp *BlockPool) ClearCacheForCreditIndex()

func (*BlockPool) RecvBlockCh

func (blkp *BlockPool) RecvBlockCh() chan net.Message

func (*BlockPool) RegisterInNetwork

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

RegisterInNetwork register message subscriber in network.

func (*BlockPool) Start

func (blkp *BlockPool) Start()

Start start loop.

func (*BlockPool) Stop

func (blkp *BlockPool) Stop()

Stop stop loop.

type Consensus

type Consensus interface {
	Setup(cloudcard cloudcard) error
	Start()
	Stop()
	EnableMining()
	DisableMining()
	IsEnable() bool
	TermId() uint64
	SetTermId(in uint64)
	ResumeMining()
	SuspendMining()
	IsSuspend() bool
	VerifyBlock(*Block) error
	HandleFork() error
	UpdateFixedBlock()
	Coinbase() *Address
	Paxos() Paxos
	IsValidStandbyNode(string) bool
}

ConsensusEngine

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"`
	SuperNodes             []*corepb.TokenDistribution `yaml:"super_nodes"`
	StandbyNodes           []*corepb.TokenDistribution `yaml:"standby_nodes"`
	Foundation             *corepb.TokenDistribution   `yaml:"foundation"`
	FoundingTeam           *corepb.TokenDistribution   `yaml:"founding_team"`
	NodeDeployment         *corepb.TokenDistribution   `yaml:"node_deployment"`
	EcologicalConstruction *corepb.TokenDistribution   `yaml:"ecological_construction"`
	FoundingCommunity      *corepb.TokenDistribution   `yaml:"founding_community"`
}

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 Paxos

type Paxos interface {
	Propose(proposalId uint64) (*corepb.Propose, error)
	NotifyNoBlockArrive()
	NotifyNotEnoughWitness()
	NotifyRecvConsensusBlock()
}

type Synchronize

type Synchronize interface {
	Start()
	Stop()
	StartActiveSync() bool
	StopActiveSync()
	WaitingForFinish()
	IsActiveSyncing() bool
}

Synchronize interface of sync service

type Transaction

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

Transaction

func NewComplexTransaction

func NewComplexTransaction(from, to *Address, amount *big.Int, nonce uint64, chainId, priority uint32, txType string, msg []byte) (*Transaction, error)

NewFileTransaction

func NewContractClose

func NewContractClose(from, to *Address, nonce uint64, chainId, priority uint32, txType string, msg []byte) (*Transaction, error)

NewContractClose

func NewContractCreation

func NewContractCreation(from *Address, amount *big.Int, nonce uint64, chainId, priority uint32, txType string, msg []byte) (*Transaction, error)

NewContractCreation

func NewContractInvoke

func NewContractInvoke(from, to *Address, nonce uint64, chainId, priority uint32, txType string, msg []byte) (*Transaction, error)

NewContractInvoke

func NewPledgeTransaction

func NewPledgeTransaction(from *Address, amount *big.Int, nonce uint64, chainId, priority uint32, txType string, msg []byte) (*Transaction, error)

NewPledgeTransaction

func NewTransaction

func NewTransaction(from, to *Address, amount *big.Int, nonce uint64, chainId, priority uint32, txType string, msg []byte) (*Transaction, error)

NewTransaction

func NewTransferTransaction

func NewTransferTransaction(from, to *Address, amount *big.Int, nonce uint64, chainId, priority uint32, txType string, msg []byte) (*Transaction, error)

NewTransferTransaction

func (*Transaction) CalcFee

func (tx *Transaction) CalcFee() *big.Int

calc tx fee

func (*Transaction) CalcHash

func (tx *Transaction) CalcHash() (byteutils.Hash, error)

HashTransaction hash the transaction.

func (*Transaction) ChainId

func (tx *Transaction) ChainId() uint32

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

func (tx *Transaction) GetData() *corepb.Data

TxValue

func (*Transaction) GetFee

func (tx *Transaction) GetFee() *big.Int

TxValue

func (*Transaction) GetHexSignAndPubKey

func (tx *Transaction) GetHexSignAndPubKey() (string, string)

GetHexSignature

func (*Transaction) GetHexSignature

func (tx *Transaction) GetHexSignature() string

GetHexSignature

func (*Transaction) GetSign

func (tx *Transaction) GetSign() *corepb.Signature

func (*Transaction) GetValue

func (tx *Transaction) GetValue() *big.Int

TxValue

func (*Transaction) Hash

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

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

func (*Transaction) Priority

func (tx *Transaction) Priority() uint32

func (*Transaction) SetSign

func (tx *Transaction) SetSign(signature *corepb.Signature)

SetSign

func (*Transaction) Sign

func (tx *Transaction) Sign(signature keystore.Signature) error

Sign

func (*Transaction) String

func (tx *Transaction) String() string

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

func (tx *Transaction) Type() string

func (*Transaction) VerifyIntegrity

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

VerifyIntegrity return transaction verify result, including Hash and Signature.

type TransactionReceipt

type TransactionReceipt struct {
	Tx          *Transaction
	BlockHash   string
	BlockHeight uint64
	//tx status {1:SUCCESS、0:FAILED}
	Status uint32
	//tx error_message
	ErrorMessage string
}

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

NewTxPool

func (*TxPool) Add

func (pool *TxPool) Add(tx *Transaction) error

func (*TxPool) AddAndBroadcast

func (pool *TxPool) AddAndBroadcast(tx *Transaction) error

AddAndBroadcast adds a tx into pool and broadcast it.

func (*TxPool) AddAndRelay

func (pool *TxPool) AddAndRelay(tx *Transaction) error

AddAndRelay adds a tx into pool and relay it.

func (*TxPool) AddPledgeTransaction

func (pool *TxPool) AddPledgeTransaction(tx *Transaction)

AddPledgeTransaction

func (*TxPool) AddTransferTransaction

func (pool *TxPool) AddTransferTransaction(tx *Transaction)

AddTransferTransaction

func (*TxPool) ClearPledgeTransactions

func (pool *TxPool) ClearPledgeTransactions()

func (*TxPool) GetPendingTransactionsByPage

func (pool *TxPool) GetPendingTransactionsByPage(pageNum uint, limit uint) ([]*Transaction, error)

GetPendingTransactionsByPage

func (*TxPool) GetPendingTxSize

func (pool *TxPool) GetPendingTxSize() uint

GetPendingTxSize

func (*TxPool) GetTxsNumByAddr

func (pool *TxPool) GetTxsNumByAddr(addr string) int

func (*TxPool) PendingIsEmpty

func (pool *TxPool) PendingIsEmpty() bool

func (*TxPool) PledgeIsEmpty

func (pool *TxPool) PledgeIsEmpty() bool

func (*TxPool) RegisterInNetwork

func (pool *TxPool) RegisterInNetwork(ns network.Service)

RegisterInNetwork

func (*TxPool) Start

func (pool *TxPool) Start()

Start starts tx pool loop.

func (*TxPool) Stop

func (pool *TxPool) Stop()

Stop stops tx pool loop.

func (*TxPool) TakePledgeTransaction

func (pool *TxPool) TakePledgeTransaction() *Transaction

func (*TxPool) TakeTransferTransaction

func (pool *TxPool) TakeTransferTransaction(isPledgeTx bool) *Transaction

TakeTransaction

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 WorldState

type WorldState interface {
	GetOrCreateAccount(addr byteutils.Hash) (state.Account, error)
	GetTx(txHash byteutils.Hash) ([]byte, error)
	PutTx(txHash byteutils.Hash, txBytes []byte) error

	Reset(addr byteutils.Hash, isResetChangeLog bool) error

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

	Witnesses() ([]byteutils.Hash, error)
	WitnessRoot() byteutils.Hash
}

WorldState needed by core

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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