Documentation ¶
Overview ¶
Package blockchain define the interface of blockchain and implement its object
Index ¶
- Constants
- Variables
- func BigToCompact(n *big.Int) uint32
- func Check0x(input string) string
- func CommonAddrToStoreAddr(caddr common.Address, prefix []byte) common.Address
- func CompactToBig(compact uint32) *big.Int
- func GetMinerAmount(height uint64) uint64
- func Uint64ToBigInt(v uint64) *big.Int
- type Blockchain
- func (bc *Blockchain) AddBlock(block *block.Block) error
- func (bc *Blockchain) AddBlocks(blocks []*block.Block, limit int) error
- func (bc *Blockchain) AddSmallBlock(DBTransaction store.Transaction, block *block.Block) error
- func (bc *Blockchain) AddTempBlock(block *block.Block, DBTransaction store.Transaction) error
- func (bc *Blockchain) AddUncleBlock(block *block.Block) error
- func (bc *Blockchain) CallSmartContract(contractAddr, origin, callInput, value string) (string, string, error)
- func (bc *Blockchain) CheckBlockRegular(b *block.Block) error
- func (bc *Blockchain) Close()
- func (bc *Blockchain) DeleteBlock(height uint64) error
- func (bc *Blockchain) DeleteTempBlockTest(height uint64, DBTransaction store.Transaction) error
- func (bc *Blockchain) DeleteUncleBlock(block *block.Block) error
- func (bc *Blockchain) DifficultDetection(b *block.Block) error
- func (bc *Blockchain) FactCommit(deleteEmptyObjects bool) (common.Hash, error)
- func (bc *Blockchain) FindChainBranch(Hash []byte) (*block.Block, error)
- func (bc *Blockchain) GetAllFreezeBalance(address address.Address) (uint64, error)
- func (bc *Blockchain) GetAvailableBalance(address address.Address) (uint64, error)
- func (bc *Blockchain) GetBalance(address address.Address) (uint64, error)
- func (bc *Blockchain) GetBasePledge() (uint64, error)
- func (bc *Blockchain) GetBindingEthAddress(ktoAddr address.Address) (string, error)
- func (bc *Blockchain) GetBindingKtoAddress(ethAddr string) (address.Address, error)
- func (bc *Blockchain) GetBlockByHash(hash []byte) (*block.Block, error)
- func (bc *Blockchain) GetBlockByHeight(height uint64) (*block.Block, error)
- func (bc *Blockchain) GetCode(contractAddr string) []byte
- func (bc *Blockchain) GetFrozenTokenBal(addr address.Address, symbol []byte) (uint64, error)
- func (bc *Blockchain) GetHash(height uint64) (hash []byte, err error)
- func (bc *Blockchain) GetLogs() []*evmtypes.Log
- func (bc *Blockchain) GetMaxBlockHeight() (height uint64, err error)
- func (bc *Blockchain) GetNonce(address address.Address) (uint64, error)
- func (bc *Blockchain) GetSingleFreezeBalance(address address.Address, to address.Address) (uint64, error)
- func (bc *Blockchain) GetStorageAt(addr, hash string) common.Hash
- func (bc *Blockchain) GetTokenBalance(addr address.Address, symbol []byte) (uint64, error)
- func (bc *Blockchain) GetTokenDemic(symbol []byte) (uint64, error)
- func (bc *Blockchain) GetTokenRoot(addr address.Address, script string) ([]byte, error)
- func (bc *Blockchain) GetTotalMined(address address.Address) (uint64, error)
- func (bc *Blockchain) GetTotalPledge(address []byte) (uint64, error)
- func (bc *Blockchain) GetTransactionByHash(hash []byte) (*transaction.FinishedTransaction, error)
- func (bc *Blockchain) GetWholeNetworkPledgeAndNum() (uint64, uint64, error)
- func (bc *Blockchain) IsMainChainBlock(hash []byte) (bool, error)
- func (bc *Blockchain) NewBlock(txs []*transaction.SignedTransaction, minaddr address.Address) (*block.Block, error)
- func (bc *Blockchain) NewTransaction() store.Transaction
- func (bc *Blockchain) ReorganizeChain(hashs [][]byte, delHeight uint64) error
- func (bc *Blockchain) SetCode(contractAddr common.Address, code []byte)
- func (bc *Blockchain) SyncLock()
- func (bc *Blockchain) SyncUnlock()
- func (bc *Blockchain) Tip() (*block.Block, error)
- type Blockchains
- type ChainConfig
- type DistriKeyInfo
- type DistriValueInfo
- type NodeKeyPledge
- type NodeValuePledge
- type TxIndex
Constants ¶
const ( DIVID = 7 //dividend DIVIDEND = 10 //divid )
const ( DayPledge int = 100 PledgeCycle int = 120 DayMinedBlocks int = 8640 CycleMax = PledgeCycle * DayMinedBlocks )
const ( MinPledgeAmount uint64 = 10000000000000 MaxPledgeAmount uint64 = 1200000000000000 )
const InitHeight = 60350422
const MAXGASLIMIT uint64 = 10000000000000
const (
MAXUINT64 = ^uint64(0)
)
const MINGASLIMIT uint64 = 2100000
Variables ¶
var ( MinedKey = []byte("MinedKey") TotalMinedKey = []byte("TotalMinedKey") )
var ( PledgeKey = []byte("PledgeInfo") TotalPledgeKey = []byte("TotalPledgeKey") )
var ( // SnapRootKey key to store snaproot in database SnapRootKey = []byte("snapRoot") // HeightKey key to store height in database HeightKey = []byte("height") // FreezeKey store the map name of freeze balance FreezeKey = []byte("freeze") )
var ( // SnapRootPrefix prefix of block snapRoot SnapRootPrefix = []byte("blockSnap") // HeightPrefix prefix of block height key HeightPrefix = []byte("blockheight") BindingKey = []byte("binding") CREATECONTRACT = "create" CALLCONTRACT = "call" )
var (
BindingKey = []byte("binding")
)
var ETHDECIMAL uint64 = 10000000
var ETHDECIMAL uint64 = 10000000
Functions ¶
func BigToCompact ¶
func CommonAddrToStoreAddr ¶
func CompactToBig ¶
func GetMinerAmount ¶
func Uint64ToBigInt ¶
Types ¶
type Blockchain ¶
type Blockchain struct { ChainCfg *ChainConfig // contains filtered or unexported fields }
Blockchain blockchain data structure
func New ¶
func New(db *badger.DB, cfg *ChainConfig) (*Blockchain, error)
New create blockchain object
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(block *block.Block) error
AddBlock add blocks to blockchain
func (*Blockchain) AddBlocks ¶
func (bc *Blockchain) AddBlocks(blocks []*block.Block, limit int) error
func (*Blockchain) AddSmallBlock ¶
func (bc *Blockchain) AddSmallBlock(DBTransaction store.Transaction, block *block.Block) error
func (*Blockchain) AddTempBlock ¶
func (bc *Blockchain) AddTempBlock(block *block.Block, DBTransaction store.Transaction) error
AddBlock add blocks to blockchain
func (*Blockchain) AddUncleBlock ¶
func (bc *Blockchain) AddUncleBlock(block *block.Block) error
AddUncleBlock add uncle blocks to blockchain
func (*Blockchain) CallSmartContract ¶
func (bc *Blockchain) CallSmartContract(contractAddr, origin, callInput, value string) (string, string, error)
call contract with out transaction
func (*Blockchain) CheckBlockRegular ¶
func (bc *Blockchain) CheckBlockRegular(b *block.Block) error
func (*Blockchain) Close ¶
func (bc *Blockchain) Close()
func (*Blockchain) DeleteBlock ¶
func (bc *Blockchain) DeleteBlock(height uint64) error
DeleteBlock delete some blocks from the blockchain DeleteBlock(10):delete block data larger than 10, including 10
func (*Blockchain) DeleteTempBlockTest ¶
func (bc *Blockchain) DeleteTempBlockTest(height uint64, DBTransaction store.Transaction) error
DeleteBlock delete some blocks from the blockchain DeleteBlock(10):delete block data larger than 10, including 10
func (*Blockchain) DeleteUncleBlock ¶
func (bc *Blockchain) DeleteUncleBlock(block *block.Block) error
DeleteUncleBlock delete uncle blocks to blockchain
func (*Blockchain) DifficultDetection ¶
func (bc *Blockchain) DifficultDetection(b *block.Block) error
func (*Blockchain) FactCommit ¶
func (bc *Blockchain) FactCommit(deleteEmptyObjects bool) (common.Hash, error)
factCommit writes the state to the underlying in-memory trie database
func (*Blockchain) FindChainBranch ¶
func (bc *Blockchain) FindChainBranch(Hash []byte) (*block.Block, error)
func (*Blockchain) GetAllFreezeBalance ¶
func (bc *Blockchain) GetAllFreezeBalance(address address.Address) (uint64, error)
GetAllFreezeBalance query all frozen quotas of an address
func (*Blockchain) GetAvailableBalance ¶
func (bc *Blockchain) GetAvailableBalance(address address.Address) (uint64, error)
GetAvailableBalance get available balance of address
func (*Blockchain) GetBalance ¶
func (bc *Blockchain) GetBalance(address address.Address) (uint64, error)
GetBalance get the balance of the address
func (*Blockchain) GetBasePledge ¶
func (bc *Blockchain) GetBasePledge() (uint64, error)
func (*Blockchain) GetBindingEthAddress ¶
func (bc *Blockchain) GetBindingEthAddress(ktoAddr address.Address) (string, error)
get bingding eth address by kto address
func (*Blockchain) GetBindingKtoAddress ¶
func (bc *Blockchain) GetBindingKtoAddress(ethAddr string) (address.Address, error)
get bingding kto address by eth address
func (*Blockchain) GetBlockByHash ¶
func (bc *Blockchain) GetBlockByHash(hash []byte) (*block.Block, error)
GetBlockByHeight get the block corresponding to the block height
func (*Blockchain) GetBlockByHeight ¶
func (bc *Blockchain) GetBlockByHeight(height uint64) (*block.Block, error)
GetBlockByHeight get the block corresponding to the block height
func (*Blockchain) GetCode ¶
func (bc *Blockchain) GetCode(contractAddr string) []byte
get contract code by address
func (*Blockchain) GetFrozenTokenBal ¶
GetFrozenTokenBal get the frozen balance of tokens
func (*Blockchain) GetHash ¶
func (bc *Blockchain) GetHash(height uint64) (hash []byte, err error)
GetHash get the hash corresponding to the block height
func (*Blockchain) GetMaxBlockHeight ¶
func (bc *Blockchain) GetMaxBlockHeight() (height uint64, err error)
GetMaxBlockHeight get maximum block height
func (*Blockchain) GetNonce ¶
func (bc *Blockchain) GetNonce(address address.Address) (uint64, error)
GetNonce get the nonce of the address
func (*Blockchain) GetSingleFreezeBalance ¶
func (bc *Blockchain) GetSingleFreezeBalance(address address.Address, to address.Address) (uint64, error)
GetSingleFreezeBalance check an address and specify the frozen amount of the notary from: Frozen address. to: Notary Public
func (*Blockchain) GetStorageAt ¶
func (bc *Blockchain) GetStorageAt(addr, hash string) common.Hash
get storage at address
func (*Blockchain) GetTokenBalance ¶
GetTokenBalance get the balance of tokens
func (*Blockchain) GetTokenDemic ¶
func (bc *Blockchain) GetTokenDemic(symbol []byte) (uint64, error)
GetTokenDemic get token precision
func (*Blockchain) GetTokenRoot ¶
GetTokenRoot get token root
func (*Blockchain) GetTotalMined ¶
func (bc *Blockchain) GetTotalMined(address address.Address) (uint64, error)
Get Total Mined pledge by address
func (*Blockchain) GetTotalPledge ¶
func (bc *Blockchain) GetTotalPledge(address []byte) (uint64, error)
Get address Total Pledge
func (*Blockchain) GetTransactionByHash ¶
func (bc *Blockchain) GetTransactionByHash(hash []byte) (*transaction.FinishedTransaction, error)
GetTransactionByHash get the transaction corresponding to the transaction hash
func (*Blockchain) GetWholeNetworkPledgeAndNum ¶
func (bc *Blockchain) GetWholeNetworkPledgeAndNum() (uint64, uint64, error)
func (*Blockchain) IsMainChainBlock ¶
func (bc *Blockchain) IsMainChainBlock(hash []byte) (bool, error)
func (*Blockchain) NewBlock ¶
func (bc *Blockchain) NewBlock(txs []*transaction.SignedTransaction, minaddr address.Address) (*block.Block, error)
NewBlock create a new block for the blockchain
func (*Blockchain) NewTransaction ¶
func (bc *Blockchain) NewTransaction() store.Transaction
func (*Blockchain) ReorganizeChain ¶
func (bc *Blockchain) ReorganizeChain(hashs [][]byte, delHeight uint64) error
ReorganizeChain reorganizes the block chain by disconnecting the nodes in the main list and connecting the nodes in the branch list len(hashs) means main list need recover block lenght include tip block,
func (*Blockchain) SetCode ¶
func (bc *Blockchain) SetCode(contractAddr common.Address, code []byte)
get contract code by address
func (*Blockchain) SyncLock ¶
func (bc *Blockchain) SyncLock()
func (*Blockchain) SyncUnlock ¶
func (bc *Blockchain) SyncUnlock()
type Blockchains ¶
type Blockchains interface { // NewBlock create a new block for the blockchain NewBlock([]*transaction.SignedTransaction, address.Address) (*block.Block, error) // AddBlock add blocks to blockchain AddUncleBlock(*block.Block) error // AddBlock add blocks to blockchain AddBlock(*block.Block) error // DeleteBlock delete some blocks from the blockchain DeleteBlock(uint64) error // DeleteUncleBlock delete some blocks from the blockchain DeleteUncleBlock(*block.Block) error // GetBalance retrieves the balance from the given address or 0 if object not found GetBalance(address.Address) (uint64, error) // GetAvailableBalance get available balance of address GetAvailableBalance(address.Address) (uint64, error) // GetNonce get the nonce of the address GetNonce(address.Address) (uint64, error) // GetHash get the hash corresponding to the block height GetHash(uint64) ([]byte, error) // GetMaxBlockHeight get maximum block height GetMaxBlockHeight() (uint64, error) // GetBlockByHeight get the block corresponding to the block height GetBlockByHeight(uint64) (*block.Block, error) // GetBlockByHash get block data through hash GetBlockByHash([]byte) (*block.Block, error) // GetAllFreezeBalance query all frozen quotas of an address GetAllFreezeBalance(address.Address) (uint64, error) // GetSingleFreezeBalance check an address and specify the frozen amount of the notary GetSingleFreezeBalance(address.Address, address.Address) (uint64, error) // GetTokenBalance get the balance of tokens GetTokenBalance(address.Address, []byte) (uint64, error) // GetFrozenTokenBal get the frozen balance of tokens GetFrozenTokenBal(address.Address, []byte) (uint64, error) // GetTokenRoot get token root GetTokenRoot(address.Address, string) ([]byte, error) // GetTokenDemic get token precision GetTokenDemic([]byte) (uint64, error) ReorganizeChain([][]byte, uint64) error Tip() (*block.Block, error) //call contract CallSmartContract(contractAddr, origin, callInput, value string) (string, string, error) //get code GetCode(contractAddr string) []byte //set code SetCode(contractAddr common.Address, code []byte) //get storage by hash GetStorageAt(addr, hash string) common.Hash // GetTransactionByHash get the transaction corresponding to the transaction hash GetTransactionByHash([]byte) (*transaction.FinishedTransaction, error) //Get logs GetLogs() []*evmtypes.Log DifficultDetection(b *block.Block) error CheckBlockRegular(b *block.Block) error GetBasePledge() (uint64, error) }
Blockchains interface specification of blockchain
type ChainConfig ¶
type DistriKeyInfo ¶
type DistriKeyInfo struct {
// contains filtered or unexported fields
}
PledgeKeyInfo struct
type DistriValueInfo ¶
type DistriValueInfo struct {
// contains filtered or unexported fields
}
PledgeKeyInfo struct
type NodeKeyPledge ¶
type NodeKeyPledge struct {
// contains filtered or unexported fields
}
type NodeValuePledge ¶
type NodeValuePledge struct {
// contains filtered or unexported fields
}