Python bitcoin.core.script.CScript() Examples
The following are 30
code examples of bitcoin.core.script.CScript().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bitcoin.core.script
, or try the search function
.
Example #1
Source File: transaction.py From clove with GNU General Public License v3.0 | 7 votes |
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, ])
Example #2
Source File: wallet.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
def to_scriptPubKey(self): """Convert an address to a scriptPubKey""" assert self.nVersion == bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'] return script.CScript([script.OP_DUP, script.OP_HASH160, self, script.OP_EQUALVERIFY, script.OP_CHECKSIG])
Example #3
Source File: rpc.py From replace-by-fee-tools with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: rpc.py From replace-by-fee-tools with GNU General Public License v3.0 | 6 votes |
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
Example #5
Source File: test_wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 6 votes |
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'))
Example #6
Source File: test_wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 6 votes |
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'))
Example #7
Source File: test_wallet.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
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'))
Example #8
Source File: test_wallet.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
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'))
Example #9
Source File: rpc.py From replace-by-fee-tools with GNU General Public License v3.0 | 6 votes |
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
Example #10
Source File: rpc.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
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
Example #11
Source File: rpc.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
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
Example #12
Source File: rpc.py From replace-by-fee-tools with GNU General Public License v3.0 | 6 votes |
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
Example #13
Source File: bitcoin_signer.py From hermit with Apache License 2.0 | 6 votes |
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)
Example #14
Source File: test_wallet.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
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'))
Example #15
Source File: test_wallet.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
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'))
Example #16
Source File: test_wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 6 votes |
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'))
Example #17
Source File: rpc.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
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
Example #18
Source File: rpc.py From checklocktimeverify-demos with GNU General Public License v3.0 | 6 votes |
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
Example #19
Source File: test_wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 6 votes |
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'))
Example #20
Source File: genesis.py From GenesisZ with GNU General Public License v3.0 | 6 votes |
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)
Example #21
Source File: channel.py From Lightning with MIT License | 5 votes |
def sign(self, transaction): """Sign a transaction.""" sig = self.signature(transaction) anchor_sig = AnchorScriptSig(self.anchor_index, self.their_sig, self.anchor_redeem) transaction.vin[0].scriptSig = anchor_sig.to_script(sig) # verify signing worked VerifyScript(transaction.vin[0].scriptSig, CScript(self.anchor_redeem).to_p2sh_scriptPubKey(), transaction, 0, (SCRIPT_VERIFY_P2SH,)) return transaction
Example #22
Source File: wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 5 votes |
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])
Example #23
Source File: wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 5 votes |
def to_scriptPubKey(self, nested=False): """Convert an address to a scriptPubKey""" assert self.nVersion == bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'] return script.CScript([script.OP_DUP, script.OP_HASH160, self, script.OP_EQUALVERIFY, script.OP_CHECKSIG])
Example #24
Source File: test_jsonrpcproxy.py From Lightning with MIT License | 5 votes |
def test_json_roundtrip(self): VALUES = [ 42, 0, -42, 2100000000000000, -2100000000000000, "basic string", "\u1111Unicode", "\U00010000Wide Unicode", "\x00\n\t\r\nEscape codes", "\"'\"Quotes", "", None, b"\x00\x01\xFFBinary data", b"", CBase58Data.from_bytes(b'\x00\x01\xFF', 42), P2SHBitcoinAddress.from_bytes(b'\x00\x01\xFF'), P2PKHBitcoinAddress.from_bytes(b'\x00\x01\xFF'), CMutableTxIn(COutPoint(b'\x00'*16+b'\xFF'*16, 42), CScript(b'\x00\x01\xFF'), 42), CMutableTxOut(42, CScript(b'\x00\x01\xFF')), CMutableTransaction([CMutableTxIn(COutPoint(b'\x00'*32, 42), CScript(b'\x00\x01\xFF'), 42), CMutableTxIn(COutPoint(b'\xFF'*32, 42), CScript(b'\xFF\x01\x00'), 43)], [CMutableTxOut(42, CScript(b'\x00\x01\xFF')), CMutableTxOut(43, CScript(b'\xFF\x01\x00'))], 42, 3), [1, b'\x00\x01\xFF', "List Test",], {'a':1, 'key':b'\xFF\x01\x00', 1:'Dictionary Test'}, [{3: [0, 1, 2,],}, [[b'\xFFRecursion Test',],],], ] for value in VALUES: self.assertEqual(from_json(to_json(value)), value)
Example #25
Source File: transactions.py From OpenBazaar-Server with MIT License | 5 votes |
def multisign(self, sigs, redeem_script): """ Signs a multisig transaction. Args: sigs: a `list` of `dict` with format: {"index": 0, "signatures": [sig1, sig2]} redeem_script: the redeem script in hex """ for sig in sigs: i = sig["index"] s = sig["signatures"] self.tx.vin[i].scriptSig = CScript([OP_0, x(s[0]), x(s[1]), CScript(x(redeem_script))]) VerifyScript(self.tx.vin[i].scriptSig, CScript(x(redeem_script)).to_p2sh_scriptPubKey(), self.tx, i, (SCRIPT_VERIFY_P2SH,))
Example #26
Source File: test_wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 5 votes |
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)
Example #27
Source File: test_wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 5 votes |
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)
Example #28
Source File: test_wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 5 votes |
def test_from_redeemScript(self): addr = P2SHBitcoinAddress.from_redeemScript(CScript()) self.assertEqual(str(addr), '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
Example #29
Source File: wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 5 votes |
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])
Example #30
Source File: wallet.py From replace-by-fee-tools with GNU General Public License v3.0 | 5 votes |
def to_scriptPubKey(self, nested=False): """Convert an address to a scriptPubKey""" assert self.nVersion == bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'] return script.CScript([script.OP_DUP, script.OP_HASH160, self, script.OP_EQUALVERIFY, script.OP_CHECKSIG])