コード例 #1
0
 def test_deserialize(self):
     chainparams.set_active_chain("BTC")
     # some random tx
     rawtx = '010000000198fb6f1c46eb0416b6a91bc9d0b8dfa554a96b23f00070f430bbf6d05b26ea16010000006c493046022100d00ff7bb2e9d41ef200ceb2fd874468b09a21e549ead6f2a74f35ad02ce25df8022100b1307da37c806ae638502c60d0ebbbe6da2ae9bb03f8798953059269e0ef3b46012102e7d08484e6c4c26bd2a3aabab09c65bbdcb4a6bba0ee5cf7008ef19b9540f818ffffffff0200743ba40b0000001976a91429a158767437cd82ccf4bd3e34ecd16c267fc36388aca0c01319180000001976a9140b31340661bb7a4165736ca2fc6509164b1dc96488ac00000000'
     tx = deserialize(rawtx, chainparams.get_active_chain())
     self.assertEqual(tx['version'], 1)
     # inputs
     self.assertEqual(len(tx['inputs']), 1)
     first_in = tx['inputs'][0]
     self.assertEqual(first_in['is_coinbase'], False)
     self.assertEqual(first_in['prevout_hash'], '16ea265bd0f6bb30f47000f0236ba954a5dfb8d0c91ba9b61604eb461c6ffb98')
     self.assertEqual(first_in['prevout_n'], 1)
     self.assertEqual(first_in['num_sig'], 1)
     self.assertEqual(first_in['pubkeys'], ['02e7d08484e6c4c26bd2a3aabab09c65bbdcb4a6bba0ee5cf7008ef19b9540f818'])
     self.assertEqual(first_in['signatures'], ['3046022100d00ff7bb2e9d41ef200ceb2fd874468b09a21e549ead6f2a74f35ad02ce25df8022100b1307da37c806ae638502c60d0ebbbe6da2ae9bb03f8798953059269e0ef3b46'])
     self.assertEqual(first_in['sequence'], 4294967295)
     # outputs
     self.assertEqual(len(tx['outputs']), 2)
     # output 1
     first_out = tx['outputs'][0]
     self.assertEqual(first_out['address'], '14o7zMMUJkG6De24r3JkJ6USgChq7iWF86')
     self.assertEqual(first_out['prevout_n'], 0)
     self.assertEqual(first_out['scriptPubKey'], '76a91429a158767437cd82ccf4bd3e34ecd16c267fc36388ac')
     self.assertEqual(first_out['type'], 'address')
     self.assertEqual(first_out['value'], 50000000000)
     # output 2
     second_out = tx['outputs'][1]
     self.assertEqual(second_out['address'], '122BNoyhmuUt9G9mdEm3mN4nb73c1UgNKt')
     self.assertEqual(second_out['prevout_n'], 1)
     self.assertEqual(second_out['scriptPubKey'], '76a9140b31340661bb7a4165736ca2fc6509164b1dc96488ac')
     self.assertEqual(second_out['type'], 'address')
     self.assertEqual(second_out['value'], 103499940000)
     # locktime
     self.assertEqual(tx['lockTime'], 0)
コード例 #2
0
 def test_peercoin_deserialize(self):
     chainparams.set_active_chain('PPC')
     rawtx = '0100000058e4615501a367e883a383167e64c84e9c068ba5c091672e434784982f877eede589cb7e53000000006a473044022043b9aee9187effd7e6c7bc444b09162570f17e36b4a9c02cf722126cc0efa3d502200b3ba14c809fa9a6f7f835cbdbbb70f2f43f6b30beaf91eec6b8b5981c80cea50121025edf500f18f9f2b3f175f823fa996fbb2ec52982a9aeb1dc2e388a651054fb0fffffffff0257be0100000000001976a91495efca2c6a6f0e0f0ce9530219b48607a962e77788ac45702000000000001976a914f28abfb465126d6772dcb4403b9e1ad2ea28a03488ac00000000'
     tx = deserialize(rawtx, chainparams.get_active_chain())
     self.assertEqual(tx['version'], 1)
     self.assertEqual(len(tx['inputs']), 1)
     self.assertEqual(len(tx['outputs']), 2)
     self.assertEqual(tx['lockTime'], 0)
     self.assertEqual(tx['timestamp'], 1432478808)
コード例 #3
0
 def test_peercoin_deserialize(self):
     chainparams.set_active_chain('PPC')
     rawtx = '0100000058e4615501a367e883a383167e64c84e9c068ba5c091672e434784982f877eede589cb7e53000000006a473044022043b9aee9187effd7e6c7bc444b09162570f17e36b4a9c02cf722126cc0efa3d502200b3ba14c809fa9a6f7f835cbdbbb70f2f43f6b30beaf91eec6b8b5981c80cea50121025edf500f18f9f2b3f175f823fa996fbb2ec52982a9aeb1dc2e388a651054fb0fffffffff0257be0100000000001976a91495efca2c6a6f0e0f0ce9530219b48607a962e77788ac45702000000000001976a914f28abfb465126d6772dcb4403b9e1ad2ea28a03488ac00000000'
     tx = deserialize(rawtx, chainparams.get_active_chain())
     self.assertEqual(tx['version'], 1)
     self.assertEqual(len(tx['inputs']), 1)
     self.assertEqual(len(tx['outputs']), 2)
     self.assertEqual(tx['lockTime'], 0)
     self.assertEqual(tx['timestamp'], 1432478808)
