Skip to content

Add dev-listaddrs option - #1001

Merged
cdecker merged 7 commits into
ElementsProject:masterfrom
lvaccaro:dev-listaddrs
Feb 18, 2018
Merged

Add dev-listaddrs option#1001
cdecker merged 7 commits into
ElementsProject:masterfrom
lvaccaro:dev-listaddrs

Conversation

@lvaccaro

Copy link
Copy Markdown
Contributor

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_index in vars table of sqlite file.

suggestion

If you prefer, I can add an address_type option (bech32 or p2sh, like get_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.

@Sjors

Sjors commented Feb 14, 2018

Copy link
Copy Markdown
Contributor

Quite useful, thanks.

Rather than an address_type argument and/or showing both bech32 and p2sh variants, is there a way to know which variant was used?

@Sjors

Sjors commented Feb 14, 2018

Copy link
Copy Markdown
Contributor

I'm missing an address that has funds from THEIR_UNILATERAL/OUTPUT_TO_US, though this may be specific to #1000.

@cdecker

cdecker commented Feb 14, 2018

Copy link
Copy Markdown
Member

@Sjors yes, the their_unilateral/to_us is not part of the HD tree derived from the hsm_secret, but it's the only exception.

@ZmnSCPxj ZmnSCPxj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mostly indentation changes --- we use 8-wide tabs and align to just after opening (

Comment thread wallet/walletrpc.c Outdated
const tal_t *tmpctx = tal_tmpctx(NULL);

if (!json_get_params(cmd, buffer, params,
"?bip32_max_index", &bip32tok, NULL)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Comment thread wallet/walletrpc.c Outdated

for (s64 keyidx = 0; keyidx < bip32_max_index; keyidx++) {


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Extra newline...

Comment thread wallet/walletrpc.c Outdated


if(keyidx == BIP32_INITIAL_HARDENED_CHILD){
command_fail(cmd, "Keys exhausted ");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread wallet/walletrpc.c Outdated
}

if (bip32_key_from_parent(cmd->ld->wallet->bip32_base, keyidx,
BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please indent to align just after the opening ( of the call. Tabs are eight spaces.

Comment thread wallet/walletrpc.c Outdated
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why sizeof(struct ripemd160) + 1, why not tal_count(redeemscript)?

@ZmnSCPxj

Copy link
Copy Markdown
Contributor

ACK fe224b5

@lvaccaro

Copy link
Copy Markdown
Contributor Author

Last commit resolves previous discussion, @rustyrussell suggests me to change tal_tmpctx(NULL) into tal_tmpctx(cmd). I have tested it.

Comment thread wallet/walletrpc.c Outdated
json_array_end(response);
json_object_end(response);
command_success(cmd, response);
tal_free(tmpctx);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for explanation, in the last commit I move tal_free up to command_success. Now I can remove it.

@ZmnSCPxj ZmnSCPxj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread wallet/walletrpc.c Outdated
}
json_array_end(response);
json_object_end(response);
tal_free(tmpctx);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I understand and fix.

@ZmnSCPxj

Copy link
Copy Markdown
Contributor

The CI is pointing out that you do not actually use tmpctx even if you allocate it.... remove it entirely?

@cdecker

cdecker commented Feb 18, 2018

Copy link
Copy Markdown
Member

ACK 594ac0a

@cdecker
cdecker merged commit c4590b6 into ElementsProject:master Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants