Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Wallet/RPC: sweepprivkeys method to scan UTXO set and send to local wallet #9152
Conversation
fanquake
added
RPC/REST/ZMQ
Wallet
labels
Nov 13, 2016
|
Concept ACK (Haven't really looked at the code). Possible extension: |
|
From a raw flow perspective, the generation of the sweep transaction is something that works from public information and should be possible on an online node without access to the private keys... so that one should be a 'createrawsweeptransaction' which takes a list of adresses/pubkeys/redeemscripts (and maybe private keys ... maybe some kind of BIP32 chain spec) and returns a transaction that spends all coins assigned to matching keys, potentially with arguments to limit the set of inputs collected. |
|
Hmm, what about extending RPC |
|
sweepprivkeys is intended for users, and not to import keys. Users should never use importprivkey. |
added a commit
to ryanofsky/bitcoin
that referenced
this pull request
Dec 9, 2016
ryanofsky
referenced this pull request
Dec 9, 2016
Closed
Make CCoinsViewCache::Cursor() return latest data #9306
added a commit
to ryanofsky/bitcoin
that referenced
this pull request
Dec 15, 2016
added a commit
to ryanofsky/bitcoin
that referenced
this pull request
Dec 19, 2016
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Dec 21, 2016
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Dec 21, 2016
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Dec 21, 2016
ryanofsky
reviewed
Dec 28, 2016
Re: "Refactor sweepprivkeys to deal with CCoinsView::Cursor limitations," I think I could extend #9306 to return a working cursor for CCoinsViewMemPool, if that would help.
| + LOCK(cs_main); | ||
| + mempool.FindScriptPubKey(setscriptSearch, mapcoins); | ||
| + FlushStateToDisk(); | ||
| + pcoinsTip->FindScriptPubKey(setscriptSearch, mapcoins); |
ryanofsky
Dec 28, 2016
•
Contributor
It might be appropriate to loop over mapCoins calling CTxMemPool::pruneSpent, on each entry, to avoid trying to sweep from an output that is already in the process of being spent.
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Dec 31, 2016
added a commit
to bitcoinknots/bitcoin
that referenced
this pull request
Dec 31, 2016
added a commit
to ryanofsky/bitcoin
that referenced
this pull request
Jan 2, 2017
added a commit
to ryanofsky/bitcoin
that referenced
this pull request
Jan 2, 2017
|
Concept ACK.
Please don't do this. People confuse |
laanwj
added this to the 0.15.0 milestone
Feb 27, 2017
added a commit
to ryanofsky/bitcoin
that referenced
this pull request
Jun 2, 2017
added a commit
to ryanofsky/bitcoin
that referenced
this pull request
Jun 12, 2017
|
Seems this won't be making it for 0.15. Untagging. |
sipa
removed this from the 0.15.0 milestone
Jul 12, 2017
|
Concept Re-ACK. Needs rebase. I guess this is also something we could want for 0.16. |
|
Rebased and added a simple functional test. |
promag
reviewed
Aug 19, 2017
Is it me or this could use CWallet::FundTransaction with coin control configured and with subtract fee from amount?
| + CKeyID address = pubkey.GetID(); | ||
| + CScript script = GetScriptForDestination(address); | ||
| + if (!script.empty()) { | ||
| + needles.insert(script); |
| + } | ||
| + script = GetScriptForRawPubKey(pubkey); | ||
| + if (!script.empty()) { | ||
| + needles.insert(script); |
| + } | ||
| + } | ||
| + | ||
| + // Ensure keypool is filled if possible |
luke-jr
Aug 21, 2017
Member
If it's empty, we'll throw "No value to sweep" later on. And so long as the user provides something, it will never be empty.
| + CReserveKey reservekey(pwallet); | ||
| + CPubKey pubkey; | ||
| + if (!reservekey.GetReservedKey(pubkey)) { | ||
| + throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); |
luke-jr
Aug 21, 2017
Member
I don't know how, and the two tests currently "testing" it don't make logical sense.
| + | ||
| + // Scan UTXO set for inputs | ||
| + std::vector<CTxOut> input_txos; | ||
| + { |
| + if (IsDust(tx.vout[0], ::minRelayTxFee)) { | ||
| + throw JSONRPCError(RPC_VERIFY_REJECTED, "Swept value would be dust"); | ||
| + } | ||
| + for (size_t input_index = 0; input_index < tx.vin.size(); ++input_index) { |
luke-jr
Aug 21, 2017
Member
Fee changes require resigning. Perhaps it could be made to sign only before and after the loop, but the time here is trivial in comparison to the UTXO search.
|
Fixed the test failure (missing |
luke-jr commentedNov 13, 2016
•
Edited 1 time
-
luke-jr
Aug 19, 2017
Does this look like a good approach?
TODO:
RPC tests