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-05-21 20:17:22 +02:00
|
|
|
"github.com/fatih/structs"
|
2019-09-24 20:37:03 +02:00
|
|
|
"github.com/lbryio/lbry.go/extras/errors"
|
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 {
|
2019-01-22 18:48:04 +01:00
|
|
|
_, err := d.AccountBalance(nil)
|
2017-12-28 18:14:33 +01:00
|
|
|
if err == nil {
|
|
|
|
return d
|
|
|
|
}
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-18 19:10:23 +01:00
|
|
|
func Decode(data interface{}, targetStruct interface{}) error {
|
2017-09-12 18:04:45 +02:00
|
|
|
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
|
|
|
|
}
|
2019-01-18 19:10:23 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-01-17 21:38:45 +01:00
|
|
|
//============================================
|
|
|
|
// NEW SDK
|
|
|
|
//============================================
|
2019-09-25 12:47:12 +02:00
|
|
|
|
2019-01-17 21:38:45 +01:00
|
|
|
func (d *Client) AccountList() (*AccountListResponse, error) {
|
|
|
|
response := new(AccountListResponse)
|
|
|
|
return response, d.call(response, "account_list", map[string]interface{}{})
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:47:12 +02:00
|
|
|
func (d *Client) AccountListForWallet(walletID string) (*AccountListResponse, error) {
|
|
|
|
response := new(AccountListResponse)
|
|
|
|
return response, d.call(response, "account_list", map[string]interface{}{"wallet_id": walletID})
|
|
|
|
}
|
|
|
|
|
2019-05-22 06:40:18 +02:00
|
|
|
func (d *Client) SingleAccountList(accountID string) (*Account, error) {
|
|
|
|
response := new(Account)
|
2019-05-21 19:12:00 +02:00
|
|
|
return response, d.call(response, "account_list", map[string]interface{}{"account_id": accountID})
|
|
|
|
}
|
|
|
|
|
2019-04-15 20:13:23 +02:00
|
|
|
type AccountSettings struct {
|
2019-06-12 22:18:03 +02:00
|
|
|
Default *bool `json:"default,omitempty"`
|
|
|
|
NewName *string `json:"new_name,omitempty"`
|
|
|
|
ReceivingGap *int `json:"receiving_gap,omitempty"`
|
|
|
|
ReceivingMaxUses *int `json:"receiving_max_uses,omitempty"`
|
|
|
|
ChangeGap *int `json:"change_gap,omitempty"`
|
|
|
|
ChangeMaxUses *int `json:"change_max_uses,omitempty"`
|
2019-04-15 20:13:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) AccountSet(accountID string, settings AccountSettings) (*Account, error) {
|
|
|
|
response := new(Account)
|
2019-06-12 05:23:48 +02:00
|
|
|
args := struct {
|
|
|
|
AccountID string `json:"account_id"`
|
|
|
|
AccountSettings `json:",flatten"`
|
|
|
|
}{
|
|
|
|
AccountID: accountID,
|
|
|
|
AccountSettings: settings,
|
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "account_set", structs.Map(args))
|
2019-04-15 20:13:23 +02:00
|
|
|
}
|
|
|
|
|
2019-01-17 21:38:45 +01:00
|
|
|
func (d *Client) AccountBalance(account *string) (*AccountBalanceResponse, error) {
|
|
|
|
response := new(AccountBalanceResponse)
|
|
|
|
return response, d.call(response, "account_balance", map[string]interface{}{
|
|
|
|
"account_id": account,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-12 02:53:42 +02:00
|
|
|
// funds an account. If everything is true then amount is ignored
|
|
|
|
func (d *Client) AccountFund(fromAccount string, toAccount string, amount string, outputs uint64, everything bool) (*AccountFundResponse, error) {
|
2019-01-17 21:38:45 +01:00
|
|
|
response := new(AccountFundResponse)
|
|
|
|
return response, d.call(response, "account_fund", map[string]interface{}{
|
|
|
|
"from_account": fromAccount,
|
|
|
|
"to_account": toAccount,
|
|
|
|
"amount": amount,
|
|
|
|
"outputs": outputs,
|
2019-06-12 02:53:42 +02:00
|
|
|
"everything": everything,
|
2019-01-29 21:41:28 +01:00
|
|
|
"broadcast": true,
|
2019-01-17 21:38:45 +01:00
|
|
|
})
|
|
|
|
}
|
2019-01-18 19:10:23 +01:00
|
|
|
|
2019-09-24 20:35:04 +02:00
|
|
|
func (d *Client) AccountCreate(accountName string, singleKey bool) (*Account, error) {
|
|
|
|
response := new(Account)
|
2019-05-24 16:52:04 +02:00
|
|
|
return response, d.call(response, "account_create", map[string]interface{}{
|
|
|
|
"account_name": accountName,
|
|
|
|
"single_key": singleKey,
|
|
|
|
})
|
2019-04-10 23:23:24 +02:00
|
|
|
}
|
|
|
|
|
2019-09-24 20:35:04 +02:00
|
|
|
func (d *Client) AccountRemove(accountID string) (*Account, error) {
|
|
|
|
response := new(Account)
|
2019-05-21 19:12:00 +02:00
|
|
|
return response, d.call(response, "account_remove", map[string]interface{}{
|
|
|
|
"account_id": accountID,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-18 19:10:23 +01:00
|
|
|
func (d *Client) AddressUnused(account *string) (*AddressUnusedResponse, error) {
|
|
|
|
response := new(AddressUnusedResponse)
|
|
|
|
return response, d.call(response, "address_unused", map[string]interface{}{
|
|
|
|
"account_id": account,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) ChannelList(account *string, page uint64, pageSize uint64) (*ChannelListResponse, error) {
|
2019-01-22 18:48:04 +01:00
|
|
|
if page == 0 {
|
|
|
|
return nil, errors.Err("pages start from 1")
|
|
|
|
}
|
2019-01-18 19:10:23 +01:00
|
|
|
response := new(ChannelListResponse)
|
|
|
|
return response, d.call(response, "channel_list", map[string]interface{}{
|
2019-04-21 20:29:25 +02:00
|
|
|
"account_id": account,
|
|
|
|
"page": page,
|
|
|
|
"page_size": pageSize,
|
|
|
|
"include_protobuf": true,
|
2019-01-18 19:10:23 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-04-03 00:44:30 +02:00
|
|
|
type streamType string
|
|
|
|
|
|
|
|
var (
|
|
|
|
StreamTypeVideo = streamType("video")
|
|
|
|
StreamTypeAudio = streamType("audio")
|
|
|
|
StreamTypeImage = streamType("image")
|
|
|
|
)
|
|
|
|
|
2019-04-15 20:13:23 +02:00
|
|
|
type Location struct {
|
2019-04-03 00:44:30 +02:00
|
|
|
Country *string `json:"country,omitempty"`
|
|
|
|
State *string `json:"state,omitempty"`
|
|
|
|
City *string `json:"city,omitempty"`
|
|
|
|
PostalCode *string `json:"code,omitempty"`
|
|
|
|
Latitude *string `json:"latitude,omitempty"`
|
|
|
|
Longitude *string `json:"longitude,omitempty"`
|
|
|
|
}
|
|
|
|
type ClaimCreateOptions struct {
|
2019-06-01 03:17:10 +02:00
|
|
|
Title *string `json:"title,omitempty"`
|
|
|
|
Description *string `json:"description,omitempty"`
|
2019-04-15 20:13:23 +02:00
|
|
|
Tags []string `json:"tags,omitempty"`
|
2019-05-09 16:05:19 +02:00
|
|
|
Languages []string `json:"languages,omitempty"`
|
2019-04-15 20:13:23 +02:00
|
|
|
Locations []Location `json:"locations,omitempty"`
|
|
|
|
ThumbnailURL *string `json:"thumbnail_url,omitempty"`
|
|
|
|
AccountID *string `json:"account_id,omitempty"`
|
|
|
|
ClaimAddress *string `json:"claim_address,omitempty"`
|
|
|
|
Preview *bool `json:"preview,omitempty"`
|
2019-04-03 00:44:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type ChannelCreateOptions struct {
|
2019-04-11 21:04:37 +02:00
|
|
|
ClaimCreateOptions `json:",flatten"`
|
2019-05-09 16:05:19 +02:00
|
|
|
Email *string `json:"email,omitempty"`
|
|
|
|
WebsiteURL *string `json:"website_url,omitempty"`
|
|
|
|
CoverURL *string `json:"cover_url,omitempty"`
|
|
|
|
Featured []string `json:"featured,omitempty"`
|
2019-09-06 00:16:49 +02:00
|
|
|
AccountID *string `json:"account_id,omitempty"`
|
2019-04-03 00:44:30 +02:00
|
|
|
}
|
|
|
|
|
2019-04-18 19:07:47 +02:00
|
|
|
func (d *Client) ChannelCreate(name string, bid float64, options ChannelCreateOptions) (*TransactionSummary, error) {
|
|
|
|
response := new(TransactionSummary)
|
2019-01-18 19:10:23 +01:00
|
|
|
args := struct {
|
2019-04-15 20:13:23 +02:00
|
|
|
Name string `json:"name"`
|
|
|
|
Bid string `json:"bid"`
|
|
|
|
FilePath string `json:"file_path,omitempty"`
|
2019-04-21 20:29:25 +02:00
|
|
|
IncludeProtoBuf bool `json:"include_protobuf"`
|
2019-04-15 20:13:23 +02:00
|
|
|
ChannelCreateOptions `json:",flatten"`
|
2019-06-11 18:40:48 +02:00
|
|
|
Blocking bool `json:"blocking"`
|
2019-01-18 19:10:23 +01:00
|
|
|
}{
|
2019-04-03 00:44:30 +02:00
|
|
|
Name: name,
|
|
|
|
Bid: fmt.Sprintf("%.6f", bid),
|
2019-04-21 20:29:25 +02:00
|
|
|
IncludeProtoBuf: true,
|
2019-04-03 00:44:30 +02:00
|
|
|
ChannelCreateOptions: options,
|
2019-06-11 18:40:48 +02:00
|
|
|
Blocking: true,
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
2019-04-03 00:44:30 +02:00
|
|
|
return response, d.call(response, "channel_create", structs.Map(args))
|
2019-01-18 19:10:23 +01:00
|
|
|
}
|
2019-01-18 21:52:57 +01:00
|
|
|
|
2019-05-09 16:05:19 +02:00
|
|
|
type ChannelUpdateOptions struct {
|
|
|
|
ChannelCreateOptions `json:",flatten"`
|
|
|
|
NewSigningKey *bool `json:"new_signing_key,omitempty"`
|
|
|
|
ClearFeatured *bool `json:"clear_featured,omitempty"`
|
|
|
|
ClearTags *bool `json:"clear_tags,omitempty"`
|
|
|
|
ClearLanguages *bool `json:"clear_languages,omitempty"`
|
|
|
|
ClearLocations *bool `json:"clear_locations,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) ChannelUpdate(claimID string, options ChannelUpdateOptions) (*TransactionSummary, error) {
|
|
|
|
response := new(TransactionSummary)
|
|
|
|
args := struct {
|
|
|
|
ClaimID string `json:"claim_id"`
|
|
|
|
IncludeProtoBuf bool `json:"include_protobuf"`
|
|
|
|
*ChannelUpdateOptions `json:",flatten"`
|
2019-06-11 18:40:48 +02:00
|
|
|
Blocking bool `json:"blocking"`
|
2019-05-09 16:05:19 +02:00
|
|
|
}{
|
|
|
|
ClaimID: claimID,
|
|
|
|
IncludeProtoBuf: true,
|
|
|
|
ChannelUpdateOptions: &options,
|
2019-06-11 18:40:48 +02:00
|
|
|
Blocking: true,
|
2019-05-09 16:05:19 +02:00
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "channel_update", structs.Map(args))
|
|
|
|
}
|
|
|
|
|
2019-04-03 00:44:30 +02:00
|
|
|
type StreamCreateOptions struct {
|
2019-04-11 21:04:37 +02:00
|
|
|
ClaimCreateOptions `json:",flatten"`
|
2019-04-30 08:08:40 +02:00
|
|
|
Fee *Fee `json:",omitempty,flatten"`
|
|
|
|
Author *string `json:"author,omitempty"`
|
|
|
|
License *string `json:"license,omitempty"`
|
|
|
|
LicenseURL *string `json:"license_url,omitempty"`
|
|
|
|
StreamType *streamType `json:"stream_type,omitempty"`
|
|
|
|
ReleaseTime *int64 `json:"release_time,omitempty"`
|
|
|
|
Duration *uint64 `json:"duration,omitempty"`
|
2019-06-01 03:38:48 +02:00
|
|
|
Width *uint `json:"width,omitempty"`
|
|
|
|
Height *uint `json:"height,omitempty"`
|
2019-04-30 08:08:40 +02:00
|
|
|
Preview *string `json:"preview,omitempty"`
|
|
|
|
AllowDuplicateName *bool `json:"allow_duplicate_name,omitempty"`
|
|
|
|
ChannelName *string `json:"channel_name,omitempty"`
|
|
|
|
ChannelID *string `json:"channel_id,omitempty"`
|
|
|
|
ChannelAccountID *string `json:"channel_account_id,omitempty"`
|
2019-09-02 19:47:52 +02:00
|
|
|
AccountID *string `json:"account_id,omitempty"`
|
2019-04-03 00:44:30 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 21:04:37 +02:00
|
|
|
func (d *Client) StreamCreate(name, filePath string, bid float64, options StreamCreateOptions) (*TransactionSummary, error) {
|
|
|
|
response := new(TransactionSummary)
|
2019-04-03 00:44:30 +02:00
|
|
|
args := struct {
|
2019-04-30 08:08:40 +02:00
|
|
|
Name string `json:"name"`
|
|
|
|
Bid string `json:"bid"`
|
|
|
|
FilePath string `json:"file_path,omitempty"`
|
|
|
|
FileSize *string `json:"file_size,omitempty"`
|
2019-05-08 21:14:14 +02:00
|
|
|
IncludeProtoBuf bool `json:"include_protobuf"`
|
2019-06-11 18:40:48 +02:00
|
|
|
Blocking bool `json:"blocking"`
|
2019-04-03 00:44:30 +02:00
|
|
|
*StreamCreateOptions `json:",flatten"`
|
|
|
|
}{
|
|
|
|
Name: name,
|
|
|
|
FilePath: filePath,
|
|
|
|
Bid: fmt.Sprintf("%.6f", bid),
|
2019-04-30 08:08:40 +02:00
|
|
|
IncludeProtoBuf: true,
|
2019-06-11 18:40:48 +02:00
|
|
|
Blocking: true,
|
2019-04-03 00:44:30 +02:00
|
|
|
StreamCreateOptions: &options,
|
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "stream_create", structs.Map(args))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) StreamAbandon(txID string, nOut uint64, accountID *string, blocking bool) (*ClaimAbandonResponse, error) {
|
|
|
|
response := new(ClaimAbandonResponse)
|
2019-05-30 00:18:23 +02:00
|
|
|
err := d.call(response, "stream_abandon", map[string]interface{}{
|
2019-04-21 20:29:25 +02:00
|
|
|
"txid": txID,
|
|
|
|
"nout": nOut,
|
|
|
|
"account_id": accountID,
|
|
|
|
"include_protobuf": true,
|
2019-06-11 18:40:48 +02:00
|
|
|
"blocking": true,
|
2019-01-18 21:52:57 +01:00
|
|
|
})
|
2019-04-03 00:44:30 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type StreamUpdateOptions struct {
|
|
|
|
ClearTags *bool `json:"clear_tags,omitempty"`
|
|
|
|
ClearLanguages *bool `json:"clear_languages,omitempty"`
|
|
|
|
ClearLocations *bool `json:"clear_locations,omitempty"`
|
2019-05-08 21:14:14 +02:00
|
|
|
Name *string `json:"name,omitempty"`
|
2019-04-03 00:44:30 +02:00
|
|
|
FilePath *string `json:"file_path,omitempty"`
|
2019-05-08 21:14:14 +02:00
|
|
|
FileSize *uint64 `json:"file_size,omitempty"`
|
|
|
|
Bid *string `json:"bid,omitempty"`
|
2019-04-03 00:44:30 +02:00
|
|
|
*StreamCreateOptions `json:",flatten"`
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
|
|
|
|
2019-05-08 21:14:14 +02:00
|
|
|
func (d *Client) StreamUpdate(claimID string, options StreamUpdateOptions) (*TransactionSummary, error) {
|
|
|
|
response := new(TransactionSummary)
|
2019-04-03 00:44:30 +02:00
|
|
|
args := struct {
|
|
|
|
ClaimID string `json:"claim_id"`
|
2019-04-21 20:29:25 +02:00
|
|
|
IncludeProtoBuf bool `json:"include_protobuf"`
|
2019-04-03 00:44:30 +02:00
|
|
|
*StreamUpdateOptions `json:",flatten"`
|
2019-06-11 18:40:48 +02:00
|
|
|
Blocking bool `json:"blocking"`
|
2019-04-03 00:44:30 +02:00
|
|
|
}{
|
|
|
|
ClaimID: claimID,
|
2019-04-21 20:29:25 +02:00
|
|
|
IncludeProtoBuf: true,
|
2019-04-03 00:44:30 +02:00
|
|
|
StreamUpdateOptions: &options,
|
2019-06-11 18:40:48 +02:00
|
|
|
Blocking: true,
|
2019-04-03 00:44:30 +02:00
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
2019-05-08 21:14:14 +02:00
|
|
|
return response, d.call(response, "stream_update", structs.Map(args))
|
2019-04-03 00:44:30 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:29:14 +02:00
|
|
|
func (d *Client) ChannelAbandon(txID string, nOut uint64, accountID *string, blocking bool) (*TransactionSummary, error) {
|
|
|
|
response := new(TransactionSummary)
|
|
|
|
err := d.call(response, "channel_abandon", map[string]interface{}{
|
2019-04-21 20:29:25 +02:00
|
|
|
"txid": txID,
|
|
|
|
"nout": nOut,
|
|
|
|
"account_id": accountID,
|
|
|
|
"include_protobuf": true,
|
2019-06-11 18:40:48 +02:00
|
|
|
"blocking": true,
|
2019-01-18 21:52:57 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return response, nil
|
|
|
|
}
|
|
|
|
|
2019-09-24 18:31:01 +02:00
|
|
|
func (d *Client) AddressList(account *string, address *string) (*AddressListResponse, error) {
|
2019-01-18 21:52:57 +01:00
|
|
|
response := new(AddressListResponse)
|
2019-09-24 18:31:01 +02:00
|
|
|
|
|
|
|
args := struct {
|
|
|
|
AccountID *string `json:"account_id,omitempty"`
|
|
|
|
Address *string `json:"address,omitempty"`
|
|
|
|
}{
|
|
|
|
AccountID: account,
|
|
|
|
Address: address,
|
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "address_list", structs.Map(args))
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
|
|
|
|
2019-05-08 21:14:14 +02:00
|
|
|
func (d *Client) ClaimList(account *string, page uint64, pageSize uint64) (*ClaimListResponse, error) {
|
2019-01-22 18:48:04 +01:00
|
|
|
if page == 0 {
|
|
|
|
return nil, errors.Err("pages start from 1")
|
|
|
|
}
|
2019-05-08 21:14:14 +02:00
|
|
|
response := new(ClaimListResponse)
|
2019-04-03 00:44:30 +02:00
|
|
|
err := d.call(response, "claim_list", map[string]interface{}{
|
2019-05-08 21:14:14 +02:00
|
|
|
"account_id": account,
|
|
|
|
"page": page,
|
|
|
|
"page_size": pageSize,
|
|
|
|
"include_protobuf": true,
|
2019-01-18 21:52:57 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return response, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) Status() (*StatusResponse, error) {
|
|
|
|
response := new(StatusResponse)
|
|
|
|
return response, d.call(response, "status", map[string]interface{}{})
|
|
|
|
}
|
|
|
|
|
2019-09-06 00:16:49 +02:00
|
|
|
func (d *Client) TransactionList(account *string) (*TransactionListResponse, error) {
|
|
|
|
response := new(TransactionListResponse)
|
|
|
|
return response, d.call(response, "transaction_list", map[string]interface{}{
|
|
|
|
"account_id": account,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:48:04 +01:00
|
|
|
func (d *Client) UTXOList(account *string) (*UTXOListResponse, error) {
|
2019-01-18 21:52:57 +01:00
|
|
|
response := new(UTXOListResponse)
|
|
|
|
return response, d.call(response, "utxo_list", map[string]interface{}{
|
|
|
|
"account_id": account,
|
2019-01-22 18:48:04 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-06 00:16:49 +02:00
|
|
|
func (d *Client) UTXORelease(account *string) (*UTXOReleaseResponse, error) {
|
|
|
|
response := new(UTXOReleaseResponse)
|
|
|
|
return response, d.call(response, "utxo_release", map[string]interface{}{
|
|
|
|
"account_id": account,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-04-21 20:29:25 +02:00
|
|
|
func (d *Client) Get(uri string) (*GetResponse, error) {
|
|
|
|
response := new(GetResponse)
|
|
|
|
return response, d.call(response, "get", map[string]interface{}{
|
|
|
|
"uri": uri,
|
|
|
|
"include_protobuf": true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) FileList() (*FileListResponse, error) {
|
|
|
|
response := new(FileListResponse)
|
|
|
|
return response, d.call(response, "file_list", map[string]interface{}{
|
|
|
|
"include_protobuf": true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:48:04 +01:00
|
|
|
func (d *Client) Version() (*VersionResponse, error) {
|
|
|
|
response := new(VersionResponse)
|
|
|
|
return response, d.call(response, "version", map[string]interface{}{})
|
|
|
|
}
|
|
|
|
|
2019-02-22 19:09:13 +01:00
|
|
|
func (d *Client) Resolve(urls string) (*ResolveResponse, error) {
|
2019-01-22 18:48:04 +01:00
|
|
|
response := new(ResolveResponse)
|
|
|
|
return response, d.call(response, "resolve", map[string]interface{}{
|
2019-04-21 20:29:25 +02:00
|
|
|
"urls": urls,
|
|
|
|
"include_protobuf": true,
|
2019-01-22 18:48:04 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-04-03 00:44:30 +02:00
|
|
|
func (d *Client) ClaimSearch(claimName, claimID, txid *string, nout *uint) (*ClaimSearchResponse, error) {
|
|
|
|
response := new(ClaimSearchResponse)
|
2019-08-14 17:03:21 +02:00
|
|
|
args := struct {
|
|
|
|
ClaimID *string `json:"claim_id,omitempty"`
|
|
|
|
TXID *string `json:"txid,omitempty"`
|
|
|
|
Nout *uint `json:"nout,omitempty"`
|
|
|
|
Name *string `json:"name,omitempty"`
|
|
|
|
}{
|
|
|
|
ClaimID: claimID,
|
|
|
|
TXID: txid,
|
|
|
|
Nout: nout,
|
|
|
|
Name: claimName,
|
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "claim_search", structs.Map(args))
|
2019-01-18 21:52:57 +01:00
|
|
|
}
|
2019-07-26 05:33:52 +02:00
|
|
|
|
|
|
|
func (d *Client) ChannelExport(channelClaimID string, channelName, accountID *string) (*ChannelExportResponse, error) {
|
|
|
|
response := new(ChannelExportResponse)
|
|
|
|
return response, d.call(response, "channel_export", map[string]interface{}{
|
|
|
|
"channel_id": channelClaimID,
|
|
|
|
"channel_name": channelName,
|
|
|
|
"account_id": accountID,
|
|
|
|
})
|
|
|
|
}
|
2019-08-27 00:25:47 +02:00
|
|
|
|
|
|
|
func (d *Client) SupportList(accountID *string, page uint64, pageSize uint64) (*SupportListResponse, error) {
|
|
|
|
response := new(SupportListResponse)
|
|
|
|
return response, d.call(response, "support_list", map[string]interface{}{
|
|
|
|
"account_id": accountID,
|
|
|
|
"page": page,
|
|
|
|
"page_size": pageSize,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) SupportCreate(claimID string, amount string, tip *bool, accountID *string, fundingAccountIDs []string) (*TransactionSummary, error) {
|
|
|
|
response := new(TransactionSummary)
|
|
|
|
args := struct {
|
|
|
|
ClaimID string `json:"claim_id"`
|
|
|
|
Amount string `json:"amount"`
|
|
|
|
Tip *bool `json:"tip,omitempty"`
|
|
|
|
AccountID *string `json:"account_id,omitempty"`
|
|
|
|
FundingAccountIDs []string `json:"funding_account_ids,omitempty"`
|
|
|
|
Preview bool `json:"preview,omitempty"`
|
|
|
|
Blocking bool `json:"blocking,omitempty"`
|
|
|
|
}{
|
|
|
|
ClaimID: claimID,
|
|
|
|
AccountID: accountID,
|
|
|
|
Blocking: true,
|
|
|
|
Amount: amount,
|
|
|
|
FundingAccountIDs: fundingAccountIDs,
|
|
|
|
Preview: false,
|
|
|
|
Tip: tip,
|
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "support_create", structs.Map(args))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) SupportAbandon(claimID *string, txid *string, nout *uint, keep *string, accountID *string) (*TransactionSummary, error) {
|
|
|
|
if claimID == nil && (txid == nil || nout == nil) {
|
|
|
|
return nil, errors.Err("either claimID or txid+nout must be supplied")
|
|
|
|
}
|
|
|
|
response := new(TransactionSummary)
|
|
|
|
args := struct {
|
|
|
|
ClaimID *string `json:"claim_id,omitempty"`
|
|
|
|
TxID *string `json:"claim_id,omitempty"`
|
|
|
|
Nout *uint `json:"nout,omitempty"`
|
|
|
|
AccountID *string `json:"account_id,omitempty"`
|
|
|
|
Preview bool `json:"preview,omitempty"`
|
|
|
|
Blocking bool `json:"blocking,omitempty"`
|
|
|
|
}{
|
|
|
|
ClaimID: claimID,
|
|
|
|
AccountID: accountID,
|
|
|
|
Nout: nout,
|
|
|
|
TxID: txid,
|
|
|
|
Blocking: true,
|
|
|
|
Preview: false,
|
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "support_abandon", structs.Map(args))
|
|
|
|
}
|
2019-09-24 20:35:04 +02:00
|
|
|
|
|
|
|
func (d *Client) AccountAdd(accountName string, seed *string, privateKey *string, publicKey *string, singleKey *bool, walletID *string) (*Account, error) {
|
|
|
|
response := new(Account)
|
|
|
|
|
|
|
|
args := struct {
|
|
|
|
AccountName string `json:"account_name"`
|
|
|
|
Seed *string `json:"seed,omitempty"`
|
|
|
|
PrivateKey *string `json:"private_key,omitempty"`
|
|
|
|
PublicKey *string `json:"public_key,omitempty"`
|
|
|
|
SingleKey *bool `json:"single_key,omitempty"`
|
|
|
|
WalletID *string `json:"wallet_id,omitempty"`
|
|
|
|
}{
|
|
|
|
AccountName: accountName,
|
|
|
|
Seed: seed,
|
|
|
|
PrivateKey: privateKey,
|
|
|
|
PublicKey: publicKey,
|
|
|
|
SingleKey: singleKey,
|
|
|
|
WalletID: walletID,
|
|
|
|
}
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "account_add", structs.Map(args))
|
|
|
|
}
|
2019-09-25 12:47:12 +02:00
|
|
|
|
|
|
|
type WalletCreateOpts struct {
|
2019-10-02 09:56:37 +02:00
|
|
|
ID string `json:"wallet_id"`
|
|
|
|
SkipOnStartup bool `json:"skip_on_startup,omitempty"`
|
|
|
|
CreateAccount bool `json:"create_account,omitempty"`
|
|
|
|
SingleKey bool `json:"single_key,omitempty"`
|
2019-09-25 12:47:12 +02:00
|
|
|
}
|
|
|
|
|
2019-09-25 13:00:37 +02:00
|
|
|
func (d *Client) WalletCreate(id string, opts *WalletCreateOpts) (*Wallet, error) {
|
|
|
|
response := new(Wallet)
|
2019-09-25 12:47:12 +02:00
|
|
|
if opts == nil {
|
|
|
|
opts = &WalletCreateOpts{}
|
|
|
|
}
|
2019-10-02 09:56:37 +02:00
|
|
|
opts.ID = id
|
|
|
|
structs.DefaultTagName = "json"
|
|
|
|
return response, d.call(response, "wallet_create", structs.Map(opts))
|
2019-09-25 12:47:12 +02:00
|
|
|
}
|
|
|
|
|
2019-09-25 13:00:37 +02:00
|
|
|
func (d *Client) WalletAdd(id string) (*Wallet, error) {
|
|
|
|
response := new(Wallet)
|
2019-09-25 12:47:12 +02:00
|
|
|
return response, d.call(response, "wallet_add", map[string]interface{}{"wallet_id": id})
|
|
|
|
}
|
|
|
|
|
2019-09-25 13:00:37 +02:00
|
|
|
func (d *Client) WalletList(id string) (*WalletList, error) {
|
|
|
|
response := new(WalletList)
|
|
|
|
params := map[string]interface{}{}
|
|
|
|
if id != "" {
|
|
|
|
params["wallet_id"] = id
|
|
|
|
}
|
|
|
|
return response, d.call(response, "wallet_list", params)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Client) WalletRemove(id string) (*Wallet, error) {
|
|
|
|
response := new(Wallet)
|
2019-09-25 12:47:12 +02:00
|
|
|
return response, d.call(response, "wallet_remove", map[string]interface{}{"wallet_id": id})
|
|
|
|
}
|