tcabcireadgoclient

package module
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

TCABCI Read Node Go WebSocket Client

Go Report Card

TransferChain Fastest Read Network WebSocket Client
Read Node Address: https://read-node-01.transferchain.io
Read Node WebSocket Address: wss://read-node-01.transferchain.io/ws

Installation

$ go get github.com/TransferChain/tcabci-read-go-client 

Example

Subscribe, Listen and Unsubscribe Example

package main

import (
	"log"
	tcabcireadgoclient "github.com/TransferChain/tcabci-read-go-client"
)

func main() {
	readNodeClient, _ := tcabcireadgoclient.NewClient("https://read-node-01.transferchain.io", "wss://read-node-01.transferchain.io/ws")

	if err := readNodeClient.Start(); err != nil {
		log.Fatal(err)
    }
	
	addresses := []string{
		"<your-public-address-one>",
		"<your-public-address-two>",
	}

	if err := readNodeClient.Subscribe(addresses); err != nil {
		log.Fatal(err)
	}

	done := make(chan struct{})
	// If a transaction has been sent to your addresses, the callback you set here will be called.
	readNodeClient.SetListenCallback(func(transaction *tcabcireadgoclient.Transaction) {
		// 
		done <- struct{}{}
	})
	
	<-done
	close(done)

	_ = readNodeClient.Unsubscribe()
	readNodeClient.Stop()
}

Thanks

Websocket client code referenced here https://github.com/webdeveloppro/golang-websocket-client.

License

tcabci-read-go-client is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Documentation

Index

Constants

View Source
const (
	HandshakeTimeout = 5 * time.Second
)

Variables

View Source
var ErrAlreadyStarted = errors.New("already started")
View Source
var ErrNoConnected = errors.New("websocket: not connected")

ErrNoConnected ... Reference: https://github.com/recws-org/recws/blob/master/recws.go

View Source
var ErrNotStarted = errors.New("not started yet")

Functions

This section is empty.

Types

type Broadcast added in v1.2.0

type Broadcast struct {
	ID            string `json:"id"` //Hash of the transaction
	Version       uint32 `json:"version"`
	Type          Type   `json:"type"`
	SenderAddr    string `json:"sender_addr"`
	RecipientAddr string `json:"recipient_addr"`
	Data          []byte `json:"data"`
	Sign          []byte `json:"sign"`
	Fee           uint64 `json:"fee"`
}

func (*Broadcast) ToJSON added in v1.2.0

func (b *Broadcast) ToJSON() ([]byte, error)

func (*Broadcast) ToRequest added in v1.2.0

func (b *Broadcast) ToRequest() (*http.Request, error)

func (*Broadcast) URI added in v1.2.0

func (b *Broadcast) URI() string

type BroadcastResponse added in v1.2.0

type BroadcastResponse struct {
	Data struct {
		Hash      string `json:"hash"`
		Code      uint32 `json:"code"`
		Data      []byte `json:"data"`
		Log       string `json:"log"`
		Codespace string `json:"codespace"`
	} `json:"data"`
}

type Bytea

type Bytea struct {
	Bytes  []byte
	Status int
}

Bytea transaction byte data

type Client

type Client interface {
	Start() error
	Stop() error
	SetListenCallback(func(transaction *Transaction))
	Subscribe(addresses []string, txTypes ...Type) error
	Unsubscribe() error
	Write(b []byte) error
	LastBlock() (*LastBlock, error)
	TxSummary(summary *Summary) (lastBlockHeight uint64, lastTransaction *Transaction, totalCount uint64, err error)
	TxSearch(search *Search) (txs []*Transaction, totalCount uint64, err error)
	Broadcast(id string, version uint32, typ Type, data []byte, senderAddress, recipientAddress string, sign []byte, fee uint64) (*BroadcastResponse, error)
}

Client TCABCI Read Node Websocket Client

func NewClient

func NewClient(address string, wsAddress string) (Client, error)

