uniclient

package
v0.0.0-...-ea2125a Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package uniclient provides a unified JSON-RPC client for interacting with EthBackNode services. It supports address management, balance queries, transactions, and service operations.

Index

Constants

View Source
const (
	JSON_RPC_VERSION_2_0 = "2.0"

	ERROR_CODE_PARSE_ERROR         = -32700
	ERROR_MESSAGE_PARSE_ERROR      = "Parse error"
	ERROR_CODE_INVALID_REQUEST     = -32600
	ERROR_MESSAGE_INVALID_REQUEST  = "invalid request"
	ERROR_CODE_METHOD_NOT_FOUND    = -32601
	ERROR_MESSAGE_METHOD_NOT_FOUND = "method not found"
	ERROR_CODE_SERVER_ERROR        = -32000
	ERROR_MESSAGE_SERVER_ERROR     = "server error"
)

JSON-RPC 2.0 constants and standard error codes.

Variables

View Source
var (
	// ErrInvalidBalanceResponse is returned when balance response format is invalid.
	ErrInvalidBalanceResponse = errors.New("invalid balance response")
)

Error definitions for uniclient operations.

Functions

This section is empty.

Types

type AddressInfo

type AddressInfo struct {
	Address       string   `json:"address"`
	PrivateKey    string   `json:"privateKey,omitempty"`
	UserId        int64    `json:"userId,omitempty"`
	InvoiceId     int64    `json:"invoiceId,omitempty"`
	WatchOnly     bool     `json:"watchOnly,omitempty"`
	Bip39Support  bool     `json:"bip39Support,omitempty"`
	Bip39Mnemonic []string `json:"bip39Mnemonic,omitempty"`
}

AddressInfo contains information about a managed address.

type Client

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

Client is a JSON-RPC client for EthBackNode API.

func NewClient

func NewClient(options ...ClientOption) *Client

NewClient creates a new unified RPC client with the given options.

func (*Client) AddressGetNew

func (c *Client) AddressGetNew(userId, invoiceId int64, watchOnly bool) (addressInfo *AddressInfo, err error)

AddressGetNew generates a new address for the given user and invoice.

func (*Client) AddressGetNewFullInfo

func (c *Client) AddressGetNewFullInfo(userId, invoiceId int64, watchOnly bool) (addressInfo *AddressInfo, err error)

AddressGetNewFullInfo generates a new address and returns full info including private key.

func (*Client) BalanceGetForAddress

func (c *Client) BalanceGetForAddress(address string, symbol string) (balance string, err error)

BalanceGetForAddress retrieves the balance of a specific asset for an address.

func (*Client) BalanceGetForAddressAllAssets

func (c *Client) BalanceGetForAddressAllAssets(address string) (balance map[string]json.Number, err error)

BalanceGetForAddressAllAssets retrieves balances for all assets at an address.

func (*Client) Call

func (c *Client) Call(request *Request, response interface{}) (err error)

Call executes a raw RPC request and populates the response.

func (*Client) GetNodeInfo

func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error)

GetNodeInfo retrieves information about the node, including supported tokens.

func (*Client) SetDebug

func (c *Client) SetDebug(debug bool)

SetDebug enables or disables debug logging of requests and responses.

func (*Client) TransferAsset

func (c *Client) TransferAsset(addressFrom, addressTo string, amount json.Number, symbol string, formated bool) (transferResult *TransferAssetsResult, err error)

TransferAsset initiates an asset transfer from one address to another.

func (*Client) TransferGetEstimatedFee

func (c *Client) TransferGetEstimatedFee(addressFrom, addressTo string, amount json.Number, symbol string, formated bool) (estimatedFee json.Number, err error)

TransferGetEstimatedFee estimates the fee for a transfer operation.

func (*Client) TransferInfo

func (c *Client) TransferInfo(txID string) (transferResult *TransferInfo, err error)

TransferInfo retrieves details about a specific transaction by ID.

func (*Client) TransfersByAddress

func (c *Client) TransfersByAddress(address string) (transfersList []*TransferInfo, err error)

TransfersByAddress retrieves all transfers involving the given address.

type ClientOption

type ClientOption func(client *Client)

ClientOption is a function that configures a Client.

func WithHttpTransport

func WithHttpTransport(endpointUrl string, headers map[string]string) ClientOption

WithHttpTransport configures the client to use HTTP transport with the given endpoint.

func WithServiceId

func WithServiceId(serviceId int) ClientOption

WithServiceId sets the service ID for subscription-based operations.

