当前位置: 首页>>代码示例>>Python>>正文


Python core.Transaction类代码示例

本文整理汇总了Python中hashmal_lib.core.Transaction的典型用法代码示例。如果您正苦于以下问题:Python Transaction类的具体用法?Python Transaction怎么用?Python Transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_change_tx_fields

    def test_change_tx_fields(self):
        tx = Transaction.deserialize(maza_raw_tx)

        chainparams.set_tx_fields(peercoin_fields)
        tx2 = Transaction.deserialize(ppc_raw_tx)

        self.assertNotEqual(tx.fields, tx2.fields)
开发者ID:Christewart,项目名称:hashmal,代码行数:7,代码来源:test_chainparams.py

示例2: insight_parse_raw_tx

def insight_parse_raw_tx(res):
    version = int(res.get('version'))
    locktime = int(res.get('locktime'))
    vin = []
    vout = []
    for i in res.get('vin'):
        prev_txid = i['txid']
        prev_n = int(i['n'])

        seq = int(i['sequence'])
        script_asm = i['scriptSig']['asm']
        script = Script.from_human(script_asm)

        tx_outpoint = COutPoint(lx(prev_txid), prev_n)
        tx_input = CTxIn(tx_outpoint, x(script.get_hex()), seq)
        vin.append(tx_input)

    for o in res.get('vout'):
        value = float(o['value'])
        value = int(value * pow(10, 8))

        script_asm = o['scriptPubKey']['asm']
        script = Script.from_human(script_asm)

        tx_output = CTxOut(value, x(script.get_hex()))
        vout.append(tx_output)

    tx = Transaction(vin, vout, locktime, version)
    return b2x(tx.serialize())
开发者ID:Kefkius,项目名称:hashmal-plugins,代码行数:29,代码来源:explorers.py

示例3: abe_parse_raw_tx

def abe_parse_raw_tx(res):
    version = int(res.get('ver'))
    locktime = int(res.get('lock_time'))
    vin = []
    vout = []
    for i in res.get('in'):
        prev_txid = i['prev_out']['hash']
        prev_n = int(i['prev_out']['n'])
        tx_outpoint = COutPoint(lx(prev_txid), prev_n)

        scriptSig = Script(x( i['raw_scriptSig'] ))
        sequence = int(i['sequence'])
        
        tx_input = CTxIn(tx_outpoint, x(scriptSig.get_hex()), sequence)
        vin.append(tx_input)

    for o in res.get('out'):
        value = float(o['value'])
        value = int(value * pow(10, 8))

        script = Script(x( o['raw_scriptPubKey'] ))
        tx_output = CTxOut(value, x(script.get_hex()))
        vout.append(tx_output)

    tx = Transaction(vin, vout, locktime, version)
    return b2x(tx.serialize())
开发者ID:Kefkius,项目名称:hashmal-plugins,代码行数:26,代码来源:explorers.py

示例4: test_preset_chainparams

    def test_preset_chainparams(self):
        chainparams.set_to_preset('Bitcoin')
        tx = Transaction.deserialize(maza_raw_tx)
        self.assertRaises(Exception, Transaction.deserialize, clams_raw_tx)
        self.assertRaises(Exception, Transaction.deserialize, ppc_raw_tx)

        chainparams.set_to_preset('Clams')
        tx = Transaction.deserialize(clams_raw_tx)
        self.assertRaises(Exception, Transaction.deserialize, maza_raw_tx)

        chainparams.set_to_preset('Peercoin')
        tx = Transaction.deserialize(ppc_raw_tx)
        self.assertRaises(Exception, Transaction.deserialize, clams_raw_tx)
        self.assertRaises(Exception, Transaction.deserialize, maza_raw_tx)
开发者ID:mazaclub,项目名称:hashmal,代码行数:14,代码来源:test_chainparams.py

示例5: test_from_tx_with_transaction_argument

 def test_from_tx_with_transaction_argument(self):
     tx = Transaction()
     chainparams.set_to_preset('Peercoin')
     self.assertRaises(AttributeError, getattr, tx, 'Timestamp')
     tx2 = Transaction.from_tx(tx)
     self.assertIsNot(tx, tx2)
     self.assertEqual(tx2.Timestamp, 0)
