Test
This commit is contained in:
@@ -1048,14 +1048,14 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
|
|||||||
BOOST_CHECK(tx.vout.size() == 0);
|
BOOST_CHECK(tx.vout.size() == 0);
|
||||||
|
|
||||||
CAmount amount = 123.456;
|
CAmount amount = 123.456;
|
||||||
proxy.add_taddr_change_output_to_tx(amount);
|
proxy.add_taddr_change_output_to_tx(0,amount);
|
||||||
tx = proxy.getTx();
|
tx = proxy.getTx();
|
||||||
BOOST_CHECK(tx.vout.size() == 1);
|
BOOST_CHECK(tx.vout.size() == 1);
|
||||||
CTxOut out = tx.vout[0];
|
CTxOut out = tx.vout[0];
|
||||||
BOOST_CHECK_EQUAL(out.nValue, amount);
|
BOOST_CHECK_EQUAL(out.nValue, amount);
|
||||||
|
|
||||||
amount = 1.111;
|
amount = 1.111;
|
||||||
proxy.add_taddr_change_output_to_tx(amount);
|
proxy.add_taddr_change_output_to_tx(0,amount);
|
||||||
tx = proxy.getTx();
|
tx = proxy.getTx();
|
||||||
BOOST_CHECK(tx.vout.size() == 2);
|
BOOST_CHECK(tx.vout.size() == 2);
|
||||||
out = tx.vout[1];
|
out = tx.vout[1];
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
CAmount change = funds - fundsSpent;
|
CAmount change = funds - fundsSpent;
|
||||||
|
|
||||||
if (change > 0) {
|
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",
|
LogPrint("zrpc", "%s: transparent change in transaction output (amount=%s)\n",
|
||||||
getId(),
|
getId(),
|
||||||
@@ -395,7 +395,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
|||||||
"allow any change as there is currently no way to specify a change address "
|
"allow any change as there is currently no way to specify a change address "
|
||||||
"in z_sendmany.", FormatMoney(change)));
|
"in z_sendmany.", FormatMoney(change)));
|
||||||
} else {
|
} 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",
|
LogPrint("zrpc", "%s: transparent change in transaction output (amount=%s)\n",
|
||||||
getId(),
|
getId(),
|
||||||
FormatMoney(change)
|
FormatMoney(change)
|
||||||
@@ -1102,23 +1102,24 @@ void AsyncRPCOperation_sendmany::add_taddr_outputs_to_tx() {
|
|||||||
tx_ = CTransaction(rawTx);
|
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);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
|
|
||||||
EnsureWalletIsUnlocked();
|
EnsureWalletIsUnlocked();
|
||||||
//if ( 0 )
|
CScript scriptPubKey;
|
||||||
// CScript scriptPubKey = GetScriptForDestination(fromaddress.Get());
|
CReserveKey keyChange(pwalletMain);
|
||||||
//else
|
CPubKey vchPubKey;
|
||||||
//{
|
if ( fromaddress != 0 )
|
||||||
CReserveKey keyChange(pwalletMain);
|
scriptPubKey = GetScriptForDestination(fromaddress->Get());
|
||||||
CPubKey vchPubKey;
|
else
|
||||||
|
{
|
||||||
bool ret = keyChange.GetReservedKey(vchPubKey);
|
bool ret = keyChange.GetReservedKey(vchPubKey);
|
||||||
if (!ret) {
|
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
|
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);
|
CTxOut out(amount, scriptPubKey);
|
||||||
|
|
||||||
CMutableTransaction rawTx(tx_);
|
CMutableTransaction rawTx(tx_);
|
||||||
|
|||||||
Reference in New Issue
Block a user