From 820becd8083b1dac3244af60721d0a1974c667ba Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 15 May 2020 17:38:32 +0200 Subject: [PATCH] Sort trustlines by asset code and issuer in `GET /acounts/{id}` (#2596) 698593a43c972293c084ce8ad0bea99b95b6dd9b sorts the balances for `GET /accounts` but not `GET /accounts/{id}`. This PR ties the loop. --- services/horizon/internal/actions/account.go | 2 +- services/horizon/internal/db2/history/trust_lines.go | 7 ++----- services/horizon/internal/db2/history/trust_lines_test.go | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/services/horizon/internal/actions/account.go b/services/horizon/internal/actions/account.go index 9ab92e3172..95c3cbc288 100644 --- a/services/horizon/internal/actions/account.go +++ b/services/horizon/internal/actions/account.go @@ -39,7 +39,7 @@ func AccountInfo(ctx context.Context, hq *history.Q, addr string) (*protocol.Acc return nil, errors.Wrap(err, "getting history signers") } - trustlines, err = hq.GetTrustLinesByAccountID(addr) + trustlines, err = hq.GetSortedTrustLinesByAccountID(addr) if err != nil { return nil, errors.Wrap(err, "getting history trustlines") } diff --git a/services/horizon/internal/db2/history/trust_lines.go b/services/horizon/internal/db2/history/trust_lines.go index f87bac089f..d0c3aab97d 100644 --- a/services/horizon/internal/db2/history/trust_lines.go +++ b/services/horizon/internal/db2/history/trust_lines.go @@ -32,11 +32,8 @@ func (q *Q) CountTrustLines() (int, error) { return count, nil } -func (q *Q) GetTrustLinesByAccountID(id string) ([]TrustLine, error) { - var trustLines []TrustLine - sql := selectTrustLines.Where(sq.Eq{"account_id": id}) - err := q.Select(&trustLines, sql) - return trustLines, err +func (q *Q) GetSortedTrustLinesByAccountID(id string) ([]TrustLine, error) { + return q.GetSortedTrustLinesByAccountIDs([]string{id}) } // GetTrustLinesByKeys loads a row from the `trust_lines` table, selected by multiple keys. diff --git a/services/horizon/internal/db2/history/trust_lines_test.go b/services/horizon/internal/db2/history/trust_lines_test.go index 657d23130f..89741df41f 100644 --- a/services/horizon/internal/db2/history/trust_lines_test.go +++ b/services/horizon/internal/db2/history/trust_lines_test.go @@ -352,7 +352,7 @@ func TestGetTrustLinesByAccountID(t *testing.T) { _, err := q.InsertTrustLine(eurTrustLine, 1234) tt.Assert.NoError(err) - record, err := q.GetTrustLinesByAccountID(eurTrustLine.AccountId.Address()) + record, err := q.GetSortedTrustLinesByAccountID(eurTrustLine.AccountId.Address()) tt.Assert.NoError(err) asset := xdr.MustNewCreditAsset(record[0].AssetCode, record[0].AssetIssuer)