本文整理汇总了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)
示例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())
示例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())
示例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)
示例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)
示例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()
示例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)
示例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)
示例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'
示例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
示例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)
示例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()
示例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()
示例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
示例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())