blockshot

package
v0.0.0-...-b6c1db7 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: Apache-2.0 Imports: 23 Imported by: 3

Documentation

Overview

Package blockshot provides functions for iterating over the Celo blockchain block-by-block to perform a list of extraction tasks over each block.

Index

Constants

This section is empty.

Variables

View Source
var (
	//DowntimeSlasher.sol
	DowntimeSlashPerformedHash = TopicHashHex("DowntimeSlashPerformed(address,uint256)")

	ValidatorGroupMarkedEligibleHash   = TopicHashHex("ValidatorGroupMarkedEligible(address)")
	ValidatorGroupMarkedIneligibleHash = TopicHashHex("ValidatorGroupMarkedIneligible(address)")

	ValidatorGroupVoteCastHash           = TopicHashHex("ValidatorGroupVoteCast(address,address,uint256)")
	ValidatorGroupPendingVoteRevokedHash = TopicHashHex("ValidatorGroupPendingVoteRevoked(address,address,uint256)")

	ValidatorGroupVoteActivatedHash     = TopicHashHex("ValidatorGroupVoteActivated(address,address,uint256,uint256)")
	ValidatorGroupActiveVoteRevokedHash = TopicHashHex("ValidatorGroupActiveVoteRevoked(address,address,uint256,uint256)")

	ProposalQueuedHash        = TopicHashHex("ProposalQueued(uint256,address,uint256,uint256,uint256)")
	ProposalUpvotedHash       = TopicHashHex("ProposalUpvoted(uint256,address,uint256)")
	ProposalUpvoteRevokedHash = TopicHashHex("ProposalUpvoteRevoked(uint256,address,uint256)")
	ProposalDequeuedHash      = TopicHashHex("ProposalDequeued(uint256,uint256)")
	ProposalApprovedHash      = TopicHashHex("ProposalApproved(uint256)")
	ProposalVotedHash         = TopicHashHex("ProposalVoted(uint256,address,uint256,uint256)")
	ProposalExecutedHash      = TopicHashHex("ProposalExecuted(uint256)")
	ProposalExpiredHash       = TopicHashHex("ProposalExpired(uint256)")

	//GovernanceSlasher.sol
	SlashingApprovedHash         = TopicHashHex("SlashingApproved(address,uint256)")
	GovernanceSlashPerformedHash = TopicHashHex("GovernanceSlashPerformed(address,uint256)")

	GoldLockedHash     = TopicHashHex("GoldLocked(address,uint256)")
	GoldUnlockedHash   = TopicHashHex("GoldUnlocked(address,uint256,uint256)")
	GoldRelockedHash   = TopicHashHex("GoldRelocked(address,uint256)")
	GoldWithdrawnHash  = TopicHashHex("GoldWithdrawn(address,uint256)")
	AccountSlashedHash = TopicHashHex("AccountSlashed(address,uint256,address,uint256)")

	TransferHash        = TopicHashHex("Transfer(address,address,uint256)")
	TransferCommentHash = TopicHashHex("TransferComment(string)")

	//Transfer and TransferComment - same signatures as StableToken.sol
	ApprovalHash = TopicHashHex("Approval(address,address,uint256)")
)

List of all relevant Topic Signatures in Keccak256 Hash Format

Functions

func BlockIterator

func BlockIterator(db *sql.DB, tasks []Task)

BlockIterator iterates over the blocks and performs the supplied extraction tasks

func CreateCommissionsSnapshotDataTable

func CreateCommissionsSnapshotDataTable(db *sql.DB)

func CreateEventLogsTable

func CreateEventLogsTable(db *sql.DB)

CreateLogsTable creates the block_iterator_event_logs table

func CreateRewardsSnapshotDataTable

func CreateRewardsSnapshotDataTable(db *sql.DB)

func CreateSnapshotBlocksTable

func CreateSnapshotBlocksTable(db *sql.DB)

func CreateSnapshotDataTable

func CreateSnapshotDataTable(db *sql.DB)

func CreateStatusTable

func CreateStatusTable(db *sql.DB)

CreateStatusTable creates the block_iterator_status table

func CreateSystemSnapshotDataTable

