Skip to content

Commit 06764c3

Browse files
committed
add support for SDK 0.48.1
1 parent b68c49a commit 06764c3

File tree

3 files changed

+144
-75
lines changed

3 files changed

+144
-75
lines changed

extras/jsonrpc/daemon.go

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,21 @@ func (d *Client) SetRPCTimeout(timeout time.Duration) {
138138
// NEW SDK
139139
//============================================
140140

141-
func (d *Client) AccountList() (*AccountListResponse, error) {
141+
func (d *Client) AccountList(page uint64, pageSize uint64) (*AccountListResponse, error) {
142142
response := new(AccountListResponse)
143-
return response, d.call(response, "account_list", map[string]interface{}{})
143+
return response, d.call(response, "account_list", map[string]interface{}{
144+
"page": page,
145+
"page_size": pageSize,
146+
})
144147
}
145148

146149
func (d *Client) AccountListForWallet(walletID string) (*AccountListResponse, error) {
147150
response := new(AccountListResponse)
148151
return response, d.call(response, "account_list", map[string]interface{}{"wallet_id": walletID})
149152
}
150153

151-
func (d *Client) SingleAccountList(accountID string) (*Account, error) {
152-
response := new(Account)
154+
func (d *Client) SingleAccountList(accountID string) (*AccountListResponse, error) {
155+
response := new(AccountListResponse)
153156
return response, d.call(response, "account_list", map[string]interface{}{"account_id": accountID})
154157
}
155158

@@ -416,25 +419,31 @@ func (d *Client) ChannelAbandon(txID string, nOut uint64, accountID *string, blo
416419
return response, nil
417420
}
418421

419-
func (d *Client) AddressList(account *string, address *string) (*AddressListResponse, error) {
422+
func (d *Client) AddressList(account *string, address *string, page uint64, pageSize uint64) (*AddressListResponse, error) {
420423
response := new(AddressListResponse)
421424

422425
args := struct {
423426
AccountID *string `json:"account_id,omitempty"`
424427
Address *string `json:"address,omitempty"`
428+
Page uint64 `json:"page"`
429+
PageSize uint64 `json:"page_size"`
425430
}{
426431
AccountID: account,
427432
Address: address,
433+
Page: page,
434+
PageSize: pageSize,
428435
}
429436
structs.DefaultTagName = "json"
430437
return response, d.call(response, "address_list", structs.Map(args))
431438
}
432439

433-
func (d *Client) StreamList(account *string) (*StreamListResponse, error) {
440+
func (d *Client) StreamList(account *string, page uint64, pageSize uint64) (*StreamListResponse, error) {
434441
response := new(StreamListResponse)
435442
err := d.call(response, "stream_list", map[string]interface{}{
436443
"account_id": account,
437444
"include_protobuf": true,
445+
"page": page,
446+
"page_size": pageSize,
438447
})
439448
if err != nil {
440449
return nil, err
@@ -464,17 +473,21 @@ func (d *Client) Status() (*StatusResponse, error) {
464473
return response, d.call(response, "status", map[string]interface{}{})
465474
}
466475

467-
func (d *Client) TransactionList(account *string) (*TransactionListResponse, error) {
476+
func (d *Client) TransactionList(account *string, page uint64, pageSize uint64) (*TransactionListResponse, error) {
468477
response := new(TransactionListResponse)
469478
return response, d.call(response, "transaction_list", map[string]interface{}{
470479
"account_id": account,
480+
"page": page,
481+
"page_size": pageSize,
471482
})
472483
}
473484

474-
func (d *Client) UTXOList(account *string) (*UTXOListResponse, error) {
485+
func (d *Client) UTXOList(account *string, page uint64, pageSize uint64) (*UTXOListResponse, error) {
475486
response := new(UTXOListResponse)
476487
return response, d.call(response, "utxo_list", map[string]interface{}{
477488
"account_id": account,
489+
"page": page,
490+
"page_size": pageSize,
478491
})
479492
}
480493

@@ -493,10 +506,12 @@ func (d *Client) Get(uri string) (*GetResponse, error) {
493506
})
494507
}
495508

496-
func (d *Client) FileList() (*FileListResponse, error) {
509+
func (d *Client) FileList(page uint64, pageSize uint64) (*FileListResponse, error) {
497510
response := new(FileListResponse)
498511
return response, d.call(response, "file_list", map[string]interface{}{
499512
"include_protobuf": true,
513+
"page": page,
514+
"page_size": pageSize,
500515
})
501516
}
502517

@@ -513,20 +528,24 @@ func (d *Client) Resolve(urls string) (*ResolveResponse, error) {
513528
})
514529
}
515530

516-
func (d *Client) ClaimSearch(claimName, claimID, txid *string, nout *uint) (*ClaimSearchResponse, error) {
531+
func (d *Client) ClaimSearch(claimName, claimID, txid *string, nout *uint, page uint64, pageSize uint64) (*ClaimSearchResponse, error) {
517532
response := new(ClaimSearchResponse)
518533
args := struct {
519534
ClaimID *string `json:"claim_id,omitempty"`
520535
TXID *string `json:"txid,omitempty"`
521536
Nout *uint `json:"nout,omitempty"`
522537
Name *string `json:"name,omitempty"`
523538
IncludeProtobuf bool `json:"include_protobuf"`
539+
Page uint64 `json:"page"`
540+
PageSize uint64 `json:"page_size"`
524541
}{
525542
ClaimID: claimID,
526543
TXID: txid,
527544
Nout: nout,
528545
Name: claimName,
529546
IncludeProtobuf: true,
547+
Page: page,
548+
PageSize: pageSize,
530549
}
531550
structs.DefaultTagName = "json"
532551
return response, d.call(response, "claim_search", structs.Map(args))
@@ -558,7 +577,7 @@ func (d *Client) SupportList(accountID *string, page uint64, pageSize uint64) (*
558577
})
559578
}
560579

561-
func (d *Client) SupportCreate(claimID string, amount string, tip *bool, accountID *string, fundingAccountIDs []string) (*TransactionSummary, error) {
580+
func (d *Client) SupportCreate(claimID string, amount string, tip *bool, accountID *string, fundingAccountIDs []string, walletID *string) (*TransactionSummary, error) {
562581
response := new(TransactionSummary)
563582
args := struct {
564583
ClaimID string `json:"claim_id"`
@@ -568,6 +587,7 @@ func (d *Client) SupportCreate(claimID string, amount string, tip *bool, account
568587
FundingAccountIDs []string `json:"funding_account_ids,omitempty"`
569588
Preview bool `json:"preview,omitempty"`
570589
Blocking bool `json:"blocking,omitempty"`
590+
WalletID *string `json:"wallet_id,omitempty"`
571591
}{
572592
ClaimID: claimID,
573593
AccountID: accountID,
@@ -649,9 +669,13 @@ func (d *Client) WalletAdd(id string) (*Wallet, error) {
649669
return response, d.call(response, "wallet_add", map[string]interface{}{"wallet_id": id})
650670
}
651671

652-
func (d *Client) WalletList(id string) (*WalletList, error) {
672+
func (d *Client) WalletList(id string, page uint64, pageSize uint64) (*WalletList, error) {
653673
response := new(WalletList)
654-
params := map[string]interface{}{}
674+
params := map[string]interface {
675+
}{
676+
"page": page,
677+
"page_size": pageSize,
678+
}
655679
if id != "" {
656680
params["wallet_id"] = id
657681
}

extras/jsonrpc/daemon_test.go

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ func TestMain(m *testing.M) {
3030

3131
func TestClient_AccountFund(t *testing.T) {
3232
d := NewClient("")
33-
accounts, err := d.AccountList()
33+
accounts, err := d.AccountList(1, 20)
3434
if err != nil {
3535
t.Error(err)
3636
return
3737
}
38-
account := (accounts.LBCRegtest)[0].ID
38+
account := (accounts.Items)[0].ID
3939
balanceString, err := d.AccountBalance(&account)
4040
if err != nil {
4141
t.Error(err)
@@ -56,7 +56,7 @@ func TestClient_AccountFund(t *testing.T) {
5656

5757
func TestClient_AccountList(t *testing.T) {
5858
d := NewClient("")
59-
got, err := d.AccountList()
59+
got, err := d.AccountList(1, 20)
6060
if err != nil {
6161
t.Error(err)
6262
return
@@ -72,13 +72,16 @@ func TestClient_SingleAccountList(t *testing.T) {
7272
t.Fatal(err)
7373
}
7474
account, err := d.SingleAccountList(createdAccount.ID)
75+
if err != nil {
76+
t.Error(err)
77+
}
7578
prettyPrint(*createdAccount)
7679
prettyPrint(*account)
7780
if err != nil {
7881
t.Fatal(err)
7982
}
80-
if account.Name != name {
81-
t.Fatalf("account name mismatch: %v != %v", account.Name, name)
83+
if account.Items[0].Name != name {
84+
t.Fatalf("account name mismatch: %v != %v", account.Items[0].Name, name)
8285
}
8386
}
8487

@@ -116,7 +119,7 @@ var channelID string
116119

117120
func TestClient_ChannelCreate(t *testing.T) {
118121
d := NewClient("")
119-
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
122+
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 1.337, ChannelCreateOptions{
120123
ClaimCreateOptions: ClaimCreateOptions{
121124
Title: util.PtrToString("Mess with the channels"),
122125
Description: util.PtrToString("And you'll get what you deserve"),
@@ -150,7 +153,14 @@ func TestClient_StreamCreate(t *testing.T) {
150153
return
151154
}
152155
address := string(*addressResponse)
153-
got, err := d.StreamCreate("test"+fmt.Sprintf("%d", time.Now().Unix()), "/home/niko/Downloads/IMG_20171012_205120.jpg", 14.37, StreamCreateOptions{
156+
f, e := os.OpenFile("/tmp/test.txt", os.O_RDONLY|os.O_CREATE, 0666)
157+
if e != nil {
158+
t.Error(e)
159+
return
160+
}
161+
162+
_, _ = f.WriteString("test")
163+
got, err := d.StreamCreate("test"+fmt.Sprintf("%d", time.Now().Unix()), "/tmp/test.txt", 1.437, StreamCreateOptions{
154164
ClaimCreateOptions: ClaimCreateOptions{
155165
Title: util.PtrToString("This is a Test Title" + fmt.Sprintf("%d", time.Now().Unix())),
156166
Description: util.PtrToString("My Special Description"),
@@ -261,7 +271,7 @@ func TestClient_ChannelAbandon(t *testing.T) {
261271

262272
func TestClient_AddressList(t *testing.T) {
263273
d := NewClient("")
264-
got, err := d.AddressList(nil, nil)
274+
got, err := d.AddressList(nil, nil, 1, 20)
265275
if err != nil {
266276
t.Error(err)
267277
return
@@ -283,7 +293,7 @@ func TestClient_ClaimList(t *testing.T) {
283293
func TestClient_StreamList(t *testing.T) {
284294
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
285295
d := NewClient("")
286-
got, err := d.StreamList(nil)
296+
got, err := d.StreamList(nil, 1, 20)
287297
if err != nil {
288298
t.Error(err)
289299
return
@@ -294,7 +304,7 @@ func TestClient_StreamList(t *testing.T) {
294304
func TestClient_TransactionList(t *testing.T) {
295305
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
296306
d := NewClient("")
297-
got, err := d.TransactionList(nil)
307+
got, err := d.TransactionList(nil, 1, 20)
298308
if err != nil {
299309
t.Error(err)
300310
return
@@ -327,7 +337,7 @@ func TestClient_SupportTest(t *testing.T) {
327337
return
328338
}
329339
time.Sleep(10 * time.Second)
330-
got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil)
340+
got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil, nil)
331341
if err != nil {
332342
t.Error(err)
333343
return
@@ -360,7 +370,7 @@ func TestClient_SupportTest(t *testing.T) {
360370

361371
func TestClient_ClaimSearch(t *testing.T) {
362372
d := NewClient("")
363-
got, err := d.ClaimSearch(nil, util.PtrToString(channelID), nil, nil)
373+
got, err := d.ClaimSearch(nil, util.PtrToString(channelID), nil, nil, 1, 20)
364374
if err != nil {
365375
t.Error(err)
366376
return
@@ -380,7 +390,7 @@ func TestClient_Status(t *testing.T) {
380390

381391
func TestClient_UTXOList(t *testing.T) {
382392
d := NewClient("")
383-
got, err := d.UTXOList(nil)
393+
got, err := d.UTXOList(nil, 1, 20)
384394
if err != nil {
385395
t.Error(err)
386396
return
@@ -412,7 +422,7 @@ func TestClient_GetFile(t *testing.T) {
412422
func TestClient_FileList(t *testing.T) {
413423
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
414424
d := NewClient("")
415-
got, err := d.FileList()
425+
got, err := d.FileList(1, 20)
416426
if err != nil {
417427
t.Error(err)
418428
return
@@ -428,21 +438,17 @@ func TestClient_Resolve(t *testing.T) {
428438
t.Error(err)
429439
return
430440
}
431-
if err != nil {
432-
t.Error(err)
433-
return
434-
}
435441
prettyPrint(*got)
436442
}
437443

438444
func TestClient_AccountSet(t *testing.T) {
439445
d := NewClient("")
440-
accounts, err := d.AccountList()
446+
accounts, err := d.AccountList(1, 20)
441447
if err != nil {
442448
t.Error(err)
443449
return
444450
}
445-
account := (accounts.LBCRegtest)[0].ID
451+
account := (accounts.Items)[0].ID
446452

447453
got, err := d.AccountSet(account, AccountSettings{ChangeMaxUses: util.PtrToInt(10000)})
448454
if err != nil {
@@ -506,7 +512,7 @@ func TestClient_AccountRemove(t *testing.T) {
506512

507513
account, err := d.SingleAccountList(createdAccount.ID)
508514
if err != nil {
509-
if strings.HasPrefix(err.Error(), "Error in daemon: Couldn't find account") {
515+
if strings.Contains(err.Error(), "Couldn't find account:") {
510516
prettyPrint(*removedAccount)
511517
return
512518
}
@@ -550,6 +556,9 @@ func TestClient_ChannelImport(t *testing.T) {
550556
t.Error(err)
551557
}
552558
channels, err := d.ChannelList(nil, 1, 50, nil)
559+
if err != nil {
560+
t.Error(err)
561+
}
553562
seen := false
554563
for _, c := range channels.Items {
555564
if c.Name == channelName {
@@ -567,10 +576,12 @@ func TestClient_ChannelImportWithWalletID(t *testing.T) {
567576

568577
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
569578
wallet, err := d.WalletCreate(id, nil)
570-
579+
if err != nil {
580+
t.Error(err)
581+
}
571582
// A channel created just for automated testing purposes
572583
channelName := "@LbryAutomatedTestChannel"
573-
channelkey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" +
584+
channelKey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" +
574585
"oKkfb99PgGK5efrZeYqaxg4X5XRJMJ6gKC8hqKcnwhYkmKDXmoBDNgd2ccZ9jhP8z" +
575586
"HG3NJorAN9Hh4XMyBc5goBLZYYvC9MYvBmT3Fcteb5saqMvmQxFURv74NqXLQZC1t" +
576587
"p6iRZKfTj77Pd5gsBsCYAbVmCqzbm5m1hHkUmfFEZVGcQNTYCDwZn543xSMYvSPnJ" +
@@ -582,11 +593,14 @@ func TestClient_ChannelImportWithWalletID(t *testing.T) {
582593
"hxsFwGUyNNno8eiqrrYmpbJGEwwK3S4437JboAUEFPdMNn8zNQWZcLLVrK9KyQeKM" +
583594
"XpKkf4zJV6sZJ7gBMpzvPL18ULEgXTy7VsNBKmsfC1rM4WVG9ri1UixEcLDS79foC" +
584595
"Jb3FnSr1T4MRKESeN3W"
585-
response, err := d.ChannelImport(channelkey, &wallet.ID)
596+
response, err := d.ChannelImport(channelKey, &wallet.ID)
586597
if err != nil {
587598
t.Error(err)
588599
}
589600
channels, err := d.ChannelList(nil, 1, 50, &wallet.ID)
601+
if err != nil {
602+
t.Error(err)
603+
}
590604
seen := false
591605
for _, c := range channels.Items {
592606
if c.Name == channelName {
@@ -627,7 +641,7 @@ func TestClient_WalletCreateWithOpts(t *testing.T) {
627641
}
628642
prettyPrint(wallet)
629643
prettyPrint(accounts)
630-
if accounts.LBCMainnet[0].Name == "" {
644+
if accounts.Items[0].Name == "" {
631645
t.Fatalf("account name is empty")
632646
}
633647
}
@@ -636,7 +650,7 @@ func TestClient_WalletList(t *testing.T) {
636650
d := NewClient("")
637651

638652
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
639-
wList, err := d.WalletList(id)
653+
wList, err := d.WalletList(id, 1, 20)
640654
if err == nil {
641655
t.Fatalf("wallet %v was unexpectedly found", id)
642656
}
@@ -649,15 +663,15 @@ func TestClient_WalletList(t *testing.T) {
649663
t.Fatal(err)
650664
}
651665

652-
wList, err = d.WalletList(id)
666+
wList, err = d.WalletList(id, 1, 20)
653667
if err != nil {
654668
t.Fatal(err)
655669
}
656-
if len(*wList) < 1 {
670+
if len(wList.Items) < 1 {
657671
t.Fatal("wallet list is empty")
658672
}
659-
if (*wList)[0].ID != id {
660-
t.Fatalf("wallet ID mismatch, expected %q, got %q", id, (*wList)[0].ID)
673+
if (wList.Items)[0].ID != id {
674+
t.Fatalf("wallet ID mismatch, expected %q, got %q", id, (wList.Items)[0].ID)
661675
}
662676
}
663677

0 commit comments

Comments
 (0)