kaspanet / rusty-kaspa

Kaspa full-node and related libraries in the Rust programming language. This is a stable version at the initial rollout phases.
ISC License
371 stars 118 forks source link

CLI watch-only account implementation #470

Open 1bananagirl opened 1 month ago

1bananagirl commented 1 month ago

The new account type watch-only supports:

Changes:

Future:

1bananagirl commented 1 month ago

Thanks for you review Maxim!

Refactoring

I've renamed the watch-only account to bip32-watch and removed multisig polymorphism, thus multisig watch-only remaining solely in the multisig account.

I've followed aspect's advice to add a helper function in the wallet module to format XPUB export according to network.

The new helper function is triggered by providing a new type TaggedXpub that is a pair formed of an extended public key and the network ID.

Inside the bip32 prefix submodule resides a new converter to get the right prefix for a given network.

Account feature trait

The notion of feature was added to the account trait as a fn, defaulting to Option None, and is implemented in Bip32Watch and Multisig/watch-only to return a string giving an indication on the special feature of an account - which is watch-only in our case - an indication used to highlight that feature in the list and details commands output.

That step was necessary for the iterator filtering in details and list commands to be simple stupid finding out which account without private keys to consider printing.

Commands

CLI commands for importing watch-only accounts now look like this:

   account import bip32-watch
   account import multisig-watch

I'm open to switch this to "account create" if needed.

I've found it more efficient to make a new parameter "multisig-watch" instead of bypassing "account create multisig", but if you insist, I can make that work instead.

Output

The display of xpubs for watch-only account has been moved from the CLI list command output to the details output in order to not clutter the list view.

According to the currently selected network, the xpubs are now formatted with the appropriate prefix.