WIP donation test
This commit is contained in:
@@ -46,9 +46,9 @@ class ShieldCoinbaseDonationTest (BitcoinTestFramework):
|
|||||||
'-regtest',
|
'-regtest',
|
||||||
'--daemon',
|
'--daemon',
|
||||||
#'-debug',
|
#'-debug',
|
||||||
#'-zrpc',
|
'-zrpc',
|
||||||
#'-zdebug',
|
'-zdebug',
|
||||||
##'-zrpcunsafe'
|
'-zrpcunsafe'
|
||||||
]]
|
]]
|
||||||
)
|
)
|
||||||
self.is_network_split = False
|
self.is_network_split = False
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ AsyncRPCOperation_shieldcoinbase::AsyncRPCOperation_shieldcoinbase(
|
|||||||
std::vector<ShieldCoinbaseUTXO> inputs,
|
std::vector<ShieldCoinbaseUTXO> inputs,
|
||||||
std::string toAddress,
|
std::string toAddress,
|
||||||
CAmount fee,
|
CAmount fee,
|
||||||
CAmount donation,
|
uint8_t donation,
|
||||||
UniValue contextInfo) :
|
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
|
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");
|
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
|
// Check the destination address is valid for this network i.e. not testnet being used on mainnet
|
||||||
auto address = DecodePaymentAddress(toAddress);
|
auto address = DecodePaymentAddress(toAddress);
|
||||||
if (IsValidPaymentAddress(address)) {
|
if (IsValidPaymentAddress(address)) {
|
||||||
@@ -177,11 +181,9 @@ bool AsyncRPCOperation_shieldcoinbase::main_impl() {
|
|||||||
|
|
||||||
CAmount sendAmount = targetAmount - minersFee;
|
CAmount sendAmount = targetAmount - minersFee;
|
||||||
LogPrint("zrpc", "%s: spending %s to shield %s with fee %s, donation=%d\n",
|
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
|
return boost::apply_visitor(ShieldToAddress(this, sendAmount, donation_), tozaddr_);
|
||||||
CAmount donation = 2;
|
|
||||||
return boost::apply_visitor(ShieldToAddress(this, sendAmount, donation), tozaddr_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern UniValue signrawtransaction(const UniValue& params, bool fHelp, const CPubKey& mypk);
|
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
|
//TODO: if donation>0, send X% of value to zaddr and Y% of of value to donatezaddr
|
||||||
// where X+Y=100%
|
// where X+Y=100%
|
||||||
if(donation) {
|
if(donation) {
|
||||||
//TODO: calculate exact values of sendAmount and donationAmount
|
// calculate donation as a double then convert to CAmount
|
||||||
CAmount donationAmount = (donation/100)*sendAmount;
|
CAmount donationAmount = (CAmount) ( ((double)donation/100)*sendAmount );
|
||||||
|
|
||||||
// add original recipient as first output, with sendAmount less the donation
|
// add original recipient as first output, with sendAmount less the donation
|
||||||
m_op->builder_.AddSaplingOutput(ovk, zaddr, sendAmount - donationAmount);
|
m_op->builder_.AddSaplingOutput(ovk, zaddr, sendAmount - donationAmount);
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
std::vector<ShieldCoinbaseUTXO> inputs,
|
std::vector<ShieldCoinbaseUTXO> inputs,
|
||||||
std::string toAddress,
|
std::string toAddress,
|
||||||
CAmount fee = SHIELD_COINBASE_DEFAULT_MINERS_FEE,
|
CAmount fee = SHIELD_COINBASE_DEFAULT_MINERS_FEE,
|
||||||
CAmount donation = 0, //TODO: uint8_t
|
uint8_t donation = 0,
|
||||||
UniValue contextInfo = NullUniValue);
|
UniValue contextInfo = NullUniValue);
|
||||||
virtual ~AsyncRPCOperation_shieldcoinbase();
|
virtual ~AsyncRPCOperation_shieldcoinbase();
|
||||||
|
|
||||||
@@ -76,6 +76,9 @@ private:
|
|||||||
|
|
||||||
std::vector<ShieldCoinbaseUTXO> inputs_;
|
std::vector<ShieldCoinbaseUTXO> inputs_;
|
||||||
|
|
||||||
|
// this is a donation % between 0 and 10, not a CAmount
|
||||||
|
uint8_t donation_;
|
||||||
|
|
||||||
TransactionBuilder builder_;
|
TransactionBuilder builder_;
|
||||||
CTransaction tx_;
|
CTransaction tx_;
|
||||||
|
|
||||||
@@ -92,7 +95,7 @@ class ShieldToAddress : public boost::static_visitor<bool>
|
|||||||
private:
|
private:
|
||||||
AsyncRPCOperation_shieldcoinbase *m_op;
|
AsyncRPCOperation_shieldcoinbase *m_op;
|
||||||
CAmount sendAmount;
|
CAmount sendAmount;
|
||||||
CAmount donation = 0;
|
uint8_t donation = 0;
|
||||||
public:
|
public:
|
||||||
ShieldToAddress(AsyncRPCOperation_shieldcoinbase *op, CAmount sendAmount, bool donation) :
|
ShieldToAddress(AsyncRPCOperation_shieldcoinbase *op, CAmount sendAmount, bool donation) :
|
||||||
m_op(op), sendAmount(sendAmount), donation(donation) {}
|
m_op(op), sendAmount(sendAmount), donation(donation) {}
|
||||||
|
|||||||
@@ -5563,10 +5563,12 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp, const CPubKey& myp
|
|||||||
if (params.size() > 4) {
|
if (params.size() > 4) {
|
||||||
donation = params[4].get_int();
|
donation = params[4].get_int();
|
||||||
if (donation < 0 || donation > 10 ) {
|
if (donation < 0 || donation > 10 ) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid donation percentage, must be an integer between 1 and 10");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid donation percentage, must be an integer between 0 and 10");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogPrintf("%s: donation=%d\n", __func__, donation);
|
||||||
|
|
||||||
int nextBlockHeight = chainActive.Height() + 1;
|
int nextBlockHeight = chainActive.Height() + 1;
|
||||||
bool overwinterActive = nextBlockHeight>=1 ? true : false; // NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
|
bool overwinterActive = nextBlockHeight>=1 ? true : false; // NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
|
||||||
unsigned int max_tx_size = MAX_TX_SIZE_AFTER_SAPLING;
|
unsigned int max_tx_size = MAX_TX_SIZE_AFTER_SAPLING;
|
||||||
@@ -5694,6 +5696,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp, const CPubKey& myp
|
|||||||
o.push_back(Pair("remainingValue", ValueFromAmount(remainingValue)));
|
o.push_back(Pair("remainingValue", ValueFromAmount(remainingValue)));
|
||||||
o.push_back(Pair("shieldingUTXOs", static_cast<uint64_t>(numUtxos)));
|
o.push_back(Pair("shieldingUTXOs", static_cast<uint64_t>(numUtxos)));
|
||||||
o.push_back(Pair("shieldingValue", ValueFromAmount(shieldedValue)));
|
o.push_back(Pair("shieldingValue", ValueFromAmount(shieldedValue)));
|
||||||
|
o.push_back(Pair("donation", donation));
|
||||||
o.push_back(Pair("opid", operationId));
|
o.push_back(Pair("opid", operationId));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user