Add option to create an encrypted wallet #15006

pull achow101 wants to merge 1 commits into bitcoin:master from achow101:create-encrypted-wallet changing 3 files +82 −16
  1. achow101 commented at 9:35 pm on December 19, 2018: member

    This PR adds a new passphrase argument to createwallet which will create a wallet that is encrypted with that passphrase.

    This is built on #15226 because it needs to first create an empty wallet, then encrypt the empty wallet and generate new keys that have only been stored in an encrypted state.

  2. fanquake added the label Wallet on Dec 19, 2018
  3. DrahtBot commented at 0:36 am on December 20, 2018: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #15937 (WIP: Add loadwallet and createwallet load_on_startup options by ryanofsky)
    • #13756 (wallet: “avoid_reuse” wallet flag for improved privacy by kallewoof)

    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.

  4. jonasschnelli commented at 1:13 am on December 20, 2018: contributor
    Concept ACK
  5. achow101 force-pushed on Dec 20, 2018
  6. Sjors commented at 11:17 am on December 20, 2018: member

    Concept ACK.

    Today on IRC:

  7. benthecarman deleted a comment on Dec 20, 2018
  8. achow101 force-pushed on Dec 20, 2018
  9. jnewbery commented at 7:29 pm on December 20, 2018: member
    Concept ACK
  10. in test/functional/wallet_createwallet.py:34 in 3205e6ecb0 outdated
    29+        address1 = w0.getnewaddress()
    30+
    31+        self.log.info("Test disableprivatekeys creation.")
    32+        self.nodes[0].createwallet('w1', True)
    33+        w1 = node.get_wallet_rpc('w1')
    34+        assert_raises_rpc_error(-4,"Error: Private keys are disabled for this wallet", w1.getnewaddress)
    


    practicalswift commented at 8:50 am on December 21, 2018:
    Missing whitespace after ,. Please run this newly added file through black to make sure formatting is correct :-)

    Sjors commented at 11:48 am on December 21, 2018:
    @practicalswift that’s an upstream test from #14938, where this has been fixed.
  11. laanwj commented at 12:26 pm on January 2, 2019: member
    Concept ACK
  12. laanwj commented at 7:10 pm on January 21, 2019: member

    This fails travis:

    0Assertion failed: lock cs_wallet not held in wallet/wallet.cpp:1389; locks held:
    1FAIL qt/test/test_bitcoin-qt (exit status: 134)
    
  13. achow101 force-pushed on Jan 21, 2019
  14. achow101 force-pushed on Jan 21, 2019
  15. achow101 commented at 8:02 pm on January 21, 2019: member
    Fixed by rebasing
  16. achow101 force-pushed on Jan 22, 2019
  17. achow101 commented at 3:53 am on January 22, 2019: member
    I’ve decided to base this on #15226 instead of #14938.
  18. achow101 force-pushed on Jan 22, 2019
  19. achow101 force-pushed on Jan 23, 2019
  20. DrahtBot added the label Needs rebase on Jan 29, 2019
  21. achow101 force-pushed on Jan 29, 2019
  22. achow101 commented at 7:57 pm on January 29, 2019: member
    Rebased
  23. DrahtBot removed the label Needs rebase on Jan 29, 2019
  24. in src/interfaces/wallet.cpp:504 in 51a477f8fe outdated
    487@@ -488,6 +488,10 @@ class WalletImpl : public Wallet
    488     {
    489         return MakeHandler(m_wallet.NotifyWatchonlyChanged.connect(fn));
    490     }
    491+    std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override
    


    laanwj commented at 1:12 pm on January 31, 2019:
    handleCanGetAddressesChanged is a terrible method name in itself, took me at least 5 minutes to decode it, please add a comment saying it’s a handler for changes in whether addresses can be generated or not :-)

    achow101 commented at 8:03 pm on January 31, 2019:
    That’s a change from #15225 and out of scope for this pr. sorry.

    Sjors commented at 8:29 pm on January 31, 2019:
    Fwiw I find it easy enough to read, but I’m used to similar nomenclature from iOs :-)
  25. in test/functional/test_framework/test_node.py:437 in 51a477f8fe outdated
    433@@ -434,7 +434,7 @@ def batch(self, requests):
    434     def send_cli(self, command=None, *args, **kwargs):
    435         """Run bitcoin-cli command. Deserializes returned string as python object."""
    436         pos_args = [str(arg).lower() if type(arg) is bool else str(arg) for arg in args]
    437-        named_args = [str(key) + "=" + str(value) for (key, value) in kwargs.items()]
    438+        named_args = [str(key) + "=" + (str(value).lower() if type(value) is bool else str(value)) for (key, value) in kwargs.items()]
    


    laanwj commented at 1:14 pm on January 31, 2019:
    I remember I had a comment on this (please factor out the value→cli functionality to a function instead of duplicating it) but somehow it got lost …

    achow101 commented at 3:39 pm on January 31, 2019:
    Since this issue affects multiple PRs, I’ve split the fix into a separate PR: #15301

    jnewbery commented at 9:51 pm on January 31, 2019:
    hmmm, bizarre. You definitely did have a comment here because I responded to it!
  26. DrahtBot added the label Needs rebase on Jan 31, 2019
  27. achow101 force-pushed on Jan 31, 2019
  28. DrahtBot removed the label Needs rebase on Jan 31, 2019
  29. DrahtBot added the label Needs rebase on Feb 1, 2019
  30. achow101 force-pushed on Feb 1, 2019
  31. achow101 commented at 3:40 pm on February 1, 2019: member
    Rebased
  32. DrahtBot removed the label Needs rebase on Feb 1, 2019
  33. achow101 force-pushed on Feb 7, 2019
  34. DrahtBot added the label Needs rebase on Feb 10, 2019
  35. achow101 force-pushed on Feb 10, 2019
  36. achow101 commented at 8:08 pm on February 10, 2019: member
    Rebased
  37. DrahtBot removed the label Needs rebase on Feb 10, 2019
  38. MarcoFalke added the label Needs rebase on Feb 12, 2019
  39. in src/wallet/rpcwallet.cpp:2600 in 08c294b885 outdated
    2596                 "\nCreates and loads a new wallet.\n",
    2597                 {
    2598                     {"wallet_name", RPCArg::Type::STR, /* opt */ false, /* default_val */ "", "The name for the new wallet. If this is a path, the wallet will be created at the path location."},
    2599                     {"disable_private_keys", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Disable the possibility of private keys (only watchonlys are possible in this mode)."},
    2600                     {"blank", RPCArg::Type::BOOL, /* opt */ true, /* default_val */ "false", "Create a blank wallet. A blank wallet has no keys or HD seed. One can be set using sethdseed."},
    2601+                    {"passphrase", RPCArg::Type::STR, /* opt */ true, /* default_val */ "", "Encrypt the wallet with this passphrase. The empty string (\"\") will result in an unencrypted wallet."},
    


    MarcoFalke commented at 11:51 pm on February 12, 2019:
    0                    {"passphrase", RPCArg::Type::STR, /* default */ "''", "Encrypt the wallet with this passphrase. The empty string (\"\") will result in an unencrypted wallet."},
    

    Mention that the default value is the empty string "\"\"" or "''".


    achow101 commented at 2:19 am on February 15, 2019:
    There really isn’t a default value as the default is that there is no password and the wallet is unencrypted. So I’ve changed this to be RPCArg::Optional::OMITTED.
  40. achow101 force-pushed on Feb 14, 2019
  41. DrahtBot removed the label Needs rebase on Feb 14, 2019
  42. achow101 force-pushed on Feb 15, 2019
  43. fanquake commented at 3:24 am on February 15, 2019: member

    testing b69db9a; src/bitcoin-cli createwallet test true false "\"", bitcoind aborts with:

     02019-02-15T03:19:38Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
     12019-02-15T03:19:38Z Using wallet /Users/michael/Library/Application Support/Bitcoin/wallets/test
     22019-02-15T03:19:38Z BerkeleyEnvironment::Open: LogDir=/Users/michael/Library/Application Support/Bitcoin/wallets/test/database ErrorFile=/Users/michael/Library/Application Support/Bitcoin/wallets/test/db.log
     32019-02-15T03:19:38Z init message: Loading wallet...
     42019-02-15T03:19:38Z BerkeleyEnvironment::Open: LogDir=/Users/michael/Library/Application Support/Bitcoin/wallets/test/database ErrorFile=/Users/michael/Library/Application Support/Bitcoin/wallets/test/db.log
     52019-02-15T03:19:38Z [test] nFileVersion = 179900
     62019-02-15T03:19:38Z [test] Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total. Unknown wallet records: 0
     72019-02-15T03:19:38Z [test] Performing wallet upgrade to 169900
     82019-02-15T03:19:38Z [test] Wallet completed loading in             111ms
     92019-02-15T03:19:38Z [test] setKeyPool.size() = 0
    102019-02-15T03:19:38Z [test] mapWallet.size() = 0
    112019-02-15T03:19:38Z [test] mapAddressBook.size() = 0
    122019-02-15T03:19:38Z [test] Encrypting Wallet with an nDeriveIterations of 253927
    132019-02-15T03:19:38Z BerkeleyBatch::Rewrite: Rewriting wallet.dat...
    142019-02-15T03:19:38Z BerkeleyEnvironment::Open: LogDir=/Users/michael/Library/Application Support/Bitcoin/wallets/test/database ErrorFile=/Users/michael/Library/Application Support/Bitcoin/wallets/test/db.log
    15Assertion failed: (!IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)), function GenerateNewSeed, file wallet/wallet.cpp, line 1447.
    16Process 86762 stopped
    17* thread [#2](/bitcoin-bitcoin/2/), name = 'bitcoin-httpworker', stop reason = signal SIGABRT
    18    frame [#0](/bitcoin-bitcoin/0/): 0x00007fff5fc1423e libsystem_kernel.dylib`__pthread_kill + 10
    19libsystem_kernel.dylib`__pthread_kill:
    20->  0x7fff5fc1423e <+10>: jae    0x7fff5fc14248            ; <+20>
    21    0x7fff5fc14240 <+12>: movq   %rax, %rdi
    22    0x7fff5fc14243 <+15>: jmp    0x7fff5fc0e3b7            ; cerror_nocancel
    23    0x7fff5fc14248 <+20>: retq   
    24Target 0: (bitcoind) stopped.
    25(lldb) bt
    26* thread [#2](/bitcoin-bitcoin/2/), name = 'bitcoin-httpworker', stop reason = signal SIGABRT
    27  * frame [#0](/bitcoin-bitcoin/0/): 0x00007fff5fc1423e libsystem_kernel.dylib`__pthread_kill + 10
    28    frame [#1](/bitcoin-bitcoin/1/): 0x00007fff5fccac1c libsystem_pthread.dylib`pthread_kill + 285
    29    frame [#2](/bitcoin-bitcoin/2/): 0x00007fff5fb7d1c9 libsystem_c.dylib`abort + 127
    30    frame [#3](/bitcoin-bitcoin/3/): 0x00007fff5fb45868 libsystem_c.dylib`__assert_rtn + 320
    31    frame [#4](/bitcoin-bitcoin/4/): 0x00000001003031f5 bitcoind`CWallet::GenerateNewSeed(this=<unavailable>) at wallet.cpp:1447 [opt]
    32    frame [#5](/bitcoin-bitcoin/5/): 0x00000001002b72e5 bitcoind`createwallet(request=<unavailable>) at rpcwallet.cpp:2649 [opt]
    33    frame [#6](/bitcoin-bitcoin/6/): 0x00000001001712aa bitcoind`CRPCTable::execute(this=<unavailable>, request=0x000070000fbe9ad0) const at server.cpp:557 [opt]
    34    frame [#7](/bitcoin-bitcoin/7/): 0x000000010001742e bitcoind`HTTPReq_JSONRPC(req=0x0000000118add4a0, (null)=<unavailable>) at httprpc.cpp:192 [opt]
    
  44. achow101 force-pushed on Feb 15, 2019
  45. achow101 commented at 4:49 am on February 15, 2019: member
    Fixed that problem.
  46. in src/wallet/rpcwallet.cpp:2681 in c5af1e4f83 outdated
    2598@@ -2598,8 +2599,21 @@ static UniValue createwallet(const JSONRPCRequest& request)
    2599         flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS;
    2600     }
    2601 
    2602+    bool create_blank = false;
    2603     if (!request.params[2].isNull() && request.params[2].get_bool()) {
    2604         flags |= WALLET_FLAG_BLANK_WALLET;
    2605+        create_blank = true;
    2606+    }
    2607+    SecureString passphrase;
    


    Sjors commented at 3:11 pm on February 15, 2019:
    nit: move to a shared function so it’s more clear this is identical to encryptwallet

    achow101 commented at 5:20 am on February 16, 2019:
    It’s not identical. There isn’t enough shared here to warrant that IMO
  47. in src/wallet/rpcwallet.cpp:2614 in c5af1e4f83 outdated
    2609+    if (!request.params[3].isNull()) {
    2610+        passphrase = request.params[3].get_str().c_str();
    2611+        if (!passphrase.empty()) {
    2612+            if (create_blank) {
    2613+                throw JSONRPCError(RPC_WALLET_ERROR, "Cannot create an encrypted empty wallet.");
    2614+            }
    


    Sjors commented at 3:14 pm on February 15, 2019:
    Add comment why you’re temporarily making the wallet blank:

    achow101 commented at 5:29 am on February 16, 2019:
    Done
  48. in src/wallet/rpcwallet.cpp:2612 in c5af1e4f83 outdated
    2607+    SecureString passphrase;
    2608+    passphrase.reserve(100);
    2609+    if (!request.params[3].isNull()) {
    2610+        passphrase = request.params[3].get_str().c_str();
    2611+        if (!passphrase.empty()) {
    2612+            if (create_blank) {
    


    Sjors commented at 3:17 pm on February 15, 2019:
    Can you (add a comment to) explain why?

    achow101 commented at 5:29 am on February 16, 2019:
    I removed that
  49. in test/functional/wallet_createwallet.py:105 in c5af1e4f83 outdated
    100+        assert_raises_rpc_error(-4, 'Cannot create an encrypted empty wallet.', self.nodes[0].createwallet, 'w6', False, True, 'thisisapassphrase')
    101+        # Encrypted wallet is created
    102+        self.nodes[0].createwallet('w6', False, False, 'thisisapassphrase')
    103+        w6 = node.get_wallet_rpc('w6')
    104+        w6.walletpassphrase('thisisapassphrase', 10)
    105+        # There should only be 1000 keys
    


    Sjors commented at 3:18 pm on February 15, 2019:
    Nit: 1 key (and explain that normally encrypting a wallet adds new keys)

    achow101 commented at 5:30 am on February 16, 2019:
    fine
  50. Sjors approved
  51. Sjors commented at 3:21 pm on February 15, 2019: member
    utACK c5af1e4
  52. achow101 force-pushed on Feb 16, 2019
  53. achow101 commented at 5:30 am on February 16, 2019: member
    I changed it so that you can make blank encrypted wallets
  54. Sjors commented at 8:40 am on February 16, 2019: member
    Concept ACK on that change, but you broke wallet_createwallet.py :-)
  55. achow101 force-pushed on Feb 16, 2019
  56. achow101 commented at 5:34 pm on February 16, 2019: member
    Should be fixed now.
  57. Sjors commented at 8:07 am on February 19, 2019: member

    tACK 2fb944a

    I’m tempted to make passphrase the second argument, although that breaks backwards compatibility, so users can more easily ignore the more advanced disable_private_keys and blank arguments.

    Maybe we should just start making the RPC examples use named arguments.

  58. laanwj added this to the "Blockers" column in a project

  59. in src/wallet/rpcwallet.cpp:2611 in 2fb944a153 outdated
    2606     }
    2607+    SecureString passphrase;
    2608+    passphrase.reserve(100);
    2609+    if (!request.params[3].isNull()) {
    2610+        passphrase = request.params[3].get_str().c_str();
    2611+        if (!passphrase.empty()) {
    


    ryanofsky commented at 3:28 pm on March 19, 2019:
    I think it would be safer raise an error if the passphrase is non-null and empty instead of pretending the passphrase wasn’t provided. I’m imagining a buggy shell script with bitcoin-cli createwallet "$NAME" false false "$PASS" that forgot to set the PASS variable or spelled it differently. Better to fail in this case than go on like nothing’s wrong.

    achow101 commented at 4:22 pm on March 19, 2019:
    Done
  60. ryanofsky approved
  61. ryanofsky commented at 3:32 pm on March 19, 2019: member
    utACK 2fb944a1537391c6a10773682dfd002727f14dd5. This is great. I love how the blank wallet support makes this change very simple.
  62. achow101 force-pushed on Mar 19, 2019
  63. achow101 force-pushed on Mar 19, 2019
  64. achow101 force-pushed on Mar 19, 2019
  65. ryanofsky approved
  66. ryanofsky commented at 5:17 pm on March 19, 2019: member
    utACK 341a1428f70dfe204a5daa82f43929e9b5947352. Only change since last review is throwing an error if the passphrase is empty. (Thanks!)
  67. in src/wallet/rpcwallet.cpp:2708 in 341a1428f7 outdated
    2633@@ -2620,6 +2634,25 @@ static UniValue createwallet(const JSONRPCRequest& request)
    2634 
    2635     wallet->postInitProcess();
    2636 
    2637+    // Encrypt the wallet if there's a passphrase
    


    promag commented at 2:12 pm on April 2, 2019:
    Is there a reason to have this after the above AddWallet? Currently if something fails the wallet is kept.

    promag commented at 7:58 pm on April 14, 2019:
    I suggest moving this before AddWallet(wallet).

    achow101 commented at 2:49 am on May 14, 2019:
    Done
  68. in src/wallet/rpcwallet.cpp:2711 in 341a1428f7 outdated
    2633@@ -2620,6 +2634,25 @@ static UniValue createwallet(const JSONRPCRequest& request)
    2634 
    2635     wallet->postInitProcess();
    2636 
    2637+    // Encrypt the wallet if there's a passphrase
    2638+    if (!passphrase.empty() && !(flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
    2639+        if (!wallet->EncryptWallet(passphrase)) {
    2640+            throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Wallet created but failed to encrypt.");
    


    promag commented at 7:59 pm on April 14, 2019:
    Don’t know how could these be tested.

    achow101 commented at 2:50 am on May 14, 2019:
    They can’t, but the error still needs to be handled in case of disk corruption.
  69. in doc/release-notes-15006.md:4 in 341a1428f7 outdated
    0@@ -0,0 +1,4 @@
    1+Miscellaneous RPC changes
    2+------------
    3+
    4+- `createwallet` can now create encrypted wallets
    


    promag commented at 2:32 pm on April 30, 2019:
    ... if a non empty passphrase is specified.

    achow101 commented at 2:50 am on May 14, 2019:
    Done
  70. in src/wallet/rpcwallet.cpp:2685 in 341a1428f7 outdated
    2606+    }
    2607+    SecureString passphrase;
    2608+    passphrase.reserve(100);
    2609+    if (!request.params[3].isNull()) {
    2610+        passphrase = request.params[3].get_str().c_str();
    2611+        if (passphrase.empty()) {
    


    promag commented at 2:32 pm on April 30, 2019:
    IDK if it should trim?

    achow101 commented at 2:50 am on May 14, 2019:
    I don’t think so.
  71. ryanofsky referenced this in commit cd80a0969d on May 1, 2019
  72. in src/wallet/rpcwallet.cpp:2572 in 341a1428f7 outdated
    2568@@ -2569,14 +2569,15 @@ static UniValue loadwallet(const JSONRPCRequest& request)
    2569 
    2570 static UniValue createwallet(const JSONRPCRequest& request)
    2571 {
    2572-    if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) {
    2573+    if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) {
    


    jnewbery commented at 8:59 pm on May 2, 2019:
    Consider changing this to IsValidNumArgs() rather than manually setting the number of params.

    achow101 commented at 2:50 am on May 14, 2019:
    Done
  73. in src/wallet/rpcwallet.cpp:2716 in 341a1428f7 outdated
    2640+            throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Wallet created but failed to encrypt.");
    2641+        }
    2642+
    2643+        if (!create_blank) {
    2644+            // Unlock the wallet
    2645+            if (!wallet->Unlock(passphrase)) {
    


    jnewbery commented at 9:07 pm on May 2, 2019:
    Should the wallet be relocked after setting the seed?

    achow101 commented at 2:51 am on May 14, 2019:
    I’ve changed it to relock since that’s what encryptwallet does after encryption.
  74. in test/functional/wallet_createwallet.py:103 in 341a1428f7 outdated
     95@@ -96,5 +96,22 @@ def run_test(self):
     96         assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getnewaddress)
     97         assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getrawchangeaddress)
     98 
     99+        self.log.info('New blank and encrypted wallets can be created')
    100+        self.nodes[0].createwallet(wallet_name='wblank', disable_private_keys=False, blank=True, passphrase='thisisapassphrase')
    101+        wblank = node.get_wallet_rpc('wblank')
    102+        wblank.walletpassphrase('thisisapassphrase', 10)
    


    jnewbery commented at 9:14 pm on May 2, 2019:

    Suggest adding the following tests:

    • test that the wallet is locked by calling a method that requires the wallet to be unlocked (eg signmessage) and testing that it triggers an error
    • test that there are no keys in the wallet

    achow101 commented at 2:51 am on May 14, 2019:
    Done
  75. in test/functional/wallet_createwallet.py:106 in 341a1428f7 outdated
    101+        wblank = node.get_wallet_rpc('wblank')
    102+        wblank.walletpassphrase('thisisapassphrase', 10)
    103+
    104+        self.log.info('Test creating a new encrypted wallet.')
    105+        # Born encrypted wallet is created (has keys)
    106+        self.nodes[0].createwallet('w6', False, False, 'thisisapassphrase')
    


    jnewbery commented at 9:14 pm on May 2, 2019:
    nit: prefer using named arguments for clarity

    achow101 commented at 2:51 am on May 14, 2019:
    Done
  76. in test/functional/wallet_createwallet.py:109 in 341a1428f7 outdated
    104+        self.log.info('Test creating a new encrypted wallet.')
    105+        # Born encrypted wallet is created (has keys)
    106+        self.nodes[0].createwallet('w6', False, False, 'thisisapassphrase')
    107+        w6 = node.get_wallet_rpc('w6')
    108+        w6.walletpassphrase('thisisapassphrase', 10)
    109+        # There should only be 1 keys
    


    jnewbery commented at 9:14 pm on May 2, 2019:
    nit: s/1 keys/1 key/

    achow101 commented at 2:51 am on May 14, 2019:
    Done
  77. in test/functional/wallet_createwallet.py:112 in 341a1428f7 outdated
    103+
    104+        self.log.info('Test creating a new encrypted wallet.')
    105+        # Born encrypted wallet is created (has keys)
    106+        self.nodes[0].createwallet('w6', False, False, 'thisisapassphrase')
    107+        w6 = node.get_wallet_rpc('w6')
    108+        w6.walletpassphrase('thisisapassphrase', 10)
    


    jnewbery commented at 9:15 pm on May 2, 2019:
    again, I suggest testing that the wallet is locked immediately after creation (this test will currently fail).

    achow101 commented at 2:51 am on May 14, 2019:
    Done
  78. jnewbery commented at 9:15 pm on May 2, 2019: member
    A few comments inline. @promag’s comment here: https://github.com/bitcoin/bitcoin/pull/15006/files#r275171693 still needs to be addressed
  79. ryanofsky referenced this in commit 17d54f5c48 on May 3, 2019
  80. ryanofsky referenced this in commit 5990d3eef7 on May 7, 2019
  81. ryanofsky referenced this in commit 04c80c40df on May 8, 2019
  82. in src/wallet/rpcwallet.cpp:2602 in 341a1428f7 outdated
    2598@@ -2598,7 +2599,20 @@ static UniValue createwallet(const JSONRPCRequest& request)
    2599         flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS;
    2600     }
    2601 
    2602+    bool create_blank = false; // Indicate that we the wallet is actually supposed to be blank
    


    sipa commented at 11:06 pm on May 9, 2019:
    It seems you accidentally the grammar.

    achow101 commented at 2:51 am on May 14, 2019:
    Fixed
  83. sipa commented at 11:28 pm on May 9, 2019: member
    Concept ACK
  84. Add option to create an encrypted wallet 662d1171d9
  85. achow101 force-pushed on May 14, 2019
  86. achow101 commented at 2:52 am on May 14, 2019: member
    Addressed comments. Also rebased so that IsValidNumArgs is available.
  87. in src/wallet/rpcwallet.cpp:2651 in 662d1171d9
    2656+        "\nCreates and loads a new wallet.\n",
    2657+        {
    2658+            {"wallet_name", RPCArg::Type::STR, RPCArg::Optional::NO, "The name for the new wallet. If this is a path, the wallet will be created at the path location."},
    2659+            {"disable_private_keys", RPCArg::Type::BOOL, /* default */ "false", "Disable the possibility of private keys (only watchonlys are possible in this mode)."},
    2660+            {"blank", RPCArg::Type::BOOL, /* default */ "false", "Create a blank wallet. A blank wallet has no keys or HD seed. One can be set using sethdseed."},
    2661+            {"passphrase", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Encrypt the wallet with this passphrase."},
    


    jnewbery commented at 3:01 pm on May 16, 2019:
    nit: I think this could help text could be improved by adding a second sentence: “If no passphrase is provided, the wallet will not be encrypted on creation.”
  88. in src/wallet/rpcwallet.cpp:2709 in 662d1171d9
    2703@@ -2688,6 +2704,29 @@ static UniValue createwallet(const JSONRPCRequest& request)
    2704     if (!wallet) {
    2705         throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed.");
    2706     }
    2707+
    2708+    // Encrypt the wallet if there's a passphrase
    2709+    if (!passphrase.empty() && !(flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
    


    jnewbery commented at 3:03 pm on May 16, 2019:
    nit: It’d be a better user experience if we error’ed out when the user provides disable_private_keys=true and passphrase=something. If they provide that input, they’re expecting the wallet to be encrypted somehow. Better to error out and say “wallets without private keys cannot be encrypted” than just swallow the passphrase silently.
  89. in test/functional/wallet_createwallet.py:102 in 662d1171d9
     95@@ -96,5 +96,28 @@ def run_test(self):
     96         assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getnewaddress)
     97         assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w5.getrawchangeaddress)
     98 
     99+        self.log.info('New blank and encrypted wallets can be created')
    100+        self.nodes[0].createwallet(wallet_name='wblank', disable_private_keys=False, blank=True, passphrase='thisisapassphrase')
    101+        wblank = node.get_wallet_rpc('wblank')
    102+        assert_raises_rpc_error(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.", wblank.signmessage, "needanargument", "test")
    


    jnewbery commented at 3:12 pm on May 16, 2019:

    micronit: I always prefer named arguments in tests, so there’s no ambiguity about what the RPC method call should be. In that case it’d be ...wblank.signmessage, address="fakeaddress", message="test" here.

    EDIT: assert_raises_rpc_error() itself takes an argument called message, so this doesn’t work. We should fix that (in a different PR) by making assert_raises_rpc_error’s argument something like _error_message so it doesn’t collide with any RPC arguments.


    MarcoFalke commented at 5:18 pm on May 16, 2019:
    Or use a lambda to bind the named args?
  90. in test/functional/wallet_createwallet.py:120 in 662d1171d9
    115+        # There should only be 1 key
    116+        walletinfo = w6.getwalletinfo()
    117+        assert_equal(walletinfo['keypoolsize'], 1)
    118+        assert_equal(walletinfo['keypoolsize_hd_internal'], 1)
    119+        # Empty passphrase, error
    120+        assert_raises_rpc_error(-16, 'Cannot encrypt a wallet with a blank password', self.nodes[0].createwallet, 'w7', False, False, '')
    


    jnewbery commented at 3:14 pm on May 16, 2019:

    micronit: again, I’d prefer named arguments here (and dropping the unneeded optional arguments):

    0assert_raises_rpc_error(-16, 'Cannot encrypt a wallet with a blank password', self.nodes[0].createwallet, wallet_name='w7', passphrase='')
    
  91. jnewbery commented at 3:14 pm on May 16, 2019: member

    Looks great. utACK 662d1171d9e29964b039ba4c5bc8a2304426c003

    I’ve left a few nits. Feel free to take or leave.

  92. laanwj commented at 4:19 pm on May 16, 2019: member
    utACK 662d1171d9e29964b039ba4c5bc8a2304426c003 Going to merge this, I think the micro-nits can be addressed later and don’t need to hold thi sup.
  93. laanwj merged this on May 16, 2019
  94. laanwj closed this on May 16, 2019

  95. laanwj referenced this in commit 1c719f78d3 on May 16, 2019
  96. laanwj removed this from the "Blockers" column in a project

  97. ryanofsky referenced this in commit 9d5c780dcb on Jun 8, 2019
  98. ryanofsky referenced this in commit 5ccdb044e9 on Dec 3, 2019
  99. ryanofsky referenced this in commit 36b3318a48 on Jun 5, 2020
  100. ryanofsky referenced this in commit 0547e1e7f2 on Jun 5, 2020
  101. deadalnix referenced this in commit 8345f442a7 on Jun 7, 2020
  102. ryanofsky referenced this in commit 9b69729015 on Jun 16, 2020
  103. achow101 referenced this in commit 19f81dba71 on Jun 22, 2020
  104. ryanofsky referenced this in commit d04a792fa7 on Jun 25, 2020
  105. ryanofsky referenced this in commit cd2e0e090b on Jun 25, 2020
  106. ryanofsky referenced this in commit bd720c152d on Jun 25, 2020
  107. achow101 referenced this in commit 24a02c3a8c on Jun 25, 2020
  108. ryanofsky referenced this in commit d4f445b284 on Jul 2, 2020
  109. ryanofsky referenced this in commit 43f8faefc3 on Jul 2, 2020
  110. achow101 referenced this in commit 8cbfcbf08b on Jul 6, 2020
  111. ryanofsky referenced this in commit 9a4fe0ea50 on Jul 11, 2020
  112. ryanofsky referenced this in commit 1a73d115c4 on Jul 11, 2020
  113. ryanofsky referenced this in commit 9548ae802d on Jul 13, 2020
  114. ryanofsky referenced this in commit 65bcf8e17a on Jul 13, 2020
  115. ryanofsky referenced this in commit d25eba885d on Jul 23, 2020
  116. ryanofsky referenced this in commit 4801c7f8f5 on Jul 23, 2020
  117. ryanofsky referenced this in commit b9ff147c51 on Jul 23, 2020
  118. ryanofsky referenced this in commit 0b146a4d68 on Jul 23, 2020
  119. ryanofsky referenced this in commit 3062303a68 on Jul 23, 2020
  120. achow101 referenced this in commit 69fe6cde95 on Jul 27, 2020
  121. achow101 referenced this in commit bbda06f9cd on Aug 10, 2020
  122. ryanofsky referenced this in commit a25d10a7c0 on Aug 13, 2020
  123. ryanofsky referenced this in commit 904bc013e3 on Aug 13, 2020
  124. ryanofsky referenced this in commit 61709e87c6 on Aug 13, 2020
  125. ryanofsky referenced this in commit 642ad31b41 on Aug 13, 2020
  126. 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-18 21:12 UTC

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