core

package module
v0.0.0-...-a948df4 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: GPL-3.0 Imports: 22 Imported by: 1

README

Environment variables needed:
  - DATABASE_URL
  - ETHEREUM_NODE
  - ETHERSCAN_APIKEY

TODO:
  - Given a contract address, build a history of proxy implementations
    and track logs for each.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Uint256, _    = abi.NewType("uint256", "", nil)
	Uint32, _     = abi.NewType("uint32", "", nil)
	Uint16, _     = abi.NewType("uint16", "", nil)
	String, _     = abi.NewType("string", "", nil)
	Bool, _       = abi.NewType("bool", "", nil)
	Bytes, _      = abi.NewType("bytes", "", nil)
	Bytes32, _    = abi.NewType("bytes32", "", nil)
	Address, _    = abi.NewType("address", "", nil)
	Uint64Arr, _  = abi.NewType("uint64[]", "", nil)
	AddressArr, _ = abi.NewType("address[]", "", nil)
	Int8, _       = abi.NewType("int8", "", nil)

	Approval = makeEvent("Approval",
		"owner", Address, indexed,
		"spender", Address, indexed,
		"value", Uint256, false)

	Transfer = makeEvent("Transfer",
		"from", Address, indexed,
		"to", Address, indexed,
		"amount", Uint256, false)
)
View Source
var (
	ErrInvalidContractAddress = errors.New("invalid contract address")
	ErrUnsetEnvironmentVar    = errors.New("environment variable not set")
	ErrNegativePage           = errors.New("page cannot be negative")
	ErrInvalidTopic           = errors.New("invalid topic")

	ErrInvalidResponse     = errors.New("invalid response")
	ErrInvalidResponseBody = errors.New("invalid response body")
)

Functions

func BackfillLogs

func BackfillLogs(ctx context.Context, db *gorm.DB, contract string) error

TODO: Query up to head-64 (?) to retrieve only finalized logs? And then check types.Log.Removed to confirm everything was OK!

func GetContractABI

func GetContractABI(address string) (abi.ABI, error)

func GetContractEvents

func GetContractEvents(address string) (map[string]abi.Event, error)

func GetContractEventsCached

func GetContractEventsCached(address string) (map[string]abi.Event, error)

(address string) (map[string]abi.Event, error) {

func GetTransactionBlock

func GetTransactionBlock(ctx context.Context, tx string) (uint64, error)

Given a transaction, return the block it's included in.

func Keccak256Hash

func Keccak256Hash(data ...[]byte) (common.Hash, error)

func Open

func Open() (*gorm.DB, error)

func Paginate

func Paginate(query *gorm.DB, page int, pageSize int) (*gorm.DB, error)

func QueryLogs

func QueryLogs(ctx context.Context, fromBlock uint64, contract string) (uint64, []types.Log, error)

QueryLogs returns (toBlock, logs, err), where `logs` is all logs in the range of [fromBlock, toBlock).

func SanitizeHex

func SanitizeHex(address string) string

func ValidateAddress

func ValidateAddress(address string) bool

func ValidateTopic

func ValidateTopic(topic string) bool

Types

type ContractCreation

type ContractCreation struct {
	ContractAddress string `json:"contractAddress"`
	ContractCreator string `json:"contractCreator"`
	TxHash          string `json:"txHash"`
}

func GetContractCreation

func GetContractCreation(contracts []string) ([]ContractCreation, error)

func GetContractCreation1

func GetContractCreation1(contract string) (ContractCreation, error)

type ContractSource

type ContractSource struct {
	SourceCode           string `json:"SourceCode"`
	ABI                  string `json:"ABI"`
	ContractName         string `json:"ContractName"`
	CompilerVersion      string `json:"CompilerVersion"`
	OptimizationUsed     string `json:"OptimizationUsed"`
	Runs                 string `json:"Runs"`
	ConstructorArguments string `json:"ConstructorArguments"`
	EVMVersion           string `json:"EVMVersion"`
	Library              string `json:"Library"`
	LicenseType          string `json:"LicenseType"`
	Proxy                string `json:"Proxy"`
	Implementation       string `json:"Implementation"`
	SwarmSource          string `json:"SwarmSource"`
}

func GetContractSource

func GetContractSource(address string) ([]ContractSource, error)

func (ContractSource) String

func (s ContractSource) String() string

type Events

type Events struct {
	Contract string `gorm:"uniqueContract:idx_addr;not null"`
	Events   string `gorm:"not null"`
}

func Serialize

func Serialize(address map[string]abi.Event) Events

type KeccakState

type KeccakState interface {
	hash.Hash
	Read(p []byte) (int, error)
}

type Log

type Log struct {
	ID          uint64 `gorm:"primaryKey"`
	Address     string `gorm:"uniqueIndex:idx_logs_abi;not null"`
	Topic0      string ``
	Topic1      string ``
	Topic2      string ``
	Topic3      string ``
	Data        string ``
	BlockNumber uint64 `gorm:"uniqueIndex:idx_logs_abi;not null"`
	TxHash      string `gorm:"uniqueIndex:idx_logs_hi;not null"`
	// Index of the transaction in the block.
	TxIndex uint `gorm:"not null"`
	// Index of the log in the block.
	Index uint `gorm:"uniqueIndex:idx_logs_abi;uniqueIndex:idx_logs_hi;not null"`
}

Unique constraings:

  • idx_logs_abi: (address,block_number,index)
  • idx_logs_hi: (tx_hash,index)

func FromGethLog

func FromGethLog(log types.Log) Log

func SelectLogs

func SelectLogs(db *gorm.DB, contract string, topic string, page, pageSize int) ([]Log, error)

func (Log) String

func (o Log) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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