We should be able to initialize the wallet with an arbitrary descriptor like gun init <external-descriptor> [<internal-descriptor>]
With no change descriptor:
gun init descriptor "wpkh([AAB893A5/84'/0'/0']xpub661MyMwAqRbcFGjD5niBpcDJ1evbWb51fZ5N29BZRykhud3gEefAvjKvoqGVYXBnBS8JqN1cqCpZg8qJqSPjn9dJNamSXJj/0/*
With a change descriptor:
gun init descriptor "wpkh([AAB893A5/84'/0'/0']xpub661MyMwAqRbcFGjD5niBpcDJ1evbWb51fZ5N29BZRykhud3gEefAvjKvoqGVYXBnBS8JqN1cqCpZg8qJqSPjn9dJNamSXJj/0/*)" "wpkh([AAB893A5/84'/0'/0']xpub661MyMwAqRbcFGjD5niBpcDJ1evbWb51fZ5N29BZRykhud3gEefAvjKvoqGVYXBnBS8JqN1cqCpZg8qJqSPjn9dJNamSXJj/1/*)"
The above should simplify to the below:
gun init xpub "[AAB893A5/84'/0'/0']xpub661MyMwAqRbcFGjD5niBpcDJ1evbWb51fZ5N29BZRykhud3gEefAvjKvoqGVYXBnBS8JqN1cqCpZg8qJqSPjn9dJNamSXJj"
Implementation
I think the way this information should be stored should just be in the WalletKey enum like:
enum WalletKey {
SeedWordsFile,
Descriptor { external: String, internal: Option<String> }
}
And in the config.json like:
{
"kind": "descriptor",
"external" : "wpkh([AAB893A5/84'/0'/0']xpub661MyMwAqRbcFGjD5niBpcDJ1evbWb51fZ5N29BZRykhud3gEefAvjKvoqGVYXBnBS8JqN1cqCpZg8qJqSPjn9dJNamSXJj/0/*)",
"internal" "wpkh([AAB893A5/84'/0'/0']xpub661MyMwAqRbcFGjD5niBpcDJ1evbWb51fZ5N29BZRykhud3gEefAvjKvoqGVYXBnBS8JqN1cqCpZg8qJqSPjn9dJNamSXJj/1/*)"
}
Signing
I think the right thing to do is output the PSBT if a transaction is not finalized after signing. They should be output to psbt-output-dir
(default should be $GUN_DIR/psbts
). The filename should be <tentative-txid>.psbt
. You can get the tentative-txid by doing psbt.extract_tx().txid()
.
At the moment let's just hang and wait for the user to sign the PSBT there. Whenever they press enter read the file back in and check if it has been signed. Once it has been signed, broadcast it.
Choosing the network
Right now we have a mandatory <network>
argument to init
. This should just be made into a optional --network
argument with the default being "bitcoin"
Init with seed
The existing gun init
should go under gun init seed
.