WIP donation test
This commit is contained in:
@@ -54,9 +54,9 @@ AsyncRPCOperation_shieldcoinbase::AsyncRPCOperation_shieldcoinbase(
|
||||
std::vector<ShieldCoinbaseUTXO> inputs,
|
||||
std::string toAddress,
|
||||
CAmount fee,
|
||||
CAmount donation,
|
||||
uint8_t donation,
|
||||
UniValue contextInfo) :
|
||||
builder_(builder), tx_(contextualTx), inputs_(inputs), fee_(fee), contextinfo_(contextInfo)
|
||||
builder_(builder), tx_(contextualTx), inputs_(inputs), fee_(fee), donation_(donation), contextinfo_(contextInfo)
|
||||
{
|
||||
assert(contextualTx.nVersion >= 2); // transaction format version must support vjoinsplit
|
||||
|
||||
@@ -68,6 +68,10 @@ AsyncRPCOperation_shieldcoinbase::AsyncRPCOperation_shieldcoinbase(
|
||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Empty inputs");
|
||||
}
|
||||
|
||||
if (donation < 0 || donation > 10 ) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid donation percentage, must be an integer between 0 and 10");
|
||||
}
|
||||
|
||||
// Check the destination address is valid for this network i.e. not testnet being used on mainnet
|
||||
auto address = DecodePaymentAddress(toAddress);
|
||||
if (IsValidPaymentAddress(address)) {
|
||||
@@ -177,11 +181,9 @@ bool AsyncRPCOperation_shieldcoinbase::main_impl() {
|
||||
|
||||
CAmount sendAmount = targetAmount - minersFee;
|
||||
LogPrint("zrpc", "%s: spending %s to shield %s with fee %s, donation=%d\n",
|
||||
getId(), FormatMoney(targetAmount), FormatMoney(sendAmount), FormatMoney(minersFee));
|
||||
getId(), FormatMoney(targetAmount), FormatMoney(sendAmount), FormatMoney(minersFee), donation_);
|
||||
|
||||
//TODO: pass this in from RPC
|
||||
CAmount donation = 2;
|
||||
return boost::apply_visitor(ShieldToAddress(this, sendAmount, donation), tozaddr_);
|
||||
return boost::apply_visitor(ShieldToAddress(this, sendAmount, donation_), tozaddr_);
|
||||
}
|
||||
|
||||
extern UniValue signrawtransaction(const UniValue& params, bool fHelp, const CPubKey& mypk);
|
||||
@@ -225,8 +227,9 @@ bool ShieldToAddress::operator()(const libzcash::SaplingPaymentAddress &zaddr) c
|
||||
//TODO: if donation>0, send X% of value to zaddr and Y% of of value to donatezaddr
|
||||
// where X+Y=100%
|
||||
if(donation) {
|
||||
//TODO: calculate exact values of sendAmount and donationAmount
|
||||
CAmount donationAmount = (donation/100)*sendAmount;
|
||||
// calculate donation as a double then convert to CAmount
|
||||
CAmount donationAmount = (CAmount) ( ((double)donation/100)*sendAmount );
|
||||
|
||||
// add original recipient as first output, with sendAmount less the donation
|
||||
m_op->builder_.AddSaplingOutput(ovk, zaddr, sendAmount - donationAmount);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user