client

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 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 ContractCall

type ContractCall struct {
	ContractType    string `json:"contractType"`
	ContractAddress string `json:"contractAddress"`
	MethodName      string `json:"methodName"`
	Params          struct {
		From  string `json:"_from"`
		To    string `json:"_to"`
		Value string `json:"_value"`
	} `json:"params"`
	ContractAlias    string `json:"contractAlias"`
	ContractDecimals int    `json:"contractDecimals"`
	ContractName     string `json:"contractName"`
	DecimalValue     string `json:"decimalValue"`
}

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 TransactionPayload `json:"transaction"`
	} `json:"event"`
}

EthTxPayload is payload returned from a subscription to blocknative api

type InternalTransaction

type InternalTransaction struct {
	Type         string       `json:"type"`
	From         string       `json:"from"`
	To           string       `json:"to"`
	Input        string       `json:"input"`
	Gas          int          `json:"gas"`
	GasUsed      int          `json:"gasUsed"`
	Value        string       `json:"value"`
	ContractCall ContractCall `json:"contractCall"`
}

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 NetBalanceChange

type NetBalanceChange struct {
	Address        string `json:"address"`
	BalanceChanges []struct {
		Delta string `json:"delta"`
		Asset struct {
			Type            string `json:"type"`
			Symbol          string `json:"symbol"`
			ContractAddress string `json:"contractAddress"`
		} `json:"asset"`
		Breakdown []struct {
			Counterparty string `json:"counterparty"`
			Amount       string `json:"amount"`
		} `json:"breakdown"`
	} `json:"balanceChanges"`
}

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 TransactionPayload

type TransactionPayload struct {
	Type                 uint64    `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        uint64    `json:"blocksPending"`
	Hash                 string    `json:"hash"`
	From                 string    `json:"from"`
	To                   string    `json:"to"`
	Value                string    `json:"value"`
	Gas                  float64   `json:"gas"`
	GasPrice             string    `json:"gasPrice"`
	GasPriceGwei         float64   `json:"gasPriceGwei"`
	Nonce                uint64    `json:"nonce"`
	BlockHash            string    `json:"blockHash"`
	BlockNumber          uint64    `json:"blockNumber"`
	TransactionIndex     uint64    `json:"transactionIndex"`
	Input                string    `json:"input"`
	GasUsed              float64   `json:"gasUsed"`
	Asset                string    `json:"asset"`
	WatchedAddress       string    `json:"watchedAddress"`
	Direction            string    `json:"direction"`
	Counterparty         string    `json:"counterparty"`
	// Internal Transactions Payload
	InternalTransactions []InternalTransaction `json:"internalTransactions"`
	NetBalanceChanges    []NetBalanceChange    `json:"netBalanceChanges"`
}

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