Page MenuHomePhabricator

[Cashtab] [Alias] pt 6.1 - Get latest alias tx count from payment address
ClosedPublic

Authored by emack on Jan 21 2023, 13:06.

Details

Summary

T2551

Depends on D13015

As per tg discussion this diff is now repurposed to retrieve the latest total tx count for the Alias payment address as part of a multi diff caching implementation.

I leveraged the total tx count logic from https://reviews.bitcoinabc.org/D13010 and I also validated an invalid hash160 will cause Promise.All to fail as intended.

[Cashtab] [Alias] pt 1 - Create scaffold for new Identity component
[Cashtab] [Alias] pt 2 - Upgrade sendXec() to handle alias registration
[Cashtab] [Alias] pt 3 - Implement isAliasAvailable function
[Cashtab] [Alias] pt 4 - Implement isAddressRegistered function
[Cashtab] [Alias] pt 5 - Implement getAddressFromAlias function
[Cashtab] [Alias] pt 6.1 - Get latest alias tx count from payment address
[Cashtab] [Alias] pt 6.2 - Implement getAliasesFromLocalForage
[Cashtab] [Alias] pt 6.3 - Implement updateAliases
[Cashtab] [Alias] pt 6.4 - Implement setAlisesToLocalForage
[Cashtab] [Alias] pt 6.5 - Deprecate caching related mocks and @TODOs
[Cashtab] [Alias] pt 7 - Enable alias lookup for Send XEC component
[Cashtab] [Alias] pt 8 - Enable alias lookup for Send Token component
[Cashtab] [Alias] pt 9 - Implement pricing mechanism
[Cashtab] [Alias] pt 10 - Server cron job
[Cashtab] [Alias] pt 11 - Upgrade tx history to recognize alias registration txs

Test Plan
  • npm test
  • npm start
  • navigate to the Alias page and verify console logs display the latest total tx count for the payment address and ensure it matches what's shown on explorer.e.cash
  • register a new alias, navigate to another page, then back to Alias and ensure the count in console log is incremented by 1.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

emack requested review of this revision.Jan 21 2023, 13:06

This can save some space but, since the function is just an API call, we should just make the API call. Different use cases in the app may want to handle the error differently.

This revision now requires changes to proceed.Jan 21 2023, 14:19

Updated block height retrieval to be a direct API call within Alias.js

emack retitled this revision from [Cashtab] [Alias] pt 6.1 - Create getLatestBlockHeight as a helper function to [Cashtab] [Alias] pt 6.1 - Get latest block height upon loading of Alias.js.Jan 21 2023, 14:38
emack edited the summary of this revision. (Show Details)

Do we still need to get the blockheight here? After examining, looks like we will actually need to know the latest alias transaction in the chronik tx history.

This revision now requires changes to proceed.Jan 21 2023, 14:50

repurposed to retrieve the latest total tx count for the Alias payment address as part of a multi diff caching implementation.

emack retitled this revision from [Cashtab] [Alias] pt 6.1 - Get latest block height upon loading of Alias.js to [Cashtab] [Alias] pt 6.1 - Get latest alias tx count from payment address.Jan 23 2023, 01:36
emack edited the summary of this revision. (Show Details)
emack edited the test plan for this revision. (Show Details)

This approach works and, depending on how you optimize in future diffs, worth greening here. Already a pretty big diff.

However, ultimate goal is to make getAllTxs as low-impact on the API as possible, especially if it's being called every time this page is visited. We don't need to collect the entire tx history every time the page is hit. If we have the tx history (or even just the tx count) cached, then we only need 2 api calls to get the new api count -- one to get the numPages, and another on the last page to see how many are on that page. Rest can be inferred from our txs per page variable (here 25).

i.e. if we know we have 11 pages from our first API call, we can infer we have 10*25 txs + 1*(a number less than or equal to 25).

Further optimization would be just calling the most recent page based on the tx count. i.e. if we have 255 as the last cached tx count, then we can just call for page 11 (i=10). If this page has 6 txs in it, then we know there are now 256 txs. If it still only has 5, no change. If it has 25 but numPages is still 11, then we have 275. If it has 25 and numPages=12, well, now we have to do one more call.

This revision is now accepted and ready to land.Jan 23 2023, 18:06