开发者ID:mazaclub,项目名称:hashmal,代码行数:7,代码来源:test_chainparams.py

示例6: check_raw_tx

    def check_raw_tx(self):
        txt = str(self.raw_tx_edit.toPlainText())
        # Variable substitution
        if txt.startswith('$'):
            var_value = self.handler.get_plugin('Variables').ui.get_key(txt[1:])
            if var_value:
                self.raw_tx_edit.setPlainText(var_value)
            return
        tx = None
        valid = True
        try:
            tx = Transaction.deserialize(txt.decode('hex'))
        except Exception:
            valid = False

        self.tx = tx
        self.deserialize_button.setEnabled(valid)
        self.inputs_box.setEnabled(valid)
        self.verify_button.setEnabled(valid)
        self.verify_all_button.setEnabled(valid)
        self.tx_widget.setEnabled(valid)
        self.clear()
        if valid:
            self.raw_tx_invalid.hide()
            self.inputs_box.setRange(0, len(tx.vin) - 1)
            self.deserialize()
        elif txt:
            self.raw_tx_invalid.show()
        else:
            self.raw_tx_invalid.hide()
开发者ID:Christewart,项目名称:hashmal,代码行数:30,代码来源:tx_analyzer.py

示例7: set_tx

 def set_tx(self):
     """Set the spending transaction and (en|dis)able the input index box."""
     txt = str(self.tx_edit.toPlainText())
     try:
         assert txt
         self.tx = Transaction.deserialize(txt.decode('hex'))
         self.tx_edit.setToolTip(''.join(['Tx ID: ', bitcoin.core.b2lx(self.tx.GetHash())]))
         self.input_idx.setRange(0, len(self.tx.vin) - 1)
         self.input_idx.setEnabled(True)
     except Exception:
         self.tx = None
         self.tx_edit.setToolTip('')
         self.input_idx.setEnabled(False)
开发者ID:oktoshi,项目名称:hashmal,代码行数:13,代码来源:stack.py

示例8: verify_input

    def verify_input(self):
        tx = None
        try:
            txt = str(self.raw_tx_edit.toPlainText())
            tx = Transaction.deserialize(txt.decode('hex'))
        except Exception:
            self.status_message('Could not deserialize transaction.', True)
            return
        in_idx = self.inputs_box.value()
        if in_idx >= len(tx.vin):
            self.status_message('Input {} does not exist.'.format(in_idx), True)
            return

        self.do_verify_input(tx, in_idx)
开发者ID:oktoshi,项目名称:hashmal,代码行数:14,代码来源:tx_analyzer.py

示例9: classify_data

    def classify_data(self, value):
        """Determine what to categorize a value as."""
        # If the value is not hex, assume text
        try:
            i = int(value, 16)
        except ValueError:
            return 'Text'

        # See if it's a raw transaction.
        try:
            t = Transaction.deserialize(value.decode('hex'))
            return 'Raw Transaction'
        except Exception:
            pass

        # Use the generic 'Hex' category if nothing else matches.
        return 'Hex'
开发者ID:oktoshi,项目名称:hashmal,代码行数:17,代码来源:variables.py

示例10: do_verify_inputs

    def do_verify_inputs(self, txt):
        self.needsFocus.emit()
        self.raw_tx_edit.setPlainText(txt)
        tx = Transaction.deserialize(txt.decode('hex'))
        failed_inputs = []
        self.result_edit.setText('Verifying...')
        for i in range(len(tx.vin)):
            if not self.do_verify_input(tx, i):
                failed_inputs.append(i)

        result = 'Successfully verified all inputs.'
        ret_val = True
        if failed_inputs:
            result = 'Failed to verify inputs: {}'.format(failed_inputs)
            ret_val = False
        if len(tx.vin) == 0:
            result = 'Transaction has no inputs.'
        self.result_edit.setText(result)
        return ret_val
开发者ID:oktoshi,项目名称:hashmal,代码行数:19,代码来源:tx_analyzer.py

