本文整理汇总了Python中hashmal_lib.core.Transaction.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.deserialize方法的具体用法?Python Transaction.deserialize怎么用?Python Transaction.deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hashmal_lib.core.Transaction
的用法示例。
在下文中一共展示了Transaction.deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_change_tx_fields
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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)
示例2: test_preset_chainparams
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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)
示例3: check_raw_tx
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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()
示例4: set_tx
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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)
示例5: verify_input
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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)
示例6: classify_data
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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'
示例7: do_verify_inputs
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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
示例8: set_tx
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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)
示例9: deserialize_raw
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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()
示例10: check_raw_tx
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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()
示例11: do_verify_input
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
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
示例12: test_serialize_as_hex
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
def test_serialize_as_hex(self):
tx = Transaction.deserialize(maza_raw_tx)
self.assertEqual(maza_raw_tx.encode('hex'), tx.as_hex())
示例13: test_get_unsigned_outputs_with_sighash_single_and_none
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
def test_get_unsigned_outputs_with_sighash_single_and_none(self):
# Two inputs: SIGHASH_SINGLE and SIGHASH_NONE
rawtx = '01000000027f71104801ceb380b2267c5a4f8ae619de4b91c20ea01376045d03f8cce05658010000006a47304402207ac4d4a61dcfd366de2815eeee613514d61013011ebb3bce495fe327d1fdd87c0220615099194fade423f2e5c7c6ce5d936cd60234f83375155f7a094bcba7641f1a032102d22e0c46e17c1c415eade7ce8d5ea5d3d118c801a5553c71420e77042060acf7ffffffff0000000000000000000000000000000000000000000000000000000000000000000000006b483045022100be36640aa006acc01e943b3b966d07978c87f0f3100e4d4c7779652af49754100220505ee957abd40c337d41c81fec53b52261b665352bf1ecbb82c773635dbc3912022102d22e0c46e17c1c415eade7ce8d5ea5d3d118c801a5553c71420e77042060acf7ffffffff02c09ee605000000001976a914f243c18ef3315b423b2ee33727e37b5fe318bf7c88ac00000000000000001976a914000000000000000000000000000000000000000088ac00000000'
tx = Transaction.deserialize(x(rawtx))
unsigned = get_unsigned_outputs(tx)
self.assertEqual([1], unsigned)
示例14: is_raw_tx
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
def is_raw_tx(x):
try:
t = Transaction.deserialize(x.decode('hex'))
return True
except Exception:
return False
示例15: copy_txid
# 需要导入模块: from hashmal_lib.core import Transaction [as 别名]
# 或者: from hashmal_lib.core.Transaction import deserialize [as 别名]
def copy_txid(rawtx):
txid = b2lx(Transaction.deserialize(x(rawtx)).GetHash())
QApplication.clipboard().setText(txid)