本文整理汇总了Python中pycoin.tx.Tx.from_hex方法的典型用法代码示例。如果您正苦于以下问题:Python Tx.from_hex方法的具体用法?Python Tx.from_hex怎么用?Python Tx.from_hex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycoin.tx.Tx
的用法示例。
在下文中一共展示了Tx.from_hex方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tx
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def get_tx(self, tx_hash):
url = "%s/rawtx/%s" % (self.base_url, b2h_rev(tx_hash))
result = json.loads(urlopen(url).read().decode("utf8"))
tx = Tx.from_hex(result["rawtx"])
if tx.hash() == tx_hash:
return tx
return None
示例2: sign_tx
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def sign_tx(certificate_metadata, last_input, allowable_wif_prefixes=None):
"""sign the transaction with private key"""
with open(certificate_metadata.unsigned_tx_file_name, 'rb') as in_file:
hextx = str(in_file.read(), 'utf-8')
logging.info(
'Signing tx with private key for recipient id: %s ...', certificate_metadata.uid)
tx = Tx.from_hex(hextx)
if allowable_wif_prefixes:
wif = wif_to_secret_exponent(
helpers.import_key(), allowable_wif_prefixes)
else:
wif = wif_to_secret_exponent(helpers.import_key())
lookup = build_hash160_lookup([wif])
tx.set_unspents(
[TxOut(coin_value=last_input.amount, script=last_input.script_pub_key)])
signed_tx = tx.sign(lookup)
signed_hextx = signed_tx.as_hex()
with open(certificate_metadata.unsent_tx_file_name, 'wb') as out_file:
out_file.write(bytes(signed_hextx, 'utf-8'))
logging.info('Finished signing transaction for certificate uid=%s',
certificate_metadata.uid)
示例3: test_broadcast_tx_mainnet
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def test_broadcast_tx_mainnet(self):
"""
Broadcasting tests fail because the transaction has already been pushed. So we're looking for a 'transaction
already in blockchain' error
"""
try:
tx = Tx.from_hex(MAINNET_TX)
broadcast_tx(tx)
self.assertTrue(False)
except Exception as e:
self.assertTrue('already in block chain', str(e.args[0]))
return
self.assertTrue(False)
示例4: broadcastTransaction
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def broadcastTransaction (self, transaction):
t = Tx.from_hex (transaction)
h = t.id ()
if not h in self.db['mempool']:
mp = self.db['mempool']
mp[h] = t
self.db['mempool'] = mp
self.db.sync ()
self.mempooltimer = Timer (1.0, self.announceTransactions)
self.mempooltimer.start ()
return h
示例5: sign_tx
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def sign_tx(hex_tx, tx_input):
"""
Sign the transaction with private key
:param hex_tx:
:param tx_input:
:return:
"""
logging.info('Signing tx with private key')
transaction = Tx.from_hex(hex_tx)
wif = wif_to_secret_exponent(helpers.import_key(), ALLOWABLE_WIF_PREFIXES)
lookup = build_hash160_lookup([wif])
transaction.set_unspents([TxOut(coin_value=tx_input.coin_value, script=tx_input.script)])
signed_tx = transaction.sign(lookup)
logging.info('Finished signing transaction')
return signed_tx
示例6: test_sign_bitcoind_partially_signed_2_of_2
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def test_sign_bitcoind_partially_signed_2_of_2(self):
# Finish signing a 2 of 2 transaction, that already has one signature signed by bitcoind
# This tx can be found on testnet3 blockchain, txid: 9618820d7037d2f32db798c92665231cd4599326f5bd99cb59d0b723be2a13a2
raw_script = "522103e33b41f5ed67a77d4c4c54b3e946bd30d15b8f66e42cb29fde059c16885116552102b92cb20a9fb1eb9656a74eeb7387636cf64cdf502ff50511830328c1b479986452ae"
p2sh_lookup = build_p2sh_lookup([h2b(raw_script)])
partially_signed_raw_tx = "010000000196238f11a5fd3ceef4efd5a186a7e6b9217d900418e72aca917cd6a6e634e74100000000910047304402201b41b471d9dd93cf97eed7cfc39a5767a546f6bfbf3e0c91ff9ad23ab9770f1f02205ce565666271d055be1f25a7e52e34cbf659f6c70770ff59bd783a6fcd1be3dd0147522103e33b41f5ed67a77d4c4c54b3e946bd30d15b8f66e42cb29fde059c16885116552102b92cb20a9fb1eb9656a74eeb7387636cf64cdf502ff50511830328c1b479986452aeffffffff01a0bb0d00000000001976a9143b3beefd6f7802fa8706983a76a51467bfa36f8b88ac00000000"
tx = Tx.from_hex(partially_signed_raw_tx)
tx_out = TxOut(1000000, h2b("a914a10dfa21ee8c33b028b92562f6fe04e60563d3c087"))
tx.set_unspents([tx_out])
key = Key.from_text("cThRBRu2jAeshWL3sH3qbqdq9f4jDiDbd1SVz4qjTZD2xL1pdbsx")
hash160_lookup = build_hash160_lookup([key.secret_exponent()])
self.assertEqual(tx.bad_signature_count(), 1)
tx.sign(hash160_lookup=hash160_lookup, p2sh_lookup=p2sh_lookup)
self.assertEqual(tx.bad_signature_count(), 0)
self.assertEqual(tx.id(), "9618820d7037d2f32db798c92665231cd4599326f5bd99cb59d0b723be2a13a2")
示例7: test_compare_cost
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def test_compare_cost(self):
"""
Compare our size estimation with a known transaction. The transaction contains 1 input, 6 outputs, and 1
OP_RETURN
Note that the estimation may be off +/- the number of inputs, which is why the estimate was off by 1 in this
case.
:return:
"""
tx = Tx.from_hex(
'0100000001ae17c5db3174b46ae2bdc911c25df6bc3ce88092256b6f6e564989693ecf67fc030000006b483045022100b0cfd576dd30bbdf6fd11e0d6118c59b6c6f8e7bf6513d323c7f9f5f8296bef102200174a28e28c792425b71155df99ea6110cdb67d3567792f1696e61424c1f67400121037175dfbeecd8b5a54eb5ad9a696f15b7b39da2ea7d67b4cd7a3299bb95e28884ffffffff07be0a0000000000001976a91481c706f7e6b2d9546169c1e76f50a3ee18e1e1d788acbe0a0000000000001976a914c2b9a62457e35bef48ef350a00622b1e63394d4588acbe0a0000000000001976a91481c706f7e6b2d9546169c1e76f50a3ee18e1e1d788acbe0a0000000000001976a914c2b9a62457e35bef48ef350a00622b1e63394d4588acbe0a0000000000001976a914cc0a909c4c83068be8b45d69b60a6f09c2be0fda88ac5627cb1d000000001976a9144103222e7c72b869c5e47bfe86702684531f2c9088ac0000000000000000226a206f308c70afcfcb0311ad0de989b80904fb54d9131fd3ab2187b89ca9601adab000000000')
s = io.BytesIO()
tx.stream(s)
tx_byte_count = len(s.getvalue())
estimated_byte_count = trx_utils.calculate_raw_tx_size_with_op_return(num_inputs=1, num_outputs=6)
self.assertEquals(estimated_byte_count, tx_byte_count + 1)
示例8: main
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
#.........这里部分代码省略.........
m = hex_re.search(l)
if m:
p2s = m.group(0)
script = h2b(p2s)
p2sh_lookup[hash160(script)] = script
count += 1
except Exception:
print("warning: error parsing pay-to-script file %s" % f.name)
if count == 0:
print("warning: no scripts found in %s" % f.name)
# we create the tx_db lazily
tx_db = None
for arg in args.argument:
# hex transaction id
if TX_ID_RE.match(arg):
if tx_db is None:
warning_tx_cache = message_about_tx_cache_env()
warning_tx_for_tx_hash = message_about_tx_for_tx_hash_env(args.network)
tx_db = get_tx_db(args.network)
tx = tx_db.get(h2b_rev(arg))
if not tx:
for m in [warning_tx_cache, warning_tx_for_tx_hash, warning_spendables]:
if m:
print("warning: %s" % m, file=sys.stderr)
parser.error("can't find Tx with id %s" % arg)
txs.append(tx)
continue
# hex transaction data
try:
tx = Tx.from_hex(arg)
txs.append(tx)
continue
except Exception:
pass
is_valid = is_address_valid(arg, allowable_netcodes=[args.network])
if is_valid:
payables.append((arg, 0))
continue
try:
key = Key.from_text(arg)
# TODO: check network
if key.wif() is None:
payables.append((key.address(), 0))
continue
# TODO: support paths to subkeys
key_iters.append((k.wif() for k in key.subkeys("")))
continue
except Exception:
pass
if os.path.exists(arg):
try:
with open(arg, "rb") as f:
if f.name.endswith("hex"):
f = io.BytesIO(codecs.getreader("hex_codec")(f).read())
tx = Tx.parse(f)
txs.append(tx)
try:
tx.parse_unspents(f)
except Exception as ex:
示例9: parse_context
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
#.........这里部分代码省略.........
m = hex_re.search(l)
if m:
p2s = m.group(0)
script = h2b(p2s)
p2sh_lookup[hash160(script)] = script
count += 1
except Exception:
print("warning: error parsing pay-to-script file %s" % f.name)
if count == 0:
print("warning: no scripts found in %s" % f.name)
# we create the tx_db lazily
tx_db = None
for arg in args.argument:
# hex transaction id
if TX_ID_RE.match(arg):
if tx_db is None:
warning_tx_cache = message_about_tx_cache_env()
warning_tx_for_tx_hash = message_about_tx_for_tx_hash_env(args.network)
tx_db = get_tx_db(args.network)
tx = tx_db.get(h2b_rev(arg))
if not tx:
for m in [warning_tx_cache, warning_tx_for_tx_hash, warning_spendables]:
if m:
print("warning: %s" % m, file=sys.stderr)
parser.error("can't find Tx with id %s" % arg)
txs.append(tx)
continue
# hex transaction data
try:
tx = Tx.from_hex(arg)
txs.append(tx)
continue
except Exception:
pass
is_valid = is_address_valid(arg, allowable_netcodes=[args.network])
if is_valid:
payables.append((arg, 0))
continue
try:
key = Key.from_text(arg)
# TODO: check network
if key.wif() is None:
payables.append((key.address(), 0))
continue
# TODO: support paths to subkeys
key_iters.append((k.wif() for k in key.subkeys("")))
continue
except Exception:
pass
if os.path.exists(arg):
try:
with open(arg, "rb") as f:
if f.name.endswith("hex"):
f = io.BytesIO(codecs.getreader("hex_codec")(f).read())
tx = Tx.parse(f)
txs.append(tx)
try:
tx.parse_unspents(f)
except Exception as ex:
示例10: prepare_tx_for_signing
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def prepare_tx_for_signing(hex_tx, tx_inputs):
logging.info('Preparing tx for signing')
transaction = Tx.from_hex(hex_tx)
unspents = [TxOut(coin_value=tx_input.coin_value, script=tx_input.script) for tx_input in tx_inputs]
transaction.set_unspents(unspents)
return transaction
示例11: tx_for_tx_hash
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def tx_for_tx_hash(self, tx_hash):
raw_tx = self.connection.getrawtransaction(b2h_rev(tx_hash))
tx = Tx.from_hex(raw_tx)
return tx
示例12: __init__
# 需要导入模块: from pycoin.tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx import from_hex [as 别名]
def __init__(self, hex):
self.tx = Tx.from_hex(hex)
self.signatures = []