Optional OP_RETURN in z_sendmany

This commit is contained in:
Duke
2023-03-24 10:22:31 -07:00
parent 63ad87f69b
commit 8126e706c6
3 changed files with 23 additions and 5 deletions

View File

@@ -5001,6 +5001,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
std::vector<SendManyRecipient> taddrRecipients;
std::vector<SendManyRecipient> zaddrRecipients;
CAmount nTotalOut = 0;
// Optional OP_RETURN data
CScript opret;
bool containsSaplingOutput = false;
@@ -5011,8 +5013,9 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
// sanity check, report error if unknown key-value pairs
for (const string& name_ : o.getKeys()) {
std::string s = name_;
if (s != "address" && s != "amount" && s!="memo")
if (s != "address" && s != "amount" && s!="memo" && s!="opreturn") {
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown key: ")+s);
}
}
string address = find_value(o, "address").get_str();
@@ -5034,6 +5037,13 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
// throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+address);
setAddress.insert(address);
UniValue opretValue = find_value(o, "opreturn");
// Create the CScript representation of the OP_RETURN
if (!opretValue.isNull()) {
opret << OP_RETURN << ParseHex(opretValue.get_str().c_str());
}
UniValue memoValue = find_value(o, "memo");
string memo;
if (!memoValue.isNull()) {
@@ -5207,7 +5217,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk)
// Create operation and add to global queue
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany(builder, contextualTx, fromaddress, taddrRecipients, zaddrRecipients, nMinDepth, nFee, contextInfo) );
std::shared_ptr<AsyncRPCOperation> operation( new AsyncRPCOperation_sendmany(builder, contextualTx, fromaddress, taddrRecipients, zaddrRecipients, nMinDepth, nFee, contextInfo, opret) );
q->addOperation(operation);
if(fZdebug)
LogPrintf("%s: Submitted to async queue\n", __FUNCTION__);