Add wallet commands to JSON-RPC client #73

Merged
anbsky merged 8 commits from feature/wallet into master 2019-10-08 08:08:57 +02:00
3 changed files with 50 additions and 2 deletions
Showing only changes of commit 30a9a39248 - Show all commits

View file

@ -217,7 +217,7 @@ func (d *Client) AddressUnused(account *string) (*AddressUnusedResponse, error)
}) })
} }
func (d *Client) ChannelList(account *string, page uint64, pageSize uint64) (*ChannelListResponse, error) { func (d *Client) ChannelList(account *string, page uint64, pageSize uint64, wid *string) (*ChannelListResponse, error) {
if page == 0 { if page == 0 {
return nil, errors.Err("pages start from 1") return nil, errors.Err("pages start from 1")
} }
@ -227,6 +227,7 @@ func (d *Client) ChannelList(account *string, page uint64, pageSize uint64) (*Ch
"page": page, "page": page,
"page_size": pageSize, "page_size": pageSize,
"include_protobuf": true, "include_protobuf": true,
"wallet_id": wid,
}) })
} }
@ -524,6 +525,14 @@ func (d *Client) ChannelExport(channelClaimID string, channelName, accountID *st
}) })
} }
func (d *Client) ChannelImport(key string, walletID *string) (*ChannelImportResponse, error) {
response := new(ChannelImportResponse)
return response, d.call(response, "channel_import", map[string]interface{}{
"channel_data": key,
"wallet_id": walletID,
})
}
func (d *Client) SupportList(accountID *string, page uint64, pageSize uint64) (*SupportListResponse, error) { func (d *Client) SupportList(accountID *string, page uint64, pageSize uint64) (*SupportListResponse, error) {
response := new(SupportListResponse) response := new(SupportListResponse)
return response, d.call(response, "support_list", map[string]interface{}{ return response, d.call(response, "support_list", map[string]interface{}{

View file

@ -104,7 +104,7 @@ func TestClient_AddressUnused(t *testing.T) {
func TestClient_ChannelList(t *testing.T) { func TestClient_ChannelList(t *testing.T) {
d := NewClient("") d := NewClient("")
got, err := d.ChannelList(nil, 1, 50) got, err := d.ChannelList(nil, 1, 50, nil)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
@ -516,6 +516,43 @@ func TestClient_ChannelExport(t *testing.T) {
t.Log("Export:", *response) t.Log("Export:", *response)
} }
func TestClient_ChannelImport(t *testing.T) {
d := NewClient("")
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
wallet, err := d.WalletCreate(id, nil)
// A channel created just for automated testing purposes
channelName := "@LbryAutomatedTestChannel"
channelkey := "7943FWPBHZES4dUcMXSpDYwoM5a2tsyJT1R8V54QoUhekGcqmeH3hbzDXoLLQ8" +
"oKkfb99PgGK5efrZeYqaxg4X5XRJMJ6gKC8hqKcnwhYkmKDXmoBDNgd2ccZ9jhP8z" +
"HG3NJorAN9Hh4XMyBc5goBLZYYvC9MYvBmT3Fcteb5saqMvmQxFURv74NqXLQZC1t" +
"p6iRZKfTj77Pd5gsBsCYAbVmCqzbm5m1hHkUmfFEZVGcQNTYCDwZn543xSMYvSPnJ" +
"zt8tRYCJWaPdj713uENZZMo3gxuAMb1NwSnx8tbwETp7WPkpFLL6HZ9jKpB8BURHM" +
"F1RFD1PRyqbC6YezPyPQ2oninKKHdBduvXZG5KF2G2Q3ixsuE2ntifBBo1f5PotRk" +
"UanXKEafWxvXAayJjpsmZ4bFt7n6Xg4438WZXBiZKCPobLJAiHfe72n618kE6PCNU" +
"77cyU5Rk8J3CuY6QzZPzwuiXz2GLfkUMCYd9jGT6g53XbE6SwCsmGnd9NJkBAaJf5" +
"1FAYRURrhHnp79PAoHftEWtZEuU8MCPMdSRjzxYMRS4ScUzg5viDMTAkE8frsfCVZ" +
"hxsFwGUyNNno8eiqrrYmpbJGEwwK3S4437JboAUEFPdMNn8zNQWZcLLVrK9KyQeKM" +
"XpKkf4zJV6sZJ7gBMpzvPL18ULEgXTy7VsNBKmsfC1rM4WVG9ri1UixEcLDS79foC" +
"Jb3FnSr1T4MRKESeN3W"
response, err := d.ChannelImport(channelkey, &wallet.ID)
if err != nil {
t.Error(err)
}
channels, err := d.ChannelList(nil, 1, 50, &wallet.ID)
seen := false
for _, c := range channels.Items {
if c.Name == channelName {
seen = true
}
}
if !seen {
t.Error("couldn't find imported channel")
}
t.Log("Response:", *response)
}
func TestClient_WalletCreate(t *testing.T) { func TestClient_WalletCreate(t *testing.T) {
d := NewClient("") d := NewClient("")

View file

@ -271,7 +271,9 @@ type AddressListResponse []struct {
Pubkey string `json:"pubkey"` Pubkey string `json:"pubkey"`
UsedTimes uint64 `json:"used_times"` UsedTimes uint64 `json:"used_times"`
} }
type ChannelExportResponse string type ChannelExportResponse string
type ChannelImportResponse string
type ChannelListResponse struct { type ChannelListResponse struct {
Items []Transaction `json:"items"` Items []Transaction `json:"items"`