events

package
v0.1.33 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 9 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"
	MethodAccounts   = "SubscribeToAccounts"
)

Methods

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

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 Account added in v0.1.27

type Account struct {
	Type              string    `json:"type"`
	Address           string    `json:"address"`
	Kind              string    `json:"kind"`
	Tzips             []string  `json:"tzips"`
	Alias             string    `json:"alias"`
	Balance           int64     `json:"balance"`
	Creator           Alias     `json:"creator"`
	NumContracts      int64     `json:"numContracts"`
	NumDelegations    int64     `json:"numDelegations"`
	NumOriginations   int64     `json:"numOriginations"`
	NumTransactions   int64     `json:"numTransactions"`
	NumReveals        int64     `json:"numReveals"`
	NumMigrations     int64     `json:"numMigrations"`
	FirstActivity     int64     `json:"firstActivity"`
	FirstActivityTime time.Time `json:"firstActivityTime"`
	LastActivity      int64     `json:"lastActivity"`
	LastActivityTime  time.Time `json:"lastActivityTime"`
	TypeHash          int64     `json:"typeHash"`
	CodeHash          int64     `json:"codeHash"`
}

Account -

type Alias added in v0.1.30

type Alias struct {
	Alias   string `json:"alias"`
	Address string `json:"address"`
}

Alias -

type BigMapUpdate added in v0.1.27

type BigMapUpdate struct {
	ID        uint64    `json:"id"`
	Level     uint64    `json:"level"`
	Timestamp time.Time `json:"timestamp"`
	Bigmap    int64     `json:"bigmap"`
	Contract  Alias     `json:"contract"`
	Path      string    `json:"path"`
	Action    string    `json:"action"`
	Content   *Content  `json:"content,omitempty"`
}

BigMapUpdate -

type Block added in v0.1.27

type Block struct {
	Cycle       uint64    `json:"cycle"`
	Level       uint64    `json:"level"`
	Hash        string    `json:"hash"`
	Timestamp   time.Time `json:"timestamp"`
	Proto       int64     `json:"proto"`
	Priority    int64     `json:"priority"`
	Validations int64     `json:"validations"`
	Deposit     int64     `json:"deposit"`
	Reward      int64     `json:"reward"`
	Fees        int64     `json:"fees"`
	LbEscapeEma int64     `json:"lbEscapeEma"`
	Baker       Alias     `json:"baker"`
	Software    struct {
		Version string    `json:"version"`
		Date    time.Time `json:"date"`
	} `json:"software"`
	NonceRevealed bool `json:"nonceRevealed"`
	LbEscapeVote  bool `json:"lbEscapeVote"`
}

Block -

type Content added in v0.1.27

type Content struct {
	Hash  string             `json:"hash"`
	Key   string             `json:"key"`
	Value stdJSON.RawMessage `json:"value"`
}

Content -

type Delegation added in v0.1.30

type Delegation struct {
	Operation

	ID           uint64             `json:"id"`
	Level        uint64             `json:"level"`
	Timestamp    time.Time          `json:"timestamp"`
	Block        string             `json:"block"`
	Hash         string             `json:"hash"`
	Counter      uint64             `json:"counter"`
	Initiator    *Account           `json:"initiator"`
	Sender       *Account           `json:"sender"`
	Nonce        uint64             `json:"nonce"`
	GasLimit     uint64             `json:"gasLimit"`
	GasUsed      uint64             `json:"gasUsed"`
	BakerFee     uint64             `json:"bakerFee"`
	Amount       uint64             `json:"amount"`
	PrevDelegate *Account           `json:"prevDelegate"`
	NewDelegate  *Account           `json:"newDelegate"`
	Status       string             `json:"status"`
	Errors       stdJSON.RawMessage `json:"errors,omitempty"`
	Quote        *QuoteShort        `json:"quote,omitempty"`
}

Delegation -

type Head struct {
	Chain        string          `json:"chain"`
	ChainID      string          `json:"chainId"`
	Cycle        int64           `json:"cycle"`
	Level        uint64          `json:"level"`
	Hash         string          `json:"hash"`
	Protocol     string          `json:"protocol"`
	Timestamp    time.Time       `json:"timestamp"`
	VotingEpoch  int64           `json:"votingEpoch"`
	VotingPeriod int64           `json:"votingPeriod"`
	KnownLevel   uint64          `json:"knownLevel"`
	LastSync     time.Time       `json:"lastSync"`
	Synced       bool            `json:"synced"`
	QuoteLevel   uint64          `json:"quoteLevel"`
	QuoteBtc     decimal.Decimal `json:"quoteBtc"`
	QuoteEur     decimal.Decimal `json:"quoteEur"`
	QuoteUsd     decimal.Decimal `json:"quoteUsd"`
	QuoteCny     decimal.Decimal `json:"quoteCny"`
	QuoteJpy     decimal.Decimal `json:"quoteJpy"`
	QuoteKrw     decimal.Decimal `json:"quoteKrw"`
	QuoteEth     decimal.Decimal `json:"quoteEth"`
}

