Skip to content

Conversation

w0xlt
Copy link
Contributor

@w0xlt w0xlt commented Jul 30, 2022

This PR adds a new parameter save_to_file to listdescriptors RPC, allowing the user to save the descriptors directly to a file and also adds a new parameter desriptor_file to importdescriptors RPC, allowing the user to import the descriptors directly from a file.

The first and second commits add the options parameter in a way that maintains compatibility with the previous private parameter.

With this PR, exporting / importing descriptors and creating watch-only wallet is as simple as:

$ bitcoin-cli -rpcwallet="cold_wallet"  listdescriptors "{\"save_to_file\": \"/home/user/Downloads/desc.json\"}"
$ bitcoin-cli -rpcwallet="watch_only_wallet"  importdescriptors "{\"descriptor_file\": \"/home/user/Downloads/desc.json\"}"

Without this PR, the user can manually create a file from the listdescriptors output or use jq to extract the descriptor field from listdescriptors but the idea here is to make things more automated and standardized.

And this also opens the way to add the functionality of importing descriptors from files in the GUI,

w0xlt added 2 commits July 30, 2022 01:17
author: Luke Dashjr <luke-jr+git@utopios.org>
This changes `listdescriptors` to accept `options` parameter
but retains compatibility with the previous `private` parameter.
@kristapsk
Copy link
Contributor

What's the point? Why can't you just redirect bitcoin-cli output to the file?

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 30, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26156 (test: check that listdescriptors descriptor strings are sorted by theStack)
  • #26074 (refactor: Set RPCArg options with designated initializers by MarcoFalke)
  • #22838 (descriptors: Be able to specify change and receiving in a single descriptor string by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@w0xlt
Copy link
Contributor Author

w0xlt commented Jul 31, 2022

@kristapsk with #25757, perhaps the purpose of this PR has become clearer.

From the #25757 description:
With these PRs, exporting / importing descriptors and creating watch-only wallet is as simple as:

$ bitcoin-cli -rpcwallet="cold_wallet"  listdescriptors "{\"save_to_file\": \"/home/user/Downloads/desc.json\"}"
$ bitcoin-cli -rpcwallet="watch_only_wallet"  importdescriptors "{\"descriptor_file\": \"/home/user/Downloads/desc.json\"}"

Without these PRs, the user can manually create a file from the listdescriptors output or use jq to extract the descriptor field from listdescriptors but the idea here is to make things more automated and standardized.

And this also opens the way to add the functionality of importing descriptors from files in the GUI,

@aureleoules
Copy link
Contributor

Concept ACK considering #25757 exists. I think you should add the other PR's commits to this one.
I believe this makes exporting and importing descriptors easier.

Copy link
Contributor

@aureleoules aureleoules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to save the descriptor file with
./src/bitcoin-cli -regtest -rpcwallet=test listdescriptors '{"save_to_file": "my_desc"}'
But I feel like the syntax is a bit much, is there a way to simplify it?

In this case, it would be simplier to just do ./src/bitcoin-cli -regtest -rpcwallet=test listdescriptors > my_desc

Comment on lines 82 to 90
desc_file = os.path.join(node.datadir, 'desc.json')
assert_equal({
'wallet_name': 'w2',
'descriptor_file': desc_file
}, wallet.listdescriptors({'save_to_file': desc_file}))

with open(desc_file, encoding="utf8") as json_file:
assert_equal(expected['descriptors'], json.load(json_file))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a case when the file already exists?

Copy link
Contributor Author

@w0xlt w0xlt Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in dd96b3d.

w0xlt added 3 commits August 2, 2022 16:08
This changes `importdescriptors` to accept `options` parameter
but maintains compatibility with the previous `requests` parameter.
@w0xlt w0xlt changed the title rpc: add a new parameter save_to_file to listdescriptors RPC rpc: add ability to export/import descriptor files in listdescriptors and importdescriptors Aug 2, 2022
@w0xlt
Copy link
Contributor Author

w0xlt commented Aug 2, 2022

@aureleoules As suggested, I merged the other PR's commit to this one.

Note that ./src/bitcoin-cli -regtest -rpcwallet=test listdescriptors > my_desc does not create a descriptor file, but a file whose content is the RPC response. You cannot directly import the content of this file into importdescriptors.

The save_to_file option writes in the file only the descriptors attribute of the response.

@S3RK
Copy link
Contributor

S3RK commented Aug 8, 2022

Concept NACK. Using shell redirection is enough for CLI. Probably this change is better fitting with the GUI.

@luke-jr
Copy link
Member

luke-jr commented Aug 9, 2022

Concept NACK. I think we're trying to eliminate file-based RPC methods? At the very least, we shouldn't make RPC methods that do both file-based and non-file-based access...

@w0xlt
Copy link
Contributor Author

w0xlt commented Aug 10, 2022

This PR assumes that using descriptor files is a less error-prone and less manual way of creating watch-only wallets than the current way.

If it is not the case, what is the current workflow to create a watch-only wallet ?

@luke-jr
Copy link
Member

luke-jr commented Aug 10, 2022

For that use case, I would suggest a RPC method that makes a watch-only copy of a loaded wallet.

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@achow101
Copy link
Member

This PR does not seem to have conceptual support. Please leave a comment if you would like this to be reopened.

@achow101 achow101 closed this Oct 12, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Oct 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants