chain

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = fmt.Errorf("Not implemented")

Functions

func GetTransactionType added in v0.2.1

func GetTransactionType(to, input string, internal bool) models.TransactionType

func ParseInt

func ParseInt(s string) (v int64)

func ParseUInt added in v0.2.1

func ParseUInt(s string) (v uint64)

Types

type Action added in v0.2.1

type Action struct {
	CallType string `json:"callType"`
	From     string `json:"from"`
	Gas      string `json:"gas"`
	Input    string `json:"input"`
	To       string `json:"to"`
	Value    string `json:"value"`
}

type Block

type Block struct {
	models.Pbft
	Number       string   `json:"number"`
	Timestamp    string   `json:"timestamp"`
	Transactions []string `json:"transactions"`
	TotalReward  string   `json:"totalReward"`
}

func (*Block) ToModel

func (b *Block) ToModel() (pbft *models.Pbft)

type Client added in v0.2.1

type Client interface {
	GetBlockByNumber(number uint64) (blk Block, err error)
	GetLatestPeriod() (uint64, error)
	TraceBlockTransactions(number uint64) (traces []TransactionTrace, err error)
	GetTransactionByHash(hash string) (trx Transaction, err error)
	GetPeriodTransactions(period uint64) (trxs []Transaction, err error)
	GetPbftBlockWithDagBlocks(period uint64) (pbftWithDags PbftBlockWithDags, err error)
	GetDagBlockByHash(hash string) (dag DagBlock, err error)
	GetPeriodDagBlocks(period uint64) (dags []DagBlock, err error)
	GetPreviousBlockCertVotes(period uint64) (vr VotesResponse, err error)
	GetValidatorsAtBlock(block_num uint64) (validators []dpos_interface.DposInterfaceValidatorData, err error)
	GetGenesis() (genesis GenesisObject, err error)
	GetChainStats() (ns storage.FinalizationData, err error)
	SubscribeNewHeads() (chan Block, *rpc.ClientSubscription, error)
	GetBalanceAtBlock(address string, blockNumber uint64) (balance string, err error)
	// Close disconnects from the node
	Close()
}

type ClientMock added in v0.2.1

type ClientMock struct {
	Traces            map[string][]TransactionTrace
	Transactions      map[string]Transaction
	BlockTransactions map[uint64][]string
	EventLogs         map[string][]EventLog
}

func MakeMockClient added in v0.2.1

func MakeMockClient() *ClientMock

func (*ClientMock) AddLogsFromJson added in v0.2.1

func (c *ClientMock) AddLogsFromJson(trx_json string)

func (*ClientMock) AddTracesFromJson added in v0.2.1

func (c *ClientMock) AddTracesFromJson(hash, traces_json string)

func (*ClientMock) AddTransactionFromJson added in v0.2.1

func (c *ClientMock) AddTransactionFromJson(trx_json string)

func (*ClientMock) Close added in v0.2.1

func (c *ClientMock) Close()

func (*ClientMock) GetBalanceAtBlock added in v0.2.1

func (c *ClientMock) GetBalanceAtBlock(address string, blockNumber uint64) (balance string, err error)

func (*ClientMock) GetBlockByNumber added in v0.2.1

func (c *ClientMock) GetBlockByNumber(number uint64) (blk Block, err error)

func (*ClientMock) GetChainStats added in v0.2.1

func (c *ClientMock) GetChainStats() (ns storage.FinalizationData, err error)

func (*ClientMock) GetDagBlockByHash added in v0.2.1

func (c *ClientMock) GetDagBlockByHash(hash string) (dag DagBlock, err error)

func (*ClientMock) GetGenesis added in v0.2.1

func (c *ClientMock) GetGenesis() (genesis GenesisObject, err error)

func (*ClientMock) GetLatestPeriod added in v0.2.1

func (c *ClientMock) GetLatestPeriod() (p uint64, e error)

func (*ClientMock) GetPbftBlockWithDagBlocks added in v0.2.1

func (c *ClientMock) GetPbftBlockWithDagBlocks(period uint64) (pbftWithDags PbftBlockWithDags, err error)

