From 7ba00dffccccb08b59c0956032597b1015184463 Mon Sep 17 00:00:00 2001 From: Andrey Beletsky Date: Wed, 22 May 2019 00:12:00 +0700 Subject: [PATCH] Add singular account_list method, account_remove --- extras/jsonrpc/daemon.go | 12 ++++++++++++ extras/jsonrpc/daemon_test.go | 32 ++++++++++++++++++++++++++++++++ extras/jsonrpc/daemon_types.go | 9 +++++++++ 3 files changed, 53 insertions(+) diff --git a/extras/jsonrpc/daemon.go b/extras/jsonrpc/daemon.go index e92a1ef..bc35592 100644 --- a/extras/jsonrpc/daemon.go +++ b/extras/jsonrpc/daemon.go @@ -144,6 +144,11 @@ func (d *Client) AccountList() (*AccountListResponse, error) { return response, d.call(response, "account_list", map[string]interface{}{}) } +func (d *Client) SingleAccountList(accountID string) (*SingleAccountListResponse, error) { + response := new(SingleAccountListResponse) + return response, d.call(response, "account_list", map[string]interface{}{"account_id": accountID}) +} + type AccountSettings struct { Default bool `json:"default"` NewName string `json:"new_name"` @@ -184,6 +189,13 @@ func (d *Client) AccountCreate(accountName string, singleKey bool) (*AccountCrea }) } +func (d *Client) AccountRemove(accountID string) (*AccountRemoveResponse, error) { + response := new(AccountRemoveResponse) + return response, d.call(response, "account_remove", map[string]interface{}{ + "account_id": accountID, + }) +} + func (d *Client) AddressUnused(account *string) (*AddressUnusedResponse, error) { response := new(AddressUnusedResponse) return response, d.call(response, "address_unused", map[string]interface{}{ diff --git a/extras/jsonrpc/daemon_test.go b/extras/jsonrpc/daemon_test.go index 2f025b5..97fcf37 100644 --- a/extras/jsonrpc/daemon_test.go +++ b/extras/jsonrpc/daemon_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "strconv" + "strings" "testing" "time" @@ -48,6 +49,19 @@ func TestClient_AccountList(t *testing.T) { prettyPrint(*got) } +func TestClient_SingleAccountList(t *testing.T) { + d := NewClient("") + createdAccount, err := d.AccountCreate("test"+fmt.Sprintf("%d", time.Now().Unix())+"@lbry.com", false) + if err != nil { + t.Fatal(err) + } + account, err := d.SingleAccountList(createdAccount.ID) + if err != nil { + t.Fatal(err) + } + prettyPrint(*account) +} + func TestClient_AccountBalance(t *testing.T) { d := NewClient("") got, err := d.AccountBalance(nil) @@ -317,3 +331,21 @@ func TestClient_AccountCreate(t *testing.T) { } prettyPrint(*account) } + +func TestClient_AccountRemove(t *testing.T) { + d := NewClient("") + createdAccount, err := d.AccountCreate("test"+fmt.Sprintf("%d", time.Now().Unix())+"@lbry.com", false) + if err != nil { + t.Fatal(err) + } + removedAccount, err := d.AccountRemove(createdAccount.ID) + if err != nil { + t.Error(err) + } + + _, err = d.SingleAccountList(createdAccount.ID) + if !strings.HasPrefix("Couldn't find account", err.Error()) { + t.Error("account was not removed") + } + prettyPrint(*removedAccount) +} diff --git a/extras/jsonrpc/daemon_types.go b/extras/jsonrpc/daemon_types.go index fbe33b5..6d7406c 100644 --- a/extras/jsonrpc/daemon_types.go +++ b/extras/jsonrpc/daemon_types.go @@ -209,6 +209,11 @@ type AccountListResponse struct { LBCTestnet []Account `json:"lbc_testnet"` LBCRegtest []Account `json:"lbc_regtest"` } + +type SingleAccountListResponse struct { + Account +} + type AccountBalanceResponse string type AccountCreateResponse struct { @@ -220,6 +225,10 @@ type AccountCreateResponse struct { ModifiedOn float64 `json:"modified_on"` } +type AccountRemoveResponse struct { + AccountCreateResponse +} + type Transaction struct { Address string `json:"address"` Amount string `json:"amount"`