chris-belcher / electrum-personal-server

Maximally lightweight electrum server for a single user
MIT License
599 stars 109 forks source link

api to manage xpubs #71

Open benma opened 5 years ago

benma commented 5 years ago

It would be nice if an electrum-personal-server client could add and remove xpubs through some sort of API, instead of messing with the config file, and without restarting the server.

This would be nice so electrum clients could automatically start tracking an xpub, without the user having to manually deal with this.

Possibly related: #63

chris-belcher commented 5 years ago

What use-case are you thinking of?

I ask because APIs are usually only used by other scripts and not people. Maybe a GUI option would be better (as you allude with the link to #63)

Adding xpub keys could be complicated because they might require a long rescan, and in that time the server shouldn't really be responding to client requests because it doesn't have enough information. The server should ideally shut down (but maybe not, because it can still serve information about xpubs it has rescanned). The long rescan times really mean that xpub keys should be added all at once and a single rescan started to scan them all.

Another option could be that the Electrum wallet is edited to optionally send xpub keys and wallet creation dates to the server. This is complicated because Electrum seed phrases don't store the wallet creation date so Electrum won't always know it.

chris-belcher commented 5 years ago

I was talking to Nicolas Dorier about BTCPay which could use this feature to make it easier to use EPS with BTCPay. I think they only need a way to add new empty master public keys.

This is maybe done most cleanly by having EPS periodically reload the config file and check whether any new master public keys have been added.

benma commented 5 years ago

That would be a good start. How would the proposed workflow be from a client to add an xpub? If EPS doesn't expose an API call, another sort of service would need to run alongside EPS, right?

chris-belcher commented 5 years ago

I don't think requiring another service to be running makes the most sense. It might be better to have EPS itself expose an RPC socket which supports those API calls.

Ideally we'd keep code complexity down and usability up. I think some more on the best way to do this.

benma commented 5 years ago

Agreed. Maybe one option is to extend the electrum protocol with new api endpoints (prefixed with eps or similar to keep namespaces separate from the other electrum endpoints), then the same connection can be used. A separate connection just for EPS is also ok, but it would be good to stick to the same rpc protocol and not something different.

chris-belcher commented 5 years ago

How would the proposed workflow be from a client to add an xpub?

I realized I never answered this, sorry.

The workflow would be that the user or software like BTCPay server edits the config file to add a new xpub key. Soon EPS will notice that edit and then start watching the bitcoin addresses corresponding to the new xpub, and start monitoring for new transactions if any arrive.