Skip to content

Commit 6ae869b

Browse files
authored
Merge pull request #60 from lbryio/feature/account_remove
Add singular account_list method, account_remove
2 parents 76b73ef + 818b001 commit 6ae869b

File tree

5 files changed

+84
-19
lines changed

5 files changed

+84
-19
lines changed

extras/jsonrpc/daemon.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/fatih/structs"
14-
1513
"github.com/lbryio/lbry.go/extras/errors"
1614

15+
"github.com/fatih/structs"
1716
"github.com/mitchellh/mapstructure"
1817
"github.com/shopspring/decimal"
1918
log "github.com/sirupsen/logrus"
@@ -144,6 +143,11 @@ func (d *Client) AccountList() (*AccountListResponse, error) {
144143
return response, d.call(response, "account_list", map[string]interface{}{})
145144
}
146145

146+
func (d *Client) SingleAccountList(accountID string) (*Account, error) {
147+
response := new(Account)
148+
return response, d.call(response, "account_list", map[string]interface{}{"account_id": accountID})
149+
}
150+
147151
type AccountSettings struct {
148152
Default bool `json:"default"`
149153
NewName string `json:"new_name"`
@@ -184,6 +188,13 @@ func (d *Client) AccountCreate(accountName string, singleKey bool) (*AccountCrea
184188
})
185189
}
186190

