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

indexer and api: track accounts, balances #1135

Merged
merged 1 commit into from
Nov 7, 2023
Merged

Conversation

mariajdab
Copy link
Contributor

@mariajdab mariajdab commented Oct 9, 2023

Note:

The proposal approach use upsert operation to insert or update an account, due the currently approach calls OnSetAccount Listener when an account is created and also when the balance is updated. This approach was tested in the indexer and integration test. Suggestions are welcome.

  • SQL changes
  • Query for fetching the paginated list of accounts
  • Query for fetching the list of token transfers by to_account
  • Query to count the number of accounts
  • Implement a query to count the number of transfers where the to_account is the provided address and where the from_account is the provided address
  • IAPI endpoint and APIclient method /accounts/page/:num
  • API endpoint and APIclient method /accounts/count
  • API endpoint /accounts/{accountID}/transfers/count to provide the total number of sent and received transactions
  • Current API endpoint /accounts/{accountID}/transfers/page/:page extended so it contains the received and sent transfers.
  • unit tests of the indexer new queries
  • integration tests into test/api_test.go

@mariajdab mariajdab requested review from p4u, mvdan and altergui October 9, 2023 03:08
@coveralls
Copy link

coveralls commented Oct 9, 2023

Pull Request Test Coverage Report for Build 6786885591

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 206 of 340 (60.59%) changed or added relevant lines in 7 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 61.728%

Changes Missing Coverage Covered Lines Changed/Added Lines %
vochain/indexer/db/account.sql.go 21 29 72.41%
vochain/indexer/db/token_transfers.sql.go 25 33 75.76%
cmd/end2endtest/account.go 11 21 52.38%
vochain/indexer/indexer.go 59 69 85.51%
api/accounts.go 63 90 70.0%
vochain/indexer/db/db.go 10 40 25.0%
apiclient/account.go 17 58 29.31%
Totals Coverage Status
Change from base Build 6782737322: 0.3%
Covered Lines: 14548
Relevant Lines: 23568

💛 - Coveralls

@mariajdab mariajdab force-pushed the indexer/track-account-balance branch 7 times, most recently from 4e49611 to f40ede1 Compare October 12, 2023 02:49
@mariajdab mariajdab force-pushed the indexer/track-account-balance branch 9 times, most recently from 27cc966 to 4acddf8 Compare October 23, 2023 22:39
@mariajdab mariajdab force-pushed the indexer/track-account-balance branch from 4acddf8 to f8aae38 Compare October 25, 2023 02:08
@mariajdab
Copy link
Contributor Author

@mvdan could you please review this PR when you have a chance? thanks 🙌

@mariajdab mariajdab changed the title indexer: track accounts, balances indexer and api: track accounts, balances Oct 25, 2023
@mariajdab mariajdab marked this pull request as ready for review October 25, 2023 02:19
@mariajdab mariajdab force-pushed the indexer/track-account-balance branch 2 times, most recently from 60900b3 to be2fe43 Compare October 25, 2023 03:29
Copy link
Contributor

@altergui altergui left a comment

Choose a reason for hiding this comment

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

i didn't finish the review yet but leaving here some thought about names

apiclient/account.go Outdated Show resolved Hide resolved
apiclient/account.go Outdated Show resolved Hide resolved
apiclient/account.go Outdated Show resolved Hide resolved
api/accounts.go Outdated Show resolved Hide resolved
api/accounts.go Outdated Show resolved Hide resolved
vochain/indexer/indexer.go Show resolved Hide resolved
@mariajdab mariajdab force-pushed the indexer/track-account-balance branch from be2fe43 to dd5e0fc Compare October 25, 2023 19:40
@mariajdab mariajdab requested a review from altergui October 30, 2023 11:33
@mariajdab mariajdab force-pushed the indexer/track-account-balance branch from dd5e0fc to a082c75 Compare October 31, 2023 03:41
@mariajdab mariajdab force-pushed the indexer/track-account-balance branch 2 times, most recently from 623fc56 to 68eeb23 Compare October 31, 2023 04:00
Copy link
Contributor

@altergui altergui left a comment

Choose a reason for hiding this comment

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

a couple more comments about names consistency, since i see in your commit message:

add new queries in token_transfers: GetTokenTransfersByToAccount, GetTokenTransfersByAccount, CountTokenTransfersByAccount

which sounds excellent and consistent,

yet in the code i see you missed the "By" in GetTokenTransfersAccount, CountTokenTransfersAccount. i pointed out the ones i spotted, maybe there are more

vochain/indexer/indexer.go Outdated Show resolved Hide resolved
vochain/indexer/indexer.go Outdated Show resolved Hide resolved
vochain/indexer/queries/token_transfers.sql Outdated Show resolved Hide resolved
@p4u
Copy link
Member

p4u commented Nov 6, 2023

@mariajdab could you resolve and close the pending comments please?

@mariajdab mariajdab force-pushed the indexer/track-account-balance branch 2 times, most recently from 83eb460 to 7ab05ad Compare November 6, 2023 16:54
@mariajdab
Copy link
Contributor Author

@mariajdab could you resolve and close the pending comments please?

Done 🙌

@mariajdab mariajdab requested a review from altergui November 6, 2023 16:54
@p4u
Copy link
Member

p4u commented Nov 7, 2023

It LGTM, good job @mariajdab

@p4u
Copy link
Member

p4u commented Nov 7, 2023

@mvdan it would be nice if you can take a look, however if that's not possible, we'll merge this into main, since other changes to the indexer are pending and would conflict with this one.

Copy link
Contributor

@mvdan mvdan left a comment

Choose a reason for hiding this comment

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

SGTM

vochain/indexer/queries/account.sql Show resolved Hide resolved
vochain/indexer/indexer.go Outdated Show resolved Hide resolved
…psertAccount

add new queries in token_transfers: GetTokenTransfersByToAccount, GetTokenTransfersByAccount, CountTokenTransfersByAccount
indexer: update method onSetAccount
integration test: update TestaccountAPI, add new test TestAPIAccountTokentxs
end2end: update tokenxs test
api: update GetTransfers, add countAccounts

swagger documentation
@mariajdab mariajdab force-pushed the indexer/track-account-balance branch from 7ab05ad to fdafc96 Compare November 7, 2023 15:44
@mariajdab
Copy link
Contributor Author

The last step is: open the issue in Interoperability announcing the changes to the API, so the SDK and documentation can incorporate them. Just to confirm that needs to be done before or after merge this PR ? @p4u

@mariajdab mariajdab requested a review from mvdan November 7, 2023 15:50
@p4u
Copy link
Member

p4u commented Nov 7, 2023

The last step is: open the issue in Interoperability announcing the changes to the API, so the SDK and documentation can incorporate them. Just to confirm that needs to be done before or after merge this PR ? @p4u

You can do it after. Just document the new endpoints so at some point they can be incorporated into the SDK https://github.com/vocdoni/interoperability/issues

@p4u
Copy link
Member

p4u commented Nov 7, 2023

I will merge this PR. Thanks for your work @mariajdab

@p4u p4u merged commit 62788d2 into main Nov 7, 2023
11 checks passed
@p4u p4u deleted the indexer/track-account-balance branch November 7, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants