本文整理汇总了Python中pycoin.tx.Tx.Tx.as_hex方法的典型用法代码示例。如果您正苦于以下问题:Python Tx.as_hex方法的具体用法?Python Tx.as_hex怎么用?Python Tx.as_hex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycoin.tx.Tx.Tx
的用法示例。
在下文中一共展示了Tx.as_hex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pycoin.tx.Tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx.Tx import as_hex [as 别名]
def main():
if len(sys.argv) != 2:
print("usage: %s address" % sys.argv[0])
sys.exit(-1)
# validate the address
address = sys.argv[1]
assert is_address_valid(address)
print("creating coinbase transaction to %s" % address)
tx_in = TxIn.coinbase_tx_in(script=b'')
tx_out = TxOut(50*1e8, script_for_address(address))
tx = Tx(1, [tx_in], [tx_out])
print("Here is the tx as hex:\n%s" % tx.as_hex())
示例2: do_test_tx
# 需要导入模块: from pycoin.tx.Tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx.Tx import as_hex [as 别名]
def do_test_tx(self, sighash, index_, flags):
txhash, seq, script, witness_script = b'0' * 32, 0xffffffff, b'\x51', b'000000'
out_script, spend_script, locktime = b'\x00\x00\x51', b'\x00\x51', 999999
txs_in = [TxIn(txhash, 0, script, seq),
TxIn(txhash, 1, script+b'\x51', seq-1),
TxIn(txhash, 2, script+b'\x51\x51', seq-2),
TxIn(txhash, 3, script+b'\x51\x51\x51', seq-3)]
txs_out = [TxOut(55, out_script),
TxOut(54, out_script+b'\x51'),
TxOut(53, out_script+b'\x51\x51')]
pytx = Tx(2, txs_in, txs_out, lock_time=locktime)
pytx.unspents = {0: TxOut(5000, spend_script), # FIXME: Make script unique
1: TxOut(5001, spend_script),
2: TxOut(5002, spend_script),
3: TxOut(5003, spend_script)}
unspent = pytx.unspents[index_]
pytx_hex = pytx.as_hex()
if flags & USE_WITNESS:
pytx_hash = pytx.signature_for_hash_type_segwit(unspent.script, index_, sighash)
else:
pytx_hash = pytx.signature_hash(spend_script, index_, sighash)
pytx_hash = hex_from_bytes(to_bytes_32(pytx_hash))
tx = tx_init(2, locktime, 3, 3)
tx_add_input(tx, tx_input_init(txhash, 0, seq, script, None))
tx_add_raw_input(tx, txhash, 1, seq-1, script+b'\x51', None, 0)
tx_add_raw_input(tx, txhash, 2, seq-2, script+b'\x51\x51', None, 0)
tx_add_raw_input(tx, txhash, 3, seq-3, script+b'\x51\x51\x51', None, 0)
tx_add_raw_output(tx, 55, out_script, 0)
tx_add_raw_output(tx, 54, out_script+b'\x51', 0)
tx_add_raw_output(tx, 53, out_script+b'\x51\x51', 0)
tx_hex = tx_to_hex(tx, 0)
amount = (index_ + 1) * 5000
tx_hash = tx_get_btc_signature_hash(tx, index_,
unspent.script, unspent.coin_value,
sighash, flags)
tx_hash = hex_from_bytes(tx_hash)
self.assertEqual(pytx_hex, tx_hex)
self.assertEqual(pytx_hash, tx_hash)