當前位置: 首頁>>代碼示例>>Python>>正文


Python script.CScript方法代碼示例

本文整理匯總了Python中bitcoin.core.script.CScript方法的典型用法代碼示例。如果您正苦於以下問題:Python script.CScript方法的具體用法?Python script.CScript怎麽用?Python script.CScript使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bitcoin.core.script的用法示例。


在下文中一共展示了script.CScript方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: gettxout

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def gettxout(self, outpoint, includemempool=True):
        """Return details about an unspent transaction output.

        Raises IndexError if outpoint is not found or was spent.

        includemempool - Include mempool txouts
        """
        r = self._call('gettxout', b2lx(outpoint.hash), outpoint.n, includemempool)

        if r is None:
            raise IndexError('%s.gettxout(): unspent txout %r not found' % (self.__class__.__name__, outpoint))

        r['txout'] = CTxOut(int(r['value'] * COIN),
                            CScript(unhexlify(r['scriptPubKey']['hex'])))
        del r['value']
        del r['scriptPubKey']
        r['bestblock'] = lx(r['bestblock'])
        return r 
開發者ID:petertodd,項目名稱:checklocktimeverify-demos,代碼行數:20,代碼來源:rpc.py

示例2: listunspent

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def listunspent(self, minconf=0, maxconf=9999999, addrs=None):
        """Return unspent transaction outputs in wallet

        Outputs will have between minconf and maxconf (inclusive)
        confirmations, optionally filtered to only include txouts paid to
        addresses in addrs.
        """
        r = None
        if addrs is None:
            r = self._call('listunspent', minconf, maxconf)
        else:
            addrs = [str(addr) for addr in addrs]
            r = self._call('listunspent', minconf, maxconf, addrs)

        r2 = []
        for unspent in r:
            unspent['outpoint'] = COutPoint(lx(unspent['txid']), unspent['vout'])
            del unspent['txid']
            del unspent['vout']

            unspent['address'] = CBitcoinAddress(unspent['address'])
            unspent['scriptPubKey'] = CScript(unhexlify(unspent['scriptPubKey']))
            unspent['amount'] = int(unspent['amount'] * COIN)
            r2.append(unspent)
        return r2 
開發者ID:petertodd,項目名稱:checklocktimeverify-demos,代碼行數:27,代碼來源:rpc.py

示例3: test_from_non_canonical_scriptPubKey

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def test_from_non_canonical_scriptPubKey(self):
        def T(hex_scriptpubkey, expected_str_address):
            scriptPubKey = CScript(x(hex_scriptpubkey))
            addr = P2PKHBitcoinAddress.from_scriptPubKey(scriptPubKey)
            self.assertEqual(str(addr), expected_str_address)

            # now test that CBitcoinAddressError is raised with accept_non_canonical_pushdata=False
            with self.assertRaises(CBitcoinAddressError):
                P2PKHBitcoinAddress.from_scriptPubKey(scriptPubKey, accept_non_canonical_pushdata=False)

        T('76a94c14000000000000000000000000000000000000000088ac', '1111111111111111111114oLvT2')
        T('76a94d1400000000000000000000000000000000000000000088ac', '1111111111111111111114oLvT2'),
        T('76a94e14000000000000000000000000000000000000000000000088ac', '1111111111111111111114oLvT2')

        # make sure invalid scripts raise CBitcoinAddressError
        with self.assertRaises(CBitcoinAddressError):
            P2PKHBitcoinAddress.from_scriptPubKey(x('76a94c14')) 
開發者ID:petertodd,項目名稱:checklocktimeverify-demos,代碼行數:19,代碼來源:test_wallet.py

示例4: test_from_bare_checksig_scriptPubKey

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def test_from_bare_checksig_scriptPubKey(self):
        def T(hex_scriptpubkey, expected_str_address):
            scriptPubKey = CScript(x(hex_scriptpubkey))
            addr = P2PKHBitcoinAddress.from_scriptPubKey(scriptPubKey)
            self.assertEqual(str(addr), expected_str_address)

            # now test that CBitcoinAddressError is raised with accept_non_canonical_pushdata=False
            with self.assertRaises(CBitcoinAddressError):
                P2PKHBitcoinAddress.from_scriptPubKey(scriptPubKey, accept_bare_checksig=False)

        # compressed
        T('21000000000000000000000000000000000000000000000000000000000000000000ac', '14p5cGy5DZmtNMQwTQiytBvxMVuTmFMSyU')

        # uncompressed
        T('410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ac', '1QLFaVVt99p1y18zWSZnespzhkFxjwBbdP')

        # non-canonical encoding
        T('4c21000000000000000000000000000000000000000000000000000000000000000000ac', '14p5cGy5DZmtNMQwTQiytBvxMVuTmFMSyU')

        # odd-lengths are *not* accepted
        with self.assertRaises(CBitcoinAddressError):
            P2PKHBitcoinAddress.from_scriptPubKey(x('2200000000000000000000000000000000000000000000000000000000000000000000ac')) 
開發者ID:petertodd,項目名稱:checklocktimeverify-demos,代碼行數:24,代碼來源:test_wallet.py

示例5: build_atomic_swap_contract

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def build_atomic_swap_contract(self):
        self.contract = script.CScript([
            script.OP_IF,
            script.OP_RIPEMD160,
            self.secret_hash,
            script.OP_EQUALVERIFY,
            script.OP_DUP,
            script.OP_HASH160,
            CBitcoinAddress(self.recipient_address),
            script.OP_ELSE,
            int(self.locktime.replace(tzinfo=timezone.utc).timestamp()),
            script.OP_CHECKLOCKTIMEVERIFY,
            script.OP_DROP,
            script.OP_DUP,
            script.OP_HASH160,
            CBitcoinAddress(self.sender_address),
            script.OP_ENDIF,
            script.OP_EQUALVERIFY,
            script.OP_CHECKSIG,
        ]) 
