diff --git a/extras/jsonrpc/daemon.go b/extras/jsonrpc/daemon.go index d506156..bdebf1a 100644 --- a/extras/jsonrpc/daemon.go +++ b/extras/jsonrpc/daemon.go @@ -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 { 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_size": pageSize, "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) { response := new(SupportListResponse) return response, d.call(response, "support_list", map[string]interface{}{ diff --git a/extras/jsonrpc/daemon_test.go b/extras/jsonrpc/daemon_test.go index bd7d316..3e6345a 100644 --- a/extras/jsonrpc/daemon_test.go +++ b/extras/jsonrpc/daemon_test.go @@ -104,7 +104,7 @@ func TestClient_AddressUnused(t *testing.T) { func TestClient_ChannelList(t *testing.T) { d := NewClient("") - got, err := d.ChannelList(nil, 1, 50) + got, err := d.ChannelList(nil, 1, 50, nil) if err != nil { t.Error(err) return @@ -516,6 +516,43 @@ func TestClient_ChannelExport(t *testing.T) { 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) { d := NewClient("") diff --git a/extras/jsonrpc/daemon_types.go b/extras/jsonrpc/daemon_types.go index 91c15a7..25c412f 100644 --- a/extras/jsonrpc/daemon_types.go +++ b/extras/jsonrpc/daemon_types.go @@ -271,7 +271,9 @@ type AddressListResponse []struct { Pubkey string `json:"pubkey"` UsedTimes uint64 `json:"used_times"` } + type ChannelExportResponse string +type ChannelImportResponse string type ChannelListResponse struct { Items []Transaction `json:"items"`