Bitcoin Forum
May 10, 2024, 09:40:56 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: request: decoderawtransaction in python  (Read 2952 times)
osmosis (OP)
Sr. Member
****
Offline Offline

Activity: 300
Merit: 250



View Profile
August 28, 2012, 06:38:32 AM
Last edit: August 25, 2014, 11:10:19 PM by osmosis
 #1

.
1715377256
Hero Member
*
Offline Offline

Posts: 1715377256

View Profile Personal Message (Offline)

Ignore
1715377256
Reply with quote  #2

1715377256
Report to moderator
Transactions must be included in a block to be properly completed. When you send a transaction, it is broadcast to miners. Miners can then optionally include it in their next blocks. Miners will be more inclined to include your transaction if it has a higher transaction fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
Gavin Andresen
Legendary
*
Offline Offline

Activity: 1652
Merit: 2216


Chief Scientist


View Profile WWW
August 29, 2012, 11:28:12 PM
 #2

Start here maybe:
  https://github.com/gavinandresen/bitcointools/blob/master/deserialize.py#L262

How often do you get the chance to work on a potentially world-changing project?
osmosis (OP)
Sr. Member
****
Offline Offline

Activity: 300
Merit: 250



View Profile
September 05, 2012, 05:14:37 AM
Last edit: September 14, 2012, 12:01:07 AM by osmosis
 #3

some further info on this, I found out the raw transaction I was looking at was not actually compatible with the methods added in bitcoind to import/export txs.
The tx's I am looking at apparently are in use as inventory through the bitcoin protocol
runeks
Legendary
*
Offline Offline

Activity: 980
Merit: 1008



View Profile WWW
September 12, 2012, 06:40:38 PM
 #4

Gavin, what format does the parse_Transaction function expect the data in the BCDataStream() class to be in?
I've tried initializing a BCDataStream class using the data from the first transaction output by the bitcoind getmemorypool command, like so:
Code:
from deserialize import *
from BCDataStream import *

test = BCDataStream()
test.write("0100000001da8d10a3b749dbda1658298d84512836c1bfb2bcbe7b61dcdd3e508bcb7e1477000000006c493046022100e041a6e5df8c8b44231b4fee02b34e2f12d553ab54dc434c1bf95dffb68e5f8d022100c74e5318b4c209397be7e1ea4f4ef783d036f5fbe894918e8e31c72e49f75fc30121034ecf9a2859c419500001e05710bec6673db9a8ea5faaf07497c9c996e1d28f81ffffffff0280324c35800000001976a914fc8e972d3f4c41b44a3ee71051aaf52f107ceb0f88ac005cb2ec220000001976a914847641ad2efb44d949070bf6e7b1c367c70f194388ac00000000")
parse_Transaction(test)
But the first vds.read_int32() in parse_Transaction (which is supposed to return the version, 1) returns 808464688:
Code:
(Pdb) (format, self.input, self.read_cursor)
('<i', '0100000001da8d10a3b749dbda1658298d84512836c1bfb2bcbe7b61dcdd3e508bcb7e1477000000006c493046022100e041a6e5df8c8b44231b4fee02b34e2f12d553ab54dc434c1bf95dffb68e5f8d022100c74e5318b4c209397be7e1ea4f4ef783d036f5fbe894918e8e31c72e49f75fc30121034ecf9a2859c419500001e05710bec6673db9a8ea5faaf07497c9c996e1d28f81ffffffff0280324c35800000001976a914fc8e972d3f4c41b44a3ee71051aaf52f107ceb0f88ac005cb2ec220000001976a914847641ad2efb44d949070bf6e7b1c367c70f194388ac00000000', 0)
(Pdb) struct.unpack_from(format, self.input, self.read_cursor)
(808464688,)
Gavin Andresen
Legendary
*
Offline Offline

Activity: 1652
Merit: 2216


Chief Scientist


View Profile WWW
September 12, 2012, 08:25:14 PM
 #5

BCDataStream.write takes binary data, so add a .decode('hex_codec') to the big long hex string:
Code:
test.write("0100000001da8d10a3b749dbda1658298d84512836c1bfb2bcbe7b61dcdd3e508bcb7e1477000000006c493046022100e041a6e5df8c8b44231b4fee02b34e2f12d553ab54dc434c1bf95dffb68e5f8d022100c74e5318b4c209397be7e1ea4f4ef783d036f5fbe894918e8e31c72e49f75fc30121034ecf9a2859c419500001e05710bec6673db9a8ea5faaf07497c9c996e1d28f81ffffffff0280324c35800000001976a914fc8e972d3f4c41b44a3ee71051aaf52f107ceb0f88ac005cb2ec220000001976a914847641ad2efb44d949070bf6e7b1c367c70f194388ac00000000".decode('hex_codec'))
parse_Transaction(test)
{'lockTime': 0, 'version': 1, 'txIn': [{'sequence': 4294967295, 'prevout_hash': '\xda\x8d\x10\xa3\xb7I\xdb\xda\x16X)\x8d\x84Q(6\xc1\xbf\xb2\xbc\xbe{a\xdc\xdd>P\x8b\xcb~\x14w', 'scriptSig': 'I0F\x02!\x00\xe0A\xa6\xe5\xdf\x8c\x8bD#\x1bO\xee\x02\xb3N/\x12\xd5S\xabT\xdcCL\x1b\xf9]\xff\xb6\x8e_\x8d\x02!\x00\xc7NS\x18\xb4\xc2\t9{\xe7\xe1\xeaON\xf7\x83\xd06\xf5\xfb\xe8\x94\x91\x8e\x8e1\xc7.I\xf7_\xc3\x01!\x03N\xcf\x9a(Y\xc4\x19P\x00\x01\xe0W\x10\xbe\xc6g=\xb9\xa8\xea_\xaa\xf0t\x97\xc9\xc9\x96\xe1\xd2\x8f\x81', 'prevout_n': 0}], 'txOut': [{'value': 550650000000, 'scriptPubKey': 'v\xa9\x14\xfc\x8e\x97-?LA\xb4J>\xe7\x10Q\xaa\xf5/\x10|\xeb\x0f\x88\xac'}, {'value': 150000000000, 'scriptPubKey': 'v\xa9\x14\x84vA\xad.\xfbD\xd9I\x07\x0b\xf6\xe7\xb1\xc3g\xc7\x0f\x19C\x88\xac'}]}

