common

package
v0.0.0-...-91eafdd Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlchemyConfig

type AlchemyConfig struct {
	Secret string `json:"secret"` // alchemy webhook signing key
}

type AlchemyEvent

type AlchemyEvent struct {
	Data           AlchemyEventData `bson:"data" json:"data"`
	SequenceNumber string           `bson:"sequenceNumber" json:"sequenceNumber"`
}

type AlchemyEventData

type AlchemyEventData struct {
	Block AlchemyWebhookBlock `bson:"block" json:"block"`
}

type AlchemyWebhook

type AlchemyWebhook struct {
	WebhookId string       `bson:"webhookId" json:"webhookId"`
	Id        string       `bson:"id" json:"id"`
	CreatedAt string       `bson:"createdAt" json:"createdAt"`
	Type      string       `bson:"type" json:"type"`
	Event     AlchemyEvent `bson:"event" json:"event"`
}

type AlchemyWebhookAccount

type AlchemyWebhookAccount struct {
	Address string `bson:"address" json:"address"`
}

type AlchemyWebhookBlock

type AlchemyWebhookBlock struct {
	Hash             string                      `bson:"hash" json:"hash"`
	Number           uint64                      `bson:"number" json:"number"`
	Timestamp        uint64                      `bson:"timestamp" json:"timestamp"`
	Parent           AlchemyWebhookParentBlock   `bson:"parent" json:"parent"`
	BaseFeePerGas    string                      `bson:"baseFeePerGas" json:"baseFeePerGas,omitempty"`
	GasUsed          uint64                      `bson:"gasUsed" json:"gasUsed"`
	GasLimit         uint64                      `bson:"gasLimit" json:"gasLimit"`
	MixHash          string                      `bson:"mixHash" json:"mixHash"`
	StateRoot        string                      `bson:"stateRoot" json:"stateRoot"`
	Difficulty       string                      `bson:"difficulty" json:"difficulty"`
	TotalDifficulty  string                      `bson:"totalDifficulty" json:"totalDifficulty"`
	Nonce            string                      `bson:"nonce" json:"nonce"`
	TransactionCount uint64                      `bson:"transactionCount" json:"transactionCount"`
	TransactionsRoot string                      `bson:"transactionsRoot" json:"transactionsRoot"`
	ReceiptsRoot     string                      `bson:"receiptsRoot" json:"receiptsRoot"`
	LogsBloom        string                      `bson:"logsBloom" json:"logsBloom"`
	Transactions     []AlchemyWebhookTransaction `bson:"transactions" json:"transactions"`
	Logs             []AlchemyWebhookBlockLogs   `bson:"logs" json:"logs"`
}

func (*AlchemyWebhookBlock) Convert

func (b *AlchemyWebhookBlock) Convert() Block

type AlchemyWebhookBlockLogs

type AlchemyWebhookBlockLogs struct {
	Data        string                    `bson:"data" json:"data"`
	Topics      []string                  `bson:"topics" json:"topics"`
	Index       uint64                    `bson:"index" json:"index"`
	Account     AlchemyWebhookAccount     `bson:"account" json:"account"`
	Transaction AlchemyWebhookTransaction `bson:"transaction" json:"transaction"`
}

func (*AlchemyWebhookBlockLogs) Convert

func (l *AlchemyWebhookBlockLogs) Convert() Log

type AlchemyWebhookParentBlock

type AlchemyWebhookParentBlock struct {
	Hash string `bson:"hash" json:"hash"`
}

type AlchemyWebhookTransaction

type AlchemyWebhookTransaction struct {
	Hash                 string                 `bson:"hash" json:"hash"`
	Nonce                uint64                 `bson:"nonce" json:"nonce"`
	Index                uint64                 `bson:"index" json:"index"`
	From                 AlchemyWebhookAccount  `bson:"from" json:"from"`
	To                   AlchemyWebhookAccount  `bson:"to" json:"to"`
	Value                string                 `bson:"value" json:"value"`
	GasPrice             string                 `bson:"gasPrice" json:"gasPrice"`
	MaxFeePerGas         string                 `bson:"maxFeePerGas" json:"maxFeePerGas"`
	MaxPriorityFeePerGas string                 `bson:"maxPriorityFeePerGas" json:"maxPriorityFeePerGas"`
	Gas                  uint64                 `bson:"gas" json:"gas"`
	Status               uint64                 `bson:"status" json:"status"`
	GasUsed              uint64                 `bson:"gasUsed" json:"gasUsed"`
	CumulativeGasUsed    uint64                 `bson:"cumulativeGasUsed" json:"cumulativeGasUsed"`
	EffectiveGasPrice    string                 `bson:"effectiveGasPrice" json:"effectiveGasPrice"`
	CreatedContract      *AlchemyWebhookAccount `bson:"createdContract" json:"createdContract"`
}

func (*AlchemyWebhookTransaction) Convert

