diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index f942296a8..10f2383e5 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -54,6 +54,9 @@ void TransactionBuilder::AddSaplingOutput( CAmount value, std::array memo) { + if(fZdebug) { + LogPrintf("%s: adding output with value=%ld\n", __func__, value); + } auto note = libzcash::SaplingNote(to, value); outputs.emplace_back(ovk, note, memo); mtx.valueBalance -= value; diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index a11908230..34d87b58f 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -224,19 +224,24 @@ bool ShieldToAddress::operator()(const libzcash::SaplingPaymentAddress &zaddr) c throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid donation zaddr, Unknown address format: ") + dzaddr); } - //TODO: if donation>0, send X% of value to zaddr and Y% of of value to donatezaddr - // where X+Y=100% if(donation) { + //if donation>0, send X% of value to zaddr and Y% of of value to donatezaddr where X+Y=100% + // calculate donation as a double then convert to CAmount - CAmount donationAmount = (CAmount) ( ((double)donation/100)*sendAmount ); + double amount = (static_cast(donation)/100)*static_cast(sendAmount); + CAmount donationAmount = static_cast(amount); // add original recipient as first output, with sendAmount less the donation - m_op->builder_.AddSaplingOutput(ovk, zaddr, sendAmount - donationAmount); + CAmount newAmount = sendAmount - donationAmount; + m_op->builder_.AddSaplingOutput(ovk, zaddr, newAmount); auto donationZout = boost::get(donationZaddr); m_op->builder_.AddSaplingOutput(ovk, donationZout, donationAmount); - LogPrintf("%s: donation=%ld, sendAmount=%ld, donationAmount=%ld\n", __func__, donation, sendAmount, donationAmount); + if(fZdebug) { + LogPrintf("%s: donation=%ld, sendAmount=%ld, newAmount=%ld, donationAmount=%ld, newAmount+donationAmount=%ld fee=%ld\n", __func__, + donation, sendAmount, newAmount, donationAmount, newAmount+donationAmount, m_op->fee_); + } // zdust as third output, so donation txs are indistinguishable from // non-donation z_shieldcoinbase txs