conchapp

package
v0.0.0-...-a826b38 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APPState

type APPState struct {
	HeadSt   *HeaderState
	AccoutSt *AccountState
	TxSt     *TxState
	TxRepSt  *TxRepState
	BlkSt    *BlockState
	DB       *sqlx.DB
}

APPState state set

func NewAPPState

func NewAPPState(db *sqlx.DB, log log.Logger) *APPState

NewAPPState return app state init db (if db is not exist create the database and tables)

func (*APPState) Commit

func (appSt *APPState) Commit() (string, error)

Commit commit an state return apphash, err

type Account

type Account struct {
	Address string
	Amount  *big.Int
}

Account ...

func NewAccount

func NewAccount(addr, amount string) *Account

NewAccount return account inst

type AccountState

type AccountState struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

AccountState means current account's info

func NewAccountState

func NewAccountState(db *sqlx.DB, log log.Logger) *AccountState

NewAccountState return AccountState inst

func (*AccountState) LoadAccount

func (as *AccountState) LoadAccount(address string) (*Account, error)

LoadAccount get account from cache or db

func (*AccountState) SyncToDisk

func (as *AccountState) SyncToDisk() error

SyncToDisk cache to disk

func (*AccountState) UpdateAccountCache

func (as *AccountState) UpdateAccountCache(acc *Account)

UpdateAccountCache update account in memory

type BlockState

type BlockState struct {
	APPHash   string
	TxRoot    string
	TxRepRoot string
	BlockHash string
	BlockNum  int64
	TimeStamp int64
	// contains filtered or unexported fields
}

BlockState current app block state

func NewBlockState

func NewBlockState(db *sqlx.DB, log log.Logger) *BlockState

NewBlockState block state instance

func (*BlockState) Hash

func (bs *BlockState) Hash() string

Hash return apphash

func (*BlockState) SyncToDisk

func (bs *BlockState) SyncToDisk() error

SyncToDisk to db

type ConchApplication

type ConchApplication struct {
	// validator set
	ValUpdates []types.Validator
	// contains filtered or unexported fields
}

ConchApplication is the Application's impl

func NewConchApplication

func NewConchApplication(dbDir string) *ConchApplication

NewConchApplication return new instance

func (*ConchApplication) BeginBlock

BeginBlock Track the block hash and header information

func (*ConchApplication) CheckTx

func (app *ConchApplication) CheckTx(tx []byte) types.ResponseCheckTx

CheckTx is called when one tx need be send in mempool

func (*ConchApplication) Commit

func (app *ConchApplication) Commit() types.ResponseCommit

Commit will panic if InitChain was not called

func (*ConchApplication) DeliverTx

func (app *ConchApplication) DeliverTx(tx []byte) types.ResponseDeliverTx

DeliverTx deleiver an transaction to app

func (*ConchApplication) EndBlock

EndBlock Update the validator set

func (*ConchApplication) Info

Info impl interface

func (*ConchApplication) InitChain

InitChain Save the validators in the merkle tree

func (*ConchApplication) Query

func (app *ConchApplication) Query(reqQuery types.RequestQuery) types.ResponseQuery

Query for query info

func (*ConchApplication) SetLogger

func (app *ConchApplication) SetLogger(l log.Logger)

SetLogger set logger

func (*ConchApplication) SetOption

SetOption set option

type HeaderState

type HeaderState struct {
	CurBlockNum  int64  `json:"cur_block_num"`
	CurBlockHash string `json:"cur_block_hash"`
	CurAPPHash   string `json:"cur_app_hash"`
	TimeStamp    int64  `json:"time_stamp"`
	Fee          *big.Int
	// contains filtered or unexported fields
}

HeaderState appheader state

func (*HeaderState) LoadHeaderState

func (hdSt *HeaderState) LoadHeaderState() error

LoadHeaderState from db load header

func (*HeaderState) SyncToDisk

func (hdSt *HeaderState) SyncToDisk() error

SyncToDisk to db

type QueryProcesser

type QueryProcesser struct {
	sync.Mutex
	// contains filtered or unexported fields
}

QueryProcesser 查询处理

func (*QueryProcesser) Init

func (q *QueryProcesser) Init()

Init ...

func (*QueryProcesser) Query

Query main entry

func (*QueryProcesser) RegistHandler

func (q *QueryProcesser) RegistHandler(name string, handler handerFunc)

RegistHandler ...

type Transaction