191+
func (d *Client) AccountRemove(accountID string) (*AccountRemoveResponse, error) {
192+
response := new(AccountRemoveResponse)
193+
return response, d.call(response, "account_remove", map[string]interface{}{
194+
"account_id": accountID,
195+
})
196+
}
197+
187198
func (d *Client) AddressUnused(account *string) (*AddressUnusedResponse, error) {
188199
response := new(AddressUnusedResponse)
189200
return response, d.call(response, "address_unused", map[string]interface{}{

extras/jsonrpc/daemon_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"strconv"
7+
"strings"
78
"testing"
89
"time"
910

@@ -48,6 +49,19 @@ func TestClient_AccountList(t *testing.T) {
4849
prettyPrint(*got)
4950
}
5051

52+
func TestClient_SingleAccountList(t *testing.T) {
53+
d := NewClient("")
54+
createdAccount, err := d.AccountCreate("test"+fmt.Sprintf("%d", time.Now().Unix())+"@lbry.com", false)
55+
if err != nil {
56+
t.Fatal(err)
57+
}
58+
account, err := d.SingleAccountList(createdAccount.ID)
59+
if err != nil {
60+
t.Fatal(err)
61+
}
62+
prettyPrint(*account)
63+
}
64+
5165
func TestClient_AccountBalance(t *testing.T) {
5266
d := NewClient("")
5367
got, err := d.AccountBalance(nil)
@@ -309,11 +323,38 @@ func TestClient_AccountSet(t *testing.T) {
309323
}
310324
prettyPrint(*got)
311325
}
326+
312327
func TestClient_AccountCreate(t *testing.T) {
313328
d := NewClient("")
314-
account, err := d.AccountCreate("test"+fmt.Sprintf("%d", time.Now().Unix())+"@lbry.com", false)
329+
name := "test" + fmt.Sprintf("%d", time.Now().Unix()) + "@lbry.com"
330+
account, err := d.AccountCreate(name, false)
331+
if err != nil {
332+
t.Fatal(err)
333+
}
334+
if account.Name != name {
335+
t.Errorf("account name mismatch, expected %q, got %q", name, account.Name)
336+
}
337+
prettyPrint(*account)
338+
}
339+
340+
func TestClient_AccountRemove(t *testing.T) {
341+
d := NewClient("")
342+
createdAccount, err := d.AccountCreate("test"+fmt.Sprintf("%d", time.Now().Unix())+"@lbry.com", false)
343+
if err != nil {
344+
t.Fatal(err)
345+
}
346+
removedAccount, err := d.AccountRemove(createdAccount.ID)
315347
if err != nil {
316348
t.Error(err)
317349
}
350+
if removedAccount.ID != createdAccount.ID {
351+
t.Error("accounts IDs mismatch")
352+
}
353+
354+
account, err := d.SingleAccountList(createdAccount.ID)
355+
if !strings.HasPrefix(err.Error(), "Error in daemon: Couldn't find account") {
356+
t.Error("account was not removed")
357+
}
358+
fmt.Println(err.Error())
318359
prettyPrint(*account)
319360
}

extras/jsonrpc/daemon_types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,21 @@ type AccountListResponse struct {
209209
LBCTestnet []Account `json:"lbc_testnet"`
210210
LBCRegtest []Account `json:"lbc_regtest"`
211211
}
212+
212213
type AccountBalanceResponse string
213214

214215
type AccountCreateResponse struct {
215-
Account
216-
PrivateKey string `json:"private_key,omitempty"`
216+
ID string `json:"id"`
217+
Name string `json:"name"`
217218
PublicKey string `json:"public_key"`
219+
PrivateKey string `json:"private_key"`
218220
Seed string `json:"seed"`
219221
Ledger string `json:"ledger"`
220222
ModifiedOn float64 `json:"modified_on"`
221223
}
222224

225+
type AccountRemoveResponse AccountCreateResponse
226+
223227
type Transaction struct {
224228
Address string `json:"address"`
225229
Amount string `json:"amount"`

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require (
44
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf // indirect
55
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32
66
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803
7-
github.com/davecgh/go-spew v1.1.0
7+
github.com/davecgh/go-spew v1.1.1
88
github.com/fatih/structs v1.1.0
99
github.com/go-errors/errors v1.0.1
1010
github.com/go-ini/ini v1.38.2
@@ -30,21 +30,21 @@ require (
3030
github.com/sebdah/goldie v0.0.0-20180424091453-8784dd1ab561
3131
github.com/sergi/go-diff v1.0.0
3232
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930
33-
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973
33+
github.com/sirupsen/logrus v1.2.0
3434
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
3535
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
3636
github.com/spf13/cast v1.2.0
3737
github.com/stretchr/testify v1.3.0
3838
github.com/uber-go/atomic v1.3.2
3939
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d
4040
go.uber.org/atomic v1.3.2 // indirect
41-
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4
42-
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
41+
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793
42+
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
43+
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
44+
golang.org/x/sys v0.0.0-20190520201301-c432e742b0af // indirect
4345
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
4446
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f // indirect
4547
google.golang.org/grpc v1.17.0
46-
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
47-
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
4848
gopkg.in/ini.v1 v1.41.0 // indirect
4949
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79
5050
gotest.tools v2.2.0+incompatible // indirect

go.sum

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
2222
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2323
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2424
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
25+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
26+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2527
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
2628
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
2729
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@@ -62,6 +64,8 @@ github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVY
6264
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
6365
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfMuZT83xIwfPDxEI2OHu6xUmJMFE=
6466
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
67+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
68+
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
6569
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c h1:BhdcWGsuKif/XoSZnqVGNqJ1iEmH0czWR5upj+AuR8M=
6670
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c/go.mod h1:muH7wpUqE8hRA3OrYYosw9+Sl681BF9cwcjzE+OCNK8=
6771
github.com/lbryio/lbryschema.go v0.0.0-20190428231007-c54836bca002 h1:urfYK5ElpUrAv90auPLldoVC60LwiGAcY0OE6HJB9KI=
@@ -96,15 +100,17 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
96100
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
97101
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930 h1:pSgp2x9zCkCjb8rxXFNpGE8hDIrt+UXW7jUQ5fbTlzM=
98102
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
99-
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973 h1:3AJZYTzw3gm3TNTt30x0CCKD7GOn2sdd50Hn35fQkGY=
100-
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
103+
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
104+
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
101105
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
102106
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
103107
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w=
104108
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
105109
github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg=
106110
github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
107111
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
112+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
113+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
108114
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
109115
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
110116
github.com/uber-go/atomic v1.3.2 h1:Azu9lPBWRNKzYXSIwRfgRuDuS0YKsK4NFhiQv98gkxo=
@@ -114,20 +120,27 @@ github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d/go.mod h1:XJrh1eMSzd
114120
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
115121
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
116122
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
117-
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4 h1:wviDUSmtheHRBfoY8B9U8ELl2USoXi2YFwdGdpIIkzI=
118-
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
123+
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
124+
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
119125
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
120126
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
121127
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
122128
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
123129
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
130+
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U=
131+
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
124132
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
125133
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
126134
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
135+
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
136+
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
127137
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE=
128138
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
139+
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
129140
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
130141
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
142+
golang.org/x/sys v0.0.0-20190520201301-c432e742b0af h1:NXfmMfXz6JqGfG3ikSxcz2N93j6DgScr19Oo2uwFu88=
143+
golang.org/x/sys v0.0.0-20190520201301-c432e742b0af/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
131144
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
132145
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
133146
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
@@ -140,14 +153,10 @@ google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f h1:FU37niK8AQ59mHc
140153
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
141154
google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk=
142155
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
143-
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
144-
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
145156
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
146157
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
147158
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
148159
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
149-
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNjB2u4i700xBkIT4e0=
150-
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
151160
gopkg.in/ini.v1 v1.41.0 h1:Ka3ViY6gNYSKiVy71zXBEqKplnV35ImDLVG+8uoIklE=
152161
gopkg.in/ini.v1 v1.41.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
153162
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79 h1:FpCr9V8wuOei4BAen+93HtVJ+XSi+KPbaPKm0Vj5R64=

0 commit comments

Comments
 (0)