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

Add multiple options to fundrawtransaction #7518

Closed
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
8 participants
@promag
Member

promag commented Feb 11, 2016

This PR allows to specify an address to receive the change of the fund. Currently fundrawtransaction accepts a boolean for the second parameter. With this change the second parameter can be either a boolean or a JSON object with the following optional keys: includeWatching, changeAddress and changePosition.

@promag

View changes

Show outdated Hide outdated src/wallet/rpcwallet.cpp
@promag

View changes

Show outdated Hide outdated src/wallet/wallet.h
@luke-jr

This comment has been minimized.

Show comment
Hide comment
@luke-jr

luke-jr Feb 11, 2016

Member

You need to update the help. I suggest replacing the Boolean with the Object entirely, and just supporting the boolean in code as a backward compatibility thing.

Member

luke-jr commented Feb 11, 2016

You need to update the help. I suggest replacing the Boolean with the Object entirely, and just supporting the boolean in code as a backward compatibility thing.

@promag

This comment has been minimized.

Show comment
Hide comment
@promag
Member

promag commented Feb 11, 2016

@luke-jr done.

@luke-jr

View changes

Show outdated Hide outdated src/wallet/rpcwallet.cpp
@luke-jr

View changes

Show outdated Hide outdated src/wallet/wallet.cpp
@promag

This comment has been minimized.

Show comment
Hide comment
@promag

promag Feb 11, 2016

Member

@luke-jr ok, added a test for the changeAddress option.

Member

promag commented Feb 11, 2016

@luke-jr ok, added a test for the changeAddress option.

@luke-jr

View changes

Show outdated Hide outdated src/wallet/rpcwallet.cpp
@luke-jr

This comment has been minimized.

Show comment
Hide comment
@luke-jr

luke-jr Feb 13, 2016

Member

Also, this conflicts with #7159 , so one of them will need to rebase. I think #7159 should adopt the options Object used here.

Member

luke-jr commented Feb 13, 2016

Also, this conflicts with #7159 , so one of them will need to rebase. I think #7159 should adopt the options Object used here.

@promag

This comment has been minimized.

Show comment
Hide comment
@promag

promag Feb 13, 2016

Member

@luke-jr agree #7159 should adopt options.

Member

promag commented Feb 13, 2016

@luke-jr agree #7159 should adopt options.

@promag

This comment has been minimized.

Show comment
Hide comment
@promag
Member

promag commented Feb 13, 2016

@luke-jr done.

@laanwj laanwj added the Wallet label Feb 13, 2016

@promag promag changed the title from [RPC] Add changeAddress option to fundrawtransaction to [RPC] Add change options to fundrawtransaction Feb 13, 2016

@promag

This comment has been minimized.

Show comment
Hide comment
@promag

promag Feb 13, 2016

Member

Added changePosition option to specify the desired vout index of change address.

Member

promag commented Feb 13, 2016

Added changePosition option to specify the desired vout index of change address.

@@ -575,7 +601,7 @@ def run_test(self):
outputs = {self.nodes[2].getnewaddress() : watchonly_amount / 2}
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
result = self.nodes[3].fundrawtransaction(rawtx, True)
result = self.nodes[3].fundrawtransaction(rawtx, {'includeWatching': True })

This comment has been minimized.

@MarcoFalke

MarcoFalke Feb 13, 2016

Member

Can you leave one of them and mention that this is testing backward compatibility?

@MarcoFalke

MarcoFalke Feb 13, 2016

Member

Can you leave one of them and mention that this is testing backward compatibility?

This comment has been minimized.

@promag

promag Feb 13, 2016

Member

👍

@promag

This comment has been minimized.

@promag

promag Mar 24, 2016

Member

See below.

@promag

promag Mar 24, 2016

Member

See below.

@@ -591,6 +617,7 @@ def run_test(self):
outputs = {self.nodes[2].getnewaddress() : watchonly_amount}
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
# Backward compatibility test (2nd param is includeWatching)
result = self.nodes[3].fundrawtransaction(rawtx, True)

This comment has been minimized.

@promag
@promag
@@ -735,7 +735,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
* Insert additional inputs into the transaction by
* calling CreateTransaction();
*/
bool FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosRet, std::string& strFailReason, bool includeWatching);

This comment has been minimized.

@promag

promag Feb 13, 2016

Member

I feel we should have a better argument order. Suggestion:

bool FundTransaction(CMutableTransaction& tx, const CTxDestination& changeDestination, int& changePosition, bool includeWatching, CAmount& nFeeRet, std::string& strFailReason);
@promag

