Basic implementation of a new rpc call fundrawtransaction.
This call will fill a rawtransaction containing only vouts with unspent coins from the wallet.
Currently there is no way to return the CReserveKey to the keypool.
Basic implementation of a new rpc call fundrawtransaction.
This call will fill a rawtransaction containing only vouts with unspent coins from the wallet.
Currently there is no way to return the CReserveKey to the keypool.
As createrawtransactions with potential unspent vins, this call does not lock the coins somehow.
792 | + CTransaction tx; 793 | + if (!DecodeHexTx(tx, params[0].get_str())) 794 | + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); 795 | + 796 | + if (tx.vin.size() > 0) 797 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "fundrawtransaction only supports transactions with zero exiting vins");
s/exiting/existing
ACK the idea. It seems useful.
Sweet. This should have a mechenism to also include watchonly coins.
It should support existing VINs, which are useful if you want to specifically spend a particular coin, but need more inputs to complete the txn. One reason you may want to do this is to achieve mutual exclusion with a prior transaction. If the existing vins are adequate it shouldn't add any more.
Also, not to pile on too much, but a "fundmany" would be neat as well (in addition to watchonly support in fundrawtransaction). This would be useful for batch coin selection, offline signing, and coinjoin. Plus, fundmany is not a huge jump from sendmany.
Also, gmaxwell proposed on IRC a limit=N parameter on fundrawtransaction?
Nevermind about fundmany: http://bitcoinstats.com/irc/bitcoin-dev/logs/2014/12/19#l1419025192
Added support for existing VINs.
Now comes with an extensive test-script.
@gmaxwell the proposed limit parameter needs probably some brainwork first. See (http://bitcoinstats.com/irc/bitcoin-dev/logs/2014/12/20#l1419085131). Maybe another pull.
Just fixed an issue in CreateTransaction which produced endless recursive loops. Travis should now be happy.
1372 | + if (!out.fSpendable) 1373 | + continue; 1374 | + 1375 | + nValueTroughVINs += out.tx->vout[out.i].nValue; 1376 | + 1377 | + // temporary keep the coin to add them later after SelectCoinsMinConf has added some
s/temporary/temporarily
Thanks. Fixed.
needs rebase (assigned 0.11 milestone, would be nice to have this)
rebased.
should solve #3794
binaries to test: https://builds.jonasschnelli.ch/pulls/5503/
Rebased (hard rebase after "Subtract fee from amount [#5831]"), added some code comments.
320 | @@ -321,7 +321,9 @@ static const CRPCCommand vRPCCommands[] = 321 | { "rawtransactions", "getrawtransaction", &getrawtransaction, true, false }, 322 | { "rawtransactions", "sendrawtransaction", &sendrawtransaction, false, false }, 323 | { "rawtransactions", "signrawtransaction", &signrawtransaction, false, false }, /* uses wallet if enabled */ 324 | - 325 | +#ifdef ENABLE_WALLET 326 | + { "rawtransactions", "fundrawtransaction", &fundrawtransaction, false, false },
Bug: should be 'true' to indicate wallet requirement. Otherwise, the 'pwalletMain' reference will oops when NULL (wallet support built, but disabled at runtime).
Thanks for catching this one! Fixed and pushed.
ut ACK + plan to test this this week (modulo bug fix mentioned above of course)
1892 | @@ -1823,6 +1893,14 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, 1893 | strFailReason = _("Transaction too large"); 1894 | return false; 1895 | } 1896 | + 1897 | + //remove signature if we used the signing only for the fee calculation
Why sign at all if it's only for the fee calculation? I ask because we don't want to unnecessarily require the signing keys.
We still need to remove the signature, but now, during fundrawtransaction, the signature is dummy/void.
Yes, removing a dummy sigature is fine.
Currently i'm working on this to allow fundrawtransaction to calculate serialized transaction length for getting the right fee and priority without actually signing the tx. Tests won't make sense at the moment.
Updated!
fundrawtransaction now works with locked wallets. Fee / priority calculation now goes over a new dummy-signing way in sign.cpp.
RPC tests are now even more extensive and includes multisig test, locked wallet tests as well as comparison of calculated fee and correct fee tests.
The only question is, if it would be worth to add a optional correctFee=1|0 argument for the fundrawtransaction rpc call. With settings this flag, users could enforce correct signing of the tx (would require unlocked wallet) which would end up in getting a more precise/correct fee.
rebased.
Moved RPC function "fundrawtransaction()" from rpcrawtransaction.cpp to rpcwallet.cpp (fundrawtransaction is a wallet function). Added wallet-is-presence check because we recently removed "reqWallet" check over the RPC dispatch table.
- fix typo
- fix RPCTypeCheck for fundrawtransaction
- some comments
- merged with subtractFeeFromAmout patch (non trivial)
- serialize transaction size calculation (aka dummy-signing) without the need of signing the transaction (wallet can be locked to use fundrawtransaction)
- rename VINS to vInputs
fundrawtransaction requires a wallet and therefore it belongs to rpcwallet.cpp
rpc dispatch tables reqWallet has been removed.
rebased.
I needed to use this for something and rewrote/tweaked a few chunks. See changes at https://github.com/TheBlueMatt/bitcoin/tree/frt
# Conflicts:
# src/rpcserver.cpp
Pulled in some commits from @TheBlueMatt. Only pulled in clear beneficial and easy reviewable commits. Other things (CCoinControl usage, watch-only support) may be better handled in a 2nd pull request to avoid large changeset.
# Conflicts:
# src/wallet/rpcwallet.cpp
@jonasschnelli Actually, the changes I made were mostly to limit the size of this pull request. Some of them look like it would become a big pull request, but once squashed, the total size is actually smaller than the original :)
Also, not sure when you pulled in, but I force pushe'd a few times, you may want to check that the ones you merged are the latest versions (I'm done now, I think). I also merged in a tweaked-up version of fundrawtransaction there.
@TheBlueMatt Thank you for your tweaks! Will try to go through the optimizing commits but need a clear head for that. Will do it soon.
I added two more commits to that tree and made a nice rebased version at https://github.com/TheBlueMatt/bitcoin/commits/frt2
Rebased frt2. @jonasschnelli do you want to review my changes and merge them here, or should I just open a new pull request? I'd like to keep this moving.
closing in favor of #6088
Milestone
0.11.0