當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。