type NodeInfo

type NodeInfo struct {
	Blockchain string       `json:"blockchain"`
	Id         string       `json:"id"`
	Symbol     string       `json:"symbol"`
	Decimals   int          `json:"decimals"`
	Protocols  []string     `json:"protocols"`
	Tokens     []*TokenInfo `json:"tokens"`
}

NodeInfo describes the EthBackNode server and supported tokens.

type Request

type Request struct {
	Id      RequestId   `json:"id"`
	JsonRpc string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
}

Request represents a JSON-RPC 2.0 request.

func NewRequest

func NewRequest(method string, params interface{}) (req *Request)

NewRequest creates a new JSON-RPC 2.0 request with the given method and params.

func (*Request) SetId

func (r *Request) SetId(id RequestId)

SetId sets the request ID.

func (*Request) String

func (r *Request) String() string

String returns the JSON representation of the request.

type RequestId

type RequestId string

RequestId represents a JSON-RPC request identifier that can be string or number.

func (RequestId) MarshalJSON

func (id RequestId) MarshalJSON() ([]byte, error)

MarshalJSON encodes the request ID as a number for JSON serialization.

func (RequestId) String

func (id RequestId) String() string

String returns the string representation of the request ID.

func (*RequestId) UnmarshalJSON

func (id *RequestId) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a request ID from either string or number format.

type Response

type Response struct {
	Id      RequestId       `json:"id"`
	JsonRpc string          `json:"jsonrpc"`
	Error   *RpcError       `json:"error,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
}

Response represents a JSON-RPC 2.0 response.

func NewResponse

func NewResponse() *Response

NewResponse creates a new JSON-RPC 2.0 response.

func (*Response) HasError

func (r *Response) HasError() bool

HasError returns true if the response contains an error.

func (*Response) ParseResult

func (r *Response) ParseResult(params interface{}) (err error)

ParseResult unmarshals the result field into the given struct.

type RpcError

type RpcError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RpcError represents a JSON-RPC 2.0 error object.

func (*RpcError) Error

func (e *RpcError) Error() string

Error implements the error interface for RpcError.

type TokenInfo

type TokenInfo struct {
	ContractAddress string `json:"contractAddress,omitempty"`
	Name            string `json:"name"`
	Symbol          string `json:"symbol"`
	Decimals        int    `json:"decimals"`
	Protocol        string `json:"protocol,omitempty"`
}

TokenInfo describes an ERC-20 or other token contract.

type TransferAssetsResult

type TransferAssetsResult struct {
	TxID              string      `json:"tx_id"`
	Success           bool        `json:"success"`
	NativeCoin        bool        `json:"nativeCoin,omitempty"`
	SmartContract     bool        `json:"smartContract,omitempty"`
	Symbol            string      `json:"symbol,omitempty"`
	From              string      `json:"from"`
	To                string      `json:"to"`
	Amount            json.Number `json:"amount"`
	Fee               json.Number `json:"fee"`
	FeeSymbol         string      `json:"feeSymbol,omitempty"`
	Warning           string      `json:"warning,omitempty"`
	ChainSpecificData []byte      `json:"chainSpecificData,omitempty"`
}

TransferAssetsResult contains the result of an asset transfer operation.

type TransferInfo

type TransferInfo struct {
	TxID              string      `json:"tx_id"`
	Timestamp         int64       `json:"timestamp"`
	BlockNum          int         `json:"blockNum"`
	Success           bool        `json:"success"`
	Transfer          bool        `json:"transfer"`
	NativeCoin        bool        `json:"nativeCoin,omitempty"`
	Symbol            string      `json:"symbol,omitempty"`
	Decimals          int         `json:"decimals"`
	SmartContract     bool        `json:"smartContract,omitempty"`
	From              string      `json:"from"`
	To                string      `json:"to"`
	Amount            json.Number `json:"amount"`
	Token             string      `json:"token,omitempty"`
	TokenSymbol       string      `json:"tokenSymbol,omitempty"`
	Fee               json.Number `json:"fee"`
	InPool            bool        `json:"inPool"`
	Confirmed         bool        `json:"confirmed"`
	Confirmations     int         `json:"confirmations,omitempty"`
	ChainSpecificData []byte      `json:"chainSpecificData,omitempty"`
}

TransferInfo contains details about a blockchain transfer.

type Transport

type Transport interface {
	Call(request *Request, response interface{}) (err error)
}

Transport defines the interface for RPC communication.

Jump to

Keyboard shortcuts

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