client

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NetName

func NetName(id int64) (string, error)

NetName converts chain ID to network name (string)

func NewSubscription

func NewSubscription(key string) *subscription

NewSubscription creates a carrier for tracking events

func ParseGas

func ParseGas(msg *EthTxPayload) (gasBaseFeeGwei, gasTipGwei float64, err error)

Types

type Account

type Account struct {
	Address string `json:"address"`
}

Account bundles a single account address

type AddressSubscribe

type AddressSubscribe struct {
	BaseMessage
	Account `json:"account"`
}

AddressSubscribe is used to subscribe/unsubscribe to address events

func NewAddressSubscribe

func NewAddressSubscribe(msg BaseMessage, address string) AddressSubscribe

NewAddressSubscribe constructs a address subscription message

func NewAddressUnsubscribe

func NewAddressUnsubscribe(msg BaseMessage, address string) AddressSubscribe

NewAddressUnsubscribe constructs a address unsubscribe message

type BaseMessage

type BaseMessage struct {
	CategoryCode string    `json:"categoryCode"`
	EventCode    string    `json:"eventCode"`
	Timestamp    time.Time `json:"timeStamp"`
	DappID       string    `json:"dappId"` // api key
	Version      string    `json:"version"`
	Blockchain   `json:"blockchain"`
}

BaseMessage is the base message required for all interactions with the websockets api

func NewBaseMessage

func NewBaseMessage(apiKey string, netID int64) (BaseMessage, error)

NewBaseMessage returns a base message for the supplied network ID

func NewBaseMessageMainnet

func NewBaseMessageMainnet(apiKey string) BaseMessage

NewBaseMessageMainnet returns a base message suitable for mainnet usage

type Blockchain

type Blockchain struct {
	System  string `json:"system"`
	Network string `json:"network"`
}

Blockchain is a type fulfilling the blockchain params

type Client

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

Client wraps gorilla websocket connections

func New

func New(ctx context.Context, opts Opts) (*Client, error)

New returns a new blocknative websocket client

func (*Client) APIKey

func (c *Client) APIKey() string

APIKey returns the api key being used by the client

func (*Client) Close

func (c *Client) Close() error

Close is used to terminate our websocket client

func (*Client) Initialize

func (c *Client) Initialize(msg BaseMessage) error

Initialize is used to handle blocknative websockets api initialization note we set CategoryCode and EventCode ourselves.

func (*Client) KillSubscription

func (c *Client) KillSubscription(key string)

KillSubscription unsubscribes from the subscription in the registry at the index supplied. Killing the subscription releases the resource for the Client as well notifying block native servers to not monitor for events tracked by the subscription

func (*Client) NewAddressSubscription

func (c *Client) NewAddressSubscription(address string) error

NewAddressSubscription creates a new subscription to blocknative for monitoring address activity. the subscription is added to the client's subscription registry which contains an event channel for watched events provided by blocknative servers

func (*Client) NewEventSubscription

func (c *Client) NewEventSubscription(msg Configuration) error

NewEventSubscription creates an event subscription.

func (*Client) NewTransactionSubscription

func (c *Client) NewTransactionSubscription(txHash string) error

NewTransactionSubscription creates a new subscription for monitoring a transaction by supplied transaction ID

func (*Client) ReadJSON

func (c *Client) ReadJSON(out interface{}) error

ReadJSON is a wrapper around Conn:ReadJSON

func (*Client) SubscriptionRegistry

func (c *Client) SubscriptionRegistry() map[string]Subscription

SubscriptionRegistry returns the chached subscription map

func (*Client) WriteJSON

func (c *Client) WriteJSON(out interface{}) error

WriteJSON is a wrapper around Conn:WriteJSON

type Config

type Config struct {
	//  valid Ethereum address or 'global'
	Scope string `json:"scope"`
	// A slice of valid filters (jsql: https://github.com/deitch/searchjs)
	Filters []map[string]string `json:"filters,omitempty"`
	// JSON abis
	ABI interface{} `json:"abi,omitempty"`
	// defines whether the service should automatically watch the address as defined in
	WatchAddress bool `json:"watchAddress,omitempty"`
}

Config provides a specific config instance

func NewConfig

func NewConfig(scope string, watchAddress bool, abis interface{}) Config

NewConfig returns a new config instance

type Configuration

type Configuration struct {
	BaseMessage
	Config `json:"config"`
}

