Page MenuHomePhabricator

[alias-server] Add API endpoint to get pending aliases by address
ClosedPublic

Authored by bytesofman on Sep 14 2023, 22:14.

Details

Summary

Expose /pending/<address> endpoint for use in Cashtab to prevent accidental double registration of aliases and track user's pending aliases to success / failure

Test Plan

npm test

Diff Detail

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

Event Timeline

emack requested changes to this revision.Sep 15 2023, 07:17
emack added a subscriber: emack.

I've been looking at this from a customer (wallet dev) POV. To show the latest alias list attached to the wallet I would have to call /address to get the list of confirmed aliases and then quickly followed by /pending to get the pending list.

Is it more efficient to update the /address endpoint to return the results from /pending as well?

Especially when you think of the use cases:

  • user loads Alias.js and needs to render a list of confirmed and pending aliases - one single API call would be best
  • user tries to register the same alias a 2nd time and the wallet would be parsing both confirmed and pending aliases before proceeding with registration broadcast - one single API call here would also be best
  • user successfully broadcasts a new alias registration which then refresh the aliases displayed on page

The /pending endpoint does have its use, if other wallets want to render the pending list separately. Just that from Cashtab's pov it would be good to just call /address to include pending aliases.

Also confirming:

  • This means Cashtab no longer needs to store a pending list in localForage since everything is taken off the endpoint?
  • Which also means the current interval to execute periodic pending checks is now a confirmed+pending check?
This revision now requires changes to proceed.Sep 15 2023, 07:17

This means Cashtab no longer needs to store a pending list in localForage since everything is taken off the endpoint?

Correct -- we don't want this to rely on local storage as this would make it device dependent.

Which also means the current interval to execute periodic pending checks is now a confirmed+pending check?

on load, check the pending list. if any pending, render them as such. at some fixed interval, check in on what has happened to the pending aliases. they will either become registered (appear at confirmed endpoint) or invalid (disappear from pending + some other tx with that alias is on the confirmed list). Edge case that they disappear from pending and nothing becomes confirmed, i.e. dropped from the mempool. Can also call this "invalid".

For Cashtab purposes, keep the pending list in state.

Re: adding pending to one endpoint -- yeah that makes sense, will do this.

Add pending aliases to existing /address/ endpoint

bytesofman added inline comments.
apps/alias-server/src/app.js
171 ↗(On Diff #42232)

imo it's worth keeping a separate "just give me the pending aliases by address" endpoint as there are some use cases where Cashtab may want only this information, i.e. determining which txs need to be tracked to some kind of result. Getting all the registered aliases for this case would be overkill.

Makes sense to always provide pending for /address/<address> as most dev use cases of here would need both. Can be further customized if there is a need but we don't really want the API to be a custom db query system.

Fabien added inline comments.
apps/alias-server/src/app.js
171 ↗(On Diff #42232)

You can just add a param to the query, like /address/<address> returns both, /address/<address>?pending=true returns pending only and /address/<address>?pending=false returns confirmed only

bytesofman marked an inline comment as done.
bytesofman added inline comments.
apps/alias-server/src/app.js
171 ↗(On Diff #42232)

ended up being not so trivial to implement this in express.

On further consideration, just simplify and do not keep a unique "pending only" feature. Cashtab will always be calling for both so will not need pending only. The need for pending-only is at this point hypothetical.

Will engineer for it if the need becomes clear.

apps/alias-server/src/app.js
152 ↗(On Diff #42252)

Did you consider using pagination here ? What happens if a user registers a ton of aliases to a single address ?

apps/alias-server/test/app.test.js
137 ↗(On Diff #42252)

the keys in the json are strings right ? The fact that you can use a variable name is due to the software encoding/decoding ?

bytesofman added inline comments.
apps/alias-server/src/app.js
152 ↗(On Diff #42252)

Pagination could be necessary at some point but imo we don't need it to launch. Complication for front end and back end implementation + unrelated to this diff.

apps/alias-server/test/app.test.js
137 ↗(On Diff #42252)

Right.

This revision is now accepted and ready to land.Sep 19 2023, 14:19