Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: yky_sh on October 12, 2016, 08:26:02 PM



Title: How to get wallet address from txin script, address of first character is "3"?
Post by: yky_sh on October 12, 2016, 08:26:02 PM
Now, I analysis the block information, and I don't know how to get the wallet address which first character is “3”. the tx in script is as follow.
Tx In Script:
0x00,
0x47,
0x30,0x44,0x02,0x20,
0x0c,0xf1,0x83,0x78,0x7d,0x2f,0x7e,0xf3,0x87,0xe1,0x40,0x46,0xe7,0xf3,0x8d,0x94,0x42,0xb3,0x16,0xd6,0x90,0xb3,0x11,0x6d,0xa6,0xc6,0x0d,0x4b,0x8d,0x1b,0xb5,0x43,
0x02,0x20,0x30,0x16,0x93,0xba,0x31,0xb5,0xaa,0xd8,0xd7,0x54,0x2a,0x67,0x3e,0x6b,0x96,0xf4,0x83,0x01,0x52,0xec,0x6d,0x26,0xf3,0xa8,0xbf,0x1d,0x37,0x76,0xf3,0x9d,0xe5,0x1d,0x01,
0x48,
0x30,0x45,0x02,0x21,
0x00,0x9c,0xd1,0xc1,0xb3,0xe1,0xec,0x93,0xcd,0x58,0x52,0xb4,0x2f,0xa5,0x6b,0x6a,0xf7,0x06,0xa0,0x9b,0x00,0xe0,0x56,0xd1,0xfd,0x13,0x13,0xfa,0xb4,0x23,0xbb,0x79,0x43,
0x02,0x20,0x13,0x27,0x34,0x7f,0x6c,0x9b,0xc8,0x10,0x6d,0xca,0x4e,0xb8,0x4d,0xe3,0x6b,0xd2,0x42,0xf0,0x97,0x03,0x88,0xab,0x7c,0xd5,0x86,0xe1,0x84,0x3b,0x84,0xb0,0x45,0x20,
0x01,
0x47,
0x52,0x21,
0x02,0x30,0x9d,0x6a,0x9d,0x97,0xa3,0xe8,0x14,0x24,0x7d,0x47,0x1d,0xdc,0x2c,0x47,0x6c,0x04,0x6f,0x9c,0x07,0xd9,0x80,0x79,0xd8,0x61,0xe3,0x44,0x79,0xc1,0x94,0x97,0xea,//public key 1
0x21,
0x03,0xc5,0x11,0xb8,0xfe,0x3a,0x5e,0x60,0xad,0x16,0xbb,0x14,0xb0,0x86,0x5f,0x8a,0x3f,0x19,0x2d,0xdb,0x38,0x6c,0x4f,0x8d,0x23,0xf7,0x2e,0xdd,0x24,0x76,0x4e,0x0e,0x23,//public key 2
0x52,
0xae,

I know the P2SH calculation, as follow,
1:Hash1 = sha256(public key);
2:Hash2 = RIPEMD160(Hash1), Then, get first 20 hex;
3:get check code, sha256(sha256(0x05 or 0x00 + first 20 hex)), and  get first 4 hex as the check code;
4:put the check code to the end of first 20 hex;
5:address, Encode(0x00 or 0x05 + first 20 hex + 4 hex check code);

according the script, there are two public keys in the script, so I don't know which public key to use or these is other calculation .

Thank you for your help.


Title: Re: How to get wallet address from txin script, address of first character is "3"?
Post by: achow101 on October 12, 2016, 08:35:06 PM
I know the P2SH calculation, as follow,
1:Hash1 = sha256(public key);
No, it is the hash of the redeemscript, not any of the public keys. In this case, the redeemscript starts with 0x52 and goes to the end.


Title: Re: How to get wallet address from txin script, address of first character is "3"?
Post by: yky_sh on October 12, 2016, 08:43:32 PM
I know the P2SH calculation, as follow,
1:Hash1 = sha256(public key);
No, it is the hash of the redeemscript, not any of the public keys. In this case, the redeemscript starts with 0x52 and goes to the end.

yeah, you are correct. Thank you very much.


Title: Re: How to get wallet address from txin script, address of first character is "3"?
Post by: pebwindkraft on October 13, 2016, 06:11:59 AM
just to verify, if my script is working correctly: is it " 33f7emzpgYE4JC5Wo4Gk8HZKYRu1Cqcguu" ?
I tried to decode the scriptsig, and get this result:

Code:
    47: OP_DATA_0x47:     push hex 47 (decimal 71) bytes as data
    30: OP_SEQUENCE_0x30: type tag indicating SEQUENCE, begin sigscript
    44: OP_LENGTH_0x44:   length of R + S
    02: OP_INT_0x02:      type tag indicating INTEGER
    20: OP_LENGTH_0x20:   *** this is SIG R
        0CF183787D2F7EF3:87E14046E7F38D94
        42B316D690B3116D:A6C60D4B8D1BB543
    02: OP_S_INT_0x02
    20: OP_LENGTH_0x20:   *** this is SIG S
        301693BA31B5AAD8:D7542A673E6B96F4
        830152EC6D26F3A8:BF1D3776F39DE51D
    01: OP_SIGHASHALL:    *** This terminates the ECDSA signature (ASN1-DER structure)
    48: OP_DATA_0x48:     push hex 48 (decimal 72) bytes as data
    30: OP_SEQUENCE_0x30: type tag indicating SEQUENCE, begin sigscript
    45: OP_LENGTH_0x45:   length of R + S
    02: OP_INT_0x02:      type tag indicating INTEGER
    21: OP_LENGTH_0x21:   *** this is SIG R
        009CD1C1B3E1EC93:CD5852B42FA56B6A
        F706A09B00E056D1:FD1313FAB423BB79
        43
    02: OP_INT_0x02:      type tag indicating INTEGER
    20: OP_LENGTH_0x20:   *** this is SIG S
        1327347F6C9BC810:6DCA4EB84DE36BD2
        42F0970388AB7CD5:86E1843B84B04520
    01: OP_SIGHASHALL:    *** This terminates the ECDSA signature (ASN1-DER structure)
    47: OP_DATA_0x47:     push hex 47 (decimal 71) bytes as data
    52: OP_2
    52: OP_2
       ###### we go multisig, ( 2 out of n multisig ?) #######
  21: OP_DATA_0x21: compressed pub key
        02309D6A9D97A3E8:14247D471DDC2C47
        6C046F9C07D98079:D861E34479C19497
        EA
     * This is MultiSig's Public Key (X9.63 COMPRESSED form)
     * corresponding bitcoin address is:
   1H7GTVGAm911rBx5myQv7EeACizgY81MWL
 
  21: OP_DATA_0x21: compressed pub key
        03C511B8FE3A5E60:AD16BB14B0865F8A
        3F192DDB386C4F8D:23F72EDD24764E0E
        23
     * This is MultiSig's Public Key (X9.63 COMPRESSED form)
     * corresponding bitcoin address is:
   1NrTw95nWtA9iVZg2FLge64Y3Ei9fdhqpC
  52: OP_2: push 2 Bytes onto stack
  AE: OP_CHECKMULTISIG
     ########## Multisignature end ###########
     * This terminates the MultiSig's redeem script
     * corresponding bitcoin address is:
   33f7emzpgYE4JC5Wo4Gk8HZKYRu1Cqcguu