コード例 #4
0
ファイル: test_transaction.py プロジェクト: nmarley/electrum
    def test_tx_unsigned(self):
        expected = {
            "inputs": [
                {
                    "address": "1446oU3z268EeFgfcwJv6X2VBXHfoYxfuD",
                    "is_coinbase": False,
                    "num_sig": 1,
                    "prevout_hash": "3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a",
                    "prevout_n": 0,
                    "pubkeys": ["02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6"],
                    "scriptSig": "01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000",
                    "sequence": 4294967295,
                    "signatures": [None],
                    "x_pubkeys": [
                        "ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000"
                    ],
                }
            ],
            "lockTime": 0,
            "outputs": [
                {
                    "address": "14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs",
                    "prevout_n": 0,
                    "scriptPubKey": "76a914230ac37834073a42146f11ef8414ae929feaafc388ac",
                    "type": "address",
                    "value": 1000000,
                }
            ],
            "version": 1,
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {"hex": unsigned_blob, "complete": False})
        self.assertEquals(tx.get_outputs(), [("14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs", 1000000)])
        self.assertEquals(tx.get_output_addresses(), ["14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs"])

        self.assertTrue(tx.has_address("14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs"))
        self.assertTrue(tx.has_address("1446oU3z268EeFgfcwJv6X2VBXHfoYxfuD"))
        self.assertFalse(tx.has_address("1CQj15y1N7LDHp7wTt28eoD1QhHgFgxECH"))

        self.assertEquals(tx.inputs_to_sign(), set(x_pubkey for i in expected["inputs"] for x_pubkey in i["x_pubkeys"]))
        self.assertEquals(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)