Configuration enables configuration of the blocknative websockets api and wraps the Config type

func NewConfiguration

func NewConfiguration(msg BaseMessage, config Config) Configuration

NewConfiguration constructs a new configuration message

func NewEventUnsubscribe

func NewEventUnsubscribe(msg BaseMessage, config Config) Configuration

NewEventUnsubscribe constructs an Event unsubscribe message

type ConnectResponse

type ConnectResponse struct {
	ConnectionID  string `json:"connectionId"`
	ServerVersion string `json:"serverVersion"`
	ShowUX        bool   `json:"showUX"`
	Status        string `json:"status"`
	Reason        string `json:"reason"`
	Version       int    `json:"version"`
}

ConnectResponse is the message we receive when opening a connection to the API

type EthTxPayload

type EthTxPayload struct {
	Version       int       `json:"version"`
	ServerVersion string    `json:"serverVersion"`
	TimeStamp     time.Time `json:"timeStamp"`
	ConnectionID  string    `json:"connectionId"`
	Status        string    `json:"status"`
	Event         struct {
		BaseMessage
		Transaction struct {
			Type                 int       `json:"type"`
			MaxFeePerGas         string    `json:"maxFeePerGas"`
			MaxPriorityFeePerGas string    `json:"maxPriorityFeePerGas"`
			BaseFeePerGas        string    `json:"baseFeePerGas"`
			TimeStamp            time.Time `json:"timeStamp"`
			Status               string    `json:"status"`
			MonitorID            string    `json:"monitorId"`
			MonitorVersion       string    `json:"monitorVersion"`
			TimePending          string    `json:"timePending"`
			PendingTimeStamp     time.Time `json:"pendingTimeStamp"`
			BlocksPending        int       `json:"blocksPending"`
			Hash                 string    `json:"hash"`
			From                 string    `json:"from"`
			To                   string    `json:"to"`
			Value                string    `json:"value"`
			Gas                  int       `json:"gas"`
			GasPrice             string    `json:"gasPrice"`
			GasPriceGwei         int       `json:"gasPriceGwei"`
			Nonce                int       `json:"nonce"`
			BlockHash            string    `json:"blockHash"`
			BlockNumber          int       `json:"blockNumber"`
			TransactionIndex     int       `json:"transactionIndex"`
			Input                string    `json:"input"`
			GasUsed              string    `json:"gasUsed"`
			Asset                string    `json:"asset"`
			WatchedAddress       string    `json:"watchedAddress"`
			Direction            string    `json:"direction"`
			Counterparty         string    `json:"counterparty"`
		} `json:"transaction"`
	} `json:"event"`
}

EthTxPayload is payload returned from a subscription to blocknative api

type MsgHistory

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

MsgHistory is used to store a copy of all messages we send such that in the event of connection drops we can re-establish our state

func (*MsgHistory) Len

func (mg *MsgHistory) Len() int

Len returns the length of the msg history buffewr

func (*MsgHistory) Pop

func (mg *MsgHistory) Pop() interface{}

Pop is used to pop a message out of the buffer

func (*MsgHistory) PopAll

func (mg *MsgHistory) PopAll() []interface{}

PopAll returns all elements from the buffer, resetting the buffer

func (*MsgHistory) Push

func (mg *MsgHistory) Push(msg interface{})

Push is used to push a message onto our buffer

type Opts

type Opts struct {
	Scheme               string
	Host                 string
	Path                 string
	APIKey               string
	PrintConnectResponse bool
}

Opts provides configuration over the websocket connection

type Subscription

type Subscription interface {
	Events() chan interface{}
	Unsubscribe()
	Err() chan error
}

Subscription represents a stream of events. Implementations carry a channel with which to store events returned by the subscription backend

type Transaction

type Transaction struct {
	Hash string `json:"hash"`
}

Transaction bundles a single tx

type TxSubscribe

type TxSubscribe struct {
	BaseMessage
	Transaction `json:"transaction"`
}

TxSubscribe is used to subscribe/unsubscribe to transaction id events

func NewTxSubscribe

func NewTxSubscribe(msg BaseMessage, txHash string) TxSubscribe

NewTxSubscribe constructs a Transaction subscription message

func NewTxUnsubscribe

func NewTxUnsubscribe(msg BaseMessage, txHash string) TxSubscribe

NewTxUnsubscribe constructs a Transaciton unsubscribe message

Jump to

Keyboard shortcuts

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