func CreateSystemSnapshotDataTable(db *sql.DB)

func CreateTagsTable

func CreateTagsTable(db *sql.DB)

func CreateTransactionsTable

func CreateTransactionsTable(db *sql.DB)

CreateTransactionsTable creates the block_iterator_transactions table

func CreateVotesSnapshotDataTable

func CreateVotesSnapshotDataTable(db *sql.DB)

func DBExec

func DBExec(statement string, db *sql.DB)

DBExec is a helper function that executes an SQL statement on a database connection

func DeleteTable

func DeleteTable(tableName string, db *sql.DB)

DeleteTable deletes a table from a database

func DumpEventLog

func DumpEventLog(db *sql.DB, blockNumber *big.Int, eLog *EventLog)

DumpEventLog inserts eventLog data into block_iterator_event_logs table

func DumpTagsRow

func DumpTagsRow(db *sql.DB, blockNumber *big.Int, txHash string, from string, to string, eLogs EventLogs, tags Tags)

func DumpTransaction

func DumpTransaction(db *sql.DB, blockNumber *big.Int, timestamp string, txHash string, transaction *Transaction)

DumpTransaction inserts transaction data into block_iterator_transactions table

func GenerateTransactionTags

func GenerateTransactionTags(db *sql.DB, blockNumber *big.Int) error

GenerateTransactionTags is a block iterator task to tag transactions and store these tags to the database. The data source for this task is the output of the ProcessTransactions task. Hence, in the list of tasks passed to the BlockIterator, this task should NOT appear in the list before the ProcessTransactions task.

func GetHashOfTransactions

func GetHashOfTransactions(db *sql.DB, blockNumber *big.Int) ([]string, error)

GetHashOfTransactions returns all tx hashes in the given block (number)

func InitClients

func InitClients()

InitClients initializes clients for RPC/IPC calls to the Celo blockchain

func LatestIteratedBlockNumber

func LatestIteratedBlockNumber(db *sql.DB) *big.Int

func ProcessEventLogs

func ProcessEventLogs(db *sql.DB, blockNumber *big.Int) error

ProcessEventLogs retrieves all event logs generated in the block corresponding to the specified block number and then stores them in the database

func ProcessTransactions

func ProcessTransactions(db *sql.DB, blockNumber *big.Int) error

ProcessTransactions is a task to retrieve all transactions of the given block number, extract relevant information for each transaction and store it in the database

func ResetDatabase

func ResetDatabase(db *sql.DB)

ResetDatabase deletes the block iterator tables if they exist and then creates fresh block iterator tables Table - block_iterator_status Table - block_iterator_transactions

func SetIterationStatusComplete

func SetIterationStatusComplete(db *sql.DB, blockNumber *big.Int)

SetIterationStatusComplete adds blocknumber to database and sets its value to be true

func TakeDailySnapshots

func TakeDailySnapshots(db *sql.DB, blockNumber *big.Int) error

TakeDailySnapshots evaluates if the block number is first block of UTC day and then takes a snapshot if that is indeed the case.

func TopicHashHex

func TopicHashHex(signature string) string

TopicHashHex returns Keccak256Hash of the topic signature in string format

Types

type EventLog

type EventLog struct {
	BlockLogIndex uint
	TxHash        common.Hash
	TxLogIndex    uint
	// This will be vLog.Topics[0].Hex()
	Topic   string
	Details *types.Log
}

EventLog contains relevant (to Icarus) details of a Celo event log

func EventLogFrom

func EventLogFrom(vLog *types.Log) *EventLog

EventLogFrom generates an EventLog object given a *types.Log object

type EventLogs

type EventLogs []*types.Log

EventLogs is an Icarus wrapper over types.Log to define Value() and Scan()

func (*EventLogs) Scan

func (eLogs *EventLogs) Scan(value interface{}) error

Scan decodes a JSON-encoded value to Tags

func (EventLogs) Value

func (eLogs EventLogs) Value() (driver.Value, error)

Value returns the JSON-encoded representation of EventLogs

type LogAccountSlashed

type LogAccountSlashed struct {
	Slashed  common.Address
	Penalty  *big.Int
	Reporter common.Address
	Reward   *big.Int
}

