thorscan

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 16 Imported by: 0

README

Thorscan

Thorscan provides:

  1. Python thorscan library and CLI for data wrangling of blocks, events, transactions, and messages.
  2. Golang package with a Scan function to easily scan blocks from a Golang channel.

Python

Installation

Simply run the following from this directory:

pip3 install .
Docker

You can alternatively leverage Docker for running this utility in a pre-built container:

alias thorscan="docker run -it --rm registry.gitlab.com/thorchain/thornode:thorscan"
Examples

You can use one liners in the CLI:

# all swap events
thorscan 'events(lambda b,tx,e: e, types={"swap"}), start=-1'

# gas used
thorscan 'transactions(lambda b,tx: (tx["hash"],tx["result"]["gas_used"])), start=-1'

# failed transactions
thorscan 'transactions(lambda b,tx: (tx["hash"],tx["result"]["code"]), failed=True), start=-1'

# slash and leave events
thorscan 'events(lambda b,tx,e: e, types={"slash", "validator_request_leave"}), start=-1'

# bond slash events
thorscan 'events(lambda b,tx,e: e if e["bond_type"] == "\u0003" else None, types={"bond"}), start=-1'

# observed outbounds
thorscan 'messages(lambda b,tx,m: tx, types={"MsgObservedTxOut"}), start=-1'

Alternatively import the library to create more complex listener functions:

# count outbound observations by chain
import collections, json, thorscan

counts = collections.defaultdict(lambda: 0)

def listen(height, tx, msg):
    global counts
    for tx in msg["txs"]:
        counts[tx["tx"]["chain"]] += 1

thorscan.scan(thorscan.messages(listen, types={"MsgObservedTxOut"}), start=-100, stop=-1)

print(json.dumps(counts, indent=2))

Golang

package main

import (
	"gitlab.com/thorchain/thornode/tools/thorscan"
)

func main() {
	for block := range thorscan.Scan(-200, -100) {
		println(block.Header.Height, "has", len(block.Txs), "txs")
	}
}

Advanced

Override the following default config values with the Golang or Python packages via the corresponding environment variables:

API_ENDPOINT = https://thornode-v1.ninerealms.com
RPC_ENDPOINT = https://rpc-v1.ninerealms.com
PARALLELISM  = 4

Documentation

Index

Constants

View Source
const (
	EnvAPIEndpoint = "API_ENDPOINT"
	EnvParallelism = "PARALLELISM"
)

Variables

View Source
var (
	Parallelism = 4
	APIEndpoint = "https://thornode-archive.ninerealms.com"
)

Functions

func Scan

func Scan(startHeight, stopHeight int) <-chan *BlockResponse

Types

type BlockResponse

type BlockResponse struct {
	openapi.BlockResponse
	Txs []BlockTx `json:"txs"`
}

BlockResponse wraps the openapi type with a custom Txs field for unmarshaling.

type BlockTx

type BlockTx struct {
	openapi.BlockTx
	Tx ctypes.Tx `json:"tx"`
}

BlockTx wraps the openapi type with a custom Tx field for unmarshaling.

func (*BlockTx) UnmarshalJSON

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

type Transport

type Transport struct {
	Transport http.RoundTripper
}

Transport sets the X-Client-ID header on all requests.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface.

Jump to

Keyboard shortcuts

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