diff --git a/clients/horizonclient/CHANGELOG.md b/clients/horizonclient/CHANGELOG.md index 4f98630701..09be4500f0 100644 --- a/clients/horizonclient/CHANGELOG.md +++ b/clients/horizonclient/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +- Add support for querying operation endpoint with `join` parameter [#1521](https://github.com/stellar/go/issues/1521). + + ## [v1.3.0](https://github.com/stellar/go/releases/tag/horizonclient-v1.3.0) - 2019-07-08 - Transaction information returned by methods now contain new fields: `FeeCharged` and `MaxFee`. `FeePaid` is deprecated and will be removed in later versions. diff --git a/clients/horizonclient/internal.go b/clients/horizonclient/internal.go index deb1b8500a..aefaff588f 100644 --- a/clients/horizonclient/internal.go +++ b/clients/horizonclient/internal.go @@ -95,6 +95,10 @@ func addQueryParams(params ...interface{}) string { if param { query.Add("include_failed", "true") } + case join: + if param != "" { + query.Add("join", string(param)) + } case map[string]string: for key, value := range param { if value != "" { diff --git a/clients/horizonclient/main.go b/clients/horizonclient/main.go index 9c68dae9b2..ed0fadc818 100644 --- a/clients/horizonclient/main.go +++ b/clients/horizonclient/main.go @@ -46,6 +46,9 @@ type includeFailed bool // AssetType represents `asset_type` param in queries type AssetType string +// join represents `join` param in queries +type join string + const ( // OrderAsc represents an ascending order parameter OrderAsc Order = "asc" @@ -271,6 +274,7 @@ type OperationRequest struct { Cursor string Limit uint IncludeFailed bool + Join string endpoint string } diff --git a/clients/horizonclient/main_test.go b/clients/horizonclient/main_test.go index d446f2d07e..63495c57fa 100644 --- a/clients/horizonclient/main_test.go +++ b/clients/horizonclient/main_test.go @@ -733,12 +733,12 @@ func TestOperationsRequest(t *testing.T) { HTTP: hmock, } - operationRequest := OperationRequest{} + operationRequest := OperationRequest{Join: "transactions"} // all operations hmock.On( "GET", - "https://localhost/operations", + "https://localhost/operations?join=transactions", ).ReturnString(200, multipleOpsResponse) ops, err := client.Operations(operationRequest) @@ -768,7 +768,7 @@ func TestOperationsRequest(t *testing.T) { // all payments hmock.On( "GET", - "https://localhost/payments", + "https://localhost/payments?join=transactions", ).ReturnString(200, paymentsResponse) ops, err = client.Payments(operationRequest) diff --git a/clients/horizonclient/operation_request.go b/clients/horizonclient/operation_request.go index 44865d6f2b..ff16cbff12 100644 --- a/clients/horizonclient/operation_request.go +++ b/clients/horizonclient/operation_request.go @@ -38,7 +38,7 @@ func (op OperationRequest) BuildURL() (endpoint string, err error) { } queryParams := addQueryParams(cursor(op.Cursor), limit(op.Limit), op.Order, - includeFailed(op.IncludeFailed)) + includeFailed(op.IncludeFailed), join(op.Join)) if queryParams != "" { endpoint = fmt.Sprintf("%s?%s", endpoint, queryParams) } diff --git a/clients/horizonclient/operation_request_test.go b/clients/horizonclient/operation_request_test.go index 64c8eb0412..078a8bdc78 100644 --- a/clients/horizonclient/operation_request_test.go +++ b/clients/horizonclient/operation_request_test.go @@ -56,17 +56,29 @@ func TestOperationRequestBuildUrl(t *testing.T) { assert.Contains(t, err.Error(), "invalid request: too many parameters") } - op = OperationRequest{Cursor: "123456", Limit: 30, Order: OrderAsc, endpoint: "operations"} + op = OperationRequest{Cursor: "123456", Limit: 30, Order: OrderAsc, endpoint: "operations", Join: "transactions"} endpoint, err = op.BuildURL() // It should return valid all operations endpoint with query params and no errors require.NoError(t, err) - assert.Equal(t, "operations?cursor=123456&limit=30&order=asc", endpoint) + assert.Equal(t, "operations?cursor=123456&join=transactions&limit=30&order=asc", endpoint) - op = OperationRequest{Cursor: "123456", Limit: 30, Order: OrderAsc, endpoint: "payments"} + op = OperationRequest{Cursor: "123456", Limit: 30, Order: OrderAsc, endpoint: "payments", Join: "transactions"} endpoint, err = op.BuildURL() // It should return valid all operations endpoint with query params and no errors require.NoError(t, err) - assert.Equal(t, "payments?cursor=123456&limit=30&order=asc", endpoint) + assert.Equal(t, "payments?cursor=123456&join=transactions&limit=30&order=asc", endpoint) + + op = OperationRequest{ForAccount: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU", endpoint: "payments", Join: "transactions"} + endpoint, err = op.BuildURL() + // It should return valid all operations endpoint with query params and no errors + require.NoError(t, err) + assert.Equal(t, "accounts/GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU/payments?join=transactions", endpoint) + + op = OperationRequest{forOperationID: "1234", endpoint: "payments", Join: "transactions"} + endpoint, err = op.BuildURL() + // It should return valid all operations endpoint with query params and no errors + require.NoError(t, err) + assert.Equal(t, "operations/1234?join=transactions", endpoint) } func ExampleClient_StreamOperations() {