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 47 additions and 7 deletions
Showing only changes of commit d5102a9cf6 - Show all commits

View file

@ -608,8 +608,8 @@ type WalletCreateOpts struct {
SingleKey bool SingleKey bool
} }
func (d *Client) WalletCreate(id string, opts *WalletCreateOpts) (*WalletCommandResponse, error) { func (d *Client) WalletCreate(id string, opts *WalletCreateOpts) (*Wallet, error) {
response := new(WalletCommandResponse) response := new(Wallet)
if opts == nil { if opts == nil {
opts = &WalletCreateOpts{} opts = &WalletCreateOpts{}
} }
@ -622,12 +622,21 @@ func (d *Client) WalletCreate(id string, opts *WalletCreateOpts) (*WalletCommand
return response, d.call(response, "wallet_create", params) return response, d.call(response, "wallet_create", params)
} }
func (d *Client) WalletAdd(id string) (*WalletCommandResponse, error) { func (d *Client) WalletAdd(id string) (*Wallet, error) {
response := new(WalletCommandResponse) response := new(Wallet)
return response, d.call(response, "wallet_add", map[string]interface{}{"wallet_id": id}) return response, d.call(response, "wallet_add", map[string]interface{}{"wallet_id": id})
} }
func (d *Client) WalletRemove(id string) (*WalletCommandResponse, error) { func (d *Client) WalletList(id string) (*WalletList, error) {
response := new(WalletCommandResponse) 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)
return response, d.call(response, "wallet_remove", map[string]interface{}{"wallet_id": id}) return response, d.call(response, "wallet_remove", map[string]interface{}{"wallet_id": id})
} }

View file

@ -549,6 +549,35 @@ func TestClient_WalletCreateWithOpts(t *testing.T) {
} }
} }
func TestClient_WalletList(t *testing.T) {
d := NewClient("")
id := "lbry#wallet#id:" + fmt.Sprintf("%d", rand.Int())
wList, err := d.WalletList(id)
if err == nil {
t.Fatalf("wallet %v was unexpectedly found", id)
}
if err.Error() != fmt.Sprintf("Error in daemon: Couldn't find wallet: %v.", id) {
t.Fatal(err)
}
_, err = d.WalletCreate(id, &WalletCreateOpts{CreateAccount: true, SingleKey: true})
if err != nil {
t.Fatal(err)
}
wList, err = d.WalletList(id)
if err != nil {
t.Fatal(err)
}
if len(*wList) < 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)
}
}
func TestClient_WalletRemoveWalletAdd(t *testing.T) { func TestClient_WalletRemoveWalletAdd(t *testing.T) {
d := NewClient("") d := NewClient("")

View file

@ -539,7 +539,9 @@ type NumClaimsInChannelResponse map[string]struct {
type ClaimShowResponse *Claim type ClaimShowResponse *Claim
type WalletCommandResponse struct { type Wallet struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} }
type WalletList []Wallet