Browse Source

Optional OP_RETURN in z_sendmany

pull/332/head
Duke 1 year ago
parent
commit
8126e706c6
  1. 9
      src/wallet/asyncrpcoperation_sendmany.cpp
  2. 5
      src/wallet/asyncrpcoperation_sendmany.h
  3. 14
      src/wallet/rpcwallet.cpp

9
src/wallet/asyncrpcoperation_sendmany.cpp

@ -65,8 +65,9 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany(
std::vector<SendManyRecipient> zOutputs,
int minDepth,
CAmount fee,
UniValue contextInfo) :
tx_(contextualTx), fromaddress_(fromAddress), t_outputs_(tOutputs), z_outputs_(zOutputs), mindepth_(minDepth), fee_(fee), contextinfo_(contextInfo)
UniValue contextInfo,
CScript opret) :
tx_(contextualTx), fromaddress_(fromAddress), t_outputs_(tOutputs), z_outputs_(zOutputs), mindepth_(minDepth), fee_(fee), contextinfo_(contextInfo), opret_(opret)
{
assert(fee_ >= 0);
@ -469,6 +470,10 @@ bool AsyncRPCOperation_sendmany::main_impl() {
}
}
// Add optional OP_RETURN if it exists
if ( opret_ != CScript() ) {
builder_.AddOpRet(opret_);
}
// Build the transaction
auto maybe_tx = builder_.Build();
if (!maybe_tx) {

5
src/wallet/asyncrpcoperation_sendmany.h

@ -62,7 +62,9 @@ public:
std::vector<SendManyRecipient> zOutputs,
int minDepth,
CAmount fee = ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE,
UniValue contextInfo = NullUniValue);
UniValue contextInfo = NullUniValue,
CScript opret = CScript()
);
virtual ~AsyncRPCOperation_sendmany();
// We don't want to be copied or moved around
@ -92,6 +94,7 @@ private:
CTxDestination fromtaddr_;
PaymentAddress frompaymentaddress_;
SpendingKey spendingkey_;
CScript opret_ = CScript();
uint256 joinSplitPubKey_;
unsigned char joinSplitPrivKey_[crypto_sign_SECRETKEYBYTES];

14
src/wallet/rpcwallet.cpp

@ -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__);

Loading…
Cancel
Save