NewClient make ws client

func NewClientContext added in v1.2.10

func NewClientContext(ctx context.Context, address string, wsAddress string) (Client, error)

NewClientContext make ws client with context

type HeightOperator added in v1.2.0

type HeightOperator string
const (
	Equal          HeightOperator = "="
	Less           HeightOperator = "<"
	Greater        HeightOperator = ">"
	EqualOrLess    HeightOperator = "<="
	EqualOrGreater HeightOperator = ">="
)

func (HeightOperator) IsValid added in v1.2.0

func (ho HeightOperator) IsValid() bool

type LastBlock added in v1.2.0

type LastBlock struct {
	Blocks     []*Transaction `json:"data"`
	TotalCount uint64         `json:"total_count"`
}

type Message

type Message struct {
	IsWeb   bool        `json:"is_web"`
	Type    MessageType `json:"type"`
	Addrs   []string    `json:"addrs"`
	TXTypes []Type      `json:"tx_types"`
}

Message ..

type MessageType

type MessageType string

MessageType ..

const (
	// Subscribe message
	Subscribe MessageType = "subscribe"
	// Unsubscribe message
	Unsubscribe MessageType = "unsubscribe"
)

type OrderBy added in v1.2.0

type OrderBy string
const (
	ASC  OrderBy = "ASC"
	DESC OrderBy = "DESC"
)

func (OrderBy) IsValid added in v1.2.0

func (t OrderBy) IsValid() bool

type Received added in v1.1.6

type Received struct {
	MessageType    int
	ReadingMessage []byte
	Err            error
}

Received message

type Response added in v1.2.7

type Response struct {
	Data       interface{}       `json:"data"`
	TotalCount uint64            `json:"total_count"`
	Error      bool              `json:"error"`
	Errors     map[string]string `json:"errors"`
	Detail     string            `json:"detail"`
}
type Search struct {
	Limit              uint           `json:"limit"`
	Height             uint64         `json:"-"`
	Offset             uint64         `json:"offset"`
	MaxHeight          uint64         `json:"max_height"`
	LastOrder          uint64         `json:"last_order"`
	Type               Type           `json:"typ,omitempty"`
	PHeight            string         `json:"height,omitempty"`
	OrderBy            OrderBy        `json:"order_by,omitempty"`
	OrderField         string         `json:"order_field,omitempty"`
	HeightOperator     HeightOperator `json:"-"`
	RecipientAddresses []string       `json:"recipient_addrs,omitempty"`
	SenderAddresses    []string       `json:"sender_addrs,omitempty"`
	Hashes             []string       `json:"hashes,omitempty"`
}

func (*Search) IsValid added in v1.2.0

func (s *Search) IsValid() bool

func (*Search) ToJSON added in v1.2.0

func (s *Search) ToJSON() ([]byte, error)

func (*Search) ToRequest added in v1.2.0

func (s *Search) ToRequest() (*http.Request, error)

func (*Search) URI added in v1.2.0

func (s *Search) URI() string

type SearchResponse added in v1.2.0

type SearchResponse struct {
	TXS        []*Transaction `json:"data"`
	TotalCount uint64         `json:"total_count"`
}

type Summary added in v1.2.0

type Summary struct {
	RecipientAddresses []string `json:"recipient_addrs,omitempty"`
	SenderAddresses    []string `json:"sender_addrs,omitempty"`
	Type               Type     `json:"typ,omitempty"`
}

func (*Summary) IsValid added in v1.2.0

func (s *Summary) IsValid() bool

func (*Summary) ToJSON added in v1.2.0

func (s *Summary) ToJSON() ([]byte, error)

func (*Summary) ToRequest added in v1.2.0

func (s *Summary) ToRequest() (*http.Request, error)

func (*Summary) URI added in v1.2.0

func (s *Summary) URI() string

type SummaryResponse added in v1.2.0