LogAccountSlashed - AccountSlashed(address indexed slashed, uint256 penalty, address indexed reporter, uint256 reward)

type LogApproval

type LogApproval struct {
	Owner   common.Address
	Spender common.Address
	Value   *big.Int
}

LogApproval - to capture details from an event log of form Approval

type LogGoldLocked

type LogGoldLocked struct {
	Account common.Address
	Value   *big.Int
}

LogGoldLocked - GoldLocked(address indexed account, uint256 value)

type LogGoldRelocked

type LogGoldRelocked struct {
	Account common.Address
	Value   *big.Int
}

LogGoldRelocked - GoldRelocked(address indexed account, uint256 value)

type LogGoldUnlocked

type LogGoldUnlocked struct {
	Account   common.Address
	Value     *big.Int
	Available *big.Int
}

LogGoldUnlocked - GoldUnlocked(address indexed account, uint256 value, uint256 available)

type LogGoldWithdrawn

type LogGoldWithdrawn struct {
	Account common.Address
	Value   *big.Int
}

LogGoldWithdrawn - GoldWithdrawn(address indexed account, uint256 value)

type LogGovernanceSlashPerformed

type LogGovernanceSlashPerformed struct {
	Account common.Address
	Amount  *big.Int
}

LogGovernanceSlashPerformed - GovernanceSlashPerformed(address indexed account, uint256 amount)

type LogProposalDequeued

type LogProposalDequeued struct {
	ProposalId *big.Int
	Timestamp  *big.Int
}

LogProposalDequeued - ProposalDequeued(uint256 indexed proposalId, uint256 timestamp)

type LogProposalQueued

type LogProposalQueued struct {
	ProposalId       *big.Int
	Proposer         common.Address
	TransactionCount *big.Int
	Deposit          *big.Int
	Timestamp        *big.Int
}

LogProposalQueued- ProposalQueued(uint256 indexed proposalId, address indexed proposer, uint256 transactionCount, uint256 deposit, uint256 timestamp)

type LogProposalUpvoteRevoked

type LogProposalUpvoteRevoked struct {
	ProposalId     *big.Int
	Account        common.Address
	RevokedUpvotes *big.Int
}

LogProposalUpvoteRevoked - ProposalUpvoteRevoked(uint256 indexed proposalId, address indexed account, uint256 revokedUpvotes)

type LogProposalUpvoted

type LogProposalUpvoted struct {
	ProposalId *big.Int
	Account    common.Address
	Upvotes    *big.Int
}

LogProposalUpvoted - ProposalUpvoted(uint256 indexed proposalId, address indexed account, uint256 upvotes)

type LogProposalVoted

type LogProposalVoted struct {
	ProposalId *big.Int
	Account    common.Address
	Value      *big.Int
	Weight     *big.Int
}

LogProposalVoted - ProposalVoted(uint256 indexed proposalId, address indexed account, uint256 value, uint256 weight)

type LogSlashingApproved

type LogSlashingApproved struct {
	Account common.Address
	Amount  *big.Int
}

LogSlashingApproved - SlashingApproved(address indexed account, uint256 amount)

type LogTransfer

type LogTransfer struct {
	From  common.Address
	To    common.Address
	Value *big.Int
}

LogTransfer - to capture details from an event log of form Transfer

type LogTransferComment

type LogTransferComment struct {
	Comment string
}

LogTransferComment - to capture details from an event log of form TransferComment

type LogValidatorGroupActiveVoteRevoked

type LogValidatorGroupActiveVoteRevoked struct {
	Account common.Address
	Group   common.Address
	Value   *big.Int
	Units   *big.Int
}

LogValidatorGroupActiveVoteRevoked - ValidatorGroupActiveVoteRevoked(address indexed account, address indexed group, uint256 value, uint256 units)

type LogValidatorGroupPendingVoteRevoked

type LogValidatorGroupPendingVoteRevoked struct {
	Account common.Address
	Group   common.Address
	Value   *big.Int
}

LogValidatorGroupPendingVoteRevoked - ValidatorGroupPendingVoteRevoked(address indexed account, address indexed group, uint256 value)

