Skip to content

Commit

Permalink
Sort trustlines by asset code and issuer in GET /acounts/{id} (#2596)
Browse files Browse the repository at this point in the history
698593a sorts the balances for `GET
/accounts` but not `GET /accounts/{id}`. This PR ties the loop.
  • Loading branch information
2opremio authored May 15, 2020
1 parent 362b33f commit 820becd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion services/horizon/internal/actions/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 2 additions & 5 deletions services/horizon/internal/db2/history/trust_lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/db2/history/trust_lines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 820becd

Please sign in to comment.