Skip to content

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Jun 27, 2017

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.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

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.

{
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);

if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: braces

if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
return NullUniValue;

if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: braces

+ HelpExampleCli("generate", "11")
);

int nGenerate = request.params[0].get_int();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: variable name should be lowercase, not hungarian

);

int nGenerate = request.params[0].get_int();
uint64_t nMaxTries = 1000000;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: variable name should be lowercase, not hungarian


int nGenerate = request.params[0].get_int();
uint64_t nMaxTries = 1000000;
if (request.params.size() > 1) {
Copy link
Contributor

@jnewbery jnewbery Jun 27, 2017

Choose a reason for hiding this comment

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

nit: should handle case when request.params[1] is Null (for named arguments)

pwallet->GetScriptForMining(coinbaseScript);

// If the keypool is exhausted, no script is returned at all. Catch this.
if (!coinbaseScript)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: braces

throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");

//throw an error if no script was provided
if (coinbaseScript->reserveScript.empty())
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: braces

@instagibbs
Copy link
Member

utACK 8c410a8 though nit cleanup is great too.

@jonasschnelli
Copy link
Contributor

Nice and thanks for doing this:
utACK 8c410a8fbb5f1876484a3f10d25cf9c06a8ef875

@laanwj
Copy link
Member Author

laanwj commented Jun 28, 2017

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.

@jnewbery
Copy link
Contributor

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)

@laanwj
Copy link
Member Author

laanwj commented Jun 28, 2017

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.

Copy link
Contributor

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

utACK 4cdb6209de2f712cd5847373b6bc2fb6401fb739, thanks for cleaning up CValidationInterface.

src/rpc/mining.h Outdated
#ifndef BITCOIN_RPC_MINING_H
#define BITCOIN_RPC_MINING_H

#include <script/script.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldnt this be a "-style include?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good point

laanwj added 2 commits June 29, 2017 12:02
This makes it possible to mine to any wallet when multi-wallet mode is added.
Solves the same problem as bitcoin#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`.
Fix nits by John Newbery.
@laanwj laanwj force-pushed the 2017_06_wallet_mining branch from 4cdb620 to 2a96283 Compare June 29, 2017 10:04
@laanwj
Copy link
Member Author

laanwj commented Jun 29, 2017

Updated #include style and squashed this into the first commit, where mining.h was introduced:
8c410a8fbb5f1876484a3f10d25cf9c06a8ef875 → df7e2f0
4cdb6209de2f712cd5847373b6bc2fb6401fb739 → 2a96283

@laanwj laanwj merged commit 2a96283 into bitcoin:master Jul 3, 2017
laanwj added a commit that referenced this pull request Jul 3, 2017
2a96283 rpc: Update `generate` for developer notes (Wladimir J. van der Laan)
df7e2f0 rpc: Move the `generate` RPC call to rpcwallet (Wladimir J. van der Laan)

Tree-SHA512: ec658d6178f8435dc54b9d9c6dd59f873055a8ae0c3f177c02049d77b93107dd5fc17a1ff56d50f051810d52fdf306846eaba2ef4fc8d2a6cfa831f57a1045c4
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Aug 4, 2019
2a96283 rpc: Update `generate` for developer notes (Wladimir J. van der Laan)
df7e2f0 rpc: Move the `generate` RPC call to rpcwallet (Wladimir J. van der Laan)

Tree-SHA512: ec658d6178f8435dc54b9d9c6dd59f873055a8ae0c3f177c02049d77b93107dd5fc17a1ff56d50f051810d52fdf306846eaba2ef4fc8d2a6cfa831f57a1045c4
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Aug 5, 2019
2a96283 rpc: Update `generate` for developer notes (Wladimir J. van der Laan)
df7e2f0 rpc: Move the `generate` RPC call to rpcwallet (Wladimir J. van der Laan)

Tree-SHA512: ec658d6178f8435dc54b9d9c6dd59f873055a8ae0c3f177c02049d77b93107dd5fc17a1ff56d50f051810d52fdf306846eaba2ef4fc8d2a6cfa831f57a1045c4
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Aug 6, 2019
2a96283 rpc: Update `generate` for developer notes (Wladimir J. van der Laan)
df7e2f0 rpc: Move the `generate` RPC call to rpcwallet (Wladimir J. van der Laan)

Tree-SHA512: ec658d6178f8435dc54b9d9c6dd59f873055a8ae0c3f177c02049d77b93107dd5fc17a1ff56d50f051810d52fdf306846eaba2ef4fc8d2a6cfa831f57a1045c4
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Aug 6, 2019
2a96283 rpc: Update `generate` for developer notes (Wladimir J. van der Laan)
df7e2f0 rpc: Move the `generate` RPC call to rpcwallet (Wladimir J. van der Laan)

Tree-SHA512: ec658d6178f8435dc54b9d9c6dd59f873055a8ae0c3f177c02049d77b93107dd5fc17a1ff56d50f051810d52fdf306846eaba2ef4fc8d2a6cfa831f57a1045c4
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
2a96283 rpc: Update `generate` for developer notes (Wladimir J. van der Laan)
df7e2f0 rpc: Move the `generate` RPC call to rpcwallet (Wladimir J. van der Laan)

Tree-SHA512: ec658d6178f8435dc54b9d9c6dd59f873055a8ae0c3f177c02049d77b93107dd5fc17a1ff56d50f051810d52fdf306846eaba2ef4fc8d2a6cfa831f57a1045c4
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants