blockchain

package
v0.0.0-...-85922c0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package blockchain define the interface of blockchain and implement its object

Index

Constants

View Source
const (
	DIVID    = 7  //dividend
	DIVIDEND = 10 //divid
)
View Source
const (
	DayPledge      int = 100
	PledgeCycle    int = 120
	DayMinedBlocks int = 8640
	CycleMax           = PledgeCycle * DayMinedBlocks
)
View Source
const (
	MinPledgeAmount uint64 = 10000000000000
	MaxPledgeAmount uint64 = 1200000000000000
)
View Source
const InitHeight = 60350422
View Source
const MAXGASLIMIT uint64 = 10000000000000
View Source
const (
	MAXUINT64 = ^uint64(0)
)
View Source
const MINGASLIMIT uint64 = 2100000

Variables

View Source
var (
	MinedKey      = []byte("MinedKey")
	TotalMinedKey = []byte("TotalMinedKey")
)
View Source
var (
	PledgeKey      = []byte("PledgeInfo")
	TotalPledgeKey = []byte("TotalPledgeKey")
)
View Source
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")
)
View Source
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"
)
View Source
var (
	BindingKey = []byte("binding")
)
View Source
var ETHDECIMAL uint64 = 10000000
View Source
var ETHDECIMAL uint64 = 10000000

Functions

func BigToCompact

func BigToCompact(n *big.Int) uint32

func Check0x

func Check0x(input string) string

func CommonAddrToStoreAddr

func CommonAddrToStoreAddr(caddr common.Address, prefix []byte) common.Address

func CompactToBig

func CompactToBig(compact uint32) *big.Int

func GetMinerAmount

func GetMinerAmount(height uint64) uint64

func Uint64ToBigInt

func Uint64ToBigInt(v uint64) *big.Int

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

func (bc *Blockchain) GetFrozenTokenBal(addr address.Address, symbol []byte) (uint64, error)

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

func (bc *Blockchain) GetLogs() []*evmtypes.Log

get evm logs

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

func (bc *Blockchain) GetTokenBalance(addr address.Address, symbol []byte) (uint64, error)

GetTokenBalance get the balance of tokens

func (*Blockchain) GetTokenDemic

func (bc *Blockchain) GetTokenDemic(symbol []byte) (uint64, error)

GetTokenDemic get token precision

func (*Blockchain) GetTokenRoot

func (bc *Blockchain) GetTokenRoot(addr address.Address, script string) ([]byte, error)

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

func (*Blockchain) Tip

func (bc *Blockchain) Tip() (*block.Block, error)

Get blockchain top

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 ChainConfig struct {
	ChainId   int64  `yaml:"chainid"`
	NetworkId int64  `yaml:"networkId"`
	GasLimit  uint64 `yaml:"gaslimit"`
	GasPrice  uint64 `yaml:"gasprice"`
}

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
}

type TxIndex

type TxIndex struct {
	Height uint64
	Index  uint64
}

TxIndex transaction data index structure

Jump to

Keyboard shortcuts

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