開發者ID:Lamden,項目名稱:clove,代碼行數:22,代碼來源:transaction.py

示例6: generate_multisig_address

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def generate_multisig_address(redeemscript: str, testnet: bool = False) -> str:
    """
    Generates a P2SH-multisig Bitcoin address from a redeem script

    Args:
        redeemscript: hex-encoded redeem script
                      use generate_multisig_redeem_script to create
                      the redeem script from three compressed public keys
         testnet: Should the address be testnet or mainnet?

    Example:
        TODO
    """

    if testnet:
        bitcoin.SelectParams('testnet')

    redeem_script = CScript(bitcoin.core.x(redeemscript))

    addr = P2SHBitcoinAddress.from_redeemScript(redeem_script)

    return str(addr) 
開發者ID:unchained-capital,項目名稱:hermit,代碼行數:24,代碼來源:bitcoin_signer.py

示例7: build_EquihashInputHeader

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def build_EquihashInputHeader(args):
    pszTimestamp = args.pszTimestamp if args.pszTimestamp else \
            build_pszTimestamp(args.coinname, args.timestamp)
    verb("pszTimestamp: " + pszTimestamp)
    pk, bits = args.pubkey, args.bits
    extranonce = args.extranonce if args.extranonce else bits
    # Input transaction
    scriptSig = CScript() + extranonce + b'\x04' + pszTimestamp.encode('UTF-8')
    txin=CMutableTxIn(scriptSig=scriptSig)
    # Output transaction
    scriptPubKey = CScript() + pk + OP_CHECKSIG
    txout = CMutableTxOut(nValue = args.value, scriptPubKey = scriptPubKey)

    tx = CMutableTransaction(vin=[txin], vout=[txout])
    txhash = tx.GetTxid()
    verb("TX/merkle root hash: " + b2lx(txhash))

    return CEquihashHeader(nTime=args.time, nBits=bits,
        nNonce=args.nonce, hashMerkleRoot=txhash) 
開發者ID:sebastianst,項目名稱:GenesisZ,代碼行數:21,代碼來源:genesis.py

示例8: to_scriptPubKey

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def to_scriptPubKey(self):
        """Convert an address to a scriptPubKey"""
        assert self.nVersion == bitcoin.params.BASE58_PREFIXES['SCRIPT_ADDR']
        return script.CScript([script.OP_HASH160, self, script.OP_EQUAL]) 
開發者ID:petertodd,項目名稱:checklocktimeverify-demos,代碼行數:6,代碼來源:wallet.py

示例9: test_from_nonstd_scriptPubKey

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def test_from_nonstd_scriptPubKey(self):
        """CBitcoinAddress.from_scriptPubKey() with non-standard scriptPubKeys"""

        # Bad P2SH scriptPubKeys

        # non-canonical pushdata
        scriptPubKey = CScript(x('a94c14000000000000000000000000000000000000000087'))
        with self.assertRaises(CBitcoinAddressError):
            CBitcoinAddress.from_scriptPubKey(scriptPubKey)

        # Bad P2PKH scriptPubKeys

        # Missing a byte
        scriptPubKey = CScript(x('76a914000000000000000000000000000000000000000088'))
        with self.assertRaises(CBitcoinAddressError):
            CBitcoinAddress.from_scriptPubKey(scriptPubKey)

        # One extra byte
        scriptPubKey = CScript(x('76a914000000000000000000000000000000000000000088acac'))
        with self.assertRaises(CBitcoinAddressError):
            CBitcoinAddress.from_scriptPubKey(scriptPubKey)

        # One byte changed
        scriptPubKey = CScript(x('76a914000000000000000000000000000000000000000088ad'))
        with self.assertRaises(CBitcoinAddressError):
            CBitcoinAddress.from_scriptPubKey(scriptPubKey) 
開發者ID:petertodd,項目名稱:checklocktimeverify-demos,代碼行數:28,代碼來源:test_wallet.py

示例10: test_from_invalid_scriptPubKey

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def test_from_invalid_scriptPubKey(self):
        """CBitcoinAddress.from_scriptPubKey() with invalid scriptPubKeys"""

        # We should raise a CBitcoinAddressError, not any other type of error

        # Truncated P2SH
        scriptPubKey = CScript(x('a91400000000000000000000000000000000000000'))
        with self.assertRaises(CBitcoinAddressError):
            CBitcoinAddress.from_scriptPubKey(scriptPubKey)

        # Truncated P2PKH
        scriptPubKey = CScript(x('76a91400000000000000000000000000000000000000'))
        with self.assertRaises(CBitcoinAddressError):
            CBitcoinAddress.from_scriptPubKey(scriptPubKey) 
開發者ID:petertodd,項目名稱:checklocktimeverify-demos,代碼行數:16,代碼來源:test_wallet.py

示例11: test_from_redeemScript

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [as 別名]
def test_from_redeemScript(self):
        addr = P2SHBitcoinAddress.from_redeemScript(CScript())
        self.assertEqual(str(addr), '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy') 
開發者ID:petertodd,項目名稱:checklocktimeverify-demos,代碼行數:5,代碼來源:test_wallet.py

示例12: sign

# 需要導入模塊: from bitcoin.core import script [as 別名]
# 或者: from bitcoin.core.script import CScript [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


注:本文中的bitcoin.core.script.CScript方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。