client

package
v0.0.0-...-187fd6c Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 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)

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

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

EventSub creates an event subscription.

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

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

ReadJSON is a wrapper around Conn:ReadJSON

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

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