Use static_cast when calculating donation and add some debugging
This commit is contained in:
@@ -54,6 +54,9 @@ void TransactionBuilder::AddSaplingOutput(
|
||||
CAmount value,
|
||||
std::array<unsigned char, HUSH_MEMO_SIZE> 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;
|
||||
|
||||
@@ -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<double>(donation)/100)*static_cast<double>(sendAmount);
|
||||
CAmount donationAmount = static_cast<CAmount>(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<libzcash::SaplingPaymentAddress>(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
|
||||
|
||||
Reference in New Issue
Block a user