Skip to content

Commit 3a3377d

Browse files
committed
add support related commands
improve tests
1 parent 3886142 commit 3a3377d

File tree

3 files changed

+154
-32
lines changed

3 files changed

+154
-32
lines changed

extras/jsonrpc/daemon.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,59 @@ func (d *Client) ChannelExport(channelClaimID string, channelName, accountID *st
495495
"account_id": accountID,
496496
})
497497
}
498+
499+
func (d *Client) SupportList(accountID *string, page uint64, pageSize uint64) (*SupportListResponse, error) {
500+
response := new(SupportListResponse)
501+
return response, d.call(response, "support_list", map[string]interface{}{
502+
"account_id": accountID,
503+
"page": page,
504+
"page_size": pageSize,
505+
})
506+
}
507+
508+
func (d *Client) SupportCreate(claimID string, amount string, tip *bool, accountID *string, fundingAccountIDs []string) (*TransactionSummary, error) {
509+
response := new(TransactionSummary)
510+
args := struct {
511+
ClaimID string `json:"claim_id"`
512+
Amount string `json:"amount"`
513+
Tip *bool `json:"tip,omitempty"`
514+
AccountID *string `json:"account_id,omitempty"`
515+
FundingAccountIDs []string `json:"funding_account_ids,omitempty"`
516+
Preview bool `json:"preview,omitempty"`
517+
Blocking bool `json:"blocking,omitempty"`
518+
}{
519+
ClaimID: claimID,
520+
AccountID: accountID,
521+
Blocking: true,
522+
Amount: amount,
523+
FundingAccountIDs: fundingAccountIDs,
524+
Preview: false,
525+
Tip: tip,
526+
}
527+
structs.DefaultTagName = "json"
528+
return response, d.call(response, "support_create", structs.Map(args))
529+
}
530+
531+
func (d *Client) SupportAbandon(claimID *string, txid *string, nout *uint, keep *string, accountID *string) (*TransactionSummary, error) {
532+
if claimID == nil && (txid == nil || nout == nil) {
533+
return nil, errors.Err("either claimID or txid+nout must be supplied")
534+
}
535+
response := new(TransactionSummary)
536+
args := struct {
537+
ClaimID *string `json:"claim_id,omitempty"`
538+
TxID *string `json:"claim_id,omitempty"`
539+
Nout *uint `json:"nout,omitempty"`
540+
AccountID *string `json:"account_id,omitempty"`
541+
Preview bool `json:"preview,omitempty"`
542+
Blocking bool `json:"blocking,omitempty"`
543+
}{
544+
ClaimID: claimID,
545+
AccountID: accountID,
546+
Nout: nout,
547+
TxID: txid,
548+
Blocking: true,
549+
Preview: false,
550+
}
551+
structs.DefaultTagName = "json"
552+
return response, d.call(response, "support_abandon", structs.Map(args))
553+
}

extras/jsonrpc/daemon_test.go

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/shopspring/decimal"
1313

14+
"github.com/lbryio/lbry.go/extras/errors"
15+
1416
"github.com/lbryio/lbry.go/extras/util"
1517
)
1618

