def test_Vin(self): rawtransaction = ( "01000000031091bb34c19754b689685bd5f84078b437653d08377d2d03d256b34f80eb219e010000008a4730440" "220476c26cdcecccf46fdd96fb87814661cb1044e103d1bcd5be339b9cbaceca47902201b2caafe5b36913ef475" "d4d33b9d62aa3316ece6f1ac3371a506906e61afd4510141048c632401521a105db6b62db0a2c393181b5538f2c" "56d461057611252baebc9c7794378c252c45b7393fc93ea3b8bc6d6db1c9b5506744d51d1ddd7a9acd27d81ffff" "ffffcc72f7a8acf77c1b1313d4ba229bff7db4f40e0a1b525a9b8a4dbc8ecc80b070000000008b4830450221009" "97b74ef85d3be61a96a4d8ecebfeb588979364276f54fa77571ff8fb7906e4202204390f9935695194362fbc221" "b00436b4811d01f645715105f9d081ad65977e2b014104fd579aa4983cece29365038ddbaf479af86bdf25afdca" "e67bbe8b30c268aecdac6cd8f923ef3f23ab694783f9243522f67886a46a43499e3fb3ed49623869d6fffffffff" "8ecdae566b8e8d709a32054175ce61fc2a9323e60023f62b23c342a7186beeea000000008b48304502200f95d4c" "d51bb5b867563700979ea23bf69921b1a0262ff5de3d7330bb992a713022100de58fa5822e7e62c8e6e4edbdece" "7913cb21f5a7b5a39d85fa9291874ce81a710141045f7f6eed56863bf527b8fd30cbe78038db311370da6c7054b" "eced527d60f47a65d6f1ce62278ba496f5da4a3d738eac0e2cb0f4ac38b113cbeabef59b685b16cffffffff0280" "c51b11010000000576a90088ac4cbdd397a90000001976a914d1121a58483d135c953e0f4e2cc6d126b5c6b0638" "8ac00000000" ) pybtcd_deserialized_transaction = deserialize(rawtransaction) bitcoind_json_vin0 = { "txid": "9e21eb804fb356d2032d7d37083d6537b47840f8d55b6889b65497c134bb9110", "vout": 1, "scriptSig": { "asm": "30440220476c26cdcecccf46fdd96fb87814661cb1044e103d1bcd5be339b9cbaceca47902201b2caafe5b36913ef475d4d33b9d62aa3316ece6f1ac3371a506906e61afd45101 048c632401521a105db6b62db0a2c393181b5538f2c56d461057611252baebc9c7794378c252c45b7393fc93ea3b8bc6d6db1c9b5506744d51d1ddd7a9acd27d81", "hex": "4730440220476c26cdcecccf46fdd96fb87814661cb1044e103d1bcd5be339b9cbaceca47902201b2caafe5b36913ef475d4d33b9d62aa3316ece6f1ac3371a506906e61afd4510141048c632401521a105db6b62db0a2c393181b5538f2c56d461057611252baebc9c7794378c252c45b7393fc93ea3b8bc6d6db1c9b5506744d51d1ddd7a9acd27d81", }, "sequence": 4294967295, } sut = VINDecoder.decode(pybtcd_deserialized_transaction["ins"][0]) vin = json.loads(json.dumps(bitcoind_json_vin0), parse_float=Decimal) self.assertEqual(vin, sut)
def test_decode_nonstandard_transaction_9(self): """ 91c8b08f305d895d6bc8f43bbdd36dcbc7f1d998e3df5e8f13dd9cdeebf15cb5 """ rawtransaction = ( "0100000001a30562a1cd9e907a90d7367ceaf55e859417a53ffda6190086110b7f8a4b4d2201000000020151ffff" "ffff0130d397000000000017a91469d98314fbc4dbee037f86f51392a14c4c1d41da8700000000" ) pybtcd_deserialized_transaction = deserialize(rawtransaction) bitcoind_json_vout0 = { "value": 0.09950000, "n": 0, "scriptPubKey": { "asm": "OP_HASH160 69d98314fbc4dbee037f86f51392a14c4c1d41da OP_EQUAL", "hex": "a91469d98314fbc4dbee037f86f51392a14c4c1d41da87", "reqSigs": 1, "type": "scripthash", "addresses": ["3BLhSgpY9xCFJv9Y6AyA9eSRZT6k3z6w4s"], }, } bitcoind_json_vin1 = { "txid": "224d4b8a7f0b11860019a6fd3fa51794855ef5ea7c36d7907a909ecda16205a3", "vout": 1, "scriptSig": {"asm": "81", "hex": "0151"}, "sequence": 4294967295, } sut = VOUTDecoder.decode(pybtcd_deserialized_transaction["outs"][0], 0, "main") sut_in = VINDecoder.decode(pybtcd_deserialized_transaction["ins"][0]) vin = json.loads(json.dumps(bitcoind_json_vin1), parse_float=Decimal) vout = json.loads(json.dumps(bitcoind_json_vout0), parse_float=Decimal) self.assertEqual(sut, vout) self.assertEqual(sut_in, vin)
def test_decode_standard_pubkeyhash_op_drop_vin(self): """ 51874c4b26a92dacb256f0e60303daabf60a63681111c4c1948f0bba25d8df96 """ rawtransaction = ( "010000000135ae0d99ffc1aea8fe97944e01b7842cbcbb5e186ab993438def514a2153b5cd0000000003010075f" "fffffff01b01df505000000001976a914d994aabea310efb308baa96c044aeae1fe1c413188ac00000000" ) pybtcd_deserialized_transaction = deserialize(rawtransaction) bitcoind_json_vout0 = { "value": 0.99950000, "n": 0, "scriptPubKey": { "asm": "OP_DUP OP_HASH160 d994aabea310efb308baa96c044aeae1fe1c4131 OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914d994aabea310efb308baa96c044aeae1fe1c413188ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": ["1LqTjBzMRdXQqXpRQo1zDYRiUobAVS55Lo"], }, } bitcoind_json_vin0 = { "txid": "cdb553214a51ef8d4393b96a185ebbbc2c84b7014e9497fea8aec1ff990dae35", "vout": 0, "scriptSig": {"asm": "0 OP_DROP", "hex": "010075"}, "sequence": 4294967295, } sut = VOUTDecoder.decode(pybtcd_deserialized_transaction["outs"][0], 0, "main") sut_in = VINDecoder.decode(pybtcd_deserialized_transaction["ins"][0]) vin = json.loads(json.dumps(bitcoind_json_vin0), parse_float=Decimal) vout = json.loads(json.dumps(bitcoind_json_vout0), parse_float=Decimal) self.assertEqual(sut, vout) self.assertEqual(sut_in, vin)
def test_Vin_coinbase(self): rawtransaction = ( "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff320" "380a305254b6e434d696e6572422d50322f4256383030303030302fbf2cf98be334867355cb0d80087e7f" "04000049e12b00ffffffff02fcde0600000000001976a9148c1fe3d123c397d6ed6b53e82069c0d68cabe" "cb588ac0c492e95000000001976a914396652927daedcef95e1fb89a09faf09545c322588ac00000000" ) pybtcd_deserialized_transaction = deserialize(rawtransaction) bitcoind_json_vin0 = { "coinbase": "0380a305254b6e434d696e6572422d50322f4256383030303030302fbf2cf98be334867355cb0d80087e7f04000049e12b00", "sequence": 4294967295, } sut = VINDecoder.decode(pybtcd_deserialized_transaction["ins"][0]) vin = json.loads(json.dumps(bitcoind_json_vin0), parse_float=Decimal) self.assertEqual(vin, sut)
def test_decode_nonstandard_transaction_5(self): """ 6d36bc17e947ce00bb6f12f8e7a56a1585c5a36188ffa2b05e10b4743273a74b """ rawtransaction = ( "01000000024de8b0c4c2582db95fa6b3567a989b664484c7ad6672c85a3da413773e63fdb8000000006b483045" "02205b282fbc9b064f3bc823a23edcc0048cbb174754e7aa742e3c9f483ebe02911c022100e4b0b3a117d36cab" "5a67404dddbf43db7bea3c1530e0fe128ebc15621bd69a3b0121035aa98d5f77cd9a2d88710e6fc66212aff820" "026f0dad8f32d1f7ce87457dde50ffffffff4de8b0c4c2582db95fa6b3567a989b664484c7ad6672c85a3da413" "773e63fdb8010000006f004730440220276d6dad3defa37b5f81add3992d510d2f44a317fd85e04f93a1e2daea" "64660202200f862a0da684249322ceb8ed842fb8c859c0cb94c81e1c5308b4868157a428ee01ab51210232abdc" "893e7f0631364d7fd01cb33d24da45329a00357b3a7886211ab414d55a51aeffffffff02e0fd1c000000000019" "76a914380cb3c594de4e7e9b8e18db182987bebb5a4f7088acc0c62d000000000017142a9bc5447d664c1d0141" "392a842d23dba45c4f13b17500000000" ) pybtcd_deserialized_transaction = deserialize(rawtransaction) bitcoind_json_vout0 = { "value": 0.03000000, "n": 1, "scriptPubKey": { "asm": "2a9bc5447d664c1d0141392a842d23dba45c4f13 OP_NOP2 OP_DROP", "hex": "142a9bc5447d664c1d0141392a842d23dba45c4f13b175", "type": "nonstandard", }, } bitcoind_json_vin1 = { "txid": "b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d", "vout": 1, "scriptSig": { "asm": "0 30440220276d6dad3defa37b5f81add3992d510d2f44a317fd85e04f93a1e2daea64660202200f862a0da684249322ceb8ed842fb8c859c0cb94c81e1c5308b4868157a428ee01 OP_CODESEPARATOR 1 0232abdc893e7f0631364d7fd01cb33d24da45329a00357b3a7886211ab414d55a 1 OP_CHECKMULTISIG", "hex": "004730440220276d6dad3defa37b5f81add3992d510d2f44a317fd85e04f93a1e2daea64660202200f862a0da684249322ceb8ed842fb8c859c0cb94c81e1c5308b4868157a428ee01ab51210232abdc893e7f0631364d7fd01cb33d24da45329a00357b3a7886211ab414d55a51ae", }, "sequence": 4294967295, } sut = VOUTDecoder.decode(pybtcd_deserialized_transaction["outs"][1], 1, "main") sut_in = VINDecoder.decode(pybtcd_deserialized_transaction["ins"][1]) vin = json.loads(json.dumps(bitcoind_json_vin1), parse_float=Decimal) vout = json.loads(json.dumps(bitcoind_json_vout0), parse_float=Decimal) self.maxDiff = None self.assertEqual(sut, vout) self.assertEqual(sut_in, vin)
def _deserialize(self): if not self.__json_obj: self.__json_obj = VINDecoder.decode(self._vin)
def is_coinbase(self): self._deserialize() return bool(VINDecoder.decode(self.__json_obj.get('ins')[0]).get('coinbase'))