コード例 #5
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'type': 'p2pkh',
                'address': 'PQMDbX7KC3Z6nkpkptBb19vkoEaaFo5K5o',
                'num_sig': 1,
                'prevout_hash': '94ff0738bee075823a566db3e1011f1adae98c6e31950da4475126d81b4fb580',
                'prevout_n': 0,
                'pubkeys': ['03aa69e4e3f9fddc3e087491996e9d59eae908e650c12a75054d2249e6573ff52a'],
                'scriptSig': '01ff4c53ff0488b21e000000000000000000d6f1f7cd3d082daddffc75e8e558e4d33efc1c2f0b1cf6d52cd8719621e7c49e03123e1dc268988db79c47f91dfc00b328f666c375dd9e7b5d1d2bb7658a3b027e00000000',
                'sequence': 4294967294,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e000000000000000000d6f1f7cd3d082daddffc75e8e558e4d33efc1c2f0b1cf6d52cd8719621e7c49e03123e1dc268988db79c47f91dfc00b328f666c375dd9e7b5d1d2bb7658a3b027e00000000']}],
            'lockTime': 64577,
            'outputs': [{
                'address': 'PQCuFncFVzYhuoyv9MCSE5nQU2gwr56uh4',
                'prevout_n': 0,
                'scriptPubKey': '76a914ab4b96c435fd4ac967b27745fee19982a510430888ac',
                'type': TYPE_ADDRESS,
                'value': 99999040}],
            'partial': True,
            'version': 1,
        }
        tx = transaction.Transaction(unsigned_blob)
        #trx=tx.deserialize()
        #print(trx)
        #print(trx.get("inputs"))
        self.assertEqual(tx.deserialize(), expected)
        self.assertEqual(tx.deserialize(), None)

        self.assertEqual(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
        self.assertEqual(tx.get_outputs(), [('PQCuFncFVzYhuoyv9MCSE5nQU2gwr56uh4', 99999040)])
        self.assertEqual(tx.get_output_addresses(), ['PQCuFncFVzYhuoyv9MCSE5nQU2gwr56uh4'])

        self.assertTrue(tx.has_address('PQCuFncFVzYhuoyv9MCSE5nQU2gwr56uh4'))
        self.assertTrue(tx.has_address('PQMDbX7KC3Z6nkpkptBb19vkoEaaFo5K5o'))
        self.assertFalse(tx.has_address('PUFpXCipFhCM1n3incCvY1pdJnsuBYGXopNoZ'))

        self.assertEqual(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob_signatures)
        self.assertEqual(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEqual(transaction.deserialize(blob), expected)
コード例 #6
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'address': 'LNH44gMp6kNHu4Npo5JDNY6FPjewvMKDnz',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n': 0,
                'pubkeys': ['02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'],
                'scriptSig': '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence': 4294967295,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000']}],
            'lockTime': 0,
            'outputs': [{
                'address': 'LNREont24PYd5kkxTKoxVNhbugLowNb7H8',
                'prevout_n': 0,
                'scriptPubKey': '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000}],
                'version': 1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
        self.assertEquals(tx.get_outputs(), [('LNREont24PYd5kkxTKoxVNhbugLowNb7H8', 1000000)])
        self.assertEquals(tx.get_output_addresses(), ['LNREont24PYd5kkxTKoxVNhbugLowNb7H8'])

        self.assertTrue(tx.has_address('LNREont24PYd5kkxTKoxVNhbugLowNb7H8'))
        self.assertTrue(tx.has_address('LNH44gMp6kNHu4Npo5JDNY6FPjewvMKDnz'))
        self.assertFalse(tx.has_address('LWdgGJGqSmaGYcp6e21RvpGmcuexJorNEH'))

        # Commenting out broken test until we know why inputs_without_script() is not returnng anything.
        #self.assertEquals(tx.inputs_without_script(), set(x_pubkey for i in expected['inputs'] for x_pubkey in i['x_pubkeys']))

        self.assertEquals(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)
コード例 #7
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'address': '1446oU3z268EeFgfcwJv6X2VBXHfoYxfuD',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n': 0,
                'pubkeys': ['02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'],
                'scriptSig': '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence': 4294967295,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000']}],
            'lockTime': 0,
            'outputs': [{
                'address': '14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs',
                'prevout_n': 0,
                'scriptPubKey': '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000}],
                'version': 1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
        self.assertEquals(tx.get_outputs(), [('14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs', 1000000)])
        self.assertEquals(tx.get_output_addresses(), ['14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs'])

        self.assertTrue(tx.has_address('14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs'))
        self.assertTrue(tx.has_address('1446oU3z268EeFgfcwJv6X2VBXHfoYxfuD'))
        self.assertFalse(tx.has_address('1CQj15y1N7LDHp7wTt28eoD1QhHgFgxECH'))

        # Commenting out broken test until we know why inputs_without_script() is not returnng anything.
        #self.assertEquals(tx.inputs_without_script(), set(x_pubkey for i in expected['inputs'] for x_pubkey in i['x_pubkeys']))

        self.assertEquals(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)
コード例 #8
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'address': 'LNH44gMp6kNHu4Npo5JDNY6FPjewvMKDnz',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n': 0,
                'pubkeys': ['02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'],
                'scriptSig': '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence': 4294967295,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000']}],
            'lockTime': 0,
            'outputs': [{
                'address': 'LNREont24PYd5kkxTKoxVNhbugLowNb7H8',
                'prevout_n': 0,
                'scriptPubKey': '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000}],
                'version': 1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
        self.assertEquals(tx.get_outputs(), [('LNREont24PYd5kkxTKoxVNhbugLowNb7H8', 1000000)])
        self.assertEquals(tx.get_output_addresses(), ['LNREont24PYd5kkxTKoxVNhbugLowNb7H8'])

        self.assertTrue(tx.has_address('LNREont24PYd5kkxTKoxVNhbugLowNb7H8'))
        self.assertTrue(tx.has_address('LNH44gMp6kNHu4Npo5JDNY6FPjewvMKDnz'))
        self.assertFalse(tx.has_address('LWdgGJGqSmaGYcp6e21RvpGmcuexJorNEH'))

        # Commenting out broken test until we know why inputs_without_script() is not returnng anything.
        #self.assertEquals(tx.inputs_without_script(), set(x_pubkey for i in expected['inputs'] for x_pubkey in i['x_pubkeys']))

        self.assertEquals(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)
コード例 #9
0
ファイル: test_transaction.py プロジェクト: ddude1/TestLite
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'type': 'p2pkh',
                'address': 'XSxxwxa1hbpEGUmedjrovbE947qp3zmw1w',
                'num_sig': 1,
                'prevout_hash': '9d24f0c7a62af51a3a1876ebdf9540403d08cfd03b0173dc7db6c80f66cfad97',
                'prevout_n': 0,
                'pubkeys': ['029f3eca8539b84a43f7b270e68bd7620338c4af7b825f279c526ac39ab4363483'],
                'scriptSig': '01ff4c53ff022d2533000000000000000000d6f1f7cd3d082daddffc75e8e558e4d33efc1c2f0b1cf6d52cd8719621e7c49e03123e1dc268988db79c47f91dfc00b328f666c375dd9e7b5d1d2bb7658a3b027e00000100',
                'sequence': 4294967294,
                'signatures': [None],
                'x_pubkeys': ['ff022d2533000000000000000000d6f1f7cd3d082daddffc75e8e558e4d33efc1c2f0b1cf6d52cd8719621e7c49e03123e1dc268988db79c47f91dfc00b328f666c375dd9e7b5d1d2bb7658a3b027e00000100']}],
            'lockTime': 68727,
            'outputs': [{
                'address': 'XT7HHh55Pepd9RcVKGqxhfNVPKjSQGiXjL',
                'prevout_n': 0,
                'scriptPubKey': '76a914acde39ecdffccdb347458750c36c2315342cf6bc88ac',
                'type': TYPE_ADDRESS,
                'value': 109998080}],
                'version': 1
        }
        tx = transaction.Transaction(unsigned_blob)
        dstx = tx.deserialize()
        print(dstx)
        #self.assertEqual(tx.deserialize(), expected)
        self.assertEqual(dstx, expected)
        self.assertEqual(tx.deserialize(), None)

        self.assertEqual(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
        self.assertEqual(tx.get_outputs(), [('XT7HHh55Pepd9RcVKGqxhfNVPKjSQGiXjL', 109998080)])
        self.assertEqual(tx.get_output_addresses(), ['XT7HHh55Pepd9RcVKGqxhfNVPKjSQGiXjL'])

        self.assertTrue(tx.has_address('XT7HHh55Pepd9RcVKGqxhfNVPKjSQGiXjL'))
        self.assertTrue(tx.has_address('XSxxwxa1hbpEGUmedjrovbE947qp3zmw1w'))
        self.assertFalse(tx.has_address('Xn6ZqLcuKpYoSkiXKmLMWKtoF2sNExHwjT'))

        self.assertEqual(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEqual(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEqual(transaction.deserialize(blob), expected)
コード例 #10
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'address': 't9yhrFuaBzyWWJPfjDcPgSbQ7b1U59RekK',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n': 0,
                'pubkeys': ['02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'],
                'scriptSig': '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence': 4294967295,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000']}],
            'lockTime': 0,
            'outputs': [{
                'address': 'tA7tbNRn9e9qgzmoPU88oHCkdXhL6wkbKB',
                'prevout_n': 0,
                'scriptPubKey': '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': 'address',
                'value': 1000000}],
            'version': 1
        }
        self.maxDiff = None
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {'hex': unsigned_blob, 'complete': False})
        self.assertEquals(tx.get_outputs(), [('tA7tbNRn9e9qgzmoPU88oHCkdXhL6wkbKB', 1000000)])
        self.assertEquals(tx.get_output_addresses(), ['tA7tbNRn9e9qgzmoPU88oHCkdXhL6wkbKB'])

        self.assertTrue(tx.has_address('tA7tbNRn9e9qgzmoPU88oHCkdXhL6wkbKB'))
        self.assertTrue(tx.has_address('t9yhrFuaBzyWWJPfjDcPgSbQ7b1U59RekK'))
        self.assertFalse(tx.has_address('1CQj15y1N7LDHp7wTt28eoD1QhHgFgxECH'))

        self.assertEquals(tx.inputs_to_sign(), set(x_pubkey for i in expected['inputs'] for x_pubkey in i['x_pubkeys']))
        self.assertEquals(tx.serialize(), unsigned_blob, [tx.serialize(), unsigned_blob])

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)
コード例 #11
0
    def test_tx_unsigned(self):
        expected = {
            'overwintered': False,
            'inputs': [{
                'type': 'p2pkh',
                'address': Address.from_string('t1LvhooU7zQuqEtjZZN83EL8QSBUkd8WkHR'),
                'num_sig': 1,
                'prevout_hash': '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n': 0,
                'pubkeys': ['02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'],
                'scriptSig': '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence': 4294967295,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000']}],
            'lockTime': 0,
            'outputs': [{
                'address': Address.from_string('t1M4tYuzKx46ARb7hDcdnMAjkx8Acdrbd9Z'),
                'prevout_n': 0,
                'scriptPubKey': '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000}],
                'version': 1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEqual(tx.deserialize(), expected)
        self.assertEqual(tx.deserialize(), None)

        self.assertEqual(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
        self.assertEqual(tx.get_outputs(), [(Address.from_string('t1M4tYuzKx46ARb7hDcdnMAjkx8Acdrbd9Z'), 1000000)])
        self.assertEqual(tx.get_output_addresses(), [Address.from_string('t1M4tYuzKx46ARb7hDcdnMAjkx8Acdrbd9Z')])

        self.assertTrue(tx.has_address(Address.from_string('t1M4tYuzKx46ARb7hDcdnMAjkx8Acdrbd9Z')))
        self.assertTrue(tx.has_address(Address.from_string('t1LvhooU7zQuqEtjZZN83EL8QSBUkd8WkHR')))
        self.assertFalse(tx.has_address(Address.from_string('t1VHL1RP9LS7otTAqQJqFncJvfMUkwHriZr')))

        self.assertEqual(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEqual(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEqual(transaction.deserialize(blob), expected)
コード例 #12
0
ファイル: test_transaction.py プロジェクト: DaveA50/lbryum
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'address': 'bFnNVhPUNRWiA6Y2hbd1KBAMgQBrFsc5u3',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n': 0,
                'pubkeys': ['02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'],
                'scriptSig': '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence': 4294967295,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000']}],
            'lockTime': 0,
            'outputs': [{
                'address': 'bFvZEougL4h3LnvAMr8kS1miCLsiJCpLpB',
                'prevout_n': 0,
                'scriptPubKey': '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000}],
                'version': 1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {'hex': unsigned_blob, 'complete': False})
        self.assertEquals(tx.get_outputs(), [('bFvZEougL4h3LnvAMr8kS1miCLsiJCpLpB', 1000000)])
        self.assertEquals(tx.get_output_addresses(), ['bFvZEougL4h3LnvAMr8kS1miCLsiJCpLpB'])

        self.assertTrue(tx.has_address('bFvZEougL4h3LnvAMr8kS1miCLsiJCpLpB'))
        self.assertTrue(tx.has_address('bFnNVhPUNRWiA6Y2hbd1KBAMgQBrFsc5u3'))
        self.assertFalse(tx.has_address('bScaWvgzAzFXzAcVgDDARfo9RFhdrm4pVc'))

        self.assertEquals(tx.inputs_to_sign(), set(x_pubkey for i in expected['inputs'] for x_pubkey in i['x_pubkeys']))
        self.assertEquals(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)
コード例 #13
0
 def test_deserialize(self):
     chainparams.set_active_chain("BTC")
     # some random tx
     rawtx = '010000000198fb6f1c46eb0416b6a91bc9d0b8dfa554a96b23f00070f430bbf6d05b26ea16010000006c493046022100d00ff7bb2e9d41ef200ceb2fd874468b09a21e549ead6f2a74f35ad02ce25df8022100b1307da37c806ae638502c60d0ebbbe6da2ae9bb03f8798953059269e0ef3b46012102e7d08484e6c4c26bd2a3aabab09c65bbdcb4a6bba0ee5cf7008ef19b9540f818ffffffff0200743ba40b0000001976a91429a158767437cd82ccf4bd3e34ecd16c267fc36388aca0c01319180000001976a9140b31340661bb7a4165736ca2fc6509164b1dc96488ac00000000'
     tx = deserialize(rawtx, chainparams.get_active_chain())
     self.assertEqual(tx['version'], 1)
     # inputs
     self.assertEqual(len(tx['inputs']), 1)
     first_in = tx['inputs'][0]
     self.assertEqual(first_in['is_coinbase'], False)
     self.assertEqual(
         first_in['prevout_hash'],
         '16ea265bd0f6bb30f47000f0236ba954a5dfb8d0c91ba9b61604eb461c6ffb98')
     self.assertEqual(first_in['prevout_n'], 1)
     self.assertEqual(first_in['num_sig'], 1)
     self.assertEqual(first_in['pubkeys'], [
         '02e7d08484e6c4c26bd2a3aabab09c65bbdcb4a6bba0ee5cf7008ef19b9540f818'
     ])
     self.assertEqual(first_in['signatures'], [
         '3046022100d00ff7bb2e9d41ef200ceb2fd874468b09a21e549ead6f2a74f35ad02ce25df8022100b1307da37c806ae638502c60d0ebbbe6da2ae9bb03f8798953059269e0ef3b46'
     ])
     self.assertEqual(first_in['sequence'], 4294967295)
     # outputs
     self.assertEqual(len(tx['outputs']), 2)
     # output 1
     first_out = tx['outputs'][0]
     self.assertEqual(first_out['address'],
                      '14o7zMMUJkG6De24r3JkJ6USgChq7iWF86')
     self.assertEqual(first_out['prevout_n'], 0)
     self.assertEqual(first_out['scriptPubKey'],
                      '76a91429a158767437cd82ccf4bd3e34ecd16c267fc36388ac')
     self.assertEqual(first_out['type'], 'address')
     self.assertEqual(first_out['value'], 50000000000)
     # output 2
     second_out = tx['outputs'][1]
     self.assertEqual(second_out['address'],
                      '122BNoyhmuUt9G9mdEm3mN4nb73c1UgNKt')
     self.assertEqual(second_out['prevout_n'], 1)
     self.assertEqual(second_out['scriptPubKey'],
                      '76a9140b31340661bb7a4165736ca2fc6509164b1dc96488ac')
     self.assertEqual(second_out['type'], 'address')
     self.assertEqual(second_out['value'], 103499940000)
     # locktime
     self.assertEqual(tx['lockTime'], 0)
コード例 #14
0
ファイル: test_transaction.py プロジェクト: kizmc/electrum
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'address': '1446oU3z268EeFgfcwJv6X2VBXHfoYxfuD',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n': 0,
                'pubkeys': ['02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'],
                'scriptSig': '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence': 4294967295,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000']}],
            'lockTime': 0,
            'outputs': [{
                'address': '14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs',
                'prevout_n': 0,
                'scriptPubKey': '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': 'address',
                'value': 1000000}],
                'version': 1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {'hex': unsigned_blob, 'complete': False})
        self.assertEquals(tx.get_outputs(), [('14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs', 1000000)])
        self.assertEquals(tx.get_output_addresses(), ['14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs'])

        self.assertTrue(tx.has_address('14CHYaaByjJZpx4oHBpfDMdqhTyXnZ3kVs'))
        self.assertTrue(tx.has_address('1446oU3z268EeFgfcwJv6X2VBXHfoYxfuD'))
        self.assertFalse(tx.has_address('1CQj15y1N7LDHp7wTt28eoD1QhHgFgxECH'))

        self.assertEquals(tx.inputs_to_sign(), set(x_pubkey for i in expected['inputs'] for x_pubkey in i['x_pubkeys']))
        self.assertEquals(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)
コード例 #15
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'type': 'p2pkh',
                'address': 'XdjwdihsyoLpoCHFUpd8x3iH1rsMsS2q5P',
                'num_sig': 1,
                'prevout_hash': '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n': 0,
                'pubkeys': ['02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'],
                'scriptSig': '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence': 4294967295,
                'signatures': [None],
                'x_pubkeys': ['ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000']}],
            'lockTime': 0,
            'outputs': [{
                'address': 'Xdt8NqE5wSX9ytfP958t4tKdXoZDo6Bm6T',
                'prevout_n': 0,
                'scriptPubKey': '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000}],
                'version': 1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEqual(tx.deserialize(), expected)
        self.assertEqual(tx.deserialize(), None)

        self.assertEqual(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
        self.assertEqual(tx.get_outputs(), [('Xdt8NqE5wSX9ytfP958t4tKdXoZDo6Bm6T', 1000000)])
        self.assertEqual(tx.get_output_addresses(), ['Xdt8NqE5wSX9ytfP958t4tKdXoZDo6Bm6T'])

        self.assertTrue(tx.has_address('Xdt8NqE5wSX9ytfP958t4tKdXoZDo6Bm6T'))
        self.assertTrue(tx.has_address('XdjwdihsyoLpoCHFUpd8x3iH1rsMsS2q5P'))
        self.assertFalse(tx.has_address('Xn6ZqLcuKpYoSkiXKmLMWKtoF2sNExHwjT'))

        self.assertEqual(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEqual(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEqual(transaction.deserialize(blob), expected)
コード例 #16
0
    def test_sweep(self):
        privkeys = ['9ZbqFUfCRARXUJ3bvVtTy8D9cYSq7YDTiqKCHUp6rXnFXPQHBo2']
        unspent = [
            {
                "height": 371447,
                "tx_hash": "8e4d173db094786cc128b0c12eebc2200c0d8bfc3ad04ba39f487222d18bae3c",
                "tx_pos": 0,
                "value": 599995800
            }
        ]
        to_address = 't8vj9oXYNGB9DMDcwNB3rFMBZ2SqUe7AoY'
        network = NetworkMock(unspent)
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        result = transaction.deserialize(tx.serialize())
        expected = {
            'inputs': [{
                'address': 't8vj9oXYNGB9DMDcwNB3rFMBZ2SqUe7AoY',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '8e4d173db094786cc128b0c12eebc2200c0d8bfc3ad04ba39f487222d18bae3c',
                'prevout_n': 0,
                'pubkeys': ['040d60a955c72c4fbc5aec731ff6be4da22c5d5b8cb32205b93f38e8cb484a64101187f3b0b2d5fbf629e06a30eb68438098e9856bcb205398397b78a7031888c6'],
                'scriptSig': '483045022100bf3a0258554062fa42e9dbfe409ed0ca5e1c864f3e9c09d8c50fbad223059ce20220017971244a235f5e656d2165415579568fae7f21f73263a1ad72c834ab194d220141040d60a955c72c4fbc5aec731ff6be4da22c5d5b8cb32205b93f38e8cb484a64101187f3b0b2d5fbf629e06a30eb68438098e9856bcb205398397b78a7031888c6',
                'sequence': 4294967295,
                'signatures': ['3045022100bf3a0258554062fa42e9dbfe409ed0ca5e1c864f3e9c09d8c50fbad223059ce20220017971244a235f5e656d2165415579568fae7f21f73263a1ad72c834ab194d22'],
                'x_pubkeys': ['040d60a955c72c4fbc5aec731ff6be4da22c5d5b8cb32205b93f38e8cb484a64101187f3b0b2d5fbf629e06a30eb68438098e9856bcb205398397b78a7031888c6']}],
            'lockTime': 0,
            'outputs': [{
                'address': 't8vj9oXYNGB9DMDcwNB3rFMBZ2SqUe7AoY',
                'prevout_n': 0,
                'scriptPubKey': '76a91415f62e6fd9d4623b264668cb50deebe15e3fd28588ac',
                'type': 'address',
                'value': 599990800}],
            'version': 1}
        self.assertEquals(result, expected)

        network = NetworkMock([])
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        self.assertEquals(tx, None)

        privkeys = []
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        self.assertEquals(tx, None)
コード例 #17
0
    def test_sweep(self):
        privkeys = ['5HuH1SHoSVrgtPEwew9JzVAHGoKyp47x564mBCTgVmUT2Me1Q18']
        unspent = [
            {
                "height": 371447,
                "tx_hash": "8e4d173db094786cc128b0c12eebc2200c0d8bfc3ad04ba39f487222d18bae3c",
                "tx_pos": 0,
                "value": 599995800
            }
        ]
        to_address = '1JtBahwvii2pRkBmb4QMfcJQux1rk3Jkbq'
        network = NetworkMock(unspent)
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        result = transaction.deserialize(tx.serialize())
        expected = {
            'inputs': [{
                'address': '1t28kmZypcPQrunmJk212dcPGPxbBtB6Y',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '8e4d173db094786cc128b0c12eebc2200c0d8bfc3ad04ba39f487222d18bae3c',
                'prevout_n': 0,
                'pubkeys': ['047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02'],
                'scriptSig': '48304502203f1ff200490d18bcb802c7cf7ba4264727b089f1db6746a62997285b5ac77969022100e495591ea5111bb23a782984736f32942570fda781b7ed085fc8c88a9756aaac0141047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02',
                'sequence': 4294967295,
                'signatures': ['304502203f1ff200490d18bcb802c7cf7ba4264727b089f1db6746a62997285b5ac77969022100e495591ea5111bb23a782984736f32942570fda781b7ed085fc8c88a9756aaac'],
                'x_pubkeys': ['047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02']}],
            'lockTime': 0,
            'outputs': [{'address': '1JtBahwvii2pRkBmb4QMfcJQux1rk3Jkbq',
                'prevout_n': 0,
                'scriptPubKey': '76a914c4282f6060b811ee695ebb2068b8788213451d6a88ac',
                'type': 'address',
                'value': 599990800}],
            'version': 1}
        self.assertEquals(result, expected)

        network = NetworkMock([])
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        self.assertEquals(tx, None)

        privkeys = []
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        self.assertEquals(tx, None)
コード例 #18
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{'address': Address.from_string('13Vp8Y3hD5Cb6sERfpxePz5vGJizXbWciN'),
                        'num_sig': 1,
                        'prevout_hash': 'ed6a4d07e546b677abf6ba1257c2546128c694f23f4b9ebbd822fdfe435ef349',
                        'prevout_n': 1,
                        'pubkeys': ['03b5bbebceeb33c1b61f649596b9c3611c6b2853a1f6b48bce05dd54f667fa2166'],
                        'scriptSig': '01ff4c53ff0488b21e0000000000000000004f130d773e678a58366711837ec2e33ea601858262f8eaef246a7ebd19909c9a03c3b30e38ca7d797fee1223df1c9827b2a9f3379768f520910260220e0560014600002300',
                        'sequence': 4294967294,
                        'signatures': [None],
                        'type': 'p2pkh',
                        'value': 20112600,
                        'x_pubkeys': ['ff0488b21e0000000000000000004f130d773e678a58366711837ec2e33ea601858262f8eaef246a7ebd19909c9a03c3b30e38ca7d797fee1223df1c9827b2a9f3379768f520910260220e0560014600002300']}],
            'lockTime': 507231,
            'outputs': [{'address': Address.from_string('1MYXdf4moacvaEKZ57ozerpJ3t9xSeN6LK'),
                         'prevout_n': 0,
                         'scriptPubKey': '76a914e158fb15c888037fdc40fb9133b4c1c3c688706488ac',
                         'type': 0,
                         'value': 20112408}],
            'version': 1}
        tx = transaction.Transaction(unsigned_blob)
        calc = tx.deserialize()
        self.assertEqual(calc, expected)
        self.assertEqual(tx.deserialize(), None)

        self.assertEqual(tx.as_dict(), {'hex': unsigned_blob, 'complete': False, 'final': True})
        self.assertEqual(tx.get_outputs(), [(Address.from_string('1MYXdf4moacvaEKZ57ozerpJ3t9xSeN6LK'), 20112408)])
        self.assertEqual(tx.get_output_addresses(), [Address.from_string('1MYXdf4moacvaEKZ57ozerpJ3t9xSeN6LK')])

        self.assertTrue(tx.has_address(Address.from_string('1MYXdf4moacvaEKZ57ozerpJ3t9xSeN6LK')))
        self.assertTrue(tx.has_address(Address.from_string('13Vp8Y3hD5Cb6sERfpxePz5vGJizXbWciN')))
        self.assertFalse(tx.has_address(Address.from_string('1CQj15y1N7LDHp7wTt28eoD1QhHgFgxECH')))

        self.assertEqual(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEqual(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEqual(transaction.deserialize(blob), expected)
コード例 #19
0
    def test_sweep(self):
        privkeys = ['6uD1UZqLLvKZMm8oAkwGmswTEGtT1rZyqmTvtPUiDDo4iCbep6Q']
        unspent = [
            {
                "height": 371447,
                "tx_hash": "8e4d173db094786cc128b0c12eebc2200c0d8bfc3ad04ba39f487222d18bae3c",
                "tx_pos": 0,
                "value": 599995800
            }
        ]
        to_address = 'Ld78qvFkoNGsgYsvmCPewdNB8AP8rFDEJQ'
        network = NetworkMock(unspent)
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        result = transaction.deserialize(tx.serialize())
        expected = {
            'inputs': [{
                'address': 'LL6yPy5Q4UrSffbwwSjKH3hNbUmEkzCH1S',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '8e4d173db094786cc128b0c12eebc2200c0d8bfc3ad04ba39f487222d18bae3c',
                'prevout_n': 0,
                'pubkeys': ['047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02'],
                'scriptSig': '48304502203f1ff200490d18bcb802c7cf7ba4264727b089f1db6746a62997285b5ac77969022100e495591ea5111bb23a782984736f32942570fda781b7ed085fc8c88a9756aaac0141047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02',
                'sequence': 4294967295,
                'signatures': ['304502203f1ff200490d18bcb802c7cf7ba4264727b089f1db6746a62997285b5ac77969022100e495591ea5111bb23a782984736f32942570fda781b7ed085fc8c88a9756aaac'],
                'x_pubkeys': ['047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02']}],
            'lockTime': 0,
            'outputs': [{'address': 'Ld78qvFkoNGsgYsvmCPewdNB8AP8rFDEJQ',
                'prevout_n': 0,
                'scriptPubKey': '76a914c4282f6060b811ee695ebb2068b8788213451d6a88ac',
                'type': 'address',
                'value': 599990800}],
            'version': 1}
        self.assertEquals(result, expected)

        network = NetworkMock([])
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        self.assertEquals(tx, None)

        privkeys = []
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        self.assertEquals(tx, None)
コード例 #20
0
ファイル: test_transaction.py プロジェクト: kizmc/electrum
    def test_sweep(self):
        privkeys = ['5HuH1SHoSVrgtPEwew9JzVAHGoKyp47x564mBCTgVmUT2Me1Q18']
        unspent = [
            {
                "height": 371447,
                "tx_hash": "8e4d173db094786cc128b0c12eebc2200c0d8bfc3ad04ba39f487222d18bae3c",
                "tx_pos": 0,
                "value": 599995800
            }
        ]
        to_address = '1JtBahwvii2pRkBmb4QMfcJQux1rk3Jkbq'
        network = NetworkMock(unspent)
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        result = transaction.deserialize(tx.serialize())
        expected = {
            'inputs': [{
                'address': '1t28kmZypcPQrunmJk212dcPGPxbBtB6Y',
                'is_coinbase': False,
                'num_sig': 1,
                'prevout_hash': '8e4d173db094786cc128b0c12eebc2200c0d8bfc3ad04ba39f487222d18bae3c',
                'prevout_n': 0,
                'pubkeys': ['047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02'],
                'scriptSig': '48304502203f1ff200490d18bcb802c7cf7ba4264727b089f1db6746a62997285b5ac77969022100e495591ea5111bb23a782984736f32942570fda781b7ed085fc8c88a9756aaac0141047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02',
                'sequence': 4294967295,
                'signatures': ['304502203f1ff200490d18bcb802c7cf7ba4264727b089f1db6746a62997285b5ac77969022100e495591ea5111bb23a782984736f32942570fda781b7ed085fc8c88a9756aaac'],
                'x_pubkeys': ['047b9f9014f8d0d6f24dcaf5681b6ab185bd821e0fcce29d84e0452845baf1b2dbe332a7cd4dbdab786adda6d71b2188298c756b265c63de2794f7317b71a7ac02']}],
            'lockTime': 0,
            'outputs': [{'address': '1JtBahwvii2pRkBmb4QMfcJQux1rk3Jkbq',
                'prevout_n': 0,
                'scriptPubKey': '76a914c4282f6060b811ee695ebb2068b8788213451d6a88ac',
                'type': 'address',
                'value': 599990800}],
            'version': 1}
        self.assertEquals(result, expected)

        network = NetworkMock([])
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        self.assertEquals(tx, None)

        privkeys = []
        tx = transaction.Transaction.sweep(privkeys, network, to_address, fee=5000)
        self.assertEquals(tx, None)
コード例 #21
0
from lib import transaction, bitcoin, util
from lib.util import bfh, bh2u
from lib.transaction import Transaction

kmd_unsigned_tx_serialized = 'put unsigned kmd raw tx here'
wif = 'put your wif key here'

txin_type, privkey, compressed = bitcoin.deserialize_privkey(wif)
pubkey = bitcoin.public_key_from_private_key(privkey, compressed)

jsontx = transaction.deserialize(kmd_unsigned_tx_serialized)
inputs = jsontx.get('inputs')
outputs = jsontx.get('outputs')
locktime = jsontx.get('lockTime', 0)

for txin in inputs:
    txin['type'] = txin_type
    txin['x_pubkeys'] = [pubkey]
    txin['pubkeys'] = [pubkey]
    txin['signatures'] = [None]
    txin['num_sig'] = 1
    txin['address'] = bitcoin.address_from_private_key(wif)
    txin['value'] = 100000000  # required for preimage calc

tx = Transaction.from_io(inputs, outputs, locktime=locktime)
tx.sign({pubkey: (privkey, compressed)})

print(tx.serialize())
コード例 #22
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'address':
                'bFnNVhPUNRWiA6Y2hbd1KBAMgQBrFsc5u3',
                'is_coinbase':
                False,
                'num_sig':
                1,
                'prevout_hash':
                '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n':
                0,
                'pubkeys': [
                    '02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'
                ],
                'scriptSig':
                '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence':
                4294967295,
                'signatures': [None],
                'x_pubkeys': [
                    'ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000'
                ]
            }],
            'lockTime':
            0,
            'outputs': [{
                'address': 'bFvZEougL4h3LnvAMr8kS1miCLsiJCpLpB',
                'prevout_n': 0,
                'scriptPubKey':
                '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000
            }],
            'version':
            1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {
            'hex': unsigned_blob,
            'complete': False
        })
        self.assertEquals(tx.get_outputs(),
                          [('bFvZEougL4h3LnvAMr8kS1miCLsiJCpLpB', 1000000)])
        self.assertEquals(tx.get_output_addresses(),
                          ['bFvZEougL4h3LnvAMr8kS1miCLsiJCpLpB'])

        self.assertTrue(tx.has_address('bFvZEougL4h3LnvAMr8kS1miCLsiJCpLpB'))
        self.assertTrue(tx.has_address('bFnNVhPUNRWiA6Y2hbd1KBAMgQBrFsc5u3'))
        self.assertFalse(tx.has_address('bScaWvgzAzFXzAcVgDDARfo9RFhdrm4pVc'))

        self.assertEquals(
            tx.inputs_to_sign(),
            set(x_pubkey for i in expected['inputs']
                for x_pubkey in i['x_pubkeys']))
        self.assertEquals(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)
コード例 #23
0
    def test_tx_unsigned(self):
        expected = {
            'inputs': [{
                'type':
                'p2pkh',
                'address':
                'MAxG2txPX7J3XvezquxrLndpekAqJLGTmn',
                'num_sig':
                1,
                'prevout_hash':
                '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n':
                0,
                'pubkeys': [
                    '02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'
                ],
                'scriptSig':
                '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence':
                4294967295,
                'signatures': [None],
                'x_pubkeys': [
                    'ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000'
                ]
            }],
            'lockTime':
            0,
            'outputs': [{
                'address': 'MB6Sn1UbUkUNid38WAUbTdFBAgrhKyDds5',
                'prevout_n': 0,
                'scriptPubKey':
                '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000
            }],
            'version':
            1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEqual(tx.deserialize(), expected)
        self.assertEqual(tx.deserialize(), None)

        self.assertEqual(tx.as_dict(), {
            'hex': unsigned_blob,
            'complete': False,
            'final': True
        })
        self.assertEqual(tx.get_outputs(),
                         [('MB6Sn1UbUkUNid38WAUbTdFBAgrhKyDds5', 1000000)])
        self.assertEqual(tx.get_output_addresses(),
                         ['MB6Sn1UbUkUNid38WAUbTdFBAgrhKyDds5'])

        self.assertTrue(tx.has_address('MB6Sn1UbUkUNid38WAUbTdFBAgrhKyDds5'))
        self.assertTrue(tx.has_address('MAxG2txPX7J3XvezquxrLndpekAqJLGTmn'))
        self.assertFalse(tx.has_address('1CQj15y1N7LDHp7wTt28eoD1QhHgFgxECH'))

        self.assertEqual(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEqual(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEqual(transaction.deserialize(blob), expected)
コード例 #24
0
from lib import transaction, bitcoin, util
from lib.util import bfh, bh2u
from lib.transaction import Transaction
from lib.komodo_interest import calcInterest

import urllib.request, urllib.parse, urllib.error
import urllib.request, urllib.error, urllib.parse
import json

explorerUrl = 'https://kmd.explorer.dexstats.info/insight-api-komodo/'
rawtx = 'raw tx hex here'

jsontx = transaction.deserialize(rawtx)
inputs = jsontx.get('inputs')
outputs = jsontx.get('outputs')
locktime = jsontx.get('lockTime', 0)

sumVin = 0
sumVout = 0
totalRewards = 0

for txin in inputs:
    print('get vin data', txin['prevout_hash'])
    url = explorerUrl + 'rawtx/' + txin['prevout_hash']
    response = urllib.request.urlopen(url)
    data = json.loads(response.read())

    if data is not None and 'rawtx' in data:
        # print('INSIGHT explorer response', data)
        vinTx = transaction.deserialize(data['rawtx'])
        vinOutputs = vinTx.get('outputs')
コード例 #25
0
    def test_tx_unsigned(self):
        self.maxDiff = None
        expected = {
            'inputs': [{
                'address':
                'fHAQLnNMUE9ULRvtwnxCARtDySmHNgqEev',
                'is_coinbase':
                False,
                'num_sig':
                1,
                'prevout_hash':
                '3140eb24b43386f35ba69e3875eb6c93130ac66201d01c58f598defc949a5c2a',
                'prevout_n':
                0,
                'pubkeys': [
                    '02e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6'
                ],
                'scriptSig':
                '01ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000',
                'sequence':
                4294967295,
                'signatures': [None],
                'x_pubkeys': [
                    'ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000'
                ]
            }],
            'lockTime':
            0,
            'outputs': [{
                'address': 'fHJb5ttZRsKoX8K2c3TwHGVaVPT9NE2f5u',
                'prevout_n': 0,
                'scriptPubKey':
                '76a914230ac37834073a42146f11ef8414ae929feaafc388ac',
                'type': TYPE_ADDRESS,
                'value': 1000000
            }],
            'version':
            1
        }
        tx = transaction.Transaction(unsigned_blob)
        self.assertEquals(tx.deserialize(), expected)
        self.assertEquals(tx.deserialize(), None)

        self.assertEquals(tx.as_dict(), {
            'hex': unsigned_blob,
            'complete': False,
            'final': True
        })
        self.assertEquals(tx.get_outputs(),
                          [('fHJb5ttZRsKoX8K2c3TwHGVaVPT9NE2f5u', 1000000)])
        self.assertEquals(tx.get_output_addresses(),
                          ['fHJb5ttZRsKoX8K2c3TwHGVaVPT9NE2f5u'])

        self.assertTrue(tx.has_address('fHJb5ttZRsKoX8K2c3TwHGVaVPT9NE2f5u'))
        self.assertTrue(tx.has_address('fHAQLnNMUE9ULRvtwnxCARtDySmHNgqEev'))
        self.assertFalse(tx.has_address('fRX2YQHNpFMSyzNAnjfQii4kCcmHhwFdQq'))

        self.assertEquals(
            tx.inputs_to_sign(),
            set(x_pubkey for i in expected['inputs']
                for x_pubkey in i['x_pubkeys']))
        self.assertEquals(tx.serialize(), unsigned_blob)

        tx.update_signatures(signed_blob)
        self.assertEquals(tx.raw, signed_blob)

        tx.update(unsigned_blob)
        tx.raw = None
        blob = str(tx)
        self.assertEquals(transaction.deserialize(blob), expected)