func (*ClientMock) GetPeriodDagBlocks added in v0.2.1

func (c *ClientMock) GetPeriodDagBlocks(period uint64) (dags []DagBlock, err error)

func (*ClientMock) GetPeriodTransactions added in v0.2.1

func (c *ClientMock) GetPeriodTransactions(p uint64) (trx []Transaction, err error)

func (*ClientMock) GetPreviousBlockCertVotes added in v0.2.1

func (c *ClientMock) GetPreviousBlockCertVotes(period uint64) (vr VotesResponse, err error)

func (*ClientMock) GetTransactionByHash added in v0.2.1

func (c *ClientMock) GetTransactionByHash(hash string) (trx Transaction, err error)

func (*ClientMock) GetValidatorsAtBlock added in v0.2.1

func (c *ClientMock) GetValidatorsAtBlock(uint64) (validators []dpos_interface.DposInterfaceValidatorData, err error)

func (*ClientMock) SubscribeNewHeads added in v0.2.1

func (c *ClientMock) SubscribeNewHeads() (chan Block, *rpc.ClientSubscription, error)

func (*ClientMock) TraceBlockTransactions added in v0.2.1

func (c *ClientMock) TraceBlockTransactions(num uint64) (traces []TransactionTrace, err error)

type DagBlock added in v0.2.1

type DagBlock struct {
	models.Dag
	Level        string   `json:"level"`
	Timestamp    string   `json:"timestamp"`
	Transactions []string `json:"transactions"`
}

func (*DagBlock) ToModel added in v0.2.1

func (b *DagBlock) ToModel() (dag *models.Dag)

type DposConfig added in v0.2.1

type DposConfig struct {
	BlocksPerYear        string             `json:"blocks_per_year"`
	DagProposersReward   string             `json:"dag_proposers_reward"`
	MaxBlockAuthorReward string             `json:"max_block_author_reward"`
	YieldPercentage      string             `json:"yield_percentage"`
	InitialValidators    []initialValidator `json:"initial_validators"`
}

type EventLog added in v0.2.1

type EventLog struct {
	Address          string   `json:"address"`
	Data             string   `json:"data"`
	LogIndex         string   `json:"logIndex"`
	Removed          bool     `json:"removed"`
	Topics           []string `json:"topics"`
	TransactionHash  string   `json:"transactionHash"`
	TransactionIndex string   `json:"transactionIndex"`
}

type GenesisObject

type GenesisObject struct {
	DagGenesisBlock DagBlock          `json:"dag_genesis_block"`
	InitialBalances map[string]string `json:"initial_balances"`
	Pbft            PbftConfig        `json:"pbft"`
	Dpos            DposConfig        `json:"dpos"`
}

func (*GenesisObject) ToChainConfig added in v0.2.1

func (g *GenesisObject) ToChainConfig() (c *common.ChainConfig)

type PbftBlockWithDags added in v0.2.1

type PbftBlockWithDags struct {
	BlockHash string `json:"block_hash"`
	Period    uint64 `json:"period"`
	Schedule  struct {
		DagBlocksOrder []string `json:"dag_blocks_order"`
	} `json:"schedule"`
}

type PbftConfig added in v0.2.1

type PbftConfig struct {
	CommitteeSize string `json:"committee_size"`
	LambdaMs      string `json:"lambda_ms"`
}

type TraceEntry added in v0.2.1

type TraceEntry struct {
	Action       Action           `json:"action"`
	Subtraces    uint16           `json:"subtraces"`
	TraceAddress []uint16         `json:"traceAddress"`
	Type         string           `json:"type"`
	Result       TraceEntryResult `json:"result"`
}

type TraceEntryResult added in v0.2.1

type TraceEntryResult struct {
	Output  string `json:"output"`
	GasUsed string `json:"gasUsed"`
}

type Transaction added in v0.2.1