promag Feb 13, 2016

Member

I feel we should have a better argument order. Suggestion:

bool FundTransaction(CMutableTransaction& tx, const CTxDestination& changeDestination, int& changePosition, bool includeWatching, CAmount& nFeeRet, std::string& strFailReason);

This comment has been minimized.

@luke-jr

luke-jr Feb 13, 2016

Member

It doesn't really matter as long as existing code either fails to compile or behaves the same. Note that to put destChange earlier, you would need to make it a required option.

@luke-jr

luke-jr Feb 13, 2016

Member

It doesn't really matter as long as existing code either fails to compile or behaves the same. Note that to put destChange earlier, you would need to make it a required option.

This comment has been minimized.

@jonasschnelli

jonasschnelli Feb 19, 2016

Member

I guess we should rename nChangePosRet to nChangePosInOut and add a comment in the header that -1 as a input value will result in setting a random position.

@jonasschnelli

jonasschnelli Feb 19, 2016

Member

I guess we should rename nChangePosRet to nChangePosInOut and add a comment in the header that -1 as a input value will result in setting a random position.

@promag promag referenced this pull request Feb 19, 2016

Merged

Add importmulti RPC call #7551

@jonasschnelli

View changes

Show outdated Hide outdated src/wallet/rpcwallet.cpp
@jonasschnelli

View changes

Show outdated Hide outdated src/wallet/wallet.cpp
@jonasschnelli

View changes

Show outdated Hide outdated src/wallet/wallet.cpp
@jonasschnelli

View changes

Show outdated Hide outdated src/wallet/rpcwallet.cpp
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VOBJ));
UniValue options = params[1];

This comment has been minimized.

@jonasschnelli

jonasschnelli Feb 19, 2016

Member

Maybe add a RPCTypeCheckObj() to ensure that changePosition, etc. are the correct types? Otherwise you get a plain JSON value is not a boolean as expected (etc.)?

@jonasschnelli

jonasschnelli Feb 19, 2016

Member

Maybe add a RPCTypeCheckObj() to ensure that changePosition, etc. are the correct types? Otherwise you get a plain JSON value is not a boolean as expected (etc.)?

This comment has been minimized.

@promag

promag Mar 5, 2016

Member

👍

@promag

promag Mar 5, 2016

Member

👍

This comment has been minimized.

@promag

promag Mar 24, 2016

Member

See below.

@promag

promag Mar 24, 2016

Member

See below.

@jonasschnelli

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli

jonasschnelli Feb 19, 2016

Member

utACK.
Nice work!

I'm not sure if we should add the backward compatibility fallback (includeWatchonly = true). Because it could also lead to problems in future. If so, we should also mention in in the RPC help (something like a plain True results in includeWatchonly=true).

IMO a API break would be acceptable.

Member

jonasschnelli commented Feb 19, 2016

utACK.
Nice work!

I'm not sure if we should add the backward compatibility fallback (includeWatchonly = true). Because it could also lead to problems in future. If so, we should also mention in in the RPC help (something like a plain True results in includeWatchonly=true).

IMO a API break would be acceptable.

@promag promag changed the title from [RPC] Add change options to fundrawtransaction to Add change options to fundrawtransaction Feb 25, 2016

luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Feb 25, 2016

Add change options to fundrawtransaction
Github-Pull: #7518
Rebased-From: 49cea7936dc44b5f3c3373c4190cb260996ef56b
@nunofgs

This comment has been minimized.

Show comment
Hide comment
@nunofgs

nunofgs Mar 2, 2016

@promag: it would be useful to add an option "lockUnspents: true" to ensure that chosen unspents are effectively locked before sending the transaction.

nunofgs commented Mar 2, 2016

@promag: it would be useful to add an option "lockUnspents: true" to ensure that chosen unspents are effectively locked before sending the transaction.

@promag

This comment has been minimized.

Show comment
Hide comment
@promag

promag Mar 2, 2016

Member

@nunofgs yes, that idea was also in #7498.

Member

promag commented Mar 2, 2016

@nunofgs yes, that idea was also in #7498.

@promag promag changed the title from Add change options to fundrawtransaction to Add multiple options to fundrawtransaction Mar 5, 2016

" {\n"
" \"changeAddress\" (string, optional, default pool address) The bitcoin address to receive the change\n"
" \"changePosition\" (numeric, optional, default random) The index of the change output\n"
" \"includeWatching\" (boolean, optional, default false) Also select inputs which are watch only\n"

This comment has been minimized.

@ruimarinho

