Documentation
¶
Index ¶
- Variables
- type Account
- func (o *Account) Code() []byte
- func (o *Account) Commit() (types.Hash, error)
- func (o *Account) GetNonce() uint64
- func (o *Account) GetState(key []byte) (bool, []byte)
- func (o *Account) Marshal() ([]byte, error)
- func (o *Account) Query(prefix string) (bool, [][]byte)
- func (o *Account) SetCodeAndHash(code []byte)
- func (o *Account) SetNonce(nonce uint64)
- func (o *Account) SetState(key []byte, value []byte)
- func (o *Account) SetStateRoot(hash types.Hash)
- func (o *Account) Unmarshal(data []byte) error
- type BlockchainLedger
- type ChainLedger
- func (l *ChainLedger) AddEvent(event *pb.Event)
- func (l *ChainLedger) Clear()
- func (l *ChainLedger) Close()
- func (l *ChainLedger) Commit() (types.Hash, error)
- func (l *ChainLedger) Events(txHash string) []*pb.Event
- func (l *ChainLedger) GetAccount(addr types.Address) *Account
- func (l *ChainLedger) GetBalance(addr types.Address) uint64
- func (l *ChainLedger) GetBlock(height uint64) (*pb.Block, error)
- func (l *ChainLedger) GetBlockByHash(hash types.Hash) (*pb.Block, error)
- func (l *ChainLedger) GetBlockSign(height uint64) ([]byte, error)
- func (l *ChainLedger) GetChainMeta() *pb.ChainMeta
- func (l *ChainLedger) GetCode(addr types.Address) []byte
- func (l *ChainLedger) GetNonce(addr types.Address) uint64
- func (l *ChainLedger) GetOrCreateAccount(addr types.Address) *Account
- func (l *ChainLedger) GetReceipt(hash types.Hash) (*pb.Receipt, error)
- func (l *ChainLedger) GetState(addr types.Address, key []byte) (bool, []byte)
- func (l *ChainLedger) GetTransaction(hash types.Hash) (*pb.Transaction, error)
- func (l *ChainLedger) GetTransactionMeta(hash types.Hash) (*pb.TransactionMeta, error)
- func (l *ChainLedger) PersistExecutionResult(block *pb.Block, receipts []*pb.Receipt) error
- func (l *ChainLedger) PutBlock(height uint64, block *pb.Block) error
- func (l *ChainLedger) QueryByPrefix(addr types.Address, prefix string) (bool, [][]byte)
- func (l *ChainLedger) Rollback(height uint64) error
- func (l *ChainLedger) SetBalance(addr types.Address, value uint64)
- func (l *ChainLedger) SetCode(addr types.Address, code []byte)
- func (l *ChainLedger) SetNonce(addr types.Address, nonce uint64)
- func (l *ChainLedger) SetState(addr types.Address, key []byte, v []byte)
- func (l *ChainLedger) UpdateChainMeta(meta *pb.ChainMeta)
- func (l *ChainLedger) Version() uint64
- type Ledger
- type StateAccessor
Constants ¶
This section is empty.
Variables ¶
var (
ErrorRollbackTohigherNumber = fmt.Errorf("rollback to higher blockchain height")
)
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
Nonce uint64 `json:"nonce"`
Balance uint64 `json:"balance"`
Version int64 `json:"version"`
StateRoot types.Hash `json:"merkle_root"`
CodeHash []byte `json:"code_hash"`
// contains filtered or unexported fields
}
func (*Account) SetCodeAndHash ¶
SetCodeAndHash Set the contract code and hash
func (*Account) SetStateRoot ¶
SetStateRoot Set the state root hash
type BlockchainLedger ¶
type BlockchainLedger interface {
// PutBlock put block into store
PutBlock(height uint64, block *pb.Block) error
// GetBlock get block with height
GetBlock(height uint64) (*pb.Block, error)
// GetBlockSign get the signature of block
GetBlockSign(height uint64) ([]byte, error)
// GetBlockByHash get the block using block hash
GetBlockByHash(hash types.Hash) (*pb.Block, error)
// GetTransaction get the transaction using transaction hash
GetTransaction(hash types.Hash) (*pb.Transaction, error)
// GetTransactionMeta get the transaction meta data
GetTransactionMeta(hash types.Hash) (*pb.TransactionMeta, error)
// GetReceipt get the transaction receipt
GetReceipt(hash types.Hash) (*pb.Receipt, error)
// PersistExecutionResult persist the execution result
PersistExecutionResult(block *pb.Block, receipts []*pb.Receipt) error
// GetChainMeta get chain meta data
GetChainMeta() *pb.ChainMeta
// UpdateChainMeta update the chain meta data
UpdateChainMeta(*pb.ChainMeta)
}
BlockchainLedger handles block, transaction and receipt data.
type ChainLedger ¶
type ChainLedger struct {
// contains filtered or unexported fields
}
func New ¶
func New(repoRoot string, blockchainStore storage.Storage, logger logrus.FieldLogger) (*ChainLedger, error)
New create a new ledger instance
func (*ChainLedger) AddEvent ¶
func (l *ChainLedger) AddEvent(event *pb.Event)
AddEvent add ledger event
func (*ChainLedger) Clear ¶
func (l *ChainLedger) Clear()
func (*ChainLedger) Commit ¶
func (l *ChainLedger) Commit() (types.Hash, error)
Commit commit the state
func (*ChainLedger) Events ¶
func (l *ChainLedger) Events(txHash string) []*pb.Event
Events return ledger events
func (*ChainLedger) GetAccount ¶
func (l *ChainLedger) GetAccount(addr types.Address) *Account
GetAccount get account info using account address
func (*ChainLedger) GetBalance ¶
func (l *ChainLedger) GetBalance(addr types.Address) uint64
GetBalanec get account balance using account address
func (*ChainLedger) GetBlock ¶
func (l *ChainLedger) GetBlock(height uint64) (*pb.Block, error)
GetBlock get block with height
func (*ChainLedger) GetBlockByHash ¶
GetBlockByHash get the block using block hash
func (*ChainLedger) GetBlockSign ¶
func (l *ChainLedger) GetBlockSign(height uint64) ([]byte, error)
GetBlockSign get the signature of block
func (*ChainLedger) GetChainMeta ¶
func (l *ChainLedger) GetChainMeta() *pb.ChainMeta
GetChainMeta get chain meta data
func (*ChainLedger) GetCode ¶
func (l *ChainLedger) GetCode(addr types.Address) []byte
GetCode get contract code
func (*ChainLedger) GetNonce ¶
func (l *ChainLedger) GetNonce(addr types.Address) uint64
GetNonce get account nonce
func (*ChainLedger) GetOrCreateAccount ¶
func (l *ChainLedger) GetOrCreateAccount(addr types.Address) *Account
GetOrCreateAccount get the account, if not exist, create a new account
func (*ChainLedger) GetReceipt ¶
GetReceipt get the transaction receipt
func (*ChainLedger) GetTransaction ¶
func (l *ChainLedger) GetTransaction(hash types.Hash) (*pb.Transaction, error)
GetTransaction get the transaction using transaction hash
func (*ChainLedger) GetTransactionMeta ¶
func (l *ChainLedger) GetTransactionMeta(hash types.Hash) (*pb.TransactionMeta, error)
GetTransactionMeta get the transaction meta data
func (*ChainLedger) PersistExecutionResult ¶
PersistExecutionResult persist the execution result
func (*ChainLedger) PutBlock ¶
func (l *ChainLedger) PutBlock(height uint64, block *pb.Block) error
PutBlock put block into store
func (*ChainLedger) QueryByPrefix ¶
QueryByPrefix query value using key
func (*ChainLedger) Rollback ¶
func (l *ChainLedger) Rollback(height uint64) error
Rollback rollback to history version
func (*ChainLedger) SetBalance ¶
func (l *ChainLedger) SetBalance(addr types.Address, value uint64)
SetBalance set account balance
func (*ChainLedger) SetCode ¶
func (l *ChainLedger) SetCode(addr types.Address, code []byte)
SetCode set contract code
func (*ChainLedger) SetNonce ¶
func (l *ChainLedger) SetNonce(addr types.Address, nonce uint64)
SetNonce set account nonce
func (*ChainLedger) SetState ¶
func (l *ChainLedger) SetState(addr types.Address, key []byte, v []byte)
SetState set account state value using account address and key
func (*ChainLedger) UpdateChainMeta ¶
func (l *ChainLedger) UpdateChainMeta(meta *pb.ChainMeta)
UpdateChainMeta update the chain meta data
func (*ChainLedger) Version ¶
func (l *ChainLedger) Version() uint64
Version returns the current version
type Ledger ¶
type Ledger interface {
BlockchainLedger
StateAccessor
// AddEvent
AddEvent(*pb.Event)
// Events
Events(txHash string) []*pb.Event
// Rollback
Rollback(height uint64) error
// Close release resource
Close()
}
type StateAccessor ¶
type StateAccessor interface {
// GetOrCreateAccount
GetOrCreateAccount(types.Address) *Account
// GetAccount
GetAccount(types.Address) *Account
// GetBalance
GetBalance(types.Address) uint64
// SetBalance
SetBalance(types.Address, uint64)
// GetState
GetState(types.Address, []byte) (bool, []byte)
// SetState
SetState(types.Address, []byte, []byte)
// SetCode
SetCode(types.Address, []byte)
// GetCode
GetCode(types.Address) []byte
// SetNonce
SetNonce(types.Address, uint64)
// GetNonce
GetNonce(types.Address) uint64
// QueryByPrefix
QueryByPrefix(address types.Address, prefix string) (bool, [][]byte)
// Commit commits the state data
Commit() (types.Hash, error)
// Version
Version() uint64
// Clear
Clear()
}
StateAccessor manipulates the state data