type Block

type Block struct {
	Number           uint64        `bson:"number" json:"number"`
	Timestamp        uint64        `bson:"timestamp" json:"timestamp"`
	Hash             string        `bson:"hash" json:"hash"`
	ParentHash       string        `bson:"parentHash" json:"parentHash"`
	Transactions     []Transaction `bson:"transactions" json:"transactions,omitempty"`
	BaseFeePerGas    string        `bson:"baseFeePerGas" json:"baseFeePerGas,omitempty"`
	GasUsed          uint64        `bson:"gasUsed" json:"gasUsed,omitempty"`
	GasLimit         uint64        `bson:"gasLimit" json:"gasLimit,omitempty"`
	MixHash          string        `bson:"mixHash" json:"mixHash,omitempty"`
	StateRoot        string        `bson:"stateRoot" json:"stateRoot,omitempty"`
	TotalDifficulty  string        `bson:"totalDifficulty" json:"totalDifficulty,omitempty"`
	Sha3Uncles       string        `bson:"sha3Uncles" json:"sha3Uncles,omitempty"`
	Miner            string        `bson:"miner" json:"miner,omitempty"`
	Difficulty       string        `bson:"difficulty" json:"difficulty,omitempty"`
	Nonce            string        `bson:"nonce" json:"nonce,omitempty"`
	TransactionCount uint64        `bson:"transactionCount" json:"transactionCount,omitempty"`
	TransactionsRoot string        `bson:"transactionsRoot" json:"transactionsRoot,omitempty"`
	ReceiptsRoot     string        `bson:"receiptsRoot" json:"receiptsRoot,omitempty"`
	LogsBloom        string        `bson:"logsBloom" json:"logsBloom,omitempty"`
	ExtraData        string        `bson:"extraData" json:"extraData,omitempty"`
	Uncles           []string      `bson:"uncles" json:"uncles,omitempty"`
	Logs             []Log         `bson:"logs" json:"logs,omitempty"`
}

type Log

type Log struct {
	Address     string   `bson:"address" json:"address"`
	Topics      []string `bson:"topics" json:"topics"`
	Data        string   `bson:"data" json:"data"`
	Index       uint64   `bson:"index" json:"index"`
	Transaction Transaction
}

type LogRequest

type LogRequest struct {
	Address   []string `bson:"address" json:"address"`
	Topics    []string `bson:"topics" json:"topics"`
	BlockHash string   `bson:"blockHash" json:"blockHash"`
}

type RPCClient

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

func NewRPCClient

func NewRPCClient(cfg *RPCConfig) *RPCClient

func (*RPCClient) GetBlockByHash

func (r *RPCClient) GetBlockByHash(hash string) (RawBlock, error)

func (*RPCClient) GetBlockByHeight

func (r *RPCClient) GetBlockByHeight(height uint64) (RawBlock, error)

func (*RPCClient) GetLatestBlock

func (r *RPCClient) GetLatestBlock() (RawBlock, error)

func (*RPCClient) GetLogs

func (r *RPCClient) GetLogs(address []string, hash string, topics []string) ([]RawLog, error)

func (*RPCClient) GetTransactionReceipt

func (r *RPCClient) GetTransactionReceipt(hash string) (*RawTransactionReceipt, error)

func (*RPCClient) LatestBlockNumber

func (r *RPCClient) LatestBlockNumber() (uint64, error)

func (*RPCClient) Ping

func (r *RPCClient) Ping() (string, error)

type RPCConfig

type RPCConfig struct {
	Type     string `json:"type"`
	Endpoint string `json:"endpoint"`
}

type RawBlock

type RawBlock struct {
	Hash             string           `bson:"hash" json:"hash"`
	Number           string           `bson:"number" json:"number"`
	Timestamp        string           `bson:"timestamp" json:"timestamp"`
	Transactions     []RawTransaction `bson:"transactions" json:"transactions"`
	ParentHash       string           `bson:"parentHash" json:"parentHash"`
	Sha3Uncles       string           `bson:"sha3Uncles" json:"sha3Uncles"`
	Miner            string           `bson:"miner" json:"miner"`
	MixHash          string           `bson:"mixHash" json:"mixHash"`
	Difficulty       string           `bson:"difficulty" json:"difficulty"`
	TotalDifficulty  string           `bson:"totalDifficulty" json:"totalDifficulty"`
	Size             string           `bson:"size" json:"size"`
	GasUsed          string           `bson:"gasUsed" json:"gasUsed"`
	GasLimit         string           `bson:"gasLimit" json:"gasLimit"`
	Nonce            string           `bson:"nonce" json:"nonce"`
	Uncles           []string         `bson:"uncles" json:"uncles"`
	BaseFeePerGas    string           `bson:"baseFeePerGas" json:"baseFeePerGas,omitempty"`
	ExtraData        string           `bson:"extraData" json:"extraData"`
	LogsBloom        string           `bson:"logsBloom" json:"logsBloom"`
	ReceiptsRoot     string           `bson:"receiptsRoot" json:"receiptsRoot"`
	StateRoot        string           `bson:"stateRoot" json:"stateRoot"`
	TransactionsRoot string           `bson:"transactionsRoot" json:"transactionsRoot"`
}

