2017-09-12 18:04:45 +02:00
|
|
|
package jsonrpc
|
|
|
|
|
|
|
|
import (
|
2017-09-12 22:38:18 +02:00
|
|
|
"encoding/json"
|
2017-09-19 20:14:52 +02:00
|
|
|
"fmt"
|
2018-03-09 01:27:54 +01:00
|
|
|
"net/http"
|
2017-09-19 20:14:52 +02:00
|
|
|
"reflect"
|
2017-10-04 16:31:03 +02:00
|
|
|
"sort"
|
2017-09-12 18:04:45 +02:00
|
|
|
"strconv"
|
2017-09-19 20:14:52 +02:00
|
|
|
"strings"
|
2017-12-28 18:14:33 +01:00
|
|
|
"time"
|
2017-09-12 18:04:45 +02:00
|
|
|
|
2019-01-09 19:05:41 +01:00
|
|
|
"github.com/lbryio/lbry.go/extras/errors"
|
2018-03-09 17:47:38 +01:00
|
|
|
|
2017-09-12 18:04:45 +02:00
|
|
|
"github.com/mitchellh/mapstructure"
|
2017-11-02 16:20:22 +01:00
|
|
|
"github.com/shopspring/decimal"
|
2017-09-13 00:15:26 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2017-09-12 18:04:45 +02:00
|
|
|
"github.com/ybbus/jsonrpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
const DefaultPort = 5279
|
|
|
|
|
|
|
|
type Client struct {
|
2018-05-09 00:11:24 +02:00
|
|
|
conn jsonrpc.RPCClient
|
|
|
|
address string
|
2017-09-12 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewClient(address string) *Client {
|
|
|
|
d := Client{}
|
|
|
|
|
|
|
|
if address == "" {
|
|
|
|
address = "http://localhost:" + strconv.Itoa(DefaultPort)
|
|
|
|
}
|
|
|
|
|
2018-05-09 00:11:24 +02:00
|
|
|
d.conn = jsonrpc.NewClient(address)
|
|
|
|
d.address = address
|
2017-09-12 18:04:45 +02:00
|
|
|
|
|
|
|
return &d
|
|
|
|
}
|
|
|
|
|
2017-12-28 18:14:33 +01:00
|
|
|
func NewClientAndWait(address string) *Client {
|
|
|
|
d := NewClient(address)
|
|
|
|
for {
|
|
|
|
_, err := d.WalletBalance()
|
|
|
|
if err == nil {
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-12 18:04:45 +02:00
|
|
|
func decode(data interface{}, targetStruct interface{}) error {
|
|
|
|
config := &mapstructure.DecoderConfig{
|
|
|
|
Metadata: nil,
|
|
|
|
Result: targetStruct,
|
|
|
|
TagName: "json",
|
|
|
|
//WeaklyTypedInput: true,
|
|
|
|
DecodeHook: fixDecodeProto,
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder, err := mapstructure.NewDecoder(config)
|
|
|
|
if err != nil {
|
2017-11-02 16:20:22 +01:00
|
|
|
return errors.Wrap(err, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = decoder.Decode(data)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, 0)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeNumber(data interface{}) (decimal.Decimal, error) {
|
|
|
|
var number string
|
|
|
|
|
|
|
|
switch d := data.(type) {
|
|
|
|
case json.Number:
|
|
|
|
number = d.String()
|
|
|
|
case string:
|
|
|
|
number = d
|
|
|
|
default:
|
2018-03-09 17:47:38 +01:00
|
|
|
return decimal.Decimal{}, errors.Err("unexpected number type")
|
2017-11-02 16:20:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dec, err := decimal.NewFromString(number)
|
|
|
|
if err != nil {
|
|
|
|
return decimal.Decimal{}, errors.Wrap(err, 0)
|
2017-09-12 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
2017-11-02 16:20:22 +01:00
|
|
|
return dec, nil
|
2017-09-12 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 21:13:59 +02:00
|
|
|
func debugParams(params map[string]interface{}) string {
|
|
|
|
var s []string
|
|
|
|
for k, v := range params {
|
|
|
|
r := reflect.ValueOf(v)
|
2017-09-16 00:13:13 +02:00
|
|
|
if r.Kind() == reflect.Ptr {
|
|
|
|
if r.IsNil() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
v = r.Elem().Interface()
|
2017-09-14 21:13:59 +02:00
|
|
|
}
|
|
|
|
s = append(s, fmt.Sprintf("%s=%+v", k, v))
|
|
|
|
}
|
2017-10-04 16:31:03 +02:00
|
|
|
sort.Strings(s)
|
2017-09-14 21:13:59 +02:00
|
|
|
return strings.Join(s, " ")
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:38:18 +02:00
|
|
|
func (d *Client) callNoDecode(command string, params map[string]interface{}) (interface{}, error) {
|
2017-09-14 21:13:59 +02:00
|
|
|
log.Debugln("jsonrpc: " + command + " " + debugParams(params))
|
2018-05-09 00:11:24 +02:00
|
|
|
r, err := d.conn.Call(command, params)
|
2017-09-12 18:04:45 +02:00
|
|
|
if err != nil {
|
2017-11-02 16:20:22 +01:00
|
|
|
return nil, errors.Wrap(err, 0)
|
2017-09-12 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if r.Error != nil {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("Error in daemon: " + r.Error.Message)
|
2017-09-12 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
2017-09-12 22:38:18 +02:00
|
|
|
return r.Result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) call(response interface{}, command string, params map[string]interface{}) error {
|
|
|
|
result, err := d.callNoDecode(command, params)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return decode(result, response)
|
2017-09-12 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
2018-03-09 01:27:54 +01:00
|
|
|
func (d *Client) SetRPCTimeout(timeout time.Duration) {
|
2018-05-09 00:11:24 +02:00
|
|
|
d.conn = jsonrpc.NewClientWithOpts(d.address, &jsonrpc.RPCClientOpts{
|
|
|
|
HTTPClient: &http.Client{Timeout: timeout},
|
|
|
|
})
|
2018-03-09 01:27:54 +01:00
|
|
|
}
|
|
|
|
|
2017-09-12 18:04:45 +02:00
|
|
|
func (d *Client) Commands() (*CommandsResponse, error) {
|
2017-09-12 22:38:18 +02:00
|
|
|
response := new(CommandsResponse)
|
|
|
|
return response, d.call(response, "commands", map[string]interface{}{})
|
2017-09-12 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) Status() (*StatusResponse, error) {
|
2017-09-12 22:38:18 +02:00
|
|
|
response := new(StatusResponse)
|
|
|
|
return response, d.call(response, "status", map[string]interface{}{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) WalletBalance() (*WalletBalanceResponse, error) {
|
2017-11-02 16:20:22 +01:00
|
|
|
rawResponse, err := d.callNoDecode("wallet_balance", map[string]interface{}{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
dec, err := decodeNumber(rawResponse)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
response := WalletBalanceResponse(dec)
|
|
|
|
return &response, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) WalletList() (*WalletListResponse, error) {
|
|
|
|
response := new(WalletListResponse)
|
|
|
|
return response, d.call(response, "wallet_list", map[string]interface{}{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) UTXOList() (*UTXOListResponse, error) {
|
|
|
|
response := new(UTXOListResponse)
|
|
|
|
return response, d.call(response, "utxo_list", map[string]interface{}{})
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) Version() (*VersionResponse, error) {
|
|
|
|
response := new(VersionResponse)
|
|
|
|
return response, d.call(response, "version", map[string]interface{}{})
|
2017-09-12 18:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) Get(url string, filename *string, timeout *uint) (*GetResponse, error) {
|
2017-09-12 22:38:18 +02:00
|
|
|
response := new(GetResponse)
|
2017-09-12 18:04:45 +02:00
|
|
|
return response, d.call(response, "get", map[string]interface{}{
|
|
|
|
"uri": url,
|
|
|
|
"file_name": filename,
|
|
|
|
"timeout": timeout,
|
|
|
|
})
|
|
|
|
}
|
2017-09-12 22:38:18 +02:00
|
|
|
|
|
|
|
func (d *Client) ClaimList(name string) (*ClaimListResponse, error) {
|
|
|
|
response := new(ClaimListResponse)
|
|
|
|
return response, d.call(response, "claim_list", map[string]interface{}{
|
|
|
|
"name": name,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) ClaimShow(claimID *string, txid *string, nout *uint) (*ClaimShowResponse, error) {
|
|
|
|
response := new(ClaimShowResponse)
|
|
|
|
return response, d.call(response, "claim_show", map[string]interface{}{
|
|
|
|
"claim_id": claimID,
|
|
|
|
"txid": txid,
|
|
|
|
"nout": nout,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) PeerList(blobHash string, timeout *uint) (*PeerListResponse, error) {
|
|
|
|
rawResponse, err := d.callNoDecode("peer_list", map[string]interface{}{
|
|
|
|
"blob_hash": blobHash,
|
|
|
|
"timeout": timeout,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
castResponse, ok := rawResponse.([]interface{})
|
|
|
|
if !ok {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("invalid peer_list response")
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
peers := []PeerListResponsePeer{}
|
|
|
|
for _, peer := range castResponse {
|
2018-05-09 00:11:24 +02:00
|
|
|
t, ok := peer.(map[string]interface{})
|
2017-09-12 22:38:18 +02:00
|
|
|
if !ok {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("invalid peer_list response")
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(t) != 3 {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("invalid triplet in peer_list response")
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 00:11:24 +02:00
|
|
|
ip, ok := t["host"].(string)
|
2017-09-12 22:38:18 +02:00
|
|
|
if !ok {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("invalid ip in peer_list response")
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
2018-05-09 00:11:24 +02:00
|
|
|
port, ok := t["port"].(json.Number)
|
2017-09-12 22:38:18 +02:00
|
|
|
if !ok {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("invalid port in peer_list response")
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
2018-05-09 00:11:24 +02:00
|
|
|
nodeid, ok := t["node_id"].(string)
|
2017-09-12 22:38:18 +02:00
|
|
|
if !ok {
|
2018-05-09 00:11:24 +02:00
|
|
|
return nil, errors.Err("invalid nodeid in peer_list response")
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
portNum, err := port.Int64()
|
|
|
|
if err != nil {
|
2017-11-02 16:20:22 +01:00
|
|
|
return nil, errors.Wrap(err, 0)
|
2017-09-12 22:38:18 +02:00
|
|
|
} else if portNum < 0 {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("invalid port in peer_list response")
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
peers = append(peers, PeerListResponsePeer{
|
2018-05-09 00:11:24 +02:00
|
|
|
IP: ip,
|
|
|
|
Port: uint(portNum),
|
|
|
|
NodeId: nodeid,
|
2017-09-12 22:38:18 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
response := PeerListResponse(peers)
|
|
|
|
return &response, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) BlobGet(blobHash string, encoding *string, timeout *uint) (*BlobGetResponse, error) {
|
|
|
|
rawResponse, err := d.callNoDecode("blob_get", map[string]interface{}{
|
|
|
|
"blob_hash": blobHash,
|
|
|
|
"timeout": timeout,
|
|
|
|
"encoding": encoding,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := rawResponse.(string); ok {
|
|
|
|
return nil, nil // blob was downloaded, nothing to return
|
|
|
|
}
|
|
|
|
|
|
|
|
response := new(BlobGetResponse)
|
|
|
|
return response, decode(rawResponse, response)
|
|
|
|
}
|
|
|
|
|
2018-05-09 00:11:24 +02:00
|
|
|
func (d *Client) StreamAvailability(url string, search_timeout *uint64, blob_timeout *uint64) (*StreamAvailabilityResponse, error) {
|
|
|
|
response := new(StreamAvailabilityResponse)
|
|
|
|
return response, d.call(response, "stream_availability", map[string]interface{}{
|
|
|
|
"uri": url,
|
|
|
|
"search_timeout": search_timeout,
|
|
|
|
"blob_timeout": blob_timeout,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:38:18 +02:00
|
|
|
func (d *Client) StreamCostEstimate(url string, size *uint64) (*StreamCostEstimateResponse, error) {
|
2017-11-02 16:20:22 +01:00
|
|
|
rawResponse, err := d.callNoDecode("stream_cost_estimate", map[string]interface{}{
|
2017-09-12 22:38:18 +02:00
|
|
|
"uri": url,
|
|
|
|
"size": size,
|
|
|
|
})
|
2017-11-02 16:20:22 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
dec, err := decodeNumber(rawResponse)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
response := StreamCostEstimateResponse(dec)
|
|
|
|
return &response, nil
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
2017-09-13 00:15:26 +02:00
|
|
|
type FileListOptions struct {
|
|
|
|
SDHash *string
|
|
|
|
StreamHash *string
|
|
|
|
FileName *string
|
|
|
|
ClaimID *string
|
|
|
|
Outpoint *string
|
|
|
|
RowID *string
|
|
|
|
Name *string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) FileList(options FileListOptions) (*FileListResponse, error) {
|
2017-09-12 22:38:18 +02:00
|
|
|
response := new(FileListResponse)
|
2017-09-13 00:15:26 +02:00
|
|
|
return response, d.call(response, "file_list", map[string]interface{}{
|
|
|
|
"sd_hash": options.SDHash,
|
|
|
|
"stream_hash": options.StreamHash,
|
|
|
|
"file_name": options.FileName,
|
|
|
|
"claim_id": options.ClaimID,
|
|
|
|
"outpoint": options.Outpoint,
|
|
|
|
"rowid": options.RowID,
|
|
|
|
"name": options.Name,
|
|
|
|
})
|
2017-09-12 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) Resolve(url string) (*ResolveResponse, error) {
|
|
|
|
response := new(ResolveResponse)
|
|
|
|
return response, d.call(response, "resolve", map[string]interface{}{
|
|
|
|
"uri": url,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-09-16 00:13:13 +02:00
|
|
|
func (d *Client) ChannelNew(name string, amount float64) (*ChannelNewResponse, error) {
|
|
|
|
response := new(ChannelNewResponse)
|
|
|
|
return response, d.call(response, "channel_new", map[string]interface{}{
|
|
|
|
"channel_name": name,
|
|
|
|
"amount": amount,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-15 19:39:43 +01:00
|
|
|
func (d *Client) ChannelList() (*ChannelListResponse, error) {
|
|
|
|
response := new(ChannelListResponse)
|
|
|
|
return response, d.call(response, "channel_list", map[string]interface{}{})
|
2017-09-16 00:13:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type PublishOptions struct {
|
|
|
|
Fee *Fee
|
|
|
|
Title *string
|
|
|
|
Description *string
|
|
|
|
Author *string
|
|
|
|
Language *string
|
|
|
|
License *string
|
|
|
|
LicenseURL *string
|
|
|
|
Thumbnail *string
|
|
|
|
Preview *string
|
|
|
|
NSFW *bool
|
|
|
|
ChannelName *string
|
|
|
|
ChannelID *string
|
|
|
|
ClaimAddress *string
|
|
|
|
ChangeAddress *string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) Publish(name, filePath string, bid float64, options PublishOptions) (*PublishResponse, error) {
|
|
|
|
response := new(PublishResponse)
|
|
|
|
return response, d.call(response, "publish", map[string]interface{}{
|
|
|
|
"name": name,
|
|
|
|
"file_path": filePath,
|
|
|
|
"bid": bid,
|
|
|
|
"fee": options.Fee,
|
|
|
|
"title": options.Title,
|
|
|
|
"description": options.Description,
|
|
|
|
"author": options.Author,
|
|
|
|
"language": options.Language,
|
|
|
|
"license": options.License,
|
|
|
|
"license_url": options.LicenseURL,
|
|
|
|
"thumbnail": options.Thumbnail,
|
|
|
|
"preview": options.Preview,
|
|
|
|
"nsfw": options.NSFW,
|
|
|
|
"channel_name": options.ChannelName,
|
|
|
|
"channel_id": options.ChannelID,
|
|
|
|
"claim_address": options.ClaimAddress,
|
|
|
|
"change_address": options.ChangeAddress,
|
|
|
|
})
|
|
|
|
}
|
2017-09-22 15:24:43 +02:00
|
|
|
|
|
|
|
func (d *Client) BlobAnnounce(blobHash, sdHash, streamHash *string) (*BlobAnnounceResponse, error) {
|
|
|
|
response := new(BlobAnnounceResponse)
|
|
|
|
return response, d.call(response, "blob_announce", map[string]interface{}{
|
|
|
|
"blob_hash": blobHash,
|
|
|
|
"stream_hash": streamHash,
|
|
|
|
"sd_hash": sdHash,
|
|
|
|
})
|
|
|
|
}
|
2017-11-02 16:20:22 +01:00
|
|
|
|
|
|
|
func (d *Client) WalletPrefillAddresses(numAddresses int, amount decimal.Decimal, broadcast bool) (*WalletPrefillAddressesResponse, error) {
|
|
|
|
if numAddresses < 1 {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("must create at least 1 address")
|
2017-11-02 16:20:22 +01:00
|
|
|
}
|
|
|
|
response := new(WalletPrefillAddressesResponse)
|
|
|
|
return response, d.call(response, "wallet_prefill_addresses", map[string]interface{}{
|
|
|
|
"num_addresses": numAddresses,
|
|
|
|
"amount": amount,
|
|
|
|
"no_broadcast": !broadcast,
|
|
|
|
})
|
|
|
|
}
|
2017-11-03 13:46:27 +01:00
|
|
|
|
|
|
|
func (d *Client) WalletNewAddress() (*WalletNewAddressResponse, error) {
|
|
|
|
rawResponse, err := d.callNoDecode("wallet_new_address", map[string]interface{}{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
address, ok := rawResponse.(string)
|
|
|
|
if !ok {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("unexpected response")
|
2017-11-03 13:46:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
response := WalletNewAddressResponse(address)
|
|
|
|
return &response, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) WalletUnusedAddress() (*WalletUnusedAddressResponse, error) {
|
|
|
|
rawResponse, err := d.callNoDecode("wallet_unused_address", map[string]interface{}{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
address, ok := rawResponse.(string)
|
|
|
|
if !ok {
|
2018-03-09 17:47:38 +01:00
|
|
|
return nil, errors.Err("unexpected response")
|
2017-11-03 13:46:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
response := WalletUnusedAddressResponse(address)
|
|
|
|
return &response, nil
|
|
|
|
}
|
2017-12-28 18:14:33 +01:00
|
|
|
|
|
|
|
func (d *Client) NumClaimsInChannel(url string) (uint64, error) {
|
|
|
|
response := new(NumClaimsInChannelResponse)
|
|
|
|
err := d.call(response, "claim_list_by_channel", map[string]interface{}{
|
|
|
|
"uri": url,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
} else if response == nil {
|
2018-03-09 17:47:38 +01:00
|
|
|
return 0, errors.Err("no response")
|
2017-12-28 18:14:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
channel, ok := (*response)[url]
|
|
|
|
if !ok {
|
2018-03-09 17:47:38 +01:00
|
|
|
return 0, errors.Err("url not in response")
|
2017-12-28 18:14:33 +01:00
|
|
|
}
|
|
|
|
if channel.Error != "" {
|
2017-12-30 00:51:38 +01:00
|
|
|
if strings.Contains(channel.Error, "cannot be resolved") {
|
|
|
|
return 0, nil
|
|
|
|
}
|
2018-03-09 17:47:38 +01:00
|
|
|
return 0, errors.Err(channel.Error)
|
2017-12-28 18:14:33 +01:00
|
|
|
}
|
|
|
|
return channel.ClaimsInChannel, nil
|
|
|
|
}
|
2018-08-31 17:42:15 +02:00
|
|
|
|
|
|
|
func (d *Client) ClaimListMine() (*ClaimListMineResponse, error) {
|
|
|
|
response := new(ClaimListMineResponse)
|
|
|
|
err := d.call(response, "claim_list_mine", map[string]interface{}{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if response == nil {
|
|
|
|
return nil, errors.Err("no response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
}
|
2018-09-20 01:05:47 +02:00
|
|
|
|
|
|
|
func (d *Client) ClaimAbandon(txID string, nOut int) (*ClaimAbandonResponse, error) {
|
|
|
|
response := new(ClaimAbandonResponse)
|
|
|
|
err := d.call(response, "claim_abandon", map[string]interface{}{
|
|
|
|
"txid": txID,
|
|
|
|
"nout": nOut,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if response == nil {
|
|
|
|
return nil, errors.Err("no response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
}
|