Bitcoin Forum
May 05, 2024, 05:47:26 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: [PHP] Generate a sendmany with multiple outputs to the same address  (Read 4266 times)
SgtSpike (OP)
Legendary
*
Offline Offline

Activity: 1400
Merit: 1005



View Profile
December 31, 2012, 04:30:22 PM
 #21

Yeah, it's a bummer that you cannot specify the same address twice - I once suffered from this as well, but a workaround was fairly simple, especially in PHP.

A bigger issue I've had with sendmany is that the command requires the "<fromaccount>" parameter and you cannot just say to it like "whatever account"...
So the way I use my client, having coins spread across several "accounts" (which I personally only use to label addresses), then it seems like someone had made this parameter mandatory just to piss me off... Wink
What was the workaround?
1714888046
Hero Member
*
Offline Offline

Posts: 1714888046

View Profile Personal Message (Offline)

Ignore
1714888046
Reply with quote  #2

1714888046
Report to moderator
1714888046
Hero Member
*
Offline Offline

Posts: 1714888046

View Profile Personal Message (Offline)

Ignore
1714888046
Reply with quote  #2

1714888046
Report to moderator
1714888046
Hero Member
*
Offline Offline

Posts: 1714888046

View Profile Personal Message (Offline)

Ignore
1714888046
Reply with quote  #2

1714888046
Report to moderator
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714888046
Hero Member
*
Offline Offline

Posts: 1714888046

View Profile Personal Message (Offline)

Ignore
1714888046
Reply with quote  #2

1714888046
Report to moderator
1714888046
Hero Member
*
Offline Offline

Posts: 1714888046

View Profile Personal Message (Offline)

Ignore
1714888046
Reply with quote  #2

1714888046
Report to moderator
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
December 31, 2012, 06:18:58 PM
 #22

What was the workaround?
Well, it's a workaround only if you're fine with single transaction per a recipient address (I was).
In such case, just sum up the amounts using a map with the destination address as the key.
Something like:
Code:
$addrs = array();
for(...) {
    $destaddr = ...
    $amount = ...
    if (array_key_exists($destaddr, $addrs)) {
        $addrs[$destaddr] += $amount;
    } else {
        $addrs[$destaddr] = $amount;
    }
}
After this you have only single addresses in $addrs (with the amounts summed up), so just:
Code:
$rpc = 'sendmany "'.ACCOUNT.'" \'{';
$com = false;
foreach(array_keys($addrs) as $da) {
$am = round($addrs[$da], 8);
if ($am>0) {
if ($com)  $rpc .= ', ';
$rpc .= '"'.$da.'":'.sprintf('%.8f',$am);
$com = true;
}
}
$rpc .= '}\'';

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
mrvision
Sr. Member
****
Offline Offline

Activity: 527
Merit: 250



View Profile
May 28, 2013, 03:35:55 PM
 #23


TXOUT Amounts?
0.00100000
0.00100000
0.01000010
0.01001101
0.01001110
0.01100001
0.01100011
0.01100011
0.01100100
0.01100101
0.01100101
0.01100110
0.01101001
0.01101001
0.01101001
0.01101100
0.01101110
0.01110010
0.01110100
0.01110101
0.49730788
0.80211920

It says "Nice Minecraft Build" xD
cmilian
Member
**
Offline Offline

Activity: 93
Merit: 10


View Profile
December 15, 2014, 04:14:15 PM
 #24

What was the workaround?
Well, it's a workaround only if you're fine with single transaction per a recipient address (I was).
In such case, just sum up the amounts using a map with the destination address as the key.
Something like:
Code:
$addrs = array();
for(...) {
    $destaddr = ...
    $amount = ...
    if (array_key_exists($destaddr, $addrs)) {
        $addrs[$destaddr] += $amount;
    } else {
        $addrs[$destaddr] = $amount;
    }
}
After this you have only single addresses in $addrs (with the amounts summed up), so just:
Code:
$rpc = 'sendmany "'.ACCOUNT.'" \'{';
$com = false;
foreach(array_keys($addrs) as $da) {
$am = round($addrs[$da], 8);
if ($am>0) {
if ($com)  $rpc .= ', ';
$rpc .= '"'.$da.'":'.sprintf('%.8f',$am);
$com = true;
}
}
$rpc .= '}\'';

This look like what i need. where did you add this code?
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!