novitski / bitcoinj

Automatically exported from code.google.com/p/bitcoinj
Apache License 2.0
0 stars 0 forks source link

Support pay-to-script addresses #461

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In current implementation, pay-to-script addresses are not allowed, because 
only a version byte of "0" is accepted, as shown in MainNetParams.java:34:

        acceptableAddressCodes = new int[] { 0 };

To support pay-to-script addresses, we need to add 0x05 version byte to the 
array:

        acceptableAddressCodes = new int[] { 0, 5 };

Source: https://en.bitcoin.it/wiki/List_of_address_prefixes

Original issue reported on code.google.com by maciej.t...@gmail.com on 28 Sep 2013 at 9:44

GoogleCodeExporter commented 9 years ago
Actually, there is another thing that needs to be implemented. When sending 
money to a P2SH address you need a following template:

OP_HASH160 <hash> OP_EQUAL

Original comment by maciej.t...@gmail.com on 28 Sep 2013 at 12:58

GoogleCodeExporter commented 9 years ago
Here is a patch for some of the simple Address handling required with P2SH.

Original comment by m...@belshe.com on 23 Nov 2013 at 9:01

Attachments:

GoogleCodeExporter commented 9 years ago
LGTM but I'd prefer to wait until it's finished so the code isn't in a state 
where it will accept a P2SH address then do the wrong thing.

Original comment by hearn@google.com on 25 Nov 2013 at 10:32

GoogleCodeExporter commented 9 years ago
@hearn: What else is needed/what is not finished with the patch? I've read it 
and it looks fine to me. There is even a test, so it should be trivial to find 
if it does the right thing. So if it works, why don't merge it?

Original comment by maciej.t...@gmail.com on 26 Nov 2013 at 12:48

GoogleCodeExporter commented 9 years ago
Like I already said, if that patch was merged then code which looks correct 
could accidentally destroy money:  consider a GUI wallet that lets users enter 
addresses. What this patch does is effectively make the Address object accept 
the special P2SH version code, but doesn't teach the wallet how to use it. So 
the wallet would act as if it's a normal 1AbCD address, craft a normal 
pay-to-address output instead of a P2SH output, and bang.

Original comment by hearn@google.com on 26 Nov 2013 at 9:54

GoogleCodeExporter commented 9 years ago
@hearn - I think your comment was spot on.

Here is an updated patch.  I've taught the ScriptBuilder (used by 
TransactionOutput) how to generate P2SH outputs.  Added a test to the wallet 
which verifies outputs to p2sh addresses.

Original comment by m...@belshe.com on 30 Nov 2013 at 9:20

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 98081f0568e6.

Original comment by hearn@google.com on 30 Nov 2013 at 2:16

GoogleCodeExporter commented 9 years ago
I did some tests with wallet tool and it worked. Thanks Mike!

Original comment by hearn@google.com on 30 Nov 2013 at 2:16