type Transaction struct {
	ID          string `json:"id"`
	Sender      string `json:"sender"`
	Receiver    string `json:"receiver"`
	Input       string `json:"input"`
	Sign        string `json:"sign"`
	Value       string `json:"value"`
	TimeStamp   int64  `json:"time"`
	RefBlockNum int64  `json:"ref_block"`
	Nonce       string `json:"nonce"`
	ExpiredNum  int    `json:"expired"`
	Cache       struct {
		// contains filtered or unexported fields
	} `json:"-"`
}

Transaction tx type

func BuildNewTx

func BuildNewTx(sender, receive, input, nonce, value string, time, refBlock, expired int64) *Transaction

BuildNewTx create a new tx

func DecodeNewTx

func DecodeNewTx(data []byte) (*Transaction, error)

DecodeNewTx decode a new tx

func (*Transaction) CheckArgs

func (tx *Transaction) CheckArgs() bool

CheckArgs tx's args is vaild

func (*Transaction) FeeCalc

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

FeeCalc calc tx fee

func (*Transaction) FormCode

func (tx *Transaction) FormCode() []byte

FormCode organize tx field content then marshal

func (*Transaction) Hash

func (tx *Transaction) Hash() []byte

Hash return tx's unique hash value

func (*Transaction) IsValidTx

func (tx *Transaction) IsValidTx() bool

IsValidTx check tx valid or not

func (*Transaction) Serialization

func (tx *Transaction) Serialization() string

Serialization json tx and base64

func (*Transaction) SignTx

func (tx *Transaction) SignTx(privKey crypto.PrivKey) (string, error)

SignTx sign tx

func (*Transaction) TxID

func (tx *Transaction) TxID() string

TxID return tx's unique hash value

type TransactionReceipt

type TransactionReceipt struct {
	Status   int
	Fee      *big.Int
	BlockNum int64
	TxHash   string
	Log      string
	// contains filtered or unexported fields
}

TransactionReceipt tx receipt

func (*TransactionReceipt) Hash

func (txRep *TransactionReceipt) Hash() []byte

Hash return hash

func (*TransactionReceipt) ID

func (txRep *TransactionReceipt) ID() string

ID return hash

type TransactionReceipts

type TransactionReceipts []*TransactionReceipt

TransactionReceipts trxreps

func (TransactionReceipts) AppendTxrp

AppendTxrp append an tx receipt

func (TransactionReceipts) HashRoot

func (txrp TransactionReceipts) HashRoot() string

HashRoot merkle root

func (TransactionReceipts) Len

func (txrp TransactionReceipts) Len() int

Len return length

type Transactions

type Transactions []*Transaction

Transactions list of Transaction

func (Transactions) AppendTx

func (txs Transactions) AppendTx(tx *Transaction) Transactions

AppendTx append an tx

func (Transactions) HashRoot

func (txs Transactions) HashRoot() string

HashRoot merkle root

func (Transactions) Len

func (txs Transactions) Len() int

Len return length

type TxRepState

type TxRepState struct {
	sync.RWMutex
	Txreps TransactionReceipts
	// contains filtered or unexported fields
}

TxRepState means current tx receipt's info

func NewTxRepState

func NewTxRepState(db *sqlx.DB, log log.Logger) *TxRepState

NewTxRepState tx receipt inst

func (*TxRepState) SyncToDisk

func (txrSt *TxRepState) SyncToDisk(height int64) (hashRoot string, err error)

SyncToDisk write tx to db

func (*TxRepState) UpdateTxRep

func (txrSt *TxRepState) UpdateTxRep(tr *TransactionReceipt)

UpdateTxRep append tx

type TxState

type TxState struct {
	sync.RWMutex
	Txs Transactions
	// contains filtered or unexported fields
}

TxState means current tx's info

func NewTxState

func NewTxState(db *sqlx.DB, log log.Logger) *TxState

NewTxState txstate inst

func (*TxState) QueryTxByID

func (txState *TxState) QueryTxByID(id string) Transaction

QueryTxByID query tx by id

func (*TxState) QueryTxsByAccount

func (txState *TxState) QueryTxsByAccount(account string, start, offset int64) Transactions

QueryTxsByAccount query account related tx

func (*TxState) SyncToDisk

func (txState *TxState) SyncToDisk(height int64) (hashRoot string, err error)

SyncToDisk write tx to db

func (*TxState) UpdateTx

func (txState *TxState) UpdateTx(tx *Transaction)

UpdateTx append tx

type VMActuator

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

VMActuator vitual machine to exec transaction then update related state

func NewVMActuator

func NewVMActuator(state *APPState) *VMActuator

NewVMActuator return VMActuator inst

func (*VMActuator) ExecuteTx

func (vm *VMActuator) ExecuteTx(tx *Transaction) error

ExecuteTx exec tx and update state

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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