示例11: set_tx

 def set_tx(self):
     """Set the spending transaction and (en|dis)able the input index box."""
     txt = str(self.tx_edit.toPlainText())
     # Variable substition
     if txt.startswith('$'):
         var_value = self.handler.get_plugin('Variables').ui.get_key(txt[1:])
         if var_value:
             self.tx_edit.setPlainText(var_value)
             return
     try:
         assert txt
         self.tx = Transaction.deserialize(txt.decode('hex'))
         self.tx_edit.setToolTip(''.join(['Tx ID: ', bitcoin.core.b2lx(self.tx.GetHash())]))
         self.input_idx.setRange(0, len(self.tx.vin) - 1)
         self.input_idx.setEnabled(True)
     except Exception:
         self.tx = None
         self.tx_edit.setToolTip('')
         self.input_idx.setEnabled(False)
开发者ID:Christewart,项目名称:hashmal,代码行数:19,代码来源:stack.py

示例12: deserialize_raw

 def deserialize_raw(self, rawtx):
     """Update editor widgets with rawtx's data."""
     self.needsFocus.emit()
     try:
         tx = Transaction.deserialize(x(rawtx))
     except Exception:
         return
     else:
         self.version_edit.set_amount(tx.nVersion)
         self.inputs_tree.model.set_tx(tx)
         self.outputs_tree.model.set_tx(tx)
         self.locktime_edit.set_amount(tx.nLockTime)
         for name, w in self.tx_field_widgets:
             if name in ["nVersion", "vin", "vout", "nLockTime"]:
                 continue
             value = getattr(tx, name)
             if isinstance(w, AmountEdit):
                 w.set_amount(value)
             else:
                 w.setText(str(value))
         self.build_transaction()
开发者ID:aesedepece,项目名称:hashmal,代码行数:21,代码来源:tx_builder.py

示例13: check_raw_tx

    def check_raw_tx(self):
        txt = str(self.raw_tx_edit.toPlainText())
        tx = None
        valid = True
        try:
            tx = Transaction.deserialize(txt.decode('hex'))
        except Exception:
            valid = False

        self.tx = tx
        self.deserialize_button.setEnabled(valid)
        self.inputs_box.setEnabled(valid)
        self.verify_button.setEnabled(valid)
        self.verify_all_button.setEnabled(valid)
        self.tx_widget.setEnabled(valid)
        self.clear()
        if valid:
            self.raw_tx_invalid.hide()
            self.inputs_box.setRange(0, len(tx.vin) - 1)
            self.deserialize()
        elif txt:
            self.raw_tx_invalid.show()
        else:
            self.raw_tx_invalid.hide()
开发者ID:oktoshi,项目名称:hashmal,代码行数:24,代码来源:tx_analyzer.py

示例14: do_verify_input

    def do_verify_input(self, tx, in_idx):
        raw_prev_tx = None
        tx_in = tx.vin[in_idx]
        txid = b2lx(tx_in.prevout.hash)
        prev_out_n = tx_in.prevout.n

        try:
            raw_prev_tx = self.handler.download_blockchain_data('raw_transaction', txid)
        except Exception as e:
            self.status_message(str(e), True)
            return False

        try:
            prev_tx = Transaction.deserialize(raw_prev_tx.decode('hex'))
            result = bitcoin.core.scripteval.VerifyScript(tx_in.scriptSig, prev_tx.vout[prev_out_n].scriptPubKey, tx, in_idx)
            self.result_edit.setText('Successfully verified input {}'.format(in_idx))
            self.inputs_table.set_verified(in_idx, True)
        except Exception as e:
            self.result_edit.setText(str(e))
            self.inputs_table.set_verified(in_idx, False)
            self.status_message(str(e), True)
            return False

        return True
开发者ID:oktoshi,项目名称:hashmal,代码行数:24,代码来源:tx_analyzer.py

示例15: test_clams_fields

 def test_clams_fields(self):
     chainparams.set_tx_fields(clams_fields)
     tx = Transaction.deserialize(clams_raw_tx)
     self.assertNotEqual(bitcoin_fields, tx.fields)
     self.assertIn(('ClamSpeech', 'bytes', None, b''), tx.fields)
     self.assertEqual(clams_raw_tx, tx.serialize())
开发者ID:mazaclub,项目名称:hashmal,代码行数:6,代码来源:test_chainparams.py


注:本文中的hashmal_lib.core.Transaction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。