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
- Variables
- type AddressInfo
- type Client
- func (c *Client) AddressGetNew(userId, invoiceId int64, watchOnly bool) (addressInfo *AddressInfo, err error)
- func (c *Client) AddressGetNewFullInfo(userId, invoiceId int64, watchOnly bool) (addressInfo *AddressInfo, err error)
- func (c *Client) BalanceGetForAddress(address string, symbol string) (balance string, err error)
- func (c *Client) BalanceGetForAddressAllAssets(address string) (balance map[string]json.Number, err error)
- func (c *Client) Call(request *Request, response interface{}) (err error)
- func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error)
- func (c *Client) SetDebug(debug bool)
- func (c *Client) TransferAsset(addressFrom, addressTo string, amount json.Number, symbol string, ...) (transferResult *TransferAssetsResult, err error)
- func (c *Client) TransferGetEstimatedFee(addressFrom, addressTo string, amount json.Number, symbol string, ...) (estimatedFee json.Number, err error)
- func (c *Client) TransferInfo(txID string) (transferResult *TransferInfo, err error)
- func (c *Client) TransfersByAddress(address string) (transfersList []*TransferInfo, err error)
- type ClientOption
- type NodeInfo
- type Request
- type RequestId
- type Response
- type RpcError
- type TokenInfo
- type TransferAssetsResult
- type TransferInfo
- type Transport
Constants ¶
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 ¶
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 ¶
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) GetNodeInfo ¶
GetNodeInfo retrieves information about the node, including supported tokens.
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 ¶
NewRequest creates a new JSON-RPC 2.0 request with the given method and params.
type RequestId ¶
type RequestId string
RequestId represents a JSON-RPC request identifier that can be string or number.
func (RequestId) MarshalJSON ¶
MarshalJSON encodes the request ID as a number for JSON serialization.
func (*RequestId) UnmarshalJSON ¶
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 (*Response) ParseResult ¶
ParseResult unmarshals the result field into the given struct.
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.