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

Feature Request: Sort balances #2447

Closed
abuiles opened this issue Apr 3, 2020 · 4 comments
Closed

Feature Request: Sort balances #2447

abuiles opened this issue Apr 3, 2020 · 4 comments
Labels
feature request horizon horizon-api Issues or features related to the Horizon API

Comments

@abuiles
Copy link
Contributor

abuiles commented Apr 3, 2020

What problem does your feature solve?

Balances cam come in different order between request, the following responses contain the same data but the order is different in both:

"balances": [
    {
      "balance": "2.0100000",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 14599295,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "SLT",
      "asset_issuer": "GCKA6K5PCQ6PNF5RQBF7PQDJWRHO6UOGFMRLK3DYHDOI244V47XKQ4GP"
    },
    {
      "balance": "1.0000000",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 11479636,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "HUG",
      "asset_issuer": "GD5T6IPRNCKFOHQWT264YPKOZAWUMMZOLZBJ6BNQMUGPWGRLBK3U7ZNP"
    },
    {
      "balance": "0.0099999",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 10135487,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "EUR",
      "asset_issuer": "GDI73WJ4SX7LOG3XZDJC3KCK6ED6E5NBYK2JUBQSPBCNNWEG3ZN7T75U"
    },
    {
      "balance": "0.0024939",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000002",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 19967410,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "DEMO",
      "asset_issuer": "GBAMBOOZDWZPVV52RCLJQYMQNXOBLOXWNQAY2IF2FREV2WL46DBCH3BE"
    },
    {
      "balance": "0.0000000",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 20511785,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "BTC",
      "asset_issuer": "GAUTUYY2THLF7SGITDFMXJVYH3LHDSMGEAKSBU267M2K7A3W543CKUEF"
    },
    {
      "balance": "90.2366572",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000001",
      "asset_type": "native"
    }
  ]

vs

"balances": [
    {
      "balance": "2.0100000",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 14599295,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "SLT",
      "asset_issuer": "GCKA6K5PCQ6PNF5RQBF7PQDJWRHO6UOGFMRLK3DYHDOI244V47XKQ4GP"
    },
    {
      "balance": "1.0000000",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 11479636,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "HUG",
      "asset_issuer": "GD5T6IPRNCKFOHQWT264YPKOZAWUMMZOLZBJ6BNQMUGPWGRLBK3U7ZNP"
    },
    {
      "balance": "0.0000000",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 20511785,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "BTC",
      "asset_issuer": "GAUTUYY2THLF7SGITDFMXJVYH3LHDSMGEAKSBU267M2K7A3W543CKUEF"
    },
    {
      "balance": "0.0099999",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 10135487,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "EUR",
      "asset_issuer": "GDI73WJ4SX7LOG3XZDJC3KCK6ED6E5NBYK2JUBQSPBCNNWEG3ZN7T75U"
    },
    {
      "balance": "0.0024939",
      "limit": "922337203685.4775807",
      "buying_liabilities": "0.0000002",
      "selling_liabilities": "0.0000000",
      "last_modified_ledger": 19967410,
      "is_authorized": true,
      "asset_type": "credit_alphanum4",
      "asset_code": "DEMO",
      "asset_issuer": "GBAMBOOZDWZPVV52RCLJQYMQNXOBLOXWNQAY2IF2FREV2WL46DBCH3BE"
    },
    {
      "balance": "90.2366572",
      "buying_liabilities": "0.0000000",
      "selling_liabilities": "0.0000001",
      "asset_type": "native"
    }
  ]

What would you like to see?

I'd like for balances to keep the same order between requests. It could be trustlines first (as it is today), sorted by asset_code and native at the end.

What alternatives are there?

Not sorting

@ire-and-curses ire-and-curses added horizon horizon-api Issues or features related to the Horizon API labels Apr 3, 2020
@2opremio 2opremio self-assigned this Apr 24, 2020
@2opremio
Copy link
Contributor

I run into this when running horizon-cmp. Self-assigning (if @ire-and-curses agrees)

@ire-and-curses
Copy link
Member

Yeah, go for it!

@bartekn
Copy link
Contributor

bartekn commented May 4, 2020

I'm working on a completely unrelated code and just got a failure in TestAccountInfo:

--- FAIL: TestAccountInfo (0.72s)
    db.go:122: Test Database: test_4e220c223c3f
    db.go:122: Test Database: test_785e362bfd9c
    account_test.go:233: 
        	Error Trace:	account_test.go:233
        	Error:      	Not equal: 
        	            	expected: "USD"
        	            	actual  : "EUR"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-USD
        	            	+EUR
        	Test:       	TestAccountInfo
    account_test.go:234: 
        	Error Trace:	account_test.go:234
        	Error:      	Not equal: 
        	            	expected: "EUR"
        	            	actual  : "USD"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1 +1 @@
        	            	-EUR
        	            	+USD
        	Test:       	TestAccountInfo

Looks like we don't use the new GetSortedTrustLinesByAccountIDs in actions.AccountInfo (still used by legacy actions code).

@bartekn
Copy link
Contributor

bartekn commented May 15, 2020

Fixed in #2596.

@bartekn bartekn closed this as completed May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request horizon horizon-api Issues or features related to the Horizon API
Projects
None yet
Development

No branches or pull requests

4 participants