tcabcireadgoclient

package module
v1.6.14 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 22 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", "medusa", "v2", false, nil)

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

	if err := readNodeClient.Subscribe(addresses, signedData); 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 = 7 * 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

func InArray added in v1.6.8

func InArray(val interface{}, array interface{}) (exists bool, index int, err error)

func StringOR added in v1.6.0

func StringOR(values ...string) string

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"`
	AdditionalData *[]byte `json:"additional_data,omitempty"`
	CipherData     *[]byte `json:"cipher_data,omitempty"`
	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() (*fasthttp.Request, error)

func (*Broadcast) URI added in v1.2.0

func (b *Broadcast) URI(commit, sync bool) 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 {
	// SetLogger ..
	// Deprecated: use WithLogger/1
	SetLogger(l Logger) Client
	WithLogger(l Logger) Client
	SetVerbose(verbose bool) (Client, error)
	Start() error
	Stop() error
	SetListenCallback(func(transaction *Transaction))
	Subscribe(addresses []string, signedDatas map[string]string, txTypes ...Type) error
	Unsubscribe() error
	Write(b []byte) error
	LastBlock(chainName, chainVersion *string) (*LastBlock, error)
	Tx(id string, signature string, chainName, chainVersion *string) (*Transaction, 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, additionalData, cipherData *[]byte, senderAddress, recipientAddress string, sign []byte, fee uint64) (*BroadcastResponse, error)
	BroadcastSync(id string, version uint32, typ Type, data []byte, additionalData, cipherData *[]byte, senderAddress, recipientAddress string, sign []byte, fee uint64) (*BroadcastResponse, error)
	BroadcastCommit(id string, version uint32, typ Type, data []byte, additionalData, cipherData *[]byte, senderAddress, recipientAddress string, sign []byte, fee uint64) (*BroadcastResponse, error)
	FetchNS(identifier string) (*NS, error)
	Query(method string, path string, data []byte) (*Response, error)
}

Client TCABCI Read Node Websocket Client

func NewClient

func NewClient(address string, wsAddress string, chainName, chainVersion string, insecure bool, customFingerprint *string) (Client, error)

NewClient make ws client

func NewClientContext added in v1.2.10

func NewClientContext(ctx context.Context, address string, wsAddress string, chainName, chainVersion string, insecure bool, customFingerprint *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 Logger added in v1.6.0

type Logger interface {
	Info(args ...interface{})
	Error(args ...interface{})
	Print(args ...interface{})
}

func NewLogger added in v1.6.0

func NewLogger(ctx context.Context) Logger

type Message

type Message struct {
	IsWeb       bool              `json:"is_web"`
	Type        MessageType       `json:"type"`
	Addrs       []string          `json:"addrs"`
	SignedAddrs map[string]string `json:"signed_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 NS added in v1.6.10

type NS struct {
	Identifier string   `json:"identifier"`
	PublicIDs  []string `json:"addresses"`
}

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 {
	Message    *string           `json:"message,omitempty"`
	Data       interface{}       `json:"data,omitempty"`
	TotalCount uint64            `json:"total_count,omitempty"`
	Error      bool              `json:"error"`
	Errors     map[string]string `json:"errors,omitempty"`
	Detail     *string           `json:"detail,omitempty"`
}

func (*Response) GetData added in v1.6.0

func (r *Response) GetData() interface{}

func (*Response) GetDetail added in v1.6.0

func (r *Response) GetDetail() string

func (*Response) GetMessage added in v1.6.0

func (r *Response) GetMessage() string
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"`
	Types              []Type            `json:"types,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"`
	SignedAddresses    map[string]string `json:"signed_addrs,omitempty"`
	Hashes             []string          `json:"hashes,omitempty"`
	ChainName          *string           `json:"chain_name,omitempty"`
	ChainVersion       *string           `json:"chain_version,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() (*fasthttp.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"`
	ChainName          *string           `json:"chain_name,omitempty"`
	ChainVersion       *string           `json:"chain_version,omitempty"`
	SignedAddresses    map[string]string `json:"signed_addrs,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() (*fasthttp.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"`
	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"`
	AdditionalData *Bytea      `json:"additional_data,omitempty"`
	CipherData     *Bytea      `json:"cipher_data,omitempty"`
	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"
	TypeNS                    Type = "ns"
	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"
	TypePasswdDataV2          Type = "pwdd"
	TypePasswdDataV2Policy    Type = "pwdd_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