How often do you get the chance to work on a potentially world-changing project?
runeks
Legendary
*
Offline Offline

Activity: 980
Merit: 1008



View Profile WWW
September 13, 2012, 01:09:17 PM
 #6

Great! Thanks Gavin.
osmosis (OP)
Sr. Member
****
Offline Offline

Activity: 300
Merit: 250



View Profile
September 13, 2012, 08:44:21 PM
 #7

runeks - What is the long hex string you used from?  I was able to get your code working, but it still doesnt apply to the raw tx bitcoin protocol examples from my earlier posts.
runeks
Legendary
*
Offline Offline

Activity: 980
Merit: 1008



View Profile WWW
September 13, 2012, 10:56:53 PM
 #8

runeks - What is the long hex string you used from?  I was able to get your code working, but it still doesnt apply to the raw tx bitcoin protocol examples from my earlier posts.
The long hex strings are returned by the getmemorypool RPC call to bitcoind. They're basically the raw transactions in little endian byte order.
Looks like the format you've posted is in base64, so you need to call .decode('base64') on that string before you can pass it to the write() function:

Code:
from deserialize import *
from BCDataStream import *

test = BCDataStream()
base64 = "AQAAAAGw1WkFCJGRItGLQp7dPArGvrtfDlheEjX3mP27Z6Q78gAAAACLSDBFAiApxKNT7M4U+a/FWYEgBxWUNNZ9Q5FmES/BvJQ/vIS8bQIhAPEMzKmvQKcPo8BwWCLYh7APxgf2jdT3GnYc8zgGuG3RAUEEQk0WIYcg4L8t4IjnajF4EKhimP/O5aYjgPdS2zUAOucxYX2FjQkoDHudfjGUO0UiYVp8l4CLpMwgZdaw2/b4Iv////8Crfq6AAAAAAAZdqkUpDMOE0p53KNyECLVfDFEoH5zHLuIrOAiAgAAAAAAGXapFDvG92mooiCXrws61hW1ln4M/SzBiKwAAAAA"
test.write(base64.decode('base64'))
tx = parse_Transaction(test)
print tx
for txOut in tx['txOut']:
   print decode_script(txOut['scriptPubKey'])
Output:
Code:
{'lockTime': 0, 'version': 1, 'txIn': [{'sequence': 4294967295, 'prevout_hash': '\xb0\xd5i\x05\x08\x91\x91"\xd1\x8bB\x9e\xdd<\n\xc6\xbe\xbb_\x0eX^\x125\xf7\x98\xfd\xbbg\xa4;\xf2', 'scriptSig': 'H0E\x02 )\xc4\xa3S\xec\xce\x14\xf9\xaf\xc5Y\x81 \x07\x15\x944\xd6}C\x91f\x11/\xc1\xbc\x94?\xbc\x84\xbcm\x02!\x00\xf1\x0c\xcc\xa9\xaf@\xa7\x0f\xa3\xc0pX"\xd8\x87\xb0\x0f\xc6\x07\xf6\x8d\xd4\xf7\x1av\x1c\xf38\x06\xb8m\xd1\x01A\x04BM\x16!\x87 \xe0\xbf-\xe0\x88\xe7j1x\x10\xa8b\x98\xff\xce\xe5\xa6#\x80\xf7R\xdb5\x00:\xe71a}\x85\x8d\t(\x0c{\x9d~1\x94;E"aZ|\x97\x80\x8b\xa4\xcc e\xd6\xb0\xdb\xf6\xf8"', 'prevout_n': 0}], 'txOut': [{'value': 12253869, 'scriptPubKey': 'v\xa9\x14\xa43\x0e\x13Jy\xdc\xa3r\x10"\xd5|1D\xa0~s\x1c\xbb\x88\xac'}, {'value': 140000, 'scriptPubKey': 'v\xa9\x14;\xc6\xf7i\xa8\xa2 \x97\xaf\x0b:\xd6\x15\xb5\x96~\x0c\xfd,\xc1\x88\xac'}]}
DUP HASH160 20:a433...1cbb EQUALVERIFY CHECKSIG
DUP HASH160 20:3bc6...2cc1 EQUALVERIFY CHECKSIG
osmosis (OP)
Sr. Member
****
Offline Offline

Activity: 300
Merit: 250



View Profile
September 13, 2012, 11:31:57 PM
 #9

runeks, perfect..thx
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!