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/>.
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/>.
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/>.
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 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/>.
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/>.
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/>.
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/>.
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/>.
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/>.
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/>.
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/>.
Index ¶
- Constants
- Variables
- func AcceptTransaction(tx *Transaction, ws WorldState) (bool, error)
- func CUintStringToNcUintBigInt(valueStr string) (*big.Int, error)
- func CheckGenesisBlock(block *Block) bool
- func CheckGenesisTx(coinbase *Address, tx *Transaction) bool
- func CheckTransaction(tx *Transaction, ws WorldState) (bool, error)
- func CheckTxType(txType string) error
- func HashPbBlock(pbBlock *corepb.Block) (byteutils.Hash, error)
- func LoadGenesisConf(filePath string) (*corepb.Genesis, error)
- func NcUnitToCUnitString(value *big.Int) string
- func VerifyExecution(tx *Transaction, block *Block, ws WorldState) (bool, error)
- type AccountManager
- type Address
- type AddressType
- type Block
- func (block *Block) Begin() error
- func (block *Block) CalcHash() error
- func (block *Block) CanElect() bool
- func (block *Block) Coinbase() *Address
- func (block *Block) Commit()
- func (block *Block) ConsensusRoot() byteutils.Hash
- func (block *Block) ExecuteTransaction(tx *Transaction, ws WorldState) (bool, error)
- func (block *Block) Extra() byteutils.Hash
- func (block *Block) FromProto(msg proto.Message) error
- func (block *Block) Hash() byteutils.Hash
- func (block *Block) Header() *BlockHeader
- func (block *Block) Height() uint64
- func (block *Block) LinkParentBlock(chain *BlockChain, parentBlock *Block) error
- func (block *Block) PackTransactions(deadline int64)
- func (block *Block) ParentHash() byteutils.Hash
- func (block *Block) PutBackTxs()
- func (block *Block) PutWitnesses(wts *corepb.WitnessState) error
- func (block *Block) RollBack()
- func (block *Block) Seal() error
- func (block *Block) Sealed() bool
- func (block *Block) SetHeight(height uint64)
- func (block *Block) SetParent(hash byteutils.Hash)
- func (block *Block) SetTermId(id uint64)
- func (block *Block) SetTimestamp(time int64)
- func (block *Block) SetWorldState(parent *Block)
- func (block *Block) Sign(signature keystore.Signature) error
- func (block *Block) SignHash() byteutils.Hash
- func (block *Block) Signature() *corepb.Signature
- func (block *Block) StateRoot() byteutils.Hash
- func (block *Block) TermId() uint64
- func (block *Block) Timestamp() int64
- func (block *Block) ToProto() (proto.Message, error)
- func (block *Block) Transactions() Transactions
- func (block *Block) Txs() []*Transaction
- func (block *Block) TxsRoot() byteutils.Hash
- func (block *Block) VerifyExecution() error
- func (block *Block) VerifyIntegrity(chainId uint32, consensus Consensus) error
- func (block *Block) WitnessRoot() byteutils.Hash
- func (block *Block) WorldState() state.WorldState
- type BlockChain
- func (bc *BlockChain) BlockPool() *BlockPool
- func (bc *BlockChain) ChainId() uint32
- func (bc *BlockChain) Consensus() Consensus
- func (bc *BlockChain) DetachedTailBlocks() []*Block
- func (bc *BlockChain) FixedBlock() *Block
- func (bc *BlockChain) GenesisBlock() *Block
- func (bc *BlockChain) GetBlock(hash byteutils.Hash) *Block
- func (bc *BlockChain) GetBlockOnCanonicalChainByHash(blockHash byteutils.Hash) *Block
- func (bc *BlockChain) GetBlockOnCanonicalChainByHeight(height uint64) *Block
- func (bc *BlockChain) GetBlocksByHeight(height uint64) []*Block
- func (bc *BlockChain) GetIndexAndHashesByHeight(height uint64) (int, []byteutils.Hash)
- func (bc *BlockChain) GetTransactionByContractAddress(contrctAddress *Address) (*TransactionReceipt, error)
- func (bc *BlockChain) GetTransactionByHash(txHash string) (*TransactionReceipt, error)
- func (bc *BlockChain) GetTransactionHeight(hash byteutils.Hash) (uint64, error)
- func (bc *BlockChain) IsActiveSyncing() bool
- func (bc *BlockChain) LatestPropose() *corepb.Propose
- func (bc *BlockChain) LoadBlockFromStorage(blockHash byteutils.Hash) *Block
- func (bc *BlockChain) LoadFixedFromStorage() (*Block, error)
- func (bc *BlockChain) LoadGenesisFromStorage() (*Block, error)
- func (bc *BlockChain) LoadLatestProposeFromStorage() (*corepb.Propose, error)
- func (bc *BlockChain) LoadStandbyNodesFromStorage() []string
- func (bc *BlockChain) LoadTailFromStorage() (*Block, error)
- func (bc *BlockChain) LoadTermIdFromStorage() uint64
- func (bc *BlockChain) SetFixedBlock(block *Block)
- func (bc *BlockChain) SetLatestPropose(latestPropose *corepb.Propose)
- func (bc *BlockChain) SetSyncEngine(syncEngine Synchronize)
- func (bc *BlockChain) SetTailBlock(newTail *Block) error
- func (bc *BlockChain) Setup(cloudcard cloudcard) error
- func (bc *BlockChain) Start()
- func (bc *BlockChain) StartActiveSync() bool
- func (bc *BlockChain) Stop()
- func (bc *BlockChain) Storage() cdb.Storage
- func (bc *BlockChain) StoreBlockToStorage(block *Block) error
- func (bc *BlockChain) StoreFixedHashToStorage(block *Block) error
- func (bc *BlockChain) StoreLatestProposeFromStorage(propose *corepb.Propose) error
- func (bc *BlockChain) StoreTailHashToStorage(block *Block) error
- func (bc *BlockChain) StoreTermIdToStorage(id uint64)
- func (bc *BlockChain) TailBlock() *Block
- func (bc *BlockChain) TxPool() *TxPool
- type BlockHeader
- func (h *BlockHeader) ChainId() uint32
- func (h *BlockHeader) Coinbase() *Address
- func (h *BlockHeader) Extra() []byte
- func (h *BlockHeader) FromProto(msg proto.Message) error
- func (h *BlockHeader) Hash() []byte
- func (h *BlockHeader) Height() uint64
- func (h *BlockHeader) ParentHash() []byte
- func (h *BlockHeader) SetAccountsRoot(hash byteutils.Hash)
- func (h *BlockHeader) SetChainId(id uint32)
- func (h *BlockHeader) SetCoinbase(addr Address)
- func (h *BlockHeader) SetHash(hash byteutils.Hash)
- func (h *BlockHeader) SetHeight(height uint64)
- func (h *BlockHeader) SetParentHash(hash []byte)
- func (h *BlockHeader) SetTimestamp(t int64)
- func (h *BlockHeader) SetTxsRoot(hash byteutils.Hash)
- func (h *BlockHeader) SetWitnessReward(reward int64)
- func (h *BlockHeader) Sign() *corepb.Signature
- func (h *BlockHeader) Timestamp() int64
- func (h *BlockHeader) ToProto() (proto.Message, error)
- func (h *BlockHeader) TxsRoot() []byte
- func (h *BlockHeader) WitnessReward() *big.Int
- type BlockPool
- func (blkp *BlockPool) Add(block *Block) error
- func (blkp *BlockPool) AddAndBroadcast(block *Block) error
- func (blkp *BlockPool) AddAndRelay(sender string, block *Block) error
- func (blkp *BlockPool) ClearCacheForCreditIndex()
- func (blkp *BlockPool) RecvBlockCh() chan net.Message
- func (blkp *BlockPool) RegisterInNetwork(ns net.Service)
- func (blkp *BlockPool) Start()
- func (blkp *BlockPool) Stop()
- type Consensus
- type ContractSet
- type Genesis
- type HandledData
- type Paxos
- type Synchronize
- type Transaction
- func NewComplexTransaction(from, to *Address, amount *big.Int, nonce uint64, chainId, priority uint32, ...) (*Transaction, error)
- func NewContractClose(from, to *Address, nonce uint64, chainId, priority uint32, txType string, ...) (*Transaction, error)
- func NewContractCreation(from *Address, amount *big.Int, nonce uint64, chainId, priority uint32, ...) (*Transaction, error)
- func NewContractInvoke(from, to *Address, nonce uint64, chainId, priority uint32, txType string, ...) (*Transaction, error)
- func NewPledgeTransaction(from *Address, amount *big.Int, nonce uint64, chainId, priority uint32, ...) (*Transaction, error)
- func NewTransaction(from, to *Address, amount *big.Int, nonce uint64, chainId, priority uint32, ...) (*Transaction, error)
- func NewTransferTransaction(from, to *Address, amount *big.Int, nonce uint64, chainId, priority uint32, ...) (*Transaction, error)
- func (tx *Transaction) CalcFee() *big.Int
- func (tx *Transaction) CalcHash() (byteutils.Hash, error)
- func (tx *Transaction) ChainId() uint32
- func (tx *Transaction) From() *Address
- func (tx *Transaction) FromProto(msg proto.Message) error
- func (tx *Transaction) GetData() *corepb.Data
- func (tx *Transaction) GetFee() *big.Int
- func (tx *Transaction) GetHexSignAndPubKey() (string, string)
- func (tx *Transaction) GetHexSignature() string
- func (tx *Transaction) GetSign() *corepb.Signature
- func (tx *Transaction) GetValue() *big.Int
- func (tx *Transaction) Hash() byteutils.Hash
- func (tx *Transaction) Nonce() uint64
- func (tx *Transaction) Priority() uint32
- func (tx *Transaction) SetSign(signature *corepb.Signature)
- func (tx *Transaction) Sign(signature keystore.Signature) error
- func (tx *Transaction) String() string
- func (tx *Transaction) Timestamp() int64
- func (tx *Transaction) To() *Address
- func (tx *Transaction) ToProto() (proto.Message, error)
- func (tx *Transaction) Type() string
- func (tx *Transaction) VerifyIntegrity(chainId uint32) error
- type TransactionReceipt
- type TransactionSet
- type Transactions
- type TxPool
- func (pool *TxPool) Add(tx *Transaction) error
- func (pool *TxPool) AddAndBroadcast(tx *Transaction) error
- func (pool *TxPool) AddAndRelay(tx *Transaction) error
- func (pool *TxPool) AddPledgeTransaction(tx *Transaction)
- func (pool *TxPool) AddTransferTransaction(tx *Transaction)
- func (pool *TxPool) ClearPledgeTransactions()
- func (pool *TxPool) GetPendingTransactionsByPage(pageNum uint, limit uint) ([]*Transaction, error)
- func (pool *TxPool) GetPendingTxSize() uint
- func (pool *TxPool) GetTxsNumByAddr(addr string) int
- func (pool *TxPool) PendingIsEmpty() bool
- func (pool *TxPool) PledgeIsEmpty() bool
- func (pool *TxPool) RegisterInNetwork(ns network.Service)
- func (pool *TxPool) Start()
- func (pool *TxPool) Stop()
- func (pool *TxPool) TakePledgeTransaction() *Transaction
- func (pool *TxPool) TakeTransferTransaction(isPledgeTx bool) *Transaction
- type Voter
- type WorldState
Constants ¶
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 )
const ( MiningReward = int64(1000000000) WitnessNum = 4 AllNum = WitnessNum * 4 )
const ( NoSender = "" StandbyWaitTime = 21 * 5 )
constants
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" )
const ( MessageTypeNewBlock = "newblock" MessageTypeParentBlockDownloadRequest = "dlblock" MessageTypeBlockDownloadResponse = "dlreply" MessageTypeNewTx = "newtx" )
MessageType
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]+)?" )
const (
AddressVersion = 0x60
)
const (
DefaultGenesisPath = "conf/genesis.yaml"
)
const (
Padding byte = 0x51
)
const
Variables ¶
var ( ContractAddressIsNilError = errors.New("contract address is nil") TxHashLengthNotMatchError = errors.New("tx hash is not 64") TransactionNotFoundInBlock = errors.New("transaction not found in block") )
var ( GenesisHash = []byte("990c9490a8fe664c1da047c9447da525c37b345bc5058b5d08d939b54a799882") GenesisTimestamp = int64(1561615240) GenesisCoinbase, _ = NewAddressFromPublicKey(make([]byte, PublicKeyDataLength)) )
Genesis Block Hash
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") )
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") )
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 ¶
CUintStringToNcUintBigInt
func CheckGenesisBlock ¶
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 HashPbBlock ¶
HashPbBlock return the hash of pb block.
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 AddressParseFromBytes ¶
func NewAddress ¶
func NewAddressFromPublicKey ¶
NewAddressFromPublicKey return new address from publickey bytes
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 NewGenesis ¶
func NewGenesis(cfg *corepb.Genesis, chain *BlockChain) (*Block, error)
NewGenesis
func (*Block) ConsensusRoot ¶
ConsensusRoot returns block's consensus root.
func (*Block) ExecuteTransaction ¶
func (block *Block) ExecuteTransaction(tx *Transaction, ws WorldState) (bool, error)
ExecuteTx
func (*Block) Header ¶
func (block *Block) Header() *BlockHeader
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) ParentHash ¶
ParentHash return parent hash.
func (*Block) PutBackTxs ¶
func (block *Block) PutBackTxs()
func (*Block) PutWitnesses ¶
func (block *Block) PutWitnesses(wts *corepb.WitnessState) error
func (*Block) SetTimestamp ¶
func (*Block) SetWorldState ¶
func (*Block) Transactions ¶
func (block *Block) Transactions() Transactions
Transactions returns block transactions
func (*Block) Txs ¶
func (block *Block) Txs() []*Transaction
func (*Block) VerifyExecution ¶
VerifyExecution execute the block and verify the execution result.
func (*Block) VerifyIntegrity ¶
VerifyIntegrity verify block's hash, txs' integrity and consensus acceptable.
func (*Block) WitnessRoot ¶
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 ¶
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) StartActiveSync ¶
func (bc *BlockChain) StartActiveSync() bool
StartActiveSync start active sync task
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 ¶
NewBlockPool return new BlockPool instance.
func (*BlockPool) AddAndBroadcast ¶
AddAndBroadcast adds block into block pool and broadcast it.
func (*BlockPool) AddAndRelay ¶
AddAndRelay adds block into block pool and relay it.
func (*BlockPool) ClearCacheForCreditIndex ¶
func (blkp *BlockPool) ClearCacheForCreditIndex()
func (*BlockPool) RecvBlockCh ¶
func (*BlockPool) RegisterInNetwork ¶
RegisterInNetwork register message subscriber in network.
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 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) CalcHash ¶
func (tx *Transaction) CalcHash() (byteutils.Hash, error)
HashTransaction hash the transaction.
func (*Transaction) ChainId ¶
func (tx *Transaction) ChainId() uint32
func (*Transaction) FromProto ¶
func (tx *Transaction) FromProto(msg proto.Message) error
FromProto converts proto Tx to domain Tx
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) 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) String ¶
func (tx *Transaction) String() string
func (*Transaction) Timestamp ¶
func (tx *Transaction) Timestamp() int64
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 TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool
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) GetTxsNumByAddr ¶
func (*TxPool) PendingIsEmpty ¶
func (*TxPool) PledgeIsEmpty ¶
func (*TxPool) RegisterInNetwork ¶
RegisterInNetwork
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) HandledData ¶
func (v *Voter) HandledData() *HandledData
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