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}'
sendmany
.sendmany
in the first place) should detect when multiple outputs to the same address are requested, and combine them into one. For instance, if you have a payment to address 1abc for BTC 0.1, and another to the same address for BTC 0.2, you should callsendmany
asking for one payment to 1abd for BTC 0.3.