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


Python Tx.unspents方法代码示例

本文整理汇总了Python中pycoin.tx.Tx.Tx.unspents方法的典型用法代码示例。如果您正苦于以下问题:Python Tx.unspents方法的具体用法?Python Tx.unspents怎么用?Python Tx.unspents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycoin.tx.Tx.Tx的用法示例。


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

示例1: do_test_tx

# 需要导入模块: from pycoin.tx.Tx import Tx [as 别名]
# 或者: from pycoin.tx.Tx.Tx import unspents [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)
开发者ID:jgriffiths,项目名称:libwally-core,代码行数:42,代码来源:reconcile_sigs.py


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