示例#1
0
 def electrum_tx_to_txtype(self, tx):
     t = self.types.TransactionType()
     d = deserialize(tx.raw)
     t.version = d['version']
     t.lock_time = d['lockTime']
     inputs = self.tx_inputs(tx)
     t.inputs.extend(inputs)
     for vout in d['outputs']:
         o = t.bin_outputs.add()
         o.amount = vout['value']
         o.script_pubkey = bfh(vout['scriptPubKey'])
     return t
示例#2
0
 def electrum_tx_to_txtype(self, tx):
     t = self.types.TransactionType()
     if tx is None:
         # probably for segwit input and we don't need this prev txn
         return t
     d = deserialize(tx.raw)
     t.version = d['version']
     t.lock_time = d['lockTime']
     inputs = self.tx_inputs(tx)
     t._extend_inputs(inputs)
     for vout in d['outputs']:
         o = t._add_bin_outputs()
         o.amount = vout['value']
         o.script_pubkey = bfh(vout['scriptPubKey'])
     return t
示例#3
0
 def electrum_tx_to_txtype(self, tx, xpub_path):
     t = TransactionType()
     if tx is None:
         # probably for segwit input and we don't need this prev txn
         return t
     d = deserialize(tx.raw)
     t.version = d['version']
     t.lock_time = d['lockTime']
     t.inputs = self.tx_inputs(tx, xpub_path)
     t.bin_outputs = [
         TxOutputBinType(amount=vout['value'],
                         script_pubkey=bfh(vout['scriptPubKey']))
         for vout in d['outputs']
     ]
     return t
示例#4
0
 def electrum_tx_to_txtype(self, tx):
     t = self.types.TransactionType()
     if tx is None:
         # probably for segwit input and we don't need this prev txn
         return t
     d = deserialize(tx.raw)
     t.version = d['version']
     t.lock_time = d['lockTime']
     inputs = self.tx_inputs(tx)
     t.inputs.extend(inputs)
     for vout in d['outputs']:
         o = t.bin_outputs.add()
         o.amount = vout['value']
         o.script_pubkey = bfh(vout['scriptPubKey'])
     if t.version > 2:
         tx_type = d['tx_type']
         if tx_type:
             t.extra_data = to_varbytes(serialize_extra_payload(tx))
             t.version |= tx_type << 16
     return t
    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_type':
            0,
            'extra_payload':
            b''
        }
        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(),
                         [('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)