eosws

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 10 Imported by: 0

README

eosws Go bindings (from the dfuse API)

Websocket consumer for the https://dfuse.io API on EOS networks.

Connecting

    jwt, exp, err := eosws.Auth("server_1234567....")
    if err != nil {
        log.Fatalf("cannot get auth token: %s", err.Error())
    }
    time.AfterFunc(time.Until(exp), log.Println("JWT is now expired, renew it before reconnecting client")) // make sure that you handle updating your JWT

	client, err := eosws.New("wss://mainnet.zsw.dfuse.io/v1/stream", jwt, "https://origin.example.com")
    if err != nil {
        log.Fatalf("cannot connect to dfuse endpoint: %s", err.Error())
    }

Sending requests

	ga := &eosws.GetActionTraces{
		ga := &eosws.GetActionTraces{
			ReqID:      "myreq1",
			StartBlock: -5,
			Listen:     true,
		}
	}
	ga.Data.Accounts = "zswhq"
	ga.Data.ActionNames = "onblock"
	err = client.Send(ga)
	if err != nil {
		log.Fatalf("error sending request")
    }

Reading responses

	for {
		msg, err := client.Read()
		errorCheck("reading message", err)

		switch m := msg.(type) {
		case *eosws.ActionTrace:
			fmt.Println(m.Data.Trace)
		default:
			fmt.Println("Unsupported message", m)
			break
		}
	}

Examples

See examples folder

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IncomingMessageMap = map[string]reflect.Type{}
View Source
var IncomingStructMap = map[reflect.Type]string{}
View Source
var OutgoingMessageMap = map[string]reflect.Type{}
View Source
var OutgoingStructMap = map[reflect.Type]string{}

Functions

func Auth

func Auth(apiKey string) (token string, expiration time.Time, err error)

func AuthWithURL

func AuthWithURL(apiKey string, authServiceURL string) (token string, expiration time.Time, err error)

func NameToString

func NameToString(in uint64) string

func RegisterIncomingMessage

func RegisterIncomingMessage(typeName string, obj interface{})

func RegisterOutgoingMessage

func RegisterOutgoingMessage(typeName string, obj interface{})

func StringToName

func StringToName(s string) (val uint64, err error)

Types

type ActionTrace

type ActionTrace struct {
	CommonIn
	Data struct {
		BlockNum      uint32          `json:"block_num"`
		BlockID       string          `json:"block_id"`
		TransactionID string          `json:"trx_id"`
		ActionIndex   int             `json:"idx"`
		ActionDepth   int             `json:"depth"`
		Trace         json.RawMessage `json:"trace"`
		DBOps         json.RawMessage `json:"dbops,omitempty"`
		RAMOps        json.RawMessage `json:"ramops,omitempty"`
		DTrxOps       json.RawMessage `json:"dtrxops,omitempty"`
	} `json:"data"`
}

type Client

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

func New

func New(endpoint, token, origin string) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Read

func (c *Client) Read() (interface{}, error)

func (*Client) Send

func (c *Client) Send(msg OutgoingMessager) error

Send to the websocket, one of the messages registered through `RegisterOutboundMessage`.

type CommonIn

type CommonIn struct {
	Type  string `json:"type"`
	ReqID string `json:"req_id"`
}

type CommonOut

type CommonOut struct {
	Type             string `json:"type"`
	ReqID            string `json:"req_id,omitempty"`
	Fetch            bool   `json:"fetch,omitempty"`
	Listen           bool   `json:"listen,omitempty"`
	StartBlock       int64  `json:"start_block,omitempty"`
	IrreversibleOnly bool   `json:"irreversible_only"`
	WithProgress     int64  `json:"with_progress,omitempty"`
}

func (*CommonOut) SetReqID

func (c *CommonOut) SetReqID(v string)

func (*CommonOut) SetType

func (c *CommonOut) SetType(v string)

type Error

type Error struct {
	CommonIn

	Data struct {
		Code    string                 `json:"code"`
		Message string                 `json:"message"`
		Details map[string]interface{} `json:"details"`
	} `json:"data"`
}

type GetActionTraces

type GetActionTraces struct {
	CommonOut

	Data struct {
		Receivers        string `json:"receivers,omitempty"`
		Accounts         string `json:"accounts"`
		ActionNames      string `json:"action_names,omitempty"`
		Receiver         string `json:"receiver,omitempty"`
		Account          string `json:"account,omitempty"`
		ActionName       string `json:"action_name,omitempty"`
		WithDBOps        bool   `json:"with_dbops"`
		WithRAMOps       bool   `json:"with_ramops"`
		WithDTrxOps      bool   `json:"with_dtrxops"`
		WithInlineTraces bool   `json:"with_inline_traces"`
	} `json:"data"`
}

type GetTableRows

type GetTableRows struct {
	CommonOut

	Data struct {
		JSON    bool `json:"json,omitempty"`
		Verbose bool `json:"verbose,omitempty"`

		Code  string `json:"code"`
		Scope string `json:"scope"`
		Table string `json:"table"`
	} `json:"data"`
}

type Listening

type Listening struct {
	CommonOut
	Data struct {
		NextBlock uint32 `json:"next_block"`
	} `json:"data"`
}

type MsgIn

type MsgIn struct {
	CommonIn
	Data json.RawMessage `json:"data"`
}

type MsgOut

type MsgOut struct {
	CommonOut
	Data interface{}
}

type OutgoingMessager

type OutgoingMessager interface {
	SetType(v string)
	SetReqID(v string)
}

type Progress

type Progress struct {
	CommonIn
	Data struct {
		BlockNum uint32 `json:"block_num"`
		BlockID  string `json:"block_id"`
	} `json:"data"`
}

type TableDelta

type TableDelta struct {
	CommonIn

	Data struct {
		BlockNum uint32   `json:"block_num"`
		DBOp     *v1.DBOp `json:"dbop"`
		Step     string   `json:"step"`
	} `json:"data"`
}

type TableSnapshot

type TableSnapshot struct {
	CommonIn

	Data struct {
		BlockNum uint32            `json:"block_num"`
		Rows     []json.RawMessage `json:"rows"`
	} `json:"data"`
}

type TableSnapshotRow

type TableSnapshotRow struct {
	Key  string          `json:"key"`
	Data json.RawMessage `json:"data"`
}

type Unlisten

type Unlisten struct {
	CommonOut
	Data struct {
		ReqID string `json:"req_id"`
	} `json:"data"`
}

type Unlistened

type Unlistened struct {
	CommonIn
	Data struct {
		Success bool `json:"success"`
	} `json:"data"`
}

Directories

Path Synopsis
examples
mdl
v0
v1

Jump to

Keyboard shortcuts

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