Author

Topic: request: decoderawtransaction in python (Read 2974 times)

sr. member
Activity: 300
Merit: 250
September 13, 2012, 06:31:57 PM
#9
runeks, perfect..thx
legendary
Activity: 980
Merit: 1008
September 13, 2012, 05: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
sr. member
Activity: 300
Merit: 250
September 13, 2012, 03: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.
legendary
Activity: 980
Merit: 1008
September 13, 2012, 08:09:17 AM
#6
Great! Thanks Gavin.
legendary
Activity: 1652
Merit: 2301
Chief Scientist
September 12, 2012, 03: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'}]}
legendary
Activity: 980
Merit: 1008
September 12, 2012, 01: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)
('(Pdb) struct.unpack_from(format, self.input, self.read_cursor)
(808464688,)
sr. member
Activity: 300
Merit: 250
September 05, 2012, 12:14:37 AM
#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
legendary
Activity: 1652
Merit: 2301
Chief Scientist
sr. member
Activity: 300
Merit: 250
August 28, 2012, 01:38:32 AM
#1
.
Jump to: