Add wallet commands to JSON-RPC client #73
3 changed files with 47 additions and 7 deletions
|
@ -608,8 +608,8 @@ type WalletCreateOpts struct {
|
|||
SingleKey bool
|
||||
}
|
||||
|
||||
func (d *Client) WalletCreate(id string, opts *WalletCreateOpts) (*WalletCommandResponse, error) {
|
||||
response := new(WalletCommandResponse)
|
||||
func (d *Client) WalletCreate(id string, opts *WalletCreateOpts) (*Wallet, error) {
|
||||
response := new(Wallet)
|
||||
if opts == nil {
|
||||
opts = &WalletCreateOpts{}
|
||||
}
|
||||
|
@ -622,12 +622,21 @@ func (d *Client) WalletCreate(id string, opts *WalletCreateOpts) (*WalletCommand
|
|||
return response, d.call(response, "wallet_create", params)
|
||||
}
|
||||
|
||||
func (d *Client) WalletAdd(id string) (*WalletCommandResponse, error) {
|
||||
response := new(WalletCommandResponse)
|
||||
func (d *Client) WalletAdd(id string) (*Wallet, error) {
|
||||
response := new(Wallet)
|
||||
return response, d.call(response, "wallet_add", map[string]interface{}{"wallet_id": id})
|
||||
}
|
||||
|
||||
func (d *Client) WalletRemove(id string) (*WalletCommandResponse, error) {
|
||||
response := new(WalletCommandResponse)
|
||||
func (d *Client) WalletList(id string) (*WalletList, error) {
|
||||
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})
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
d := NewClient("")
|
||||
|
||||
|
|
|
@ -539,7 +539,9 @@ type NumClaimsInChannelResponse map[string]struct {
|
|||
|
||||
type ClaimShowResponse *Claim
|
||||
|
||||
type WalletCommandResponse struct {
|
||||
type Wallet struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type WalletList []Wallet
|
||||
|
|
Loading…
Reference in a new issue