Page MenuHomePhabricator

[Cashtab] [Alias] pt 4 - Implement isAddressRegistered function
ClosedPublic

Authored by emack on Dec 18 2022, 04:22.

Details

Summary

T2551

Depends on D12907

This diff fleshes out the isAddressRegistered function which is called upon loading the Alias component to check whether the current active wallet has any onchain aliases attached to it.

The payment address tx history retrieval logic was moved into it's own getAliasPaymentHistory function so that it can be reused by both isAddressRegistered and isAliasAvailable.

isAddressRegistered basically filters for valid incoming registration transactions at the alias payment address and extracts the hash160 of inputs[0] (the sender address of a valid registration tx) and compares it to the active wallet's hash160 (wallet.Path1899.hash160).

In later diffs the chronik API calls in isAddressRegistered will retrieve cached tx histories if the tx count of the alias payment address has not changed.

[Cashtab] [Alias] pt 1 - Create scaffold for new Identity component
[Cashtab] [Alias] pt 2 - Implement registerNewAlias() 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 - Implement isLocalAliasStateLatest function
[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
  • use a wallet that you have previously registered an alias with from part 3 of this stack
  • navigate to the Alias page and verify the 'Does this active wallet have an onchain alias? : true' console log message is displayed
  • switch to a wallet that did not previously register an alias then navigate to the Alias page and verify the 'Does this active wallet have an onchain alias? : false' console log message is displayed

Diff Detail

Repository
rABC Bitcoin ABC
Branch
aliases
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 21621
Build 42883: Build Diffcashtab-tests
Build 42882: arc lint + arc unit

Event Timeline

emack requested review of this revision.Dec 18 2022, 04:22

For both isAliasAvailable and isAddressRegistered, the input data should be the same. The missing piece here is a fetchAndCacheValidAliasesThroughLatestBlock function. This should return an object that looks something like

{
  validAliases = {registeredAliases: [{alias: alias1, address: address1}, {alias: alias2, address: address2}, ... , {alias: aliasN, address: addressN}] 
  validThruBlockheight: <blockheight where registeredAliases is valid through>
}
  • adjusted inline hash160 conversions in line with part 3
  • updated OP_RETURN parsing to following the prefix standard set in part 3
bytesofman added inline comments.
web/cashtab/src/utils/chronik.js
162 ↗(On Diff #37547)

I'm not sure this function is necessary.

Once this system is live, the behavior we want is

On Cashtab load, update alias list to current blockheight
If we have an isAddressRegistered function, it should only be checking localStorage

As time goes on, we could add checkpoints -- i.e. add list of aliases, addresses, and blockheight to which the list is valid to currency.Ticker instead of localStorage, so that new Cashtab users aren't forced to parse the whole tx history of the alias address when they first use the app.

So, instead of implementing caching in this function -- this function should just depend on the output of the extractAliasesFromPaymentAddress function from Part 2

164 ↗(On Diff #37547)

local storage should preserve a list of valid alias registrations, their address, and the blockheight to which it is valid

This revision now requires changes to proceed.Jan 17 2023, 23:45
emack marked 2 inline comments as done.
  • refactored isAddressRegistered to parse a mocked (for now) localStorage object rather than an onchain call to chronik
  • removed runtime hash160 address conversions as per D12907
This revision is now accepted and ready to land.Jan 18 2023, 14:25