diff --git a/extras/jsonrpc/daemon.go b/extras/jsonrpc/daemon.go index f134d75..b66bfa6 100644 --- a/extras/jsonrpc/daemon.go +++ b/extras/jsonrpc/daemon.go @@ -138,9 +138,12 @@ func (d *Client) SetRPCTimeout(timeout time.Duration) { // NEW SDK //============================================ -func (d *Client) AccountList() (*AccountListResponse, error) { +func (d *Client) AccountList(page uint64, pageSize uint64) (*AccountListResponse, error) { response := new(AccountListResponse) - return response, d.call(response, "account_list", map[string]interface{}{}) + return response, d.call(response, "account_list", map[string]interface{}{ + "page": page, + "page_size": pageSize, + }) } func (d *Client) AccountListForWallet(walletID string) (*AccountListResponse, error) { @@ -148,8 +151,8 @@ func (d *Client) AccountListForWallet(walletID string) (*AccountListResponse, er return response, d.call(response, "account_list", map[string]interface{}{"wallet_id": walletID}) } -func (d *Client) SingleAccountList(accountID string) (*Account, error) { - response := new(Account) +func (d *Client) SingleAccountList(accountID string) (*AccountListResponse, error) { + response := new(AccountListResponse) return response, d.call(response, "account_list", map[string]interface{}{"account_id": accountID}) } @@ -416,25 +419,31 @@ func (d *Client) ChannelAbandon(txID string, nOut uint64, accountID *string, blo return response, nil } -func (d *Client) AddressList(account *string, address *string) (*AddressListResponse, error) { +func (d *Client) AddressList(account *string, address *string, page uint64, pageSize uint64) (*AddressListResponse, error) { response := new(AddressListResponse) args := struct { AccountID *string `json:"account_id,omitempty"` Address *string `json:"address,omitempty"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` }{ AccountID: account, Address: address, + Page: page, + PageSize: pageSize, } structs.DefaultTagName = "json" return response, d.call(response, "address_list", structs.Map(args)) } -func (d *Client) StreamList(account *string) (*StreamListResponse, error) { +func (d *Client) StreamList(account *string, page uint64, pageSize uint64) (*StreamListResponse, error) { response := new(StreamListResponse) err := d.call(response, "stream_list", map[string]interface{}{ "account_id": account, "include_protobuf": true, + "page": page, + "page_size": pageSize, }) if err != nil { return nil, err @@ -464,17 +473,21 @@ func (d *Client) Status() (*StatusResponse, error) { return response, d.call(response, "status", map[string]interface{}{}) } -func (d *Client) TransactionList(account *string) (*TransactionListResponse, error) { +func (d *Client) TransactionList(account *string, page uint64, pageSize uint64) (*TransactionListResponse, error) { response := new(TransactionListResponse) return response, d.call(response, "transaction_list", map[string]interface{}{ "account_id": account, + "page": page, + "page_size": pageSize, }) } -func (d *Client) UTXOList(account *string) (*UTXOListResponse, error) { +func (d *Client) UTXOList(account *string, page uint64, pageSize uint64) (*UTXOListResponse, error) { response := new(UTXOListResponse) return response, d.call(response, "utxo_list", map[string]interface{}{ "account_id": account, + "page": page, + "page_size": pageSize, }) } @@ -493,10 +506,12 @@ func (d *Client) Get(uri string) (*GetResponse, error) { }) } -func (d *Client) FileList() (*FileListResponse, error) { +func (d *Client) FileList(page uint64, pageSize uint64) (*FileListResponse, error) { response := new(FileListResponse) return response, d.call(response, "file_list", map[string]interface{}{ "include_protobuf": true, + "page": page, + "page_size": pageSize, }) } @@ -513,7 +528,7 @@ func (d *Client) Resolve(urls string) (*ResolveResponse, error) { }) } -func (d *Client) ClaimSearch(claimName, claimID, txid *string, nout *uint) (*ClaimSearchResponse, error) { +func (d *Client) ClaimSearch(claimName, claimID, txid *string, nout *uint, page uint64, pageSize uint64) (*ClaimSearchResponse, error) { response := new(ClaimSearchResponse) args := struct { ClaimID *string `json:"claim_id,omitempty"` @@ -521,12 +536,16 @@ func (d *Client) ClaimSearch(claimName, claimID, txid *string, nout *uint) (*Cla Nout *uint `json:"nout,omitempty"` Name *string `json:"name,omitempty"` IncludeProtobuf bool `json:"include_protobuf"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` }{ ClaimID: claimID, TXID: txid, Nout: nout, Name: claimName, IncludeProtobuf: true, + Page: page, + PageSize: pageSize, } structs.DefaultTagName = "json" return response, d.call(response, "claim_search", structs.Map(args)) @@ -558,7 +577,7 @@ func (d *Client) SupportList(accountID *string, page uint64, pageSize uint64) (* }) } -func (d *Client) SupportCreate(claimID string, amount string, tip *bool, accountID *string, fundingAccountIDs []string) (*TransactionSummary, error) { +func (d *Client) SupportCreate(claimID string, amount string, tip *bool, accountID *string, fundingAccountIDs []string, walletID *string) (*TransactionSummary, error) { response := new(TransactionSummary) args := struct { ClaimID string `json:"claim_id"` @@ -568,6 +587,7 @@ func (d *Client) SupportCreate(claimID string, amount string, tip *bool, account FundingAccountIDs []string `json:"funding_account_ids,omitempty"` Preview bool `json:"preview,omitempty"` Blocking bool `json:"blocking,omitempty"` + WalletID *string `json:"wallet_id,omitempty"` }{ ClaimID: claimID, AccountID: accountID, @@ -649,9 +669,13 @@ func (d *Client) WalletAdd(id string) (*Wallet, error) { return response, d.call(response, "wallet_add", map[string]interface{}{"wallet_id": id}) } -func (d *Client) WalletList(id string) (*WalletList, error) { +func (d *Client) WalletList(id string, page uint64, pageSize uint64) (*WalletList, error) { response := new(WalletList) - params := map[string]interface{}{} + params := map[string]interface { + }{ + "page": page, + "page_size": pageSize, + } if id != "" { params["wallet_id"] = id } diff --git a/extras/jsonrpc/daemon_test.go b/extras/jsonrpc/daemon_test.go index 3e69c26..7b4bc6e 100644 --- a/extras/jsonrpc/daemon_test.go +++ b/extras/jsonrpc/daemon_test.go @@ -30,12 +30,12 @@ func TestMain(m *testing.M) { func TestClient_AccountFund(t *testing.T) { d := NewClient("") - accounts, err := d.AccountList() + accounts, err := d.AccountList(1, 20) if err != nil { t.Error(err) return } - account := (accounts.LBCRegtest)[0].ID + account := (accounts.Items)[0].ID balanceString, err := d.AccountBalance(&account) if err != nil { t.Error(err) @@ -56,7 +56,7 @@ func TestClient_AccountFund(t *testing.T) { func TestClient_AccountList(t *testing.T) { d := NewClient("") - got, err := d.AccountList() + got, err := d.AccountList(1, 20) if err != nil { t.Error(err) return @@ -72,13 +72,16 @@ func TestClient_SingleAccountList(t *testing.T) { t.Fatal(err) } account, err := d.SingleAccountList(createdAccount.ID) + if err != nil { + t.Error(err) + } prettyPrint(*createdAccount) prettyPrint(*account) if err != nil { t.Fatal(err) } - if account.Name != name { - t.Fatalf("account name mismatch: %v != %v", account.Name, name) + if account.Items[0].Name != name { + t.Fatalf("account name mismatch: %v != %v", account.Items[0].Name, name) } } @@ -116,7 +119,7 @@ var channelID string func TestClient_ChannelCreate(t *testing.T) { d := NewClient("") - got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{ + got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 1.337, ChannelCreateOptions{ ClaimCreateOptions: ClaimCreateOptions{ Title: util.PtrToString("Mess with the channels"), Description: util.PtrToString("And you'll get what you deserve"), @@ -150,7 +153,14 @@ func TestClient_StreamCreate(t *testing.T) { return } address := string(*addressResponse) - got, err := d.StreamCreate("test"+fmt.Sprintf("%d", time.Now().Unix()), "/home/niko/Downloads/IMG_20171012_205120.jpg", 14.37, StreamCreateOptions{ + f, e := os.OpenFile("/tmp/test.txt", os.O_RDONLY|os.O_CREATE, 0666) + if e != nil { + t.Error(e) + return + } + + _, _ = f.WriteString("test") + got, err := d.StreamCreate("test"+fmt.Sprintf("%d", time.Now().Unix()), "/tmp/test.txt", 1.437, StreamCreateOptions{ ClaimCreateOptions: ClaimCreateOptions{ Title: util.PtrToString("This is a Test Title" + fmt.Sprintf("%d", time.Now().Unix())), Description: util.PtrToString("My Special Description"), @@ -261,7 +271,7 @@ func TestClient_ChannelAbandon(t *testing.T) { func TestClient_AddressList(t *testing.T) { d := NewClient("") - got, err := d.AddressList(nil, nil) + got, err := d.AddressList(nil, nil, 1, 20) if err != nil { t.Error(err) return @@ -283,7 +293,7 @@ func TestClient_ClaimList(t *testing.T) { func TestClient_StreamList(t *testing.T) { _ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest") d := NewClient("") - got, err := d.StreamList(nil) + got, err := d.StreamList(nil, 1, 20) if err != nil { t.Error(err) return @@ -294,7 +304,7 @@ func TestClient_StreamList(t *testing.T) { func TestClient_TransactionList(t *testing.T) { _ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest") d := NewClient("") - got, err := d.TransactionList(nil) + got, err := d.TransactionList(nil, 1, 20) if err != nil { t.Error(err) return @@ -327,7 +337,7 @@ func TestClient_SupportTest(t *testing.T) { return } time.Sleep(10 * time.Second) - got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil) + got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil, nil) if err != nil { t.Error(err) return @@ -360,7 +370,7 @@ func TestClient_SupportTest(t *testing.T) { func TestClient_ClaimSearch(t *testing.T) { d := NewClient("") - got, err := d.ClaimSearch(nil, util.PtrToString(channelID), nil, nil) + got, err := d.ClaimSearch(nil, util.PtrToString(channelID), nil, nil, 1, 20) if err != nil { t.Error(err) return @@ -380,7 +390,7 @@ func TestClient_Status(t *testing.T) { func TestClient_UTXOList(t *testing.T) { d := NewClient("") - got, err := d.UTXOList(nil) + got, err := d.UTXOList(nil, 1, 20) if err != nil { t.Error(err) return @@ -412,7 +422,7 @@ func TestClient_GetFile(t *testing.T) { func TestClient_FileList(t *testing.T) { _ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest") d := NewClient("") - got, err := d.FileList() + got, err := d.FileList(1, 20) if err != nil { t.Error(err) return @@ -428,21 +438,17 @@ func TestClient_Resolve(t *testing.T) { t.Error(err) return } - if err != nil { - t.Error(err) - return - } prettyPrint(*got) } func TestClient_AccountSet(t *testing.T) { d := NewClient("") - accounts, err := d.AccountList() + accounts, err := d.AccountList(1, 20) if err != nil { t.Error(err) return } - account := (accounts.LBCRegtest)[0].ID + account := (accounts.Items)[0].ID got, err := d.AccountSet(account, AccountSettings{ChangeMaxUses: util.PtrToInt(10000)}) if err != nil { @@ -506,7 +512,7 @@ func TestClient_AccountRemove(t *testing.T) { account, err := d.SingleAccountList(createdAccount.ID) if err != nil { - if strings.HasPrefix(err.Error(), "Error in daemon: Couldn't find account") { + if strings.Contains(err.Error(), "Couldn't find account:") { prettyPrint(*removedAccount) return } @@ -550,6 +556,9 @@ func TestClient_ChannelImport(t *testing.T) { t.Error(err) } channels, err := d.ChannelList(nil, 1, 50, nil) + if err != nil { + t.Error(err) + } seen := false for _, c := range channels.Items { if c.Name == channelName { @@ -567,10 +576,12 @@ func TestClient_ChannelImportWithWalletID(t *testing.T) { id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int()) wallet, err := d.WalletCreate(id, nil) - + if err != nil { + t.Error(err) + } // A channel created just for automated testing purposes channelName := "@LbryAutomatedTestChannel" - channelkey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" + + channelKey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" + "oKkfb99PgGK5efrZeYqaxg4X5XRJMJ6gKC8hqKcnwhYkmKDXmoBDNgd2ccZ9jhP8z" + "HG3NJorAN9Hh4XMyBc5goBLZYYvC9MYvBmT3Fcteb5saqMvmQxFURv74NqXLQZC1t" + "p6iRZKfTj77Pd5gsBsCYAbVmCqzbm5m1hHkUmfFEZVGcQNTYCDwZn543xSMYvSPnJ" + @@ -582,11 +593,14 @@ func TestClient_ChannelImportWithWalletID(t *testing.T) { "hxsFwGUyNNno8eiqrrYmpbJGEwwK3S4437JboAUEFPdMNn8zNQWZcLLVrK9KyQeKM" + "XpKkf4zJV6sZJ7gBMpzvPL18ULEgXTy7VsNBKmsfC1rM4WVG9ri1UixEcLDS79foC" + "Jb3FnSr1T4MRKESeN3W" - response, err := d.ChannelImport(channelkey, &wallet.ID) + response, err := d.ChannelImport(channelKey, &wallet.ID) if err != nil { t.Error(err) } channels, err := d.ChannelList(nil, 1, 50, &wallet.ID) + if err != nil { + t.Error(err) + } seen := false for _, c := range channels.Items { if c.Name == channelName { @@ -627,7 +641,7 @@ func TestClient_WalletCreateWithOpts(t *testing.T) { } prettyPrint(wallet) prettyPrint(accounts) - if accounts.LBCMainnet[0].Name == "" { + if accounts.Items[0].Name == "" { t.Fatalf("account name is empty") } } @@ -636,7 +650,7 @@ func TestClient_WalletList(t *testing.T) { d := NewClient("") id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int()) - wList, err := d.WalletList(id) + wList, err := d.WalletList(id, 1, 20) if err == nil { t.Fatalf("wallet %v was unexpectedly found", id) } @@ -649,15 +663,15 @@ func TestClient_WalletList(t *testing.T) { t.Fatal(err) } - wList, err = d.WalletList(id) + wList, err = d.WalletList(id, 1, 20) if err != nil { t.Fatal(err) } - if len(*wList) < 1 { + if len(wList.Items) < 1 { t.Fatal("wallet list is empty") } - if (*wList)[0].ID != id { - t.Fatalf("wallet ID mismatch, expected %q, got %q", id, (*wList)[0].ID) + if (wList.Items)[0].ID != id { + t.Fatalf("wallet ID mismatch, expected %q, got %q", id, (wList.Items)[0].ID) } } diff --git a/extras/jsonrpc/daemon_types.go b/extras/jsonrpc/daemon_types.go index 9c1584d..a1490be 100644 --- a/extras/jsonrpc/daemon_types.go +++ b/extras/jsonrpc/daemon_types.go @@ -176,7 +176,12 @@ type StreamAvailabilityResponse struct { } type GetResponse File -type FileListResponse []File +type FileListResponse struct { + Items []File `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` +} type WalletListResponse []string @@ -222,9 +227,10 @@ type Account struct { } type AccountListResponse struct { - LBCMainnet []Account `json:"lbc_mainnet"` - LBCTestnet []Account `json:"lbc_testnet"` - LBCRegtest []Account `json:"lbc_regtest"` + Items []Account `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` } type AccountBalanceResponse struct { @@ -265,11 +271,16 @@ type AccountFundResponse TransactionSummary type Address string type AddressUnusedResponse Address -type AddressListResponse []struct { - Account string `json:"account"` - Address Address `json:"address"` - Pubkey string `json:"pubkey"` - UsedTimes uint64 `json:"used_times"` +type AddressListResponse struct { + Items []struct { + Account string `json:"account"` + Address Address `json:"address"` + Pubkey string `json:"pubkey"` + UsedTimes uint64 `json:"used_times"` + } `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` } type ChannelExportResponse string @@ -396,7 +407,12 @@ func (c *Claim) GetStreamSizeByMagic() (streamSize uint64, e error) { return streamSize, nil } -type StreamListResponse []Claim +type StreamListResponse struct { + Items []Claim `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` +} type ClaimListResponse struct { Claims []Claim `json:"items"` @@ -463,16 +479,21 @@ type StatusResponse struct { } `json:"wallet"` } -type UTXOListResponse []struct { - Address string `json:"address"` - Amount string `json:"amount"` - Confirmations int `json:"confirmations"` - Height int `json:"height"` - IsChange bool `json:"is_change"` - IsMine bool `json:"is_mine"` - Nout int `json:"nout"` - Txid string `json:"txid"` - Type string `json:"type"` +type UTXOListResponse struct { + Items []struct { + Address string `json:"address"` + Amount string `json:"amount"` + Confirmations int `json:"confirmations"` + Height int `json:"height"` + IsChange bool `json:"is_change"` + IsMine bool `json:"is_mine"` + Nout int `json:"nout"` + Txid string `json:"txid"` + Type string `json:"type"` + } `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` } type UTXOReleaseResponse *string @@ -498,17 +519,22 @@ type supportBlob struct { IsTip bool `json:"is_tip"` } -type TransactionListResponse []struct { - AbandonInfo []transactionListBlob `json:"abandon_info"` - ClaimInfo []transactionListBlob `json:"claim_info"` - Confirmations int64 `json:"confirmations"` - Date string `json:"date"` - Fee string `json:"fee"` - SupportInfo []supportBlob `json:"support_info"` - Timestamp int64 `json:"timestamp"` - Txid string `json:"txid"` - UpdateInfo []transactionListBlob `json:"update_info"` - Value string `json:"value"` +type TransactionListResponse struct { + Items []struct { + AbandonInfo []transactionListBlob `json:"abandon_info"` + ClaimInfo []transactionListBlob `json:"claim_info"` + Confirmations int64 `json:"confirmations"` + Date string `json:"date"` + Fee string `json:"fee"` + SupportInfo []supportBlob `json:"support_info"` + Timestamp int64 `json:"timestamp"` + Txid string `json:"txid"` + UpdateInfo []transactionListBlob `json:"update_info"` + Value string `json:"value"` + } `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` } type VersionResponse struct { @@ -548,4 +574,9 @@ type Wallet struct { Name string `json:"name"` } -type WalletList []Wallet +type WalletList struct { + Items []Wallet `json:"items"` + Page uint64 `json:"page"` + PageSize uint64 `json:"page_size"` + TotalPages uint64 `json:"total_pages"` +}