type LogValidatorGroupVoteActivated

type LogValidatorGroupVoteActivated struct {
	Account common.Address
	Group   common.Address
	Value   *big.Int
	Units   *big.Int
}

LogValidatorGroupVoteActivated - ValidatorGroupVoteActivated(address indexed account, address indexed group, uint256 value, uint256 units)

type LogValidatorGroupVoteCast

type LogValidatorGroupVoteCast struct {
	Account common.Address
	Group   common.Address
	Value   *big.Int
}

LogValidatorGroupVoteCast - ValidatorGroupVoteCast(address indexed account, address indexed group, uint256 value)

type Tag

type Tag struct {
	Name string `json:"eventname"`

	Source     string            `json:"source"`
	Parameters map[string]string `json:"parameters"`
	// contains filtered or unexported fields
}

Tag represents an Icarus tag on a Celo transaction

func NewTag

func NewTag(name string, prettyName string, source string) *Tag

NewTag is a constructor for Tag

func ProcessTags

func ProcessTags(logs []*types.Log) []*Tag

ProcessTags generates tags for a transaction from the logs provided

func (*Tag) Scan

func (tag *Tag) Scan(value interface{}) error

Scan decodes a JSON-encoded value into a Tag struct

func (Tag) Value

func (tag Tag) Value() (driver.Value, error)

Value returns the JSON-encoded representation of the Tag struct.

type Tags

type Tags []*Tag

Tags is a type representation for a slice of Tag pointers

func (*Tags) Scan

func (tags *Tags) Scan(value interface{}) error

Scan decodes a JSON-encoded value to Tags

func (Tags) Value

func (tags Tags) Value() (driver.Value, error)

Value returns the JSON-encoded representation of Tags

type Task

type Task = func(*sql.DB, *big.Int) error

Task is a type alias for extraction tasks

type Transaction

type Transaction struct {
	Nonce               uint64          `json:"nonce"`
	GasLimit            uint64          `json:"gasLimit"`
	GasPrice            *big.Int        `json:"gasPrice"`
	GasUsed             uint64          `json:"gasUsed"`
	FeeCurrency         *common.Address `json:"feeCurrency"`
	GatewayFeeRecipient *common.Address `json:"gatewayFeeRecipient"`
	GatewayFee          *big.Int        `json:"gatewayFee"`
	To                  *common.Address `json:"to"`
	Val                 *big.Int        `json:"value"`

	Raw *types.Transaction `json:"raw"`
}

Transaction struct contains relevant (to Icarus) details of a Celo transaction

func TransactionFrom

func TransactionFrom(tx *types.Transaction, gasReceipt *blockchain.GasReceipt) *Transaction

TransactionFrom creates a Transaction object given a *types.Transaction object and gas details

func (*Transaction) Scan

func (tx *Transaction) Scan(value interface{}) error

Scan decodes a JSON-encoded value into a Transaction struct

func (Transaction) Value

func (tx Transaction) Value() (driver.Value, error)

Value returns the JSON-encoded representation of the Transaction struct.

type TransactionDetailed

type TransactionDetailed struct {
	BlockNumber string      `json:"blockNumber"`
	Timestamp   string      `json:"timestamp"`
	TxHash      string      `json:"hash"`
	Details     Transaction `json:"details"`
	From        string      `json:"from"`
	To          string      `json:"to"`
	ELogs       EventLogs   `json:"logs"`
	Tags        Tags        `json:"tags"`
}

TransactionDetailed wraps relevant details of a transaction including its event logs + tags generated by Icarus for the transaction

func FetchTransactionByTxHash

func FetchTransactionByTxHash(db *sql.DB, txHash string) (*TransactionDetailed, error)

FetchTransactionByTxHash returns all transactions involving the given address upto the given blockheight (with tagging metadata)

func FetchTransactions

func FetchTransactions(db *sql.DB, address string, uptoBlockNumber *big.Int, limit int, offset int, sourceContract string) ([]*TransactionDetailed, error)

FetchTransactions returns all transactions involving the given address upto the given blockheight (with tagging metadata)

Jump to

Keyboard shortcuts

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