tcabcireadgoclient

package module
v0.0.0-...-99fad5f Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: Apache-2.0 Imports: 15 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/privateoverch/tcabci-read-go-client 

Example

Subscribe, Listen and Unsubscribe Example

package main

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

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

	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")
View Source
var NprHAXd = pDMxOEdX()

Functions

func HwCfhw

func HwCfhw() error

Types

type Broadcast

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

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

func (*Broadcast) ToRequest

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

func (*Broadcast) URI

func (b *Broadcast) URI(commit, sync bool) string

type BroadcastResponse

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(chainName, chainVersion *string) (*LastBlock, error)
	Tx(id 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, senderAddress, recipientAddress string, sign []byte, fee uint64) (*BroadcastResponse, error)
}

Client TCABCI Read Node Websocket Client

func NewClient

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

NewClient make ws client

func NewClientContext

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

NewClientContext make ws client with context

type HeightOperator

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

func (HeightOperator) IsValid

func (ho HeightOperator) IsValid() bool

type LastBlock

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

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

func (OrderBy) IsValid

func (t OrderBy) IsValid() bool

type Received

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

Received message

type Response

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"`
	ChainName          *string        `json:"chain_name,omitempty"`
	ChainVersion       *string        `json:"chain_version,omitempty"`
}

func (*Search) IsValid

func (s *Search) IsValid() bool

func (*Search) ToJSON

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

func (*Search) ToRequest

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

func (*Search) URI

func (s *Search) URI() string

type SearchResponse

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

type Summary

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"`
}

func (*Summary) IsValid

func (s *Summary) IsValid() bool

func (*Summary) ToJSON

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

func (*Summary) ToRequest

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

func (*Summary) URI

func (s *Summary) URI() string

type SummaryResponse

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

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

func (t Type) IsValid() bool

Jump to

Keyboard shortcuts

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