events

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 10 Imported by: 3

README

TzKT events wrapper

Golang library for TzKT events API

Usage

Full docs for TzKT API can be found here.

TzKT client

First of all, import library

import events "github.com/dipdup-net/go-lib/tzkt/events"

Then create TzKT client, connect to server and subscribe to channels.

tzkt := events.NewTzKT(data.BaseEventsURL)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if err := tzkt.Connect(ctx); err != nil {
	log.Panic(err)
}
defer tzkt.Close()

if err := tzkt.SubscribeToBlocks(); err != nil {
    log.Panic(err)
}

Now, you can listen message channel

for msg := range tzkt.Listen() {
    log.Println(msg)
}

Message is struct with fields:

type Message struct {
	Channel string       // is channel name: head, block or operations
	Type    MessageType  // is message type: 0, 1 or 2 (state, data, reorg)
	State   uint64       // is current level
	Body    interface{}  // is map or array of data depending of channel
}
SignalR

If you want to write custom client or re-use SignalR in another package you can import only signalr and use it.

import "github.com/dipdup-net/go-lib/tzkt/events/signalr"

client := signalr.NewSignalR("https://api.tzkt.io/v1/ws")

Documentation

Index

Constants

View Source
const (
	MethodHead           = "SubscribeToHead"
	MethodBlocks         = "SubscribeToBlocks"
	MethodOperations     = "SubscribeToOperations"
	MethodBigMap         = "SubscribeToBigMaps"
	MethodAccounts       = "SubscribeToAccounts"
	MethodTokenTransfers = "SubscribeToTokenTransfers"
	MethodTokenBalances  = "SubscribeToTokenBalances"
	MethodCycles         = "SubscribeToCycles"
)

Methods

View Source
const (
	ChannelHead          = "head"
	ChannelBlocks        = "blocks"
	ChannelOperations    = "operations"
	ChannelBigMap        = "bigmaps"
	ChannelAccounts      = "accounts"
	ChannelTransfers     = "transfers"
	ChannelCycles        = "cycles"
	ChannelTokenBalances = "token_balances"
)

Channels

View Source
const (
	BigMapTagMetadata      = "metadata"
	BigMapTagTokenMetadata = "token_metadata"
)

Big map tags

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Channel string
	Type    MessageType `json:"type"`
	State   uint64      `json:"state"`
	Body    interface{} `json:"data"`
}

Message - message struct

func (Message) String

func (msg Message) String() string

String -

type MessageType

type MessageType int

MessageType - TzKT message type

const (
	MessageTypeState MessageType = iota
	MessageTypeData
	MessageTypeReorg
	MessageTypeSubscribed
)

message types

type Packet added in v0.1.27

type Packet struct {
	Type  MessageType        `json:"type"`
	State uint64             `json:"state"`
	Data  stdJSON.RawMessage `json:"data,omitempty"`
}

Packet -

type TzKT

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

TzKT - struct that used for connection to TzKT events server

func NewTzKT

func NewTzKT(url string) *TzKT

NewTzKT - constructor of `TzKT`. `url` is TzKT events base URL. If it's empty https://api.tzkt.io/v1/ws is set.

func (*TzKT) Close

func (tzkt *TzKT) Close() error

Close - closing all connections

func (*TzKT) Connect

func (tzkt *TzKT) Connect(ctx context.Context) error

Connect - connect to events SignalR server

func (*TzKT) IsConnected added in v0.1.37

func (tzkt *TzKT) IsConnected() bool

IsConnected - reports whether the connection to TzKT events is established

func (*TzKT) Listen

func (tzkt *TzKT) Listen() <-chan Message

Listen - listen channel with all received messages

func (*TzKT) SetLogger added in v0.2.19

func (tzkt *TzKT) SetLogger(logger zerolog.Logger)

SetLogger -

func (*TzKT) SubscribeToAccounts added in v0.1.17

func (tzkt *TzKT) SubscribeToAccounts(addresses ...string) error

SubscribeToAccounts - subscribe to accounts channel. Sends touched accounts (affected by any operation in any way)..

func (*TzKT) SubscribeToBigMaps

func (tzkt *TzKT) SubscribeToBigMaps(ptr *int64, contract, path string, tags ...string) error

SubscribeToBigMaps - subscribe to bigmaps channel. Sends bigmap updates.

func (*TzKT) SubscribeToBlocks

func (tzkt *TzKT) SubscribeToBlocks() error

SubscribeToBlocks - subscribe to blocks channel. Sends blocks added to the blockchain.

func (*TzKT) SubscribeToCycles added in v0.2.26

func (tzkt *TzKT) SubscribeToCycles(delayBlocks uint64) error

SubscribeToCycles - notifies of the start of a new cycle with a specified delay. delayBlocks is the number of blocks (2 by default) to delay a new cycle notification. It should be >= 2 (to not worry abour reorgs) and < cycle size

func (*TzKT) SubscribeToHead

func (tzkt *TzKT) SubscribeToHead() error

SubscribeToHead - subscribe to head channel. Sends the blockchain head every time it has been updated.

func (*TzKT) SubscribeToOperations

func (tzkt *TzKT) SubscribeToOperations(address string, types ...string) error

SubscribeToOperations - subscribe to operations channel. Sends operations of specified types or related to specified accounts, included into the blockchain. Filters by `address` and list of `types` is appliable.

func (*TzKT) SubscribeToTokenBalances added in v0.2.26

func (tzkt *TzKT) SubscribeToTokenBalances(account, contract, tokenID string) error

SubscribeToTokenBalances - sends token balances when they are updated.

func (*TzKT) SubscribeToTokenTransfers added in v0.2.6

func (tzkt *TzKT) SubscribeToTokenTransfers(account, contract, tokenID string) error

SubscribeToTokenTransfers - subscribe to transfers channel. Sends token transfers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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