type SummaryResponse struct {
	Data struct {
		LastBlockHeight uint64       `json:"last_block_height"`
		LastTransaction *Transaction `json:"last_transaction"`
	} `json:"data"`
	TotalCount uint64 `json:"total_count"`
}

type Transaction

type Transaction struct {
	Order         *uint64     `json:"order,omitempty"`
	ID            interface{} `json:"id"`
	BlockID       uint64      `json:"block_id"`
	Height        uint64      `json:"height"`
	Identifier    string      `json:"identifier"`
	Version       uint        `json:"version"`
	Typ           Type        `json:"typ"`
	SenderAddr    string      `json:"sender_addr"`
	RecipientAddr string      `json:"recipient_addr"`
	Data          Bytea       `json:"data"`
	Sign          Bytea       `json:"sign"`
	Fee           uint64      `json:"fee"`
	Hash          string      `json:"hash"`
	InsertedAt    time.Time   `json:"inserted_at"`
}

Transaction read node transaction model

type Type added in v1.2.0

type Type string
const (
	TypeMaster                Type = "initial_storage"
	TypeAddress               Type = "interim_storage"
	TypeAddresses             Type = "interim_storages"
	TypeSubMaster             Type = "initial_sub_storage"
	TypeSubAddresses          Type = "interim_sub_storages"
	TypeAccount               Type = "initial_account"
	TypeAccountInitialTXS     Type = "initial_account_txs"
	TypeMessage               Type = "message"
	TypeMessageSent           Type = "inherit_message"
	TypeMessageThreadDelete   Type = "inherit_message_recv"
	TypeTransfer              Type = "transfer"
	TypeTransferCancel        Type = "transfer_Cancel"
	TypeTransferSent          Type = "transfer_sent"
	TypeTransferReceiveDelete Type = "transfer_receive_delete"
	TypeTransferInfo          Type = "transfer_info"
	TypeStorage               Type = "storage"
	TypeStorageDelete         Type = "storage_delete"
	TypeBackup                Type = "backup"
	TypeContact               Type = "interim_message"
	TypeFileVirtual           Type = "fs_virt"
	TypeFileFs                Type = "fs_real"
	TypeRfileVirtual          Type = "fs_rvirt"
	TypeRfileFs               Type = "fs_rreal"
	TypeDfileVirtual          Type = "fs_dvirt"
	TypeDfileFs               Type = "fs_dreal"
	TypePfileVirtual          Type = "fs_pvirt"
	TypeRequest               Type = "request"
	TypeRequestIn             Type = "request_in"
	TypeRequestUpload         Type = "request_upload"
	TypeRequestCancel         Type = "request_Cancel"
	TypeDataRoom              Type = "data_room"
	TypeDataRoomPolicy        Type = "data_room_policy"
	TypeDataRoomF             Type = "data_roomF"
	TypeDataRoomData          Type = "data_room_data"
	TypeDataRoomDataDelete    Type = "data_room_data_delete"
	TypeDataRoomDataPolicy    Type = "data_room_data_policy"
	TypeMultiStorage          Type = "multi_storage"
	TypeMultiTransfer         Type = "multi_transfer"
	TypeMultiTransferSent     Type = "multi_transfer_sent"
	TypeMultiBackup           Type = "multi_backup"
	TypeMultiDataRoom         Type = "multi_data_room"
	TypePasswdData            Type = "passwd_data"
	TypePasswdRoom            Type = "passwd_room"
	TypePasswdRoomPolicy      Type = "passwd_room_policy"
	TypePasswdRoomF           Type = "passwd_roomF"
	TypePasswdRoomData        Type = "passwd_room_data"
	TypePasswdRoomDataDelete  Type = "passwd_room_data_delete"
	TypePasswdRoomDataPolicy  Type = "passwd_room_data_policy"
)

func (Type) IsValid added in v1.2.0

func (t Type) IsValid() bool

Jump to

Keyboard shortcuts

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