Error trying to send payments with RPC sendmany Need help fixing this error. 

Error trying to send payments with RPC sendmany {"code":-8,"message":"Invalid parameter, duplicated address

I a running a NOMP mining pool that has payment job breaking because there are two same wallet address payments in the same sendmany job. I need to limit amount sent to minimize chance of having the payment in the same transaction for a while until I get rid of this so that the payments go thru. Or, do something so that this is ignored.
I had this problem on a NOMP pool recently, I will share how we fixed it. For us, the problem was that a user had used the same address twice, but added some whitespace to their username the second time. So NOMP wouldn't recognize it as a duplicate, but the sendmany command would still fail. The solution for us was to do two things.


Eliminate the whitespace from workers' names. This commit shows how to do that.
Combine payouts together when there is more than one worker with the same address. The code for that is shown below.


In paymentProcessor.js, change

var address = worker.address = (worker.address || getProperAddress(w));
worker.sent = addressAmounts[address] = satoshisToCoins(toSend);


to

var address = worker.address = (worker.address || getProperAddress(w)).trim();
if (!worker.sent) {
    worker.sent = 0;
}
worker.sent += satoshisToCoins(toSend);
if (!(address in addressAmounts)) {
    addressAmounts[address] = 0;
}
addressAmounts[address] += satoshisToCoins(toSend);




If you want to know more about what caused this, the problem here is just what was explained in the error: there are duplicate addresses in the JSON object.

For example, I generated a new address of my own (1PSXKQdR5nG8T5ueG76RaWwhdwqv9JJWzy) and ran:

./bitcoin-cli sendmany "" '{"1PSXKQdR5nG8T5ueG76RaWwhdwqv9JJWzy":0.01, "1PSXKQdR5nG8T5ueG76RaWwhdwqv9JJWzy":0.01}'


And the error was: 

Invalid parameter, duplicated address: 1PSXKQdR5nG8T5ueG76RaWwhdwqv9JJWzy (code -8)


To fix this problem, you either need to (1) add up all the amounts and pay to the address in one go, or (2) do separate RPC sendmany RPC calls, making sure to not have any duplicates.

In my case, (1) would look like:

./bitcoin-cli sendmany "" '{"1PSXKQdR5nG8T5ueG76RaWwhdwqv9JJWzy":0.02}'


And (2) would look like:

./bitcoin-cli sendmany "" '{"1PSXKQdR5nG8T5ueG76RaWwhdwqv9JJWzy":0.01}'
./bitcoin-cli sendmany "" '{"1PSXKQdR5nG8T5ueG76RaWwhdwqv9JJWzy":0.01}'