From d8d7463ea05274a28a00dc193cfc39c19296ba60 Mon Sep 17 00:00:00 2001 From: blackjok3rtt <30971146+blackjok3rtt@users.noreply.github.com> Date: Mon, 18 Mar 2019 15:22:20 +0800 Subject: [PATCH] Fix sendmany bug for Alright (#1336) * fix sendmany bug, when sending to multiple address diffrent amounts would always use the first seen value. * Possible fix for multi node musig. Needs to be tested. Was getting stuck at nonce stage, as reported by gcharang. --- src/cc/musig.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 35293088c..bc113bc5c 100644 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -538,7 +538,7 @@ UniValue musig_commit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) for (i=0; i<33; i++) sprintf(&str[i<<1],"%02x",((uint8_t *)pk.begin())[i]); str[66] = 0; - if ( n == 5 ) + if ( n == 3 ) MUSIG[myind]->numnonces = 1; result.push_back(Pair("myind",MUSIG[myind]->myind)); result.push_back(Pair("nonce",str)); @@ -629,7 +629,7 @@ UniValue musig_nonce(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) result.push_back(Pair("myind",MUSIG[myind]->myind)); result.push_back(Pair("partialsig",str)); result.push_back(Pair("result","success")); - if ( n == 5 ) + if ( n == 3 ) MUSIG[myind]->numpartials = 1; return(result); } else return(cclib_error(result,"error serializing partial sig")); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 38c21d2bd..471364b91 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1457,24 +1457,19 @@ UniValue sendmany(const UniValue& params, bool fHelp) if (params.size() > 4) subtractFeeFromAmount = params[4].get_array(); - std::set destinations; std::vector vecSend; CAmount totalAmount = 0; std::vector keys = sendTo.getKeys(); + int32_t i = 0; for (const std::string& name_ : keys) { CTxDestination dest = DecodeDestination(name_); if (!IsValidDestination(dest)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Zcash address: ") + name_); } - /*if (destinations.count(dest)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ") + name_); - }*/ - destinations.insert(dest); - CScript scriptPubKey = GetScriptForDestination(dest); - CAmount nAmount = AmountFromValue(sendTo[name_]); + CAmount nAmount = AmountFromValue(sendTo[i]); if (nAmount <= 0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); totalAmount += nAmount; @@ -1488,6 +1483,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) CRecipient recipient = {scriptPubKey, nAmount, fSubtractFeeFromAmount}; vecSend.push_back(recipient); + i++; } EnsureWalletIsUnlocked();