func (*RawBlock) Convert

func (b *RawBlock) Convert(rpcClient *RPCClient, receipts *[]RawTransactionReceipt) (Block, error)

TODO(iquidus): refactor this, separate out txn receipts without introducing any additional looping

type RawLog

type RawLog struct {
	Address          string   `bson:"address" json:"address"`
	Topics           []string `bson:"topics" json:"topics"`
	Data             string   `bson:"data" json:"data"`
	BlockNumber      string   `bson:"blockNumber" json:"blockNumber"`
	TransactionIndex string   `bson:"transactionIndex" json:"transactionIndex"`
	TransactionHash  string   `bson:"transactionHash" json:"transactionHash"`
	BlockHash        string   `bson:"blockHash" json:"blockHash"`
	LogIndex         string   `bson:"logIndex" json:"logIndex"`
	Removed          bool     `bson:"removed" json:"removed"`
}

func (*RawLog) Convert

func (l *RawLog) Convert(txn Transaction) Log

type RawTransaction

type RawTransaction struct {
	BlockHash            string `json:"blockHash"`
	BlockNumber          string `json:"blockNumber"`
	From                 string `json:"from"`
	Gas                  string `json:"gas"`
	GasPrice             string `json:"gasPrice"`
	MaxFeePerGas         string `bson:"maxFeePerGas" json:"maxFeePerGas,omitempty"`
	MaxPriorityFeePerGas string `bson:"maxPriorityFeePerGas" json:"maxPriorityFeePerGas,omitempty"`
	Hash                 string `json:"hash"`
	Input                string `json:"input"`
	Nonce                string `json:"nonce"`
	To                   string `json:"to"`
	TransactionIndex     string `json:"transactionIndex"`
	Value                string `json:"value"`
	Type                 string `bson:"type" json:"type,omitempty"`
	ChainId              string `json:"chainId"`
	V                    string `json:"v"`
	R                    string `json:"r"`
	S                    string `json:"s"`
}

func (*RawTransaction) Convert

func (rt *RawTransaction) Convert(receipt RawTransactionReceipt) Transaction

type RawTransactionReceipt

type RawTransactionReceipt struct {
	BlockHash         string   `bson:"blockHash" json:"blockHash"`
	BlockNumber       string   `bson:"blockNumber" json:"blockNumber"`
	ContractAddress   string   `bson:"contractAddress" json:"contractAddress"`
	CumulativeGasUsed string   `bson:"cumulativeGasUsed" json:"cumulativeGasUsed"`
	From              string   `bson:"from" json:"from"`
	EffectiveGasPrice string   `bson:"effectiveGasPrice" json:"effectiveGasPrice"`
	GasUsed           string   `bson:"gasUsed" json:"gasUsed"`
	Logs              []RawLog `bson:"logs" json:"logs"`
	LogsBloom         string   `bson:"logsBloom" json:"logsBloom"`
	Status            string   `bson:"status" json:"status"`
	To                string   `bson:"to" json:"to"`
	TransactionHash   string   `bson:"transactionHash" json:"transactionHash"`
	TransactionIndex  string   `bson:"transactionIndex" json:"transactionIndex"`
	Type              string   `bson:"type" json:"type,omitempty"`
}

type Transaction

type Transaction struct {
	// from txn
	From                 string `bson:"from" json:"from"`
	Gas                  uint64 `bson:"gas" json:"gas"`
	GasPrice             uint64 `bson:"gasPrice" json:"gasPrice"`
	Hash                 string `bson:"hash" json:"hash"`
	Index                uint64 `bson:"index" json:"index"`
	MaxFeePerGas         uint64 `bson:"maxFeePerGas" json:"maxFeePerGas,omitempty"`
	MaxPriorityFeePerGas uint64 `bson:"maxPriorityFeePerGas" json:"maxPriorityFeePerGas,omitempty"`
	Nonce                uint64 `bson:"nonce" json:"nonce"`
	To                   string `bson:"to" json:"to"`
	Value                string `bson:"value" json:"value"`
	// from receipt
	Status            uint64 `json:"status"`
	GasUsed           uint64 `bson:"gasUsed" json:"gasUsed"`
	CumulativeGasUsed uint64 `bson:"cumulativeGasUsed" json:"cumulativeGasUsed,omitempty"`
	EffectiveGasPrice uint64 `bson:"effectiveGasPrice" json:"effectiveGasPrice,omitempty"`
	CreatedContract   string `bson:"createdContract" json:"createdContract,omitempty"`
}

Jump to

Keyboard shortcuts

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