Add deriveaddresses RPC util method #14667

pull Sjors wants to merge 1 commits into bitcoin:master from Sjors:2018/11/deriveaddress changing 5 files +149 −0
  1. Sjors commented at 2:25 pm on November 6, 2018: member

    Usage:

    0bitcoin-cli deriveaddresses "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/0)"
    1[
    2  "bc1qg6ucjz7kgdedam7v5yarecy54uqw82yym06z3q"
    3] // part of the BIP32 test vector
    

    Avoids the need for external (BIP32) libraries to derive an address. Can be used in conjunction with scantxoutset as a poor mans wallet. Might be useful to test more complicated future descriptors.

    To keep it as simple as possible it only supports descriptors that result in a single address, so no combo() and ranges.

    As discussed recently on IRC it might make sense to put this in a separate utility along with other descriptor and psbt utility functions which don’t need a chain or wallet context. However I prefer to leave that to another PR.

  2. laanwj commented at 2:30 pm on November 6, 2018: member
    I know, this comes up every time—see for example #14476 (comment) —wasn’t the idea to not add more pure-utility RPC calls? We really need a clear stance on this.
  3. DrahtBot commented at 2:44 pm on November 6, 2018: member

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

    Conflicts

    No conflicts as of last run.

  4. Sjors commented at 3:23 pm on November 6, 2018: member
    I created an issue to discuss a tool that could replace pure utility RPC calls: #14671
  5. fanquake added the label RPC/REST/ZMQ on Nov 6, 2018
  6. in src/rpc/misc.cpp:144 in 4f6fa3172a outdated
    138@@ -138,6 +139,64 @@ static UniValue createmultisig(const JSONRPCRequest& request)
    139     return result;
    140 }
    141 
    142+UniValue deriveaddress(const JSONRPCRequest& request)
    143+{
    144+    if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
    


    practicalswift commented at 9:06 am on November 7, 2018:
    Nit: request.params.empty() instead of request.params.size() < 1 :-)
  7. in src/rpc/misc.cpp:168 in 4f6fa3172a outdated
    163+            ""
    164+        );
    165+
    166+    RPCTypeCheck(request.params, {UniValue::VSTR});
    167+
    168+    UniValue result(UniValue::VSTR);
    


    practicalswift commented at 9:07 am on November 7, 2018:
    Remove this unused variable :-)
  8. Sjors force-pushed on Nov 7, 2018
  9. in src/rpc/misc.cpp:176 in 9a55d5f9e3 outdated
    171+    auto desc = Parse(desc_str, provider);
    172+    if (!desc) {
    173+        throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Invalid descriptor"));
    174+    }
    175+    if (desc->IsRange()){
    176+        throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Descriptor range not supported"));
    


    meshcollider commented at 2:20 am on November 9, 2018:
    It would be easy enough to add support for picking a specific index from a ranged descriptor, is there a reason you chose to disallow it? Just add a second parameter which specifies the index. EDIT: thinking about it, it would be just as easy to not use a ranged descriptor if we’re only using a single key, don’t worry.

    sipa commented at 4:02 am on November 10, 2018:
    It seems a weird anti-feature to me. I don’t understand why you’re adding extra complexity to the function just to prevent a range. If you only want one, you can still do so.

    Sjors commented at 8:24 am on November 10, 2018:
    I initially did that to prevent extra complexity, but I’ve actually encountered a situation where allowing ranges would be very useful. Will change this to return an array.

    meshcollider commented at 10:49 am on November 10, 2018:
    @Sjors I assume that also includes allowing combo right? Sounds good 👍

    Sjors commented at 4:22 pm on November 10, 2018:
    @MeshCollider yes, no reason anymore to exclude combo()
  10. meshcollider commented at 3:16 am on November 9, 2018: contributor
    This looks good, and after the discussion in the meeting this morning I think its worth adding. utACK https://github.com/bitcoin/bitcoin/pull/14667/commits/9a55d5f9e3a92026c25d26a5c2fd531883ab3609
  11. in doc/release-notes-13152.md:6 in 9a55d5f9e3 outdated
    2@@ -3,3 +3,4 @@ New RPC methods
    3 
    4 - `getnodeaddresses` returns peer addresses known to this node. It may be used to connect to nodes over TCP without using the DNS seeds.
    5 - `listwalletdir` returns a list of wallets in the wallet directory which is configured with `-walletdir` parameter.
    6+- `deriveaddress` returns the address corresponding to an [output descriptor](/doc/descriptors.md).
    


    sipa commented at 3:05 am on November 11, 2018:
    This doesn’t seem to belong in this file (the file is specific per PR).

    Sjors commented at 1:04 pm on November 11, 2018:
    listwalletdir was already hijacking that file, so I joined, but I can add a new one.

    MarcoFalke commented at 3:32 pm on November 14, 2018:
    In which case we could add them to the main file in the first place.

    Sjors commented at 1:26 pm on November 19, 2018:
    I thought the point of these extra files was mainly to prevent constant rebasing, which seemed mostly a result of different sections interfering, and less when you’re just adding one line an existing entry. Though I’m not sure exactly what trips up git.

    MarcoFalke commented at 2:50 pm on November 19, 2018:
    This file was removed in master. Also, if another patch added a line in the meantime, git(hub) would also report a merge conflict.
  12. DrahtBot added the label Needs rebase on Nov 14, 2018
  13. Sjors force-pushed on Nov 19, 2018
  14. Sjors commented at 6:58 pm on November 19, 2018: member
    Rebased. Result is now an array of addresses, so combo() and ranges can be used. Added range arguments.
  15. Sjors force-pushed on Nov 19, 2018
  16. DrahtBot removed the label Needs rebase on Nov 19, 2018
  17. Sjors force-pushed on Nov 19, 2018
  18. in src/rpc/misc.cpp:147 in f0e881f931 outdated
    138@@ -138,6 +139,80 @@ static UniValue createmultisig(const JSONRPCRequest& request)
    139     return result;
    140 }
    141 
    142+UniValue deriveaddress(const JSONRPCRequest& request)
    143+{
    144+    if (request.fHelp || request.params.empty() || request.params.size() > 3)
    145+        throw std::runtime_error(
    146+            "deriveaddress \"descriptor\" ( \"start\" \"end\" )\n"
    147+            "\nDerives the address corresponding to an output descriptor.\n"
    


    meshcollider commented at 7:12 pm on November 19, 2018:
    Should be plural now :)
  19. Sjors commented at 7:15 pm on November 19, 2018: member

    Getting a rather cryptic linter error: @MarcoFalke?

    Update: #14718 was merged right before I pushed this. I rebased again and now I’m able to reproduce the linter error. It happens on master too.

  20. in src/rpc/misc.cpp:181 in f0e881f931 outdated
    176+    if (request.params.size() >= 2) {
    177+        if (request.params.size() >= 3) {
    178+            range_start = request.params[1].get_int();
    179+            range_end = request.params[2].get_int();
    180+        } else {
    181+            range_end = request.params[1].get_int() - 1;
    


    meshcollider commented at 7:15 pm on November 19, 2018:
    I feel like this is unnecessarily complicated, I’d prefer just start and end parameters without the “n” parameter
  21. Sjors force-pushed on Nov 19, 2018
  22. Sjors force-pushed on Nov 19, 2018
  23. meshcollider commented at 7:38 pm on November 19, 2018: contributor
    Looking good
  24. Sjors force-pushed on Nov 20, 2018
  25. Sjors force-pushed on Nov 20, 2018
  26. Sjors renamed this:
    Add deriveaddress RPC util method
    Add deriveaddresses RPC util method
    on Nov 20, 2018
  27. Sjors commented at 1:33 pm on November 20, 2018: member
    Rebased so CI works again. Renamed to plural deriveaddresses. Simplified the range arguments (must provide start and end).
  28. Sjors force-pushed on Nov 20, 2018
  29. meshcollider commented at 2:22 am on November 22, 2018: contributor

    utACK https://github.com/bitcoin/bitcoin/pull/14667/commits/82d2a8fc19e6d4c00fcb4af4032ebfdcdd457991

    One last nit, I would add a comment about the default behavior of 0 for ranged descriptors if start and end aren’t provided.

    EDIT: Actually, I think the helptext needs to be switched to RPCHelpMan

  30. Sjors commented at 11:53 am on November 23, 2018: member

    @MeshCollider alternatively I could make the range argument mandatory for ranged descriptors.

    What do you mean with RPCHelpMan?

  31. meshcollider commented at 10:48 am on November 24, 2018: contributor
  32. Sjors force-pushed on Nov 27, 2018
  33. Sjors commented at 3:31 pm on November 27, 2018: member

    Rebased due to #14726 and using RPCHelpMan now.

    Range argument is now mandatory for ranged descriptors (typing 0 instead of * is trivial).

  34. laanwj commented at 3:58 pm on January 8, 2019: member
    Concept ACK
  35. in src/rpc/misc.cpp:211 in dfad416439 outdated
    212+        }
    213+
    214+        for (const CScript &script : scripts) {
    215+            CTxDestination dest;
    216+            if (!ExtractDestination(script, dest)) {
    217+                throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Descriptor produced invalid address"));
    


    sipa commented at 4:03 pm on January 8, 2019:
    Nit: This condition would appear when the scriptPubKey does not have a corresponding address (I think this is only currently possible through “raw” or through bare multisig). Perhaps a better error message is possible?

    promag commented at 11:31 pm on January 8, 2019:
    Could also have a test for this error?

    Sjors commented at 6:51 pm on January 9, 2019:
    If anyone has an example (raw) descriptor that triggers this error, I can add it, and think of a better message.

    sipa commented at 7:55 pm on January 9, 2019:
    Try “multi(1,key1,key2)” for some public keys.

    Sjors commented at 6:05 pm on January 15, 2019:
    Added the bare multisig example and reworded error to “Descriptor does not have a corresponding address”.
  36. sipa commented at 4:04 pm on January 8, 2019: member
    utACK with a small nit.
  37. in src/rpc/misc.cpp:151 in dfad416439 outdated
    142@@ -142,6 +143,87 @@ static UniValue createmultisig(const JSONRPCRequest& request)
    143     return result;
    144 }
    145 
    146+UniValue deriveaddresses(const JSONRPCRequest& request)
    147+{
    148+    if (request.fHelp || request.params.empty() || request.params.size() > 3)
    149+        throw std::runtime_error(
    150+            RPCHelpMan{"deriveaddresses",
    151+              "\nDerives one or more addresses corresponding to an output descriptor.\n"
    


    promag commented at 11:25 pm on January 8, 2019:
    bad indentation?
  38. in src/rpc/misc.cpp:186 in dfad416439 outdated
    181+    int range_start = 0;
    182+    int range_end = 0;
    183+
    184+    if (request.params.size() >= 2) {
    185+        if (request.params.size() == 2) {
    186+          throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing range end parameter");
    


    promag commented at 11:27 pm on January 8, 2019:
    indentation.

    promag commented at 11:30 pm on January 8, 2019:
    missing test for this error.
  39. in src/rpc/misc.cpp:193 in dfad416439 outdated
    185+        if (request.params.size() == 2) {
    186+          throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing range end parameter");
    187+        }
    188+        range_start = request.params[1].get_int();
    189+        range_end = request.params[2].get_int();
    190+    }
    


    promag commented at 11:28 pm on January 8, 2019:
    validate range_start < range_end?

    Sjors commented at 6:09 pm on January 15, 2019:
    Added check and test.
  40. in src/rpc/misc.cpp:162 in dfad416439 outdated
    157+              "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
    158+              "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
    159+              "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n",
    160+              {
    161+                {"descriptor", RPCArg::Type::STR, false},
    162+                {"start",  RPCArg::Type::NUM, true},
    


    promag commented at 11:28 pm on January 8, 2019:
    micronit, s/start/begin?
  41. jonasschnelli commented at 11:29 pm on January 8, 2019: contributor
    Needs non conflict rebase to fix the new RPCHelpMan() argument section (default and comments).
  42. in src/rpc/misc.cpp:232 in dfad416439 outdated
    219+
    220+            addresses.push_back(EncodeDestination(dest));
    221+        }
    222+    }
    223+
    224+    return addresses;
    


    promag commented at 11:32 pm on January 8, 2019:
    Is it possible to return empty?

    Sjors commented at 6:59 pm on January 9, 2019:

    Addresses can be an empty UniValue array in theory: UniValue addresses(UniValue::VARR);

    I guess not in practice, do you want an error check?


    Sjors commented at 6:14 pm on January 15, 2019:
    I added an RPC error in case the result is empty. I don’t know how to produce that, so there’s no test.
  43. Sjors force-pushed on Jan 9, 2019
  44. Sjors force-pushed on Jan 9, 2019
  45. Sjors commented at 7:28 pm on January 9, 2019: member
    Rebased for RPCHelpMan and addressed some of the nits. Will continue later.
  46. Sjors force-pushed on Jan 15, 2019
  47. Sjors commented at 6:18 pm on January 15, 2019: member
    Rebased for no particular reason, all feedback should be addressed now.
  48. FrancisPouliot commented at 9:30 pm on January 22, 2019: none
    Concept ack. Many web services (including mine) derive receiving addresses from external xpub and need to run some other utility like pycoin to do this, and then import adresses in Bitcoin Core to watch them.
  49. sipa commented at 3:55 am on January 25, 2019: member
    utACK f8f115da64f18e3b81e6cbaa0f26d96156acfc3c
  50. fanquake commented at 3:56 am on January 27, 2019: member

    testing f8f115d. bitcoind will abort if you pass a range begin < 0;

    i.e src/bitcoin-cli deriveaddresses "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)" -1 0

     02019-01-27T03:47:50Z UpdateTip: new best=0000000000000000002d802cf5fdbbfa94926be7f03b40be75eb6c3c13cbc8e4 height=560180 version=0x20000000 log2_work=90.279438 tx=376715337 date='2019-01-26T12:02:01Z' progress=0.999639 cache=17.7MiB(131993txo) warning='25 of last 100 blocks have unexpected version'
     1Assertion failed: ((nChild >> 31) == 0), function Derive, file pubkey.cpp, line 229.
     2Process 25118 stopped
     3* thread [#2](/bitcoin-bitcoin/2/), name = 'bitcoin-httpworker', stop reason = signal SIGABRT
     4    frame [#0](/bitcoin-bitcoin/0/): 0x00007fff5ba9523e libsystem_kernel.dylib`__pthread_kill + 10
     5libsystem_kernel.dylib`__pthread_kill:
     6->  0x7fff5ba9523e <+10>: jae    0x7fff5ba95248            ; <+20>
     7    0x7fff5ba95240 <+12>: movq   %rax, %rdi
     8    0x7fff5ba95243 <+15>: jmp    0x7fff5ba8f3b7            ; cerror_nocancel
     9    0x7fff5ba95248 <+20>: retq   
    10Target 0: (bitcoind) stopped.
    11(lldb) bt
    12* thread [#2](/bitcoin-bitcoin/2/), name = 'bitcoin-httpworker', stop reason = signal SIGABRT
    13  * frame [#0](/bitcoin-bitcoin/0/): 0x00007fff5ba9523e libsystem_kernel.dylib`__pthread_kill + 10
    14    frame [#1](/bitcoin-bitcoin/1/): 0x00007fff5bb4bc1c libsystem_pthread.dylib`pthread_kill + 285
    15    frame [#2](/bitcoin-bitcoin/2/): 0x00007fff5b9fe1c9 libsystem_c.dylib`abort + 127
    16    frame [#3](/bitcoin-bitcoin/3/): 0x00007fff5b9c6868 libsystem_c.dylib`__assert_rtn + 320
    17    frame [#4](/bitcoin-bitcoin/4/): 0x00000001003cfee5 bitcoind`CPubKey::Derive(this=0x000070000305501c, pubkeyChild=0x000070000305501c, ccChild=0x0000700003054ffc, nChild=<unavailable>, cc=<unavailable>) const at pubkey.cpp:229 [opt]
    18    frame [#5](/bitcoin-bitcoin/5/): 0x00000001003d01c9 bitcoind`CExtPubKey::Derive(this=<unavailable>, out=<unavailable>, _nChild=4294967295) const at pubkey.cpp:271 [opt]
    19    frame [#6](/bitcoin-bitcoin/6/): 0x000000010037cdaf bitcoind`(anonymous namespace)::BIP32PubkeyProvider::GetPubKey(this=0x0000000133aa7420, pos=-1, arg=<unavailable>, key=<unavailable>, info=0x0000000176f57888) const at descriptor.cpp:173 [opt]
    20    frame [#7](/bitcoin-bitcoin/7/): 0x000000010037dc09 bitcoind`(anonymous namespace)::OriginPubkeyProvider::GetPubKey(this=0x0000000125778480, pos=<unavailable>, arg=<unavailable>, key=<unavailable>, info=0x0000000176f57888) const at descriptor.cpp:73 [opt]
    21    frame [#8](/bitcoin-bitcoin/8/): 0x000000010037f6f9 bitcoind`(anonymous namespace)::DescriptorImpl::ExpandHelper(this=<unavailable>, pos=-1, arg=0x0000700003055630, cache_read=0x0000000000000000, output_scripts=size=0, out=0x0000700003055630, cache_write=0x0000000000000000) const at descriptor.cpp:298 [opt]
    22    frame [#9](/bitcoin-bitcoin/9/): 0x000000010037efdd bitcoind`(anonymous namespace)::DescriptorImpl::Expand(this=<unavailable>, pos=<unavailable>, provider=<unavailable>, output_scripts=<unavailable>, out=<unavailable>, cache=<unavailable>) const at descriptor.cpp:343 [opt]
    23    frame [#10](/bitcoin-bitcoin/10/): 0x000000010011b02c bitcoind`deriveaddresses(request=<unavailable>) at misc.cpp:207 [opt]
    
  51. Sjors force-pushed on Jan 29, 2019
  52. Sjors commented at 3:53 pm on January 29, 2019: member

    bitcoind will abort if you pass a range begin < 0;

    Pff, don’t do that! :-) Fixed (with test). @MarcoFalke maybe we can expand RPCTypeCheck to also enforce constraints like minimum value?

  53. MarcoFalke commented at 3:58 pm on January 29, 2019: member
    Indeed, we could pass a lambda into the RPCHelpMan to validate the value and use the passed in type to validate the type (and thus get rid of RPCTypeCheck completely)
  54. Sjors force-pushed on Jan 29, 2019
  55. Sjors commented at 4:37 pm on January 29, 2019: member
    Rebased due to somewhat inexplicable Travis failure.
  56. in src/rpc/misc.cpp:164 in 7f78582ed9 outdated
    159+                "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"
    160+            }, {
    161+                {"descriptor", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The descriptor."},
    162+                {"begin", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the beginning of the range to import."},
    163+                {"end", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the end of the range to import."}
    164+            }}.ToString() +
    


    MarcoFalke commented at 4:58 pm on January 29, 2019:

    Compile failure can be fixed with (large diff due to whitespace fixes)

     0diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp
     1index 12d165fff7..e9ff8a8040 100644
     2--- a/src/rpc/misc.cpp
     3+++ b/src/rpc/misc.cpp
     4@@ -145,30 +145,29 @@ static UniValue createmultisig(const JSONRPCRequest& request)
     5 
     6 UniValue deriveaddresses(const JSONRPCRequest& request)
     7 {
     8-    if (request.fHelp || request.params.empty() || request.params.size() > 3)
     9+    if (request.fHelp || request.params.empty() || request.params.size() > 3) {
    10         throw std::runtime_error(
    11-            RPCHelpMan{"deriveaddresses", {
    12-                "\nDerives one or more addresses corresponding to an output descriptor.\n"
    13-                "Examples of output descriptors are:\n"
    14-                "    pkh(<pubkey>)                        P2PKH outputs for the given pubkey\n"
    15-                "    wpkh(<pubkey>)                       Native segwit P2PKH outputs for the given pubkey\n"
    16-                "    sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n"
    17-                "    raw(<hex script>)                    Outputs whose scriptPubKey equals the specified hex scripts\n"
    18-                "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
    19-                "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
    20-                "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"
    21-            }, {
    22-                {"descriptor", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The descriptor."},
    23-                {"begin", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the beginning of the range to import."},
    24-                {"end", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the end of the range to import."}
    25-            }}.ToString() +
    26-            "\nResult:\n"
    27-            "[ address ] (array) the derived addresses\n"
    28-            "\nExamples:\n"
    29-            "\nFirst three native segwit receive addresses\n"
    30-            + HelpExampleCli("deriveaddresses", "\"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)\" 0 2") +
    31-            ""
    32-        );
    33+            RPCHelpMan{"deriveaddresses",
    34+                {"\nDerives one or more addresses corresponding to an output descriptor.\n"
    35+                 "Examples of output descriptors are:\n"
    36+                 "    pkh(<pubkey>)                        P2PKH outputs for the given pubkey\n"
    37+                 "    wpkh(<pubkey>)                       Native segwit P2PKH outputs for the given pubkey\n"
    38+                 "    sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n"
    39+                 "    raw(<hex script>)                    Outputs whose scriptPubKey equals the specified hex scripts\n"
    40+                 "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
    41+                 "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
    42+                 "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"},
    43+                {
    44+                    {"descriptor", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The descriptor."},
    45+                    {"begin", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the beginning of the range to import."},
    46+                    {"end", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the end of the range to import."},
    47+                },
    48+                RPCResult{
    49+                    "[ address ] (array) the derived addresses\n"},
    50+                RPCExamples{
    51+                    "\nFirst three native segwit receive addresses\n" + HelpExampleCli("deriveaddresses", "\"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)\" 0 2")}}
    52+                .ToString());
    53+    }
    54 
    55     RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VNUM, UniValue::VNUM});
    56     const std::string desc_str = request.params[0].get_str();
    

    Sjors commented at 5:14 pm on January 29, 2019:
    Thanks, done.
  57. [rpc] util: add deriveaddresses method 595283851d
  58. Sjors force-pushed on Jan 29, 2019
  59. in src/rpc/misc.cpp:188 in 595283851d
    183+            throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing range end parameter");
    184+        }
    185+        range_begin = request.params[1].get_int();
    186+        range_end = request.params[2].get_int();
    187+        if (range_begin < 0) {
    188+            throw JSONRPCError(RPC_INVALID_PARAMETER, "Range should be greater or equal than 0");
    


    instagibbs commented at 2:29 pm on February 6, 2019:
    grammar nit: “Range should be greater than or equal to 0”
  60. in src/rpc/misc.cpp:162 in 595283851d
    157+            "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n"
    158+            "or more path elements separated by \"/\", where \"h\" represents a hardened child key.\n"
    159+            "For more information on output descriptors, see the documentation in the doc/descriptors.md file.\n"},
    160+            {
    161+                {"descriptor", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The descriptor."},
    162+                {"begin", RPCArg::Type::NUM, /* opt */ true, /* default_val */ "", "If a ranged descriptor is used, this specifies the beginning of the range to import."},
    


    instagibbs commented at 2:30 pm on February 6, 2019:
    meta-nit: #14491 uses “start”, not “begin”. Would be nice to sync these.
  61. in test/functional/rpc_deriveaddresses.py:48 in 595283851d
    43+        hardened_without_privkey_descriptor = "wpkh(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1'/1/0)"
    44+        assert_raises_rpc_error(-5, "Cannot derive script without private keys", self.nodes[0].deriveaddresses, hardened_without_privkey_descriptor)
    45+
    46+        bare_multisig_descriptor = "multi(1, tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/0, tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/1)"
    47+        assert_raises_rpc_error(-5, "Descriptor does not have a corresponding address", self.nodes[0].deriveaddresses, bare_multisig_descriptor)
    48+
    


    instagibbs commented at 2:39 pm on February 6, 2019:

    I’d add a wallet roundtrip test like:

    0wpkh_info = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress("", "bech32"))
    1# Trim the witness part of descriptor off, check pkh entry in wallet, match descriptor
    2pkh_desc = wpkh_info["desc"][1:]
    3pkh_addr = self.nodes[0].deriveaddresses(pkh_desc)
    4pkh_info = self.nodes[0].getaddressinfo(pkh_addr)
    5assert_equal(wpkh_info["hdkeypath"], pkh_info["hdkeypath"])
    6assert_equal(wpkh_info["pubkey"], pkh_info["pubkey"])
    
  62. instagibbs approved
  63. instagibbs commented at 2:42 pm on February 6, 2019: member
    Couple of non-blocking nits, tACK 595283851d8fe3e18553fdb2ad6e773e1a9c1a22
  64. meshcollider merged this on Feb 7, 2019
  65. meshcollider closed this on Feb 7, 2019

  66. meshcollider referenced this in commit 1933e38c1a on Feb 7, 2019
  67. Sjors deleted the branch on Feb 8, 2019
  68. deadalnix referenced this in commit dfee6a8817 on May 22, 2020
  69. vijaydasmp referenced this in commit 232f8ad8b9 on Sep 15, 2021
  70. vijaydasmp referenced this in commit a2c291a04a on Sep 16, 2021
  71. vijaydasmp referenced this in commit 7d45a846b1 on Sep 20, 2021
  72. kittywhiskers referenced this in commit 1e15fe8394 on Oct 12, 2021
  73. kittywhiskers referenced this in commit 4ea08a1bc8 on Oct 21, 2021
  74. kittywhiskers referenced this in commit d4dd7369dd on Oct 25, 2021
  75. kittywhiskers referenced this in commit 08a50107a0 on Oct 25, 2021
  76. vijaydasmp referenced this in commit 13645f6736 on Oct 26, 2021
  77. kittywhiskers referenced this in commit a46ae75b34 on Oct 26, 2021
  78. kittywhiskers referenced this in commit 1719cd5ef4 on Oct 26, 2021
  79. kittywhiskers referenced this in commit 083bc078a9 on Oct 28, 2021
  80. UdjinM6 referenced this in commit bbe9b3d1e0 on Nov 1, 2021
  81. pravblockc referenced this in commit 6069fcc1a2 on Nov 18, 2021
  82. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 00:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me