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


Python script.SignatureHash方法代码示例

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


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

示例1: sign

# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import SignatureHash [as 别名]
def sign(self, default_wallet: BitcoinWallet =None):
        """Signing transaction using the wallet object."""

        for tx_index, tx_in in enumerate(self.tx.vin):
            utxo = self.solvable_utxo[tx_index]
            wallet = utxo.wallet or default_wallet

            if wallet is None:
                raise RuntimeError('Cannot sign transaction without a wallet.')

            tx_script = utxo.parsed_script
            if utxo.contract:
                sig_hash = script.SignatureHash(
                    script.CScript.fromhex(utxo.contract),
                    self.tx,
                    tx_index,
                    script.SIGHASH_ALL
                )
            else:
                sig_hash = script.SignatureHash(
                    tx_script,
                    self.tx,
                    tx_index,
                    script.SIGHASH_ALL
                )
            sig = wallet.private_key.sign(sig_hash) + struct.pack('<B', script.SIGHASH_ALL)
            script_sig = [sig, wallet.private_key.pub] + utxo.unsigned_script_sig
            tx_in.scriptSig = script.CScript(script_sig)

            VerifyScript(
                tx_in.scriptSig,
                tx_script,
                self.tx,
                tx_index,
                (SCRIPT_VERIFY_P2SH,)
            )
        self.signed = True 
开发者ID:Lamden,项目名称:clove,代码行数:39,代码来源:transaction.py

示例2: sign

# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import SignatureHash [as 别名]
def sign(self, privkey):
        """
        Sign each of the inputs with the private key. Inputs should all be sent to
        the same scriptPubkey so we should only need one key.
        """
        seckey = CBitcoinSecret.from_secret_bytes(x(bitcointools.encode_privkey(privkey, "hex")))

        for i in range(len(self.tx.vin)):
            txin_scriptPubKey = self.tx.vin[i].scriptSig
            sighash = SignatureHash(txin_scriptPubKey, self.tx, i, SIGHASH_ALL)
            sig = seckey.sign(sighash) + struct.pack('<B', SIGHASH_ALL)
            self.tx.vin[i].scriptSig = CScript([sig, seckey.pub])

            VerifyScript(self.tx.vin[i].scriptSig, txin_scriptPubKey, self.tx, i, (SCRIPT_VERIFY_P2SH,)) 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:16,代码来源:transactions.py

示例3: create_signature

# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import SignatureHash [as 别名]
def create_signature(self, privkey, reedem_script):
        """
        Exports a raw signature suitable for use in a multisig transaction
        """
        seckey = CBitcoinSecret.from_secret_bytes(x(bitcointools.encode_privkey(privkey, "hex")))
        signatures = []
        for i in range(len(self.tx.vin)):
            sighash = SignatureHash(CScript(x(reedem_script)), self.tx, i, SIGHASH_ALL)
            signatures.append({
                "index": i,
                "signature": (seckey.sign(sighash) + struct.pack('<B', SIGHASH_ALL)).encode("hex"),
                "outpoint": b2lx(self.tx.vin[i].prevout.hash) + b2lx(struct.pack(b"<I", self.tx.vin[i].prevout.n))
            })
        return signatures 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:16,代码来源:transactions.py

示例4: signature

# 需要导入模块: from bitcoin.core import script [as 别名]
# 或者: from bitcoin.core.script import SignatureHash [as 别名]
def signature(self, transaction):
        """Signature for a transaction."""
        sighash = SignatureHash(CScript(self.anchor_redeem),
                                transaction, 0, SIGHASH_ALL)
        sig = g.seckey.sign(sighash) + bytes([SIGHASH_ALL])
        return sig 
开发者ID:hashplex,项目名称:Lightning,代码行数:8,代码来源:channel.py


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