rpc: Move the generate RPC call to rpcwallet #10683

pull laanwj wants to merge 2 commits into bitcoin:master from laanwj:2017_06_wallet_mining changing 7 files +66 −44
  1. laanwj commented at 2:59 pm on June 27, 2017: member

    This makes it possible to mine to any wallet when multi-wallet mode is added. Solves the same problem as #10649, but IMO in a cleaner way.

    It also gets rid of the circuitous ScriptForMining method on CValidationInterface, which really doesn’t belong there.

    After this change it’s still possible to mine without wallet through generatetoaddress. I first proposed this in #7965.

  2. laanwj added the label Mining on Jun 27, 2017
  3. laanwj added the label Tests on Jun 27, 2017
  4. laanwj added the label Wallet on Jun 27, 2017
  5. laanwj force-pushed on Jun 27, 2017
  6. laanwj added the label RPC/REST/ZMQ on Jun 27, 2017
  7. in src/wallet/rpcwallet.cpp:2930 in 8c410a8fbb outdated
    2922@@ -2922,6 +2923,47 @@ UniValue bumpfee(const JSONRPCRequest& request)
    2923     return result;
    2924 }
    2925 
    2926+UniValue generate(const JSONRPCRequest& request)
    2927+{
    2928+    CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
    2929+
    2930+    if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
    


    jnewbery commented at 3:56 pm on June 27, 2017:
    nit: braces
  8. in src/wallet/rpcwallet.cpp:2933 in 8c410a8fbb outdated
    2928+    CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
    2929+
    2930+    if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
    2931+        return NullUniValue;
    2932+
    2933+    if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
    


    jnewbery commented at 3:56 pm on June 27, 2017:
    nit: braces
  9. in src/wallet/rpcwallet.cpp:2947 in 8c410a8fbb outdated
    2942+            "\nExamples:\n"
    2943+            "\nGenerate 11 blocks\n"
    2944+            + HelpExampleCli("generate", "11")
    2945+        );
    2946+
    2947+    int nGenerate = request.params[0].get_int();
    


    jnewbery commented at 4:00 pm on June 27, 2017:
    nit: variable name should be lowercase, not hungarian
  10. in src/wallet/rpcwallet.cpp:2948 in 8c410a8fbb outdated
    2943+            "\nGenerate 11 blocks\n"
    2944+            + HelpExampleCli("generate", "11")
    2945+        );
    2946+
    2947+    int nGenerate = request.params[0].get_int();
    2948+    uint64_t nMaxTries = 1000000;
    


    jnewbery commented at 4:00 pm on June 27, 2017:
    nit: variable name should be lowercase, not hungarian
  11. in src/wallet/rpcwallet.cpp:2949 in 8c410a8fbb outdated
    2944+            + HelpExampleCli("generate", "11")
    2945+        );
    2946+
    2947+    int nGenerate = request.params[0].get_int();
    2948+    uint64_t nMaxTries = 1000000;
    2949+    if (request.params.size() > 1) {
    


    jnewbery commented at 4:03 pm on June 27, 2017:
    nit: should handle case when request.params[1] is Null (for named arguments)
  12. in src/wallet/rpcwallet.cpp:2957 in 8c410a8fbb outdated
    2952+
    2953+    std::shared_ptr<CReserveScript> coinbaseScript;
    2954+    pwallet->GetScriptForMining(coinbaseScript);
    2955+
    2956+    // If the keypool is exhausted, no script is returned at all.  Catch this.
    2957+    if (!coinbaseScript)
    


    jnewbery commented at 4:03 pm on June 27, 2017:
    nit: braces
  13. in src/wallet/rpcwallet.cpp:2961 in 8c410a8fbb outdated
    2956+    // If the keypool is exhausted, no script is returned at all.  Catch this.
    2957+    if (!coinbaseScript)
    2958+        throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
    2959+
    2960+    //throw an error if no script was provided
    2961+    if (coinbaseScript->reserveScript.empty())
    


    jnewbery commented at 4:03 pm on June 27, 2017:
    nit: braces
  14. jnewbery commented at 4:10 pm on June 27, 2017: member

    tested ACK 8c410a8fbb5f1876484a3f10d25cf9c06a8ef875. This is a sensible change. Anything that moves us towards #7965 and away from circular libbitcoin_server.a/libbitcoin_wallet.a dependencies is a good thing in my book.

    I realise that this is mostly code-move. There are a bunch of style nits in the moved code - entirely up to you if you want to address them as part of this PR or leave them as they are.

  15. instagibbs commented at 5:06 pm on June 27, 2017: member
  16. jonasschnelli commented at 8:13 pm on June 27, 2017: contributor
    Nice and thanks for doing this: utACK 8c410a8fbb5f1876484a3f10d25cf9c06a8ef875
  17. laanwj commented at 6:16 am on June 28, 2017: member
    Ok ok I’ll add a commit to clean up the style nits, don’t think it should be done at the time of the move as that just complicates review.
  18. laanwj force-pushed on Jun 28, 2017
  19. jnewbery commented at 12:33 pm on June 28, 2017: member

    utACK 4cdb6209de2f712cd5847373b6bc2fb6401fb739. No more nits. Thanks!

    don’t think it should be done at the time of the move as that just complicates review.

    I’d agree if the nit fixes were in the same commit, but if they’re done in their own commit either before or after the move it adds almost no review burden (as long as reviewers are reviewing commitwise)

  20. laanwj commented at 1:08 pm on June 28, 2017: member

    I’d agree if the nit fixes were in the same commit, but if they’re done in their own commit either before or after the move it adds almost no review burden (as long as reviewers are reviewing commitwise)

    Yes that’s what I meant, with a separate commit it’s fine.

  21. in src/rpc/mining.h:8 in 4cdb6209de outdated
    0@@ -0,0 +1,15 @@
    1+// Copyright (c) 2017 The Bitcoin Core developers
    2+// Distributed under the MIT software license, see the accompanying
    3+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
    4+
    5+#ifndef BITCOIN_RPC_MINING_H
    6+#define BITCOIN_RPC_MINING_H
    7+
    8+#include <script/script.h>
    


    TheBlueMatt commented at 8:23 pm on June 28, 2017:
    Shouldnt this be a “-style include?

    laanwj commented at 9:58 am on June 29, 2017:
    Yes, good point
  22. TheBlueMatt commented at 8:23 pm on June 28, 2017: member
    utACK 4cdb6209de2f712cd5847373b6bc2fb6401fb739, thanks for cleaning up CValidationInterface.
  23. rpc: Move the `generate` RPC call to rpcwallet
    This makes it possible to mine to any wallet when multi-wallet mode is added.
    Solves the same problem as #10649, but IMO in a cleaner way.
    
    It also gets rid of the circuitous `ScriptForMining` method on
    `CValidationInterface`, which really doesn't belong there.
    
    After this change it's still possible to mine without wallet through
    `generatetoaddress`.
    df7e2f057b
  24. rpc: Update `generate` for developer notes
    Fix nits by John Newbery.
    2a962834fe
  25. laanwj force-pushed on Jun 29, 2017
  26. laanwj commented at 10:04 am on June 29, 2017: member
    Updated #include style and squashed this into the first commit, where mining.h was introduced: 8c410a8fbb5f1876484a3f10d25cf9c06a8ef875df7e2f057b6c9f0f7c950f9077dc63a577f54117 4cdb6209de2f712cd5847373b6bc2fb6401fb739 → 2a962834febc9f56126ef06cf1bd5e1b02370278
  27. laanwj merged this on Jul 3, 2017
  28. laanwj closed this on Jul 3, 2017

  29. laanwj referenced this in commit d81bec7666 on Jul 3, 2017
  30. UdjinM6 referenced this in commit 59278bd308 on Aug 4, 2019
  31. PastaPastaPasta referenced this in commit 6edcf43fcd on Aug 5, 2019
  32. PastaPastaPasta referenced this in commit 62f8e2c81a on Aug 6, 2019
  33. PastaPastaPasta referenced this in commit c6f93ae253 on Aug 6, 2019
  34. barrystyle referenced this in commit 10cc01fd52 on Jan 22, 2020
  35. MarcoFalke locked this on Sep 8, 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-21 15:12 UTC

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