-
Notifications
You must be signed in to change notification settings - Fork 38.7k
[RPC] Add generatetoaddress rpc to mine to an address #7671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/rpc/mining.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use "address" instead of "base58 encoded address" (it would even be wrong because it's a base58 check encoded ripemd hash".
|
Nice! |
4ef0344 to
983d9a5
Compare
|
I like the concept, but perhaps we can separate that out to a different RPC (which then can function without wallet support)? Also, the change in arguments to |
983d9a5 to
fd85325
Compare
|
This seems unnecessary. Why not just move GBT->block code from getblocktemplate_proposals.py to blocktools? |
Why?
Not sure what you mean by this. |
0115c8f to
0422b5c
Compare
|
Rebased |
|
I'd prefer to have rpc tests as part of this pull. |
|
@MarcoFalke Where would be the best place to put such tests? |
|
@achow101 You can either start from scratch (c.f. https://github.com/bitcoin/bitcoin/blob/48f39058315c908c360acb596923cbc090119480/qa/rpc-tests/disablewallet.py) or extend an existing python script in this folder. |
|
One of the primary use cases for this, I think, would be to have RPC tests where you get an address from one node, and let another node mine directly to it, without the need to generate 100 blocks in between before you can transfer. |
|
I added rpc tests, both with and without wallets.
|
qa/rpc-tests/wallet.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
assert("Invalid or non-wallet transaction id" not in errorString)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you can remove the whole except block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, you can remove the whole except block?
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error string is always empty, so it's dead code? (Correct me if I am wrong)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, I don't think so. There is an error from gettransaction and the error string was defined earlier.
Anyways, this should work, right?
except JSONRPCException,e:
assert("Invalid or non-wallet transaction id" not in e.error['message'])
ef18efd to
3b0f6b1
Compare
|
addressed nits |
|
Random Q: Should this also be able to take an arbitrary scriptPubKey?
Also eventually we want to have at least part of the RPC tests usable without wallet. |
Do you think that it should? |
I don't deeply care myself. Just a question that came up with me, usually the discussion of custom scripts comes up immediately after allowing arbitrary addresses, as addresses map to a only a subset of the possible output scripts. So to be clear, I'm ok with just leaving it like this. |
|
OK, I'll just leave it as is. |
|
If we want to support that, perhaps we should just define an address format
that supports arbitrary scriptPubKeys. That way, it would be available
everywhere.
|
|
Needs rebase. |
Creates the generatetoaddress rpc which is virtually identical to the generate rpc except that it takes an argument for the address to mine to. It does not rely on wallet functionality. The mining code shared by generate and generatetoaddress has been moved to another method to reduce duplication.
3b0f6b1 to
8cad9b2
Compare
|
rebased |
qa/rpc-tests/disablewallet.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this line. The variable is unused and I'd prefer not to use it ever again: see 3b4324b#diff-dafb9035fa41af011fcf87041198a05aL309
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Adds two RPC tests for the generatetoaddress RPC, one in the wallet, and one when the wallet is disabled. The wallet RPC Test mines Bitcoin to another node's address and checks that that node has received the Bitcoin. The RPC test without the wallet mines Bitcoin to an arbitrary address and checks that it works. It then mines to an arbitrary invalid address and checks that that fails.
8cad9b2 to
d5c5c71
Compare
|
ACK fe00ca7 |
Add a new optional parameter to the generate call to mine to a specific address even if it doesn't exist in the wallet.