type Transaction struct {
	models.Transaction
	Logs             []EventLog `json:"logs"`
	BlockNumber      string     `json:"blockNumber"`
	Nonce            string     `json:"nonce"`
	GasPrice         string     `json:"gasPrice"`
	GasUsed          string     `json:"gasUsed"`
	Status           string     `json:"status"`
	TransactionIndex string     `json:"transactionIndex"`
	Input            string     `json:"input"`
	ContractAddress  string     `json:"contractAddress"`
}

func (*Transaction) ExtractLogs added in v0.2.1

func (t *Transaction) ExtractLogs() (logs []models.EventLog)

func (*Transaction) GetFee added in v0.2.1

func (t *Transaction) GetFee() *big.Int

func (*Transaction) ToModelWithTimestamp added in v0.2.1

func (t *Transaction) ToModelWithTimestamp(timestamp uint64) (trx models.Transaction)

type TransactionTrace added in v0.2.1

type TransactionTrace struct {
	Trace []TraceEntry `json:"trace"`
}

type Vote added in v0.2.1

type Vote struct {
	Voter  string `json:"voter"`
	Weight string `json:"weight"`
}

type VotesResponse added in v0.2.1

type VotesResponse struct {
	PeriodTotalVotesCount int64  `json:"total_votes_count,omitempty"`
	Votes                 []Vote `json:"votes,omitempty"`
}

type WsClient

type WsClient struct {
	ChainId *big.Int
	// contains filtered or unexported fields
}

WsClient is a struct that connects to a Taraxa node.

func NewWsClient

func NewWsClient(url string) (*WsClient, error)

NewWsClient creates a new instance of the WsClient struct.

func (*WsClient) Close

func (client *WsClient) Close()

Close disconnects from the node

func (*WsClient) GetBalanceAtBlock added in v0.2.1

func (client *WsClient) GetBalanceAtBlock(address string, blockNumber uint64) (balance string, err error)

func (*WsClient) GetBlockByNumber

func (client *WsClient) GetBlockByNumber(number uint64) (blk Block, err error)

func (*WsClient) GetChainId added in v0.2.1

func (client *WsClient) GetChainId() *big.Int

func (*WsClient) GetChainStats

func (client *WsClient) GetChainStats() (fd storage.FinalizationData, err error)

func (*WsClient) GetDagBlockByHash

func (client *WsClient) GetDagBlockByHash(hash string) (dag DagBlock, err error)

func (*WsClient) GetGenesis

func (client *WsClient) GetGenesis() (genesis GenesisObject, err error)

func (*WsClient) GetLatestPeriod

func (client *WsClient) GetLatestPeriod() (uint64, error)

func (*WsClient) GetPbftBlockWithDagBlocks

func (client *WsClient) GetPbftBlockWithDagBlocks(period uint64) (pbftWithDags PbftBlockWithDags, err error)

func (*WsClient) GetPeriodDagBlocks added in v0.2.1

func (client *WsClient) GetPeriodDagBlocks(period uint64) (dags []DagBlock, err error)

func (*WsClient) GetPeriodTransactions added in v0.2.1

func (client *WsClient) GetPeriodTransactions(number uint64) (trxs []Transaction, err error)

func (*WsClient) GetPreviousBlockCertVotes added in v0.2.1

func (client *WsClient) GetPreviousBlockCertVotes(period uint64) (vr VotesResponse, err error)

func (*WsClient) GetTransactionByHash

func (client *WsClient) GetTransactionByHash(hash string) (trx Transaction, err error)

TODO: Optimize this. We are making two requests here, so its pretty slow

func (*WsClient) GetValidatorsAtBlock added in v0.2.1

func (client *WsClient) GetValidatorsAtBlock(block_num uint64) (validators []dpos_interface.DposInterfaceValidatorData, err error)

func (*WsClient) SubscribeNewHeads

func (client *WsClient) SubscribeNewHeads() (chan Block, *rpc.ClientSubscription, error)

func (*WsClient) TraceBlockTransactions added in v0.2.1

func (client *WsClient) TraceBlockTransactions(number uint64) (traces []TransactionTrace, err error)

Jump to

Keyboard shortcuts

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