Head -

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
)

message types

type Operation added in v0.1.27

type Operation struct {
	Type string `json:"type"`
}

Operation -

type OriginatedContract added in v0.1.30

type OriginatedContract struct {
	Kind     string `json:"kind"`
	Alias    string `json:"alias,omitempty"`
	Address  string `json:"address,omitempty"`
	TypeHash int64  `json:"typeHash"`
	CodeHash int64  `json:"codeHash"`
}

OriginatedContract -

type Origination added in v0.1.30

type Origination struct {
	Operation

	ID                 uint64              `json:"id"`
	Level              uint64              `json:"level"`
	Timestamp          time.Time           `json:"timestamp"`
	Block              string              `json:"block"`
	Hash               string              `json:"hash"`
	Counter            uint64              `json:"counter"`
	Initiator          *Alias              `json:"initiator"`
	Sender             *Alias              `json:"sender"`
	Nonce              *uint64             `json:"nonce"`
	GasLimit           uint64              `json:"gasLimit"`
	GasUsed            uint64              `json:"gasUsed"`
	StorageLimit       uint64              `json:"storageLimit"`
	StorageUsed        uint64              `json:"storageUsed"`
	BakerFee           uint64              `json:"bakerFee"`
	StorageFee         uint64              `json:"storageFee"`
	AllocationFee      uint64              `json:"allocationFee"`
	ContractBalance    uint64              `json:"contractBalance"`
	ContractManager    *Alias              `json:"contractManager"`
	ContractDelegate   *Alias              `json:"contractDelegate"`
	Code               stdJSON.RawMessage  `json:"code"`
	Storage            stdJSON.RawMessage  `json:"storage"`
	Diffs              stdJSON.RawMessage  `json:"diffs"`
	Status             string              `json:"status"`
	Errors             stdJSON.RawMessage  `json:"errors,omitempty"`
	OriginatedContract *OriginatedContract `json:"originatedContract,omitempty"`
	Quote              *QuoteShort         `json:"quote,omitempty"`
}

Origination -

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 Parameter added in v0.1.27

type Parameter struct {
	Entrypoint string             `json:"entrypoint"`
	Value      stdJSON.RawMessage `json:"value"`
}

Parameter -

type QuoteShort added in v0.1.30

type QuoteShort struct {
	BTC decimal.Decimal `json:"btc,omitempty"`
	EUR decimal.Decimal `json:"eur,omitempty"`
	USD decimal.Decimal `json:"usd,omitempty"`
	CNY decimal.Decimal `json:"cny,omitempty"`
	JPY decimal.Decimal `json:"jpy,omitempty"`
	KRW decimal.Decimal `json:"krw,omitempty"`
	ETH decimal.Decimal `json:"eth,omitempty"`
}

QuoteShort -

type Reveal added in v0.1.30

type Reveal struct {
	Operation

	ID        uint64             `json:"id"`
	Level     uint64             `json:"level"`
	Timestamp time.Time          `json:"timestamp"`
	Block     string             `json:"block"`
	Hash      string             `json:"hash"`
	Sender    *Alias             `json:"sender"`
	Counter   uint64             `json:"counter"`
	GasLimit  uint64             `json:"gasLimit"`
	GasUsed   uint64             `json:"gasUsed"`
	BakerFee  uint64             `json:"bakerFee"`
	Status    string             `json:"status"`
	Errors    stdJSON.RawMessage `json:"errors,omitempty"`
	Quote     *QuoteShort        `json:"quote,omitempty"`
}

Reveal -

type Transaction added in v0.1.27

type Transaction struct {
	Operation

	Sender        Alias           `json:"sender"`
	Target        Alias           `json:"target"`
	Initiator     Alias           `json:"initiator"`
	Amount        decimal.Decimal `json:"amount"`
	Parameter     *Parameter      `json:"parameter"`
	Timestamp     time.Time       `json:"timestamp"`
	ID            uint64          `json:"id"`
	Level         uint64          `json:"level"`
	Counter       uint64          `json:"counter"`
	GasLimit      uint64          `json:"gasLimit"`
	GasUsed       uint64          `json:"gasUsed"`
	StorageLimit  uint64          `json:"storageLimit"`
	StorageUsed   uint64          `json:"storageUsed"`
	BakerFee      uint64          `json:"bakerFee"`
	StorageFee    uint64          `json:"storageFee"`
	AllocationFee uint64          `json:"allocationFee"`
	Status        string          `json:"status"`
	Parameters    string          `json:"parameters"`
	Block         string          `json:"block"`
	Hash          string          `json:"hash"`
	HasInternals  bool            `json:"hasInternals"`
}

Transaction -

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) SubscribeToAccounts added in v0.1.17

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

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