chain

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MinimumProtocolVersion = "1.5.0"

Variables

View Source
var ErrFutureBlock = errors.New("Block is in the future")
View Source
var ErrNotImplemented = fmt.Errorf("Not implemented")

Functions

func CheckProtocolVersion added in v0.4.0

func CheckProtocolVersion(version string) bool

func GetInternalTransactionTarget added in v0.3.3

func GetInternalTransactionTarget(trace TraceEntry) string

func GetTransactionType added in v0.2.1

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

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
	Transactions []string `json:"transactions"`
	TotalReward  string   `json:"totalReward"`
}

func (*Block) GetModel added in v1.5.4

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

func (*Block) UnmarshalJSON added in v1.5.4

func (b *Block) UnmarshalJSON(data []byte) error

type BlockData added in v1.5.4

type BlockData struct {
	Pbft         *Block
	Dags         []DagBlock
	Transactions []Transaction
	Traces       []TransactionTrace
	Votes        VotesResponse
	Validators   []Validator
}

func GetBlockData added in v1.5.4

func GetBlockData(c Client, period uint64) (bd *BlockData, err error)

func GetBlockDataFromPbft added in v1.5.4

func GetBlockDataFromPbft(c Client, pbft *Block) (bd *BlockData, err error)

func MakeEmptyBlockData added in v1.5.4

func MakeEmptyBlockData() *BlockData

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 []Validator, err error)
	GetVersion() (version string, 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)
	GetLogs(fromBlock, toBlock uint64, addresses []string, topics [][]string) (logs []EventLog, err error)
	// Close disconnects from the node
	Close()
}

type ClientMock added in v0.2.1

type ClientMock struct {
	Blocks            map[uint64]*Block
	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) AddPbftBlock added in v1.5.4

func (c *ClientMock) AddPbftBlock(period uint64, block *Block)

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) GetLogs added in v0.3.6

func (c *ClientMock) GetLogs(fromBlock, toBlock uint64, addresses []string, topics [][]string) (logs []EventLog, err 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(num uint64) (trxs []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 []Validator, err error)

func (*ClientMock) GetVersion added in v1.5.4

func (c *ClientMock) GetVersion() (version string, 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
	Sender       string   `json:"sender"`
	Transactions []string `json:"transactions"`
}

func (*DagBlock) GetModel added in v1.5.4

func (b *DagBlock) GetModel() (pbft *models.Dag)

func (*DagBlock) UnmarshalJSON added in v1.5.4

func (b *DagBlock) UnmarshalJSON(data []byte) error

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"`
	EligibilityBalanceThreshold string             `json:"eligibility_balance_threshold"`
	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"`
	BlockNumber      string   `json:"blockNumber"`
}

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"`
	Hardforks       common.HardforksConfig `json:"hardforks"`
}

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"`
	Address string `json:"address,omitempty"`
}

type Transaction added in v0.2.1

type Transaction struct {
	models.Transaction
	Logs             []EventLog     `json:"logs"`
	Nonce            models.Counter `json:"nonce"`
	GasPrice         models.Counter `json:"gasPrice"`
	GasUsed          models.Counter `json:"gasUsed"`
	TransactionIndex models.Counter `json:"transactionIndex"`
	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) GetModel added in v1.5.4

func (b *Transaction) GetModel() (trx *models.Transaction)

func (*Transaction) SetTimestamp added in v1.5.4

func (t *Transaction) SetTimestamp(timestamp uint64)

func (*Transaction) UnmarshalJSON added in v1.5.4

func (t *Transaction) UnmarshalJSON(data []byte) error

type TransactionTrace added in v0.2.1

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

type Validator added in v1.5.1

type Validator struct {
	Address    string   `json:"address"`
	TotalStake *big.Int `json:"stake"`
}

func (*Validator) UnmarshalJSON added in v1.5.1

func (v *Validator) UnmarshalJSON(data []byte) error

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) GetLogs added in v0.3.6

func (client *WsClient) GetLogs(fromBlock, toBlock uint64, addresses []string, topics [][]string) (logs []EventLog, err 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(period uint64) (validators []Validator, err error)

func (*WsClient) GetVersion added in v0.4.0

func (client *WsClient) GetVersion() (version string, 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