Add dev-listaddrs option - #1001
Conversation
|
Quite useful, thanks. Rather than an |
|
I'm missing an address that has funds from |
|
@Sjors yes, the |
ZmnSCPxj
left a comment
There was a problem hiding this comment.
Mostly indentation changes --- we use 8-wide tabs and align to just after opening (
| const tal_t *tmpctx = tal_tmpctx(NULL); | ||
|
|
||
| if (!json_get_params(cmd, buffer, params, | ||
| "?bip32_max_index", &bip32tok, NULL)) { |
There was a problem hiding this comment.
Not preferred indentation. Should be:
if (!json_get_params(cmd, buffer, params,
"?bip32_max_index", &bip32tok,
NULL)) {
(the extreme indentation rather makes the newline useless)
|
|
||
| for (s64 keyidx = 0; keyidx < bip32_max_index; keyidx++) { | ||
|
|
||
|
|
|
|
||
|
|
||
| if(keyidx == BIP32_INITIAL_HARDENED_CHILD){ | ||
| command_fail(cmd, "Keys exhausted "); |
There was a problem hiding this comment.
Why fail the command at this point? You are only listing existing addresses, not generating a new one. Maybe better to break out of this loop instead?
There was a problem hiding this comment.
dev-listaddrs supports bip32_max_index option to show all existing or not existing addresses up to bip32_max_index for testing. The default value, show only existing addresses according to bip32_max_index value inside vars table in sqlite. It is better break out instead command fail.
| } | ||
|
|
||
| if (bip32_key_from_parent(cmd->ld->wallet->bip32_base, keyidx, | ||
| BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK) { |
There was a problem hiding this comment.
Please indent to align just after the opening ( of the call. Tabs are eight spaces.
| json_add_u64(response, "keyidx", keyidx); | ||
| json_add_pubkey(response, "pubkey", &pubkey); | ||
| json_add_string(response, "p2sh", out_p2sh); | ||
| json_add_hex(response, "p2sh_redeemscript", redeemscript, sizeof(struct ripemd160) + 1); |
There was a problem hiding this comment.
Why sizeof(struct ripemd160) + 1, why not tal_count(redeemscript)?
|
ACK fe224b5 |
|
Last commit resolves previous discussion, @rustyrussell suggests me to change |
| json_array_end(response); | ||
| json_object_end(response); | ||
| command_success(cmd, response); | ||
| tal_free(tmpctx); |
There was a problem hiding this comment.
Can also remove this tal_free now: command_* resolution functions destroy the cmd, and since tmpctx has cmd as parent, tmpctx is automatically freed by the command_* resolution functions.
There was a problem hiding this comment.
Thanks for explanation, in the last commit I move tal_free up to command_success. Now I can remove it.
ZmnSCPxj
left a comment
There was a problem hiding this comment.
Also add a test in tests/test_lightningd.py for successful use of dev-listaddrs command, as well as failure cases (invalid argument, out of range argument, etc). You can use l.rpc._call to get direct access to method name and parameters object.
| } | ||
| json_array_end(response); | ||
| json_object_end(response); | ||
| tal_free(tmpctx); |
There was a problem hiding this comment.
You also need to remove the tal_free(tmpctx) calls in the failure routes. Note that json_get_params itself will call command_fail_detailed if it returns false, and since tmpctx is now rooted from cmd, you should not be calling tal_free(tmpctx) there either. Also holds for your uses of command_fail.
There was a problem hiding this comment.
Thanks, I understand and fix.
|
The CI is pointing out that you do not actually use |
|
ACK 594ac0a |
Add dev-listaddrs command to show bip32 addresses list (up to bip32_max_index). From pr #940
help
$ lightning-cli help ... command=dev-listaddrs description=Show addresses list up to derivation {index} (default is the last bip32 index) ...output
$ lightning-cli dev-listaddrs { "addresses" : [ { "keyidx" : 0, "pubkey" : "...", "p2sh": "...", "p2sh_redeemscript": "...", "bech32": "...", "bech32_redeemscript": "..." }, .... ] }Set optional value {index} to show also future derivations up to {index}. This could be useful for testing and recovery. Default {index} value is
bip32_max_indexinvarstable of sqlite file.suggestion
If you prefer, I can add an
address_typeoption (bech32 or p2sh, likeget_newaddr) to show only one kind of derivation address.In this case, it shows only 2 fields (
address,redeemscript) instead 4 fields (p2sh,p2sh_redeemscript,bech32,bech32_redeemscript) as described at discussion.