ruimarinho Mar 31, 2016

Bikeshedding but have you considered includeWatchOnly to follow a consistent nomenclature?

@ruimarinho

ruimarinho Mar 31, 2016

Bikeshedding but have you considered includeWatchOnly to follow a consistent nomenclature?

This comment has been minimized.

@promag

promag Mar 31, 2016

Member

The underlying flag is allowWatchOnly. includeWatching is the old parameter name. Happy to rename if others agree.

@promag

promag Mar 31, 2016

Member

The underlying flag is allowWatchOnly. includeWatching is the old parameter name. Happy to rename if others agree.

This comment has been minimized.

@jonasschnelli

jonasschnelli Mar 31, 2016

Member

IMO we should keep includeWatching.

@jonasschnelli

jonasschnelli Mar 31, 2016

Member

IMO we should keep includeWatching.

"1. \"hexstring\" (string, required) The hex string of the raw transaction\n"
"2. includeWatching (boolean, optional, default false) Also select inputs which are watch only\n"
"1. \"hexstring\" (string, required) The hex string of the raw transaction\n"
"2. options (object, optional)\n"

This comment has been minimized.

@jonasschnelli

jonasschnelli Mar 31, 2016

Member

nit: here we should mention something like : "for backward compatibility: passing in a true instead of an object will result in {"includeWatching":true}"

@jonasschnelli

jonasschnelli Mar 31, 2016

Member

nit: here we should mention something like : "for backward compatibility: passing in a true instead of an object will result in {"includeWatching":true}"

if (nChangePosRet != -1)
tx.vout.insert(tx.vout.begin() + nChangePosRet, wtx.vout[nChangePosRet]);
if (nChangePosInOut != -1)
tx.vout.insert(tx.vout.begin() + nChangePosInOut, wtx.vout[nChangePosInOut]);

This comment has been minimized.

@jonasschnelli

jonasschnelli Mar 31, 2016

Member

Here we need another check.
What if nChangePosInOut = 10 but tx.vout.size()==2?
We need a out-of-range exception in a such case.

@jonasschnelli

jonasschnelli Mar 31, 2016

Member

Here we need another check.
What if nChangePosInOut = 10 but tx.vout.size()==2?
We need a out-of-range exception in a such case.

This comment has been minimized.

@promag

promag Apr 2, 2016

Member

Check is in rpcwallet.cpp.

@promag

promag Apr 2, 2016

Member

Check is in rpcwallet.cpp.

This comment has been minimized.

@jonasschnelli

jonasschnelli Apr 5, 2016

Member

@promag: The check should should really be here (maybe an additional check). If someone uses CWallet::FundTransaction() with a nChangePosInOut >= wtx.vout.size(), the app crashes/throws an exceptions. Future changes might easy get trapped by this.

The problematic part is wtx.vout[nChangePosInOut]. There should be a check somewhere in CWallet::FundTransaction() that leads to a return false if a overflow has detected.

@jonasschnelli

jonasschnelli Apr 5, 2016

Member

@promag: The check should should really be here (maybe an additional check). If someone uses CWallet::FundTransaction() with a nChangePosInOut >= wtx.vout.size(), the app crashes/throws an exceptions. Future changes might easy get trapped by this.

The problematic part is wtx.vout[nChangePosInOut]. There should be a check somewhere in CWallet::FundTransaction() that leads to a return false if a overflow has detected.

@jonasschnelli

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli

jonasschnelli Mar 31, 2016

Member

Allmost done. Last iteration:

  • needs out-of-range detection of changePosition.
  • needs simple documentation of backward compatibility (true instead of an parameter object)
Member

jonasschnelli commented Mar 31, 2016

Allmost done. Last iteration:

  • needs out-of-range detection of changePosition.
  • needs simple documentation of backward compatibility (true instead of an parameter object)
@promag

This comment has been minimized.

Show comment
Hide comment
@promag

promag Apr 2, 2016

Member

@jonasschnelli updated and rebased. not sure where is the best place to put the new help message.

Member

promag commented Apr 2, 2016

@jonasschnelli updated and rebased. not sure where is the best place to put the new help message.

@jonasschnelli

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli

jonasschnelli Apr 6, 2016

Member

ping @promag: Would be nice if you could take the change output order check into CreateTransaction(): https://github.com/bitcoin/bitcoin/pull/7518/files#r58496250
I'm convince that this is the last issue before this is ready for merging.

Please also fix the commit order. The head commit is from March 5, but the HEAD~2 is March 30.

