Bitcoin Forum
May 12, 2024, 10:00:55 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Raw Transaction Deserializing  (Read 1080 times)
arbarian (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
December 15, 2014, 06:49:17 AM
 #1

Hi, I'm writing code that needs to deserialize raw Bitcoin transactions in python AND gives the destination address of an output.  I am already doing this with pybitcointools, but outputs are shown in the form:

{'value': 1000000, 'script': '76a914b0dcbf97eabf4404e31d952477ce822dadbe7e1088ac'}    only.  Note how the destination address is not shown.

By contrast, Bitcoin has decoderawtransaction, and it DOES yield the destination address.  ,
"vout" : [
{
"value" : 0.01000000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 b0dcbf97eabf4404e31d952477ce822dadbe7e10 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914b0dcbf97eabf4404e31d952477ce822dadbe7e1088ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1H8ANdafjpqYntniT3Ddxh4xPBMCSz33pj"
]




However, I'm trying to write code that does not trust nodes to do any deserializing on my behalf.  The code is not running a full node, and I don't want it merely to trust another node to deserialize correctly.  I want to do it myself, again, without running the full node. 

I also know how to confirm a public key and public-key-script.  But, of course, I don't have access to the public key of any random Bitcoin public address.  Currently I have no idea how native Bitcoin figures out the destination address if all that is written is the script itself.  Maybe it's simply that pybitcointools is neglecting to include part of the data that exists in the raw transaction.  In that case, I need help better deserializing the raw transaction.

Thanks!
1715551255
Hero Member
*
Offline Offline

Posts: 1715551255

View Profile Personal Message (Offline)

Ignore
1715551255
Reply with quote  #2

1715551255
Report to moderator
1715551255
Hero Member
*
Offline Offline

Posts: 1715551255

View Profile Personal Message (Offline)

Ignore
1715551255
Reply with quote  #2

1715551255
Report to moderator
1715551255
Hero Member
*
Offline Offline

Posts: 1715551255

View Profile Personal Message (Offline)

Ignore
1715551255
Reply with quote  #2

1715551255
Report to moderator
Whoever mines the block which ends up containing your transaction will get its fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715551255
Hero Member
*
Offline Offline

Posts: 1715551255

View Profile Personal Message (Offline)

Ignore
1715551255
Reply with quote  #2

1715551255
Report to moderator
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
December 15, 2014, 11:30:24 AM
Last edit: December 15, 2014, 11:48:34 AM by DannyHamilton
 #2

Given this script:
Code:
76 a9 14 b0dcbf97eabf4404e31d952477ce822dadbe7e10 88 ac

You have the following information in sequence:
Code:
        OP_DUP: 76
    OP_HASH160: a9
 Bytes to push: 14 (hex representation of 20 bytes)
  Data to push: b0dcbf97eabf4404e31d952477ce822dadbe7e10 (20 byte hex representation of a bitcoin address)
OP_EQUALVERIFY: 88
   OP_CHECKSIG: ac

Pulling out the hex representation of the bitcoin address from the "data to push" we get the RIPEMD-160 hash:
Code:
b0dcbf97eabf4404e31d952477ce822dadbe7e10

Looking at the technical background of version 1 bitcoin addresses wiki page we see we are at step 3.

Step 4 says to add a version byte in front of RIPEMD-160 hash (0x00 for Main Network):
Code:
00b0dcbf97eabf4404e31d952477ce822dadbe7e10

Step 5 says to perform SHA-256 hash on the extended RIPEMD-160 result:
Code:
137a662136daf0c0a5019b58a0c14372bdf69d296efd5facd1db0abb223fb087

Step 6 says to perform SHA-256 hash on the result of the previous SHA-256 hash:
Code:
5b7d2f5842d2038bf99b5ce49670e73d9a8e889b8470da9a1d47c95efccecb7e

Step 7 says to take the first 4 bytes of the second SHA-256 hash. This is the address checksum:
Code:
5b7d2f58

Step 8 says to add the 4 checksum bytes from step 7 to the end of the extended RIPEMD-160 hash from step 4. This is the 25-byte binary Bitcoin Address:
Code:
00b0dcbf97eabf4404e31d952477ce822dadbe7e105b7d2f58

Step 9 says to convert the result from a byte string into a base58 string using Base58Check encoding. This is the most commonly used Bitcoin Address format:
Code:
1H8ANdafjpqYntniT3Ddxh4xPBMCSz33pj
arbarian (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
December 18, 2014, 06:56:24 AM
 #3

Great answer.  Thank you.
Pages: [1]
  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!