Browse Source

Test

pull/4/head
jl777 7 years ago
parent
commit
ceb639e0e8
  1. 4
      src/test/rpc_wallet_tests.cpp
  2. 23
      src/wallet/asyncrpcoperation_sendmany.cpp

4
src/test/rpc_wallet_tests.cpp

@ -1048,14 +1048,14 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
BOOST_CHECK(tx.vout.size() == 0);
CAmount amount = 123.456;
proxy.add_taddr_change_output_to_tx(amount);
proxy.add_taddr_change_output_to_tx(0,amount);
tx = proxy.getTx();
BOOST_CHECK(tx.vout.size() == 1);
CTxOut out = tx.vout[0];
BOOST_CHECK_EQUAL(out.nValue, amount);
amount = 1.111;
proxy.add_taddr_change_output_to_tx(amount);
proxy.add_taddr_change_output_to_tx(0,amount);
tx = proxy.getTx();
BOOST_CHECK(tx.vout.size() == 2);
out = tx.vout[1];

23
src/wallet/asyncrpcoperation_sendmany.cpp

@ -318,7 +318,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
CAmount change = funds - fundsSpent;
if (change > 0) {
add_taddr_change_output_to_tx(change);
add_taddr_change_output_to_tx(0,change);
LogPrint("zrpc", "%s: transparent change in transaction output (amount=%s)\n",
getId(),
@ -395,7 +395,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
"allow any change as there is currently no way to specify a change address "
"in z_sendmany.", FormatMoney(change)));
} else {
add_taddr_change_output_to_tx(change);
add_taddr_change_output_to_tx(&fromtaddr_,change);
LogPrint("zrpc", "%s: transparent change in transaction output (amount=%s)\n",
getId(),
FormatMoney(change)
@ -1102,23 +1102,24 @@ void AsyncRPCOperation_sendmany::add_taddr_outputs_to_tx() {
tx_ = CTransaction(rawTx);
}
void AsyncRPCOperation_sendmany::add_taddr_change_output_to_tx(CAmount amount) {
void AsyncRPCOperation_sendmany::add_taddr_change_output_to_tx(CBitcoinAddress *fromaddress,CAmount amount) {
LOCK2(cs_main, pwalletMain->cs_wallet);
EnsureWalletIsUnlocked();
//if ( 0 )
// CScript scriptPubKey = GetScriptForDestination(fromaddress.Get());
//else
//{
CReserveKey keyChange(pwalletMain);
CPubKey vchPubKey;
CScript scriptPubKey;
CReserveKey keyChange(pwalletMain);
CPubKey vchPubKey;
if ( fromaddress != 0 )
scriptPubKey = GetScriptForDestination(fromaddress->Get());
else
{
bool ret = keyChange.GetReservedKey(vchPubKey);
if (!ret) {
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Could not generate a taddr to use as a change address"); // should never fail, as we just unlocked
}
CScript scriptPubKey = GetScriptForDestination(vchPubKey.GetID());
//}
scriptPubKey = GetScriptForDestination(vchPubKey.GetID());
}
CTxOut out(amount, scriptPubKey);
CMutableTransaction rawTx(tx_);

Loading…
Cancel
Save