commit 4b0360f4160e059b61a21a95a6106d0eed927bd9
Author: João Barbosa <joao@uphold.com>
Date:   Sat Mar 5 09:45:57 2016 +0000

commit c2a3ff1a08df8619f7af77ebe6c3b7661e858bc1
Author: João Barbosa <joao@uphold.com>
Date:   Wed Mar 30 02:04:22 2016 +0100

commit 699720b3baa9e0d3dab679b1da91ab45808aa85e
Author: João Barbosa <joao@uphold.com>
Date:   Wed Mar 30 00:59:29 2016 +0100
Member

jonasschnelli commented Apr 6, 2016

ping @promag: Would be nice if you could take the change output order check into CreateTransaction(): https://github.com/bitcoin/bitcoin/pull/7518/files#r58496250
I'm convince that this is the last issue before this is ready for merging.

Please also fix the commit order. The head commit is from March 5, but the HEAD~2 is March 30.

commit 4b0360f4160e059b61a21a95a6106d0eed927bd9
Author: João Barbosa <joao@uphold.com>
Date:   Sat Mar 5 09:45:57 2016 +0000

commit c2a3ff1a08df8619f7af77ebe6c3b7661e858bc1
Author: João Barbosa <joao@uphold.com>
Date:   Wed Mar 30 02:04:22 2016 +0100

commit 699720b3baa9e0d3dab679b1da91ab45808aa85e
Author: João Barbosa <joao@uphold.com>
Date:   Wed Mar 30 00:59:29 2016 +0100
// Insert change txn at random position:
nChangePosInOut = GetRandInt(txNew.vout.size()+1);
}
else if (nChangePosInOut > txNew.vout.size())

This comment has been minimized.

@promag

promag Apr 6, 2016

Member

@jonasschnelli I think the best place to check if index is out of range is here.

@promag

promag Apr 6, 2016

Member

@jonasschnelli I think the best place to check if index is out of range is here.

@jonasschnelli

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli

jonasschnelli Apr 13, 2016

Member

Tested ACK 18be394.

This is very useful.
It allows to fully decouple the private keys from the node/wallet.

Member

jonasschnelli commented Apr 13, 2016

Tested ACK 18be394.

This is very useful.
It allows to fully decouple the private keys from the node/wallet.

@btcdrak

This comment has been minimized.

Show comment
Hide comment
@btcdrak
Member

btcdrak commented Apr 14, 2016

utACK 18be394

laanwj added a commit that referenced this pull request Apr 15, 2016

Merge #7518: Add multiple options to fundrawtransaction
f2d0944 Add lockUnspents option to fundrawtransaction (João Barbosa)
af4fe7f Add change options to fundrawtransaction (João Barbosa)
41e835d Add strict flag to RPCTypeCheckObj (João Barbosa)
@laanwj

This comment has been minimized.

Show comment
Hide comment
@laanwj

laanwj Apr 15, 2016

Member

Merged this as be14ca5, with a trivial rebase (only overlap in test framework) to master

Member

laanwj commented Apr 15, 2016

Merged this as be14ca5, with a trivial rebase (only overlap in test framework) to master

@laanwj laanwj closed this Apr 15, 2016

@laanwj laanwj referenced this pull request Jun 8, 2016

Closed

TODO for release notes 0.13.0 #7678

14 of 16 tasks complete

luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Jun 28, 2016

codablock added a commit to codablock/dash that referenced this pull request Sep 16, 2017

Merge #7518: Add multiple options to fundrawtransaction
f2d0944 Add lockUnspents option to fundrawtransaction (João Barbosa)
af4fe7f Add change options to fundrawtransaction (João Barbosa)
41e835d Add strict flag to RPCTypeCheckObj (João Barbosa)

codablock added a commit to codablock/dash that referenced this pull request Sep 19, 2017

Merge #7518: Add multiple options to fundrawtransaction
f2d0944 Add lockUnspents option to fundrawtransaction (João Barbosa)
af4fe7f Add change options to fundrawtransaction (João Barbosa)
41e835d Add strict flag to RPCTypeCheckObj (João Barbosa)

codablock added a commit to codablock/dash that referenced this pull request Dec 20, 2017

Merge #7518: Add multiple options to fundrawtransaction
f2d0944 Add lockUnspents option to fundrawtransaction (João Barbosa)
af4fe7f Add change options to fundrawtransaction (João Barbosa)
41e835d Add strict flag to RPCTypeCheckObj (João Barbosa)

@dagurval dagurval referenced this pull request Dec 27, 2017

Merged

Add fundrawtransaction #288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment