Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clients/horizonclient: fix multi-parameter url for claimable balance query #4248

Merged
merged 16 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e681b94
bugfix: 4247 - claimable balance - check if one of the parameters is ID
iateadonut Feb 26, 2022
758d6b3
Merge branch 'master' of https://github.com/stellar/go into 4247/clai…
iateadonut Mar 1, 2022
a7e2313
Merge branch 'master' into 4247/claimable_balance
iateadonut Mar 1, 2022
4cec1fb
Merge branch '4247/claimable_balance' of github.com:iateadonut/go int…
iateadonut Mar 1, 2022
3d84568
clients/horizonclient: cursor and limit in ClaimableBalanceRequest
iateadonut Mar 4, 2022
c64d693
Merge branch 'master' into 4247/claimable_balance
iateadonut Mar 4, 2022
dfb520f
clients/horizonclient: cursor and limit in ClaimableBalanceRequest te…
iateadonut Mar 4, 2022
96a920f
Merge branch '4247/claimable_balance' of github.com:iateadonut/go int…
iateadonut Mar 4, 2022
a0be92d
Merge branch 'master' into 4247/claimable_balance
iateadonut Mar 5, 2022
2343187
clients/horizonclient: cursor and limit in ClaimableBalanceRequest - …
iateadonut Mar 5, 2022
c3ed6b2
Merge branch '4247/claimable_balance' of github.com:iateadonut/go int…
iateadonut Mar 5, 2022
3f4f3e7
Merge branch 'master' into 4247/claimable_balance
Shaptic Mar 25, 2022
9ac8dde
add test for limit; move cursor and limit out of params
iateadonut Mar 26, 2022
d54270a
Merge branch '4247/claimable_balance' of github.com:iateadonut/go int…
iateadonut Mar 26, 2022
4d0b6f0
claimable balance request: do not allow a limit of more than 200
iateadonut Mar 26, 2022
c10e167
Merge branch 'master' into 4247/claimable_balance
Shaptic Mar 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/horizonclient/claimable_balance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (cbr ClaimableBalanceRequest) BuildURL() (endpoint string, err error) {
// Only one filter parameter is allowed, and you can't mix an ID query and
// filters.
nParams := countParams(cbr.Asset, cbr.Claimant, cbr.Sponsor, cbr.ID)
if nParams > 1 {
if cbr.ID != "" && nParams > 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is necessary? countParams returns 1 if the cbr.ID is set.

Copy link
Contributor Author

@iateadonut iateadonut Mar 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is necessary; you can have more than one parameter if the ID is not set.

This is valid but returns and error with no cbr.ID != "" condition:

balances, err := client.ClaimableBalances(horizonclient.ClaimableBalanceRequest{
		Claimant: "CLAIMANT_ADDRESS",
		Asset: "AQUA:GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA",
		Limit: 200,
	})

it would query this: https://horizon.stellar.org/claimable_balances/?claimant=GDJCDWRAAB3LA6TT32OBOXV2UYVJEVPKMQXDLUWYH7FQ73MCTH3UNPT7&limit=200&asset=AQUA:GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA

see the associated test, https://github.com/stellar/go/pull/4248/files#diff-368f30ea351d73347fe7c2dac69307ae69e3cdf5f2e92f6d584e097aa256db31line 26

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, so the comment is a lie then 🤔 can you rephrase it? Then ✔️ from my perspective 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the comment to:
// You can't mix an ID query and filters.

and the error verbiage to:
return endpoint, errors.New("invalid request: you cannot have an ID query with filters")

return endpoint, errors.New("invalid request: too many parameters")
}

Expand Down
34 changes: 34 additions & 0 deletions clients/horizonclient/claimable_balance_request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package horizonclient

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestClaimableBalanceBuildUrl(t *testing.T) {

cbr := ClaimableBalanceRequest{
ID: "1235",
}
url, err := cbr.BuildURL()
assert.Equal(t, "claimable_balances/1235", url)
assert.NoError(t, err)

//if the ID is included, you cannot include another parameter
cbr = ClaimableBalanceRequest{
ID: "1235",
Claimant: "CLAIMANTADDRESS",
}
_, err = cbr.BuildURL()
assert.EqualError(t, err, "invalid request: too many parameters")

//if you have two parameters, and neither of them are ID, it must use both in the URL
cbr = ClaimableBalanceRequest{
Claimant: "CLAIMENTADDRESS",
iateadonut marked this conversation as resolved.
Show resolved Hide resolved
Asset: "TEST:ISSUERADDRESS",
}
url, err = cbr.BuildURL()
assert.NoError(t, err)
assert.Equal(t, "claimable_balances?asset=TEST%3AISSUERADDRESS&claimant=CLAIMENTADDRESS", url)
}