From 3d2986a85c248ac85402d85a53b62fc0fa474a13 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Mon, 15 Apr 2019 14:13:23 -0400 Subject: [PATCH] add accountSet fix bugs fix rebase conflicts --- extras/jsonrpc/daemon.go | 45 ++++++++++++++++---------- extras/jsonrpc/daemon_test.go | 59 ++++++++++++++++++++++++++++++----- go.sum | 4 --- 3 files changed, 81 insertions(+), 27 deletions(-) diff --git a/extras/jsonrpc/daemon.go b/extras/jsonrpc/daemon.go index 32e3a12..a63ede9 100644 --- a/extras/jsonrpc/daemon.go +++ b/extras/jsonrpc/daemon.go @@ -144,6 +144,20 @@ func (d *Client) AccountList() (*AccountListResponse, error) { return response, d.call(response, "account_list", map[string]interface{}{}) } +type AccountSettings struct { + Default bool `json:"default"` + NewName string `json:"new_name"` + ReceivingGap int `json:"receiving_gap"` + ReceivingMaxUses int `json:"receiving_max_uses"` + ChangeGap int `json:"change_gap"` + ChangeMaxUses int `json:"change_max_uses"` +} + +func (d *Client) AccountSet(accountID string, settings AccountSettings) (*Account, error) { + response := new(Account) + return response, d.call(response, "account_list", map[string]interface{}{}) +} + func (d *Client) AccountBalance(account *string) (*AccountBalanceResponse, error) { response := new(AccountBalanceResponse) return response, d.call(response, "account_balance", map[string]interface{}{ @@ -197,7 +211,7 @@ var ( StreamTypeImage = streamType("image") ) -type Locations struct { +type Location struct { Country *string `json:"country,omitempty"` State *string `json:"state,omitempty"` City *string `json:"city,omitempty"` @@ -206,16 +220,15 @@ type Locations struct { Longitude *string `json:"longitude,omitempty"` } type ClaimCreateOptions struct { - Title string `json:"title"` - Description string `json:"description"` - Tags []string `json:"tags,omitempty"` - Languages []string `json:"languages"` - Locations []Locations `json:"locations,omitempty"` - ThumbnailURL *string `json:"thumbnail_url,omitempty"` - AccountID *string `json:"account_id,omitempty"` - ClaimAddress *string `json:"claim_address,omitempty"` - ChangeAddress *string `json:"change_address,omitempty"` - Preview *bool `json:"preview,omitempty"` + Title string `json:"title"` + Description string `json:"description"` + Tags []string `json:"tags,omitempty"` + Languages []string `json:"languages"` + Locations []Location `json:"locations,omitempty"` + ThumbnailURL *string `json:"thumbnail_url,omitempty"` + AccountID *string `json:"account_id,omitempty"` + ClaimAddress *string `json:"claim_address,omitempty"` + Preview *bool `json:"preview,omitempty"` } type ChannelCreateOptions struct { @@ -225,13 +238,13 @@ type ChannelCreateOptions struct { CoverURL *string `json:"cover_url,omitempty"` } -func (d *Client) ChannelCreate(name string, bid float64, options *ChannelCreateOptions) (*PublishResponse, error) { +func (d *Client) ChannelCreate(name string, bid float64, options ChannelCreateOptions) (*PublishResponse, error) { response := new(PublishResponse) args := struct { - Name string `json:"name"` - Bid string `json:"bid"` - FilePath string `json:"file_path,omitempty"` - *ChannelCreateOptions `json:",flatten"` + Name string `json:"name"` + Bid string `json:"bid"` + FilePath string `json:"file_path,omitempty"` + ChannelCreateOptions `json:",flatten"` }{ Name: name, Bid: fmt.Sprintf("%.6f", bid), diff --git a/extras/jsonrpc/daemon_test.go b/extras/jsonrpc/daemon_test.go index 4c51f41..3137731 100644 --- a/extras/jsonrpc/daemon_test.go +++ b/extras/jsonrpc/daemon_test.go @@ -62,7 +62,7 @@ func TestClient_Publish(t *testing.T) { Description: "My Special Description", Tags: []string{"nsfw", "test"}, Languages: []string{"en-US", "fr-CH"}, - Locations: []Locations{{ + Locations: []Location{{ Country: util.PtrToString("CH"), State: util.PtrToString("Ticino"), City: util.PtrToString("Lugano"), @@ -73,8 +73,7 @@ func TestClient_Publish(t *testing.T) { ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-01-18_16-37-39-098537783.png"), AccountID: nil, ClaimAddress: &address, - //ChangeAddress: &address, - Preview: nil, + Preview: nil, }, Fee: &Fee{ @@ -106,7 +105,23 @@ func TestClient_Publish(t *testing.T) { func TestClient_ChannelCreate(t *testing.T) { d := NewClient("") - got, err := d.ChannelCreate("@Test", 13.37, nil) + got, err := d.ChannelCreate("@Test", 13.37, ChannelCreateOptions{ + ClaimCreateOptions: ClaimCreateOptions{ + Title: "Mess with the channels", + Description: "And you'll get what you deserve", + Tags: []string{"we", "got", "tags"}, + Languages: []string{"en-US"}, + Locations: []Location{{ + Country: util.PtrToString("CH"), + State: util.PtrToString("Ticino"), + City: util.PtrToString("Lugano"), + }}, + ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"), + }, + ContactEmail: util.PtrToString("niko@lbry.com"), + HomepageURL: util.PtrToString("https://lbry.com"), + CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"), + }) if err != nil { t.Error(err) } @@ -115,7 +130,23 @@ func TestClient_ChannelCreate(t *testing.T) { func TestClient_ChannelAbandon(t *testing.T) { d := NewClient("") - channelResponse, err := d.ChannelCreate("@TestToDelete", 13.37, nil) + channelResponse, err := d.ChannelCreate("@TestToDelete", 13.37, ChannelCreateOptions{ + ClaimCreateOptions: ClaimCreateOptions{ + Title: "Mess with the channels", + Description: "And you'll get what you deserve", + Tags: []string{"we", "got", "tags"}, + Languages: []string{"en-US"}, + Locations: []Location{{ + Country: util.PtrToString("CH"), + State: util.PtrToString("Ticino"), + City: util.PtrToString("Lugano"), + }}, + ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"), + }, + ContactEmail: util.PtrToString("niko@lbry.com"), + HomepageURL: util.PtrToString("https://lbry.com"), + CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"), + }) if err != nil { t.Error(err) } @@ -149,7 +180,7 @@ func TestClient_ClaimList(t *testing.T) { func TestClient_ClaimSearch(t *testing.T) { d := NewClient("") - got, err := d.ClaimSearch(nil, util.PtrToString("4742f25e6d51b4b0483d5b8cd82e3ea121dacde9"), nil, nil) + got, err := d.ClaimSearch(nil, util.PtrToString("d3d84b191b05b1915db3f78150c5d42d172f4c5f"), nil, nil) if err != nil { t.Error(err) } @@ -185,7 +216,7 @@ func TestClient_Version(t *testing.T) { func TestClient_Resolve(t *testing.T) { d := NewClient("") - got, err := d.Resolve("test") + got, err := d.Resolve("crashtest") if err != nil { t.Error(err) } @@ -218,6 +249,20 @@ func TestClient_AccountFund(t *testing.T) { log.Infof("%+v", *got) } +func TestClient_AccountSet(t *testing.T) { + d := NewClient("") + accounts, err := d.AccountList() + if err != nil { + t.Error(err) + } + account := (accounts.LBCRegtest)[0].ID + + got, err := d.AccountSet(account, AccountSettings{ChangeMaxUses: 10000}) + if err != nil { + t.Error(err) + } + log.Infof("%+v", *got) +} func TestClient_AccountCreate(t *testing.T) { d := NewClient("") account, err := d.AccountCreate("test@lbry.com", false) diff --git a/go.sum b/go.sum index 310a311..9f98be3 100644 --- a/go.sum +++ b/go.sum @@ -50,8 +50,6 @@ github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c h1:BhdcWGsuKif/Xo github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c/go.mod h1:muH7wpUqE8hRA3OrYYosw9+Sl681BF9cwcjzE+OCNK8= github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04 h1:Nze+C2HbeKvhjI/kVn+9Poj/UuEW5sOQxcsxqO7L3GI= github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04/go.mod h1:fbG/dzobG8r95KzMwckXiLMHfFjZaBRQqC9hPs2XAQ4= -github.com/lbryio/types v0.0.0-20190304154608-a6f2fd6d5f38 h1:78rErXiBhMjs7vh4Ke3ZMqQjf+pnQeNrkXYmQ8L6aKE= -github.com/lbryio/types v0.0.0-20190304154608-a6f2fd6d5f38/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE= github.com/lbryio/types v0.0.0-20190405005919-54c3c28f676a h1:twWvrsBDvSb+qnmpSq3nvFrodgC5PpXUipyo4T/W790= github.com/lbryio/types v0.0.0-20190405005919-54c3c28f676a/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE= github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 h1:AsEBgzv3DhuYHI/GiQh2HxvTP71HCCE9E/tzGUzGdtU= @@ -62,8 +60,6 @@ github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5 h1:mG83tLXWSRdcX github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5/go.mod h1:H0aPCWffGOaDcjkw1iB7W9DVLp6GXmfcJY/7YZCWPA4= github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675 h1:/rdJjIiKG5rRdwG5yxHmSE/7ZREjpyC0kL7GxGT/qJw= github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/nlopes/slack v0.2.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM= -github.com/nlopes/slack v0.3.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM= github.com/nlopes/slack v0.5.0 h1:NbIae8Kd0NpqaEI3iUrsuS0KbcEDhzhc939jLW5fNm0= github.com/nlopes/slack v0.5.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM= github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=