events

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 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"
	MethodTokenTransfers = "SubscribeToTokenTransfers"
)

Methods

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

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"
	KindMigration       = "migration"
)

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   stdJSON.RawMessage `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,omitempty"`
	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
	MessageTypeSubscribed
)

message types

type Migration added in v0.2.7

type Migration struct {
	Type          string    `json:"type"`
	ID            uint64    `json:"id"`
	Level         uint64    `json:"level"`
	Timestamp     time.Time `json:"timestamp"`
	Block         string    `json:"block"`
	Kind          string    `json:"kind"`
	Account       Alias     `json:"account"`
	BalanceChange int64     `json:"balanceChange"`
}

Migration -

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"`
	Nonce     *uint64            `json:"nonce,omitempty"`
	Status    string             `json:"status"`
	Errors    stdJSON.RawMessage `json:"errors,omitempty"`
	Quote     *QuoteShort        `json:"quote,omitempty"`
}

Reveal -

type Token added in v0.2.6

type Token struct {
	ID       uint64             `json:"id"`
	Contract Alias              `json:"contract"`
	TokenID  string             `json:"tokenId"`
	Standard string             `json:"standard"`
	Metadata stdJSON.RawMessage `json:"metadata,omitempty"`
}

Token -

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"`
	Nonce         *uint64         `json:"nonce,omitempty"`
}

Transaction -

type Transfer added in v0.2.6

type Transfer struct {
	ID            uint64    `json:"id"`
	Level         uint64    `json:"level"`
	Timestamp     time.Time `json:"timestamp"`
	Token         Token     `json:"token"`
	From          *Alias    `json:"from,omitempty"`
	To            *Alias    `json:"to,omitempty"`
	Amount        string    `json:"amount"`
	TransactionID *uint64   `json:"transactionId,omitempty"`
	OriginationID *uint64   `json:"originationId,omitempty"`
	MigrationID   *uint64   `json:"migrationId,omitempty"`
}

Transfer -

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