events

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 5 Imported by: 3

README

TzKT events wrapper

Golang library for TzKT events API

Usage

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(events.BaseURL)
if err := tzkt.Connect(); 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/events")

Documentation

Index

Constants

View Source
const (
	MethodHead       = "SubscribeToHead"
	MethodBlocks     = "SubscribeToBlocks"
	MethodOperations = "SubscribeToOperations"
	MethodBigMap     = "SubscribeToBigMaps"
)

Methods

View Source
const (
	ChannelHead       = "head"
	ChannelBlocks     = "blocks"
	ChannelOperations = "operations"
	ChannelBigMap     = "bigmaps"
)

Channels

View Source
const (
	KindTransaction     = "transaction"
	KindOrigination     = "origination"
	KindDelegation      = "delegation"
	KindEndorsement     = "endorsement"
	KindBallot          = "ballot"
	KindProposal        = "proposal"
	KindActivation      = "activation"
	KindDoubleBaking    = "double_baking"
	KindDoubleEndorsing = "double_endorsing"
	KindNonceRevelation = "nonce_revelation"
	KindReveal          = "reveal"
)

operation kinds

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

Big map tags

View Source
const (
	BaseURL = "https://api.tzkt.io/v1/events"
)

Base URL

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Channel string
	Type    MessageType
	State   uint64
	Body    interface{}
}

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
)

message types

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/events is set.

func (*TzKT) Close

func (tzkt *TzKT) Close() error

Close - closing all connections

func (*TzKT) Connect

func (tzkt *TzKT) Connect() error

Connect - connect to events SignalR server

func (*TzKT) Listen

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

Listen - listen channel with all received messages

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) 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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