@@ -32,7 +34,7 @@ func TestClient_AccountFund(t *testing.T) {
3234
t.Error(err)
3335
return
3436
}
35-
balance, err := strconv.ParseFloat(string(*balanceString), 64)
37+
balance, err := strconv.ParseFloat(balanceString.Available.String(), 64)
3638
if err != nil {
3739
t.Error(err)
3840
return
@@ -100,6 +102,35 @@ func TestClient_ChannelList(t *testing.T) {
100102
prettyPrint(*got)
101103
}
102104

105+
var channelID string
106+
107+
func TestClient_ChannelCreate(t *testing.T) {
108+
d := NewClient("")
109+
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
110+
ClaimCreateOptions: ClaimCreateOptions{
111+
Title: util.PtrToString("Mess with the channels"),
112+
Description: util.PtrToString("And you'll get what you deserve"),
113+
Tags: []string{"we", "got", "tags"},
114+
Languages: []string{"en-US"},
115+
Locations: []Location{{
116+
Country: util.PtrToString("CH"),
117+
State: util.PtrToString("Ticino"),
118+
City: util.PtrToString("Lugano"),
119+
}},
120+
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
121+
},
122+
Email: util.PtrToString("[email protected]"),
123+
WebsiteURL: util.PtrToString("https://lbry.com"),
124+
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
125+
})
126+
if err != nil {
127+
t.Error(err)
128+
return
129+
}
130+
channelID = got.Outputs[0].ClaimID
131+
prettyPrint(*got)
132+
}
133+
103134
func TestClient_StreamCreate(t *testing.T) {
104135
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
105136
d := NewClient("")
@@ -142,7 +173,7 @@ func TestClient_StreamCreate(t *testing.T) {
142173
Preview: nil,
143174
AllowDuplicateName: nil,
144175
ChannelName: nil,
145-
ChannelID: util.PtrToString("dd0b559b4f17a7af984f173efb5438534eb6ab27"),
176+
ChannelID: util.PtrToString(channelID),
146177
ChannelAccountID: nil,
147178
})
148179
if err != nil {
@@ -152,35 +183,9 @@ func TestClient_StreamCreate(t *testing.T) {
152183
prettyPrint(*got)
153184
}
154185

155-
func TestClient_ChannelCreate(t *testing.T) {
156-
d := NewClient("")
157-
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
158-
ClaimCreateOptions: ClaimCreateOptions{
159-
Title: util.PtrToString("Mess with the channels"),
160-
Description: util.PtrToString("And you'll get what you deserve"),
161-
Tags: []string{"we", "got", "tags"},
162-
Languages: []string{"en-US"},
163-
Locations: []Location{{
164-
Country: util.PtrToString("CH"),
165-
State: util.PtrToString("Ticino"),
166-
City: util.PtrToString("Lugano"),
167-
}},
168-
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
169-
},
170-
Email: util.PtrToString("[email protected]"),
171-
WebsiteURL: util.PtrToString("https://lbry.com"),
172-
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
173-
})
174-
if err != nil {
175-
t.Error(err)
176-
return
177-
}
178-
prettyPrint(*got)
179-
}
180-
181186
func TestClient_ChannelUpdate(t *testing.T) {
182187
d := NewClient("")
183-
got, err := d.ChannelUpdate("2a8b6d061c5ecb2515f1dd7e04729e9fafac660d", ChannelUpdateOptions{
188+
got, err := d.ChannelUpdate(channelID, ChannelUpdateOptions{
184189
ClearLanguages: util.PtrToBool(true),
185190
ClearLocations: util.PtrToBool(true),
186191
ClearTags: util.PtrToBool(true),
@@ -264,9 +269,65 @@ func TestClient_ClaimList(t *testing.T) {
264269
prettyPrint(*got)
265270
}
266271

272+
func TestClient_SupportTest(t *testing.T) {
273+
_ = os.Setenv("BLOCKCHAIN_NAME", "lbrycrd_regtest")
274+
d := NewClient("")
275+
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
276+
ClaimCreateOptions: ClaimCreateOptions{
277+
Title: util.PtrToString("Mess with the channels"),
278+
Description: util.PtrToString("And you'll get what you deserve"),
279+
Tags: []string{"we", "got", "tags"},
280+
Languages: []string{"en-US"},
281+
Locations: []Location{{
282+
Country: util.PtrToString("CH"),
283+
State: util.PtrToString("Ticino"),
284+
City: util.PtrToString("Lugano"),
285+
}},
286+
ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
287+
},
288+
Email: util.PtrToString("[email protected]"),
289+
WebsiteURL: util.PtrToString("https://lbry.com"),
290+
CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"),
291+
})
292+
if err != nil {
293+
t.Error(err)
294+
return
295+
}
296+
time.Sleep(10 * time.Second)
297+
got2, err := d.SupportCreate(got.Outputs[0].ClaimID, "1.0", util.PtrToBool(true), nil, nil)
298+
if err != nil {
299+
t.Error(err)
300+
return
301+
}
302+
prettyPrint(*got2)
303+
304+
got3, err := d.SupportList(nil, 1, 10)
305+
if err != nil {
306+
t.Error(err)
307+
return
308+
}
309+
found := false
310+
for _, support := range got3.Items {
311+
if support.ClaimID == got.Outputs[0].ClaimID {
312+
found = true
313+
}
314+
}
315+
if !found {
316+
t.Error(errors.Err("support not found"))
317+
return
318+
}
319+
prettyPrint(*got3)
320+
got4, err := d.SupportAbandon(util.PtrToString(got.Outputs[0].ClaimID), nil, nil, nil, nil)
321+
if err != nil {
322+
t.Error(err)
323+
return
324+
}
325+
prettyPrint(*got4)
326+
}
327+
267328
func TestClient_ClaimSearch(t *testing.T) {
268329
d := NewClient("")
269-
got, err := d.ClaimSearch(nil, util.PtrToString("2a8b6d061c5ecb2515f1dd7e04729e9fafac660d"), nil, nil)
330+
got, err := d.ClaimSearch(nil, util.PtrToString(channelID), nil, nil)
270331
if err != nil {
271332
t.Error(err)
272333
return
@@ -405,8 +466,7 @@ func TestClient_AccountRemove(t *testing.T) {
405466

406467
func TestClient_ChannelExport(t *testing.T) {
407468
d := NewClient("")
408-
channelClaimID := "f1ad0d72eae6b471cfd72b7956768c0c191b22d7"
409-
response, err := d.ChannelExport(channelClaimID, nil, nil)
469+
response, err := d.ChannelExport(channelID, nil, nil)
410470
if err != nil {
411471
t.Error(err)
412472
}

extras/jsonrpc/daemon_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ type ClaimListResponse struct {
402402
}
403403
type ClaimSearchResponse ClaimListResponse
404404

405+
type SupportListResponse struct {
406+
Items []Claim
407+
Page uint64 `json:"page"`
408+
PageSize uint64 `json:"page_size"`
409+
TotalPages uint64 `json:"total_pages"`
410+
}
405411
type StatusResponse struct {
406412
BlobManager struct {
407413
FinishedBlobs uint64 `json:"finished_blobs"`

0 commit comments

Comments
 (0)