def get_core_priv(): proxy = Proxy() address = proxy.getnewaddress() # address = 'tb1qntuv4la0lh072jtr6ce3avrsghnc200dgamlpq' proxy._call("walletpassphrase", "P@55w0rd", 5) wif = proxy.dumpprivkey(address) proxy._call("walletlock") print("address", address) return CBitcoinSecret(str(wif))
def bitcoin_rpc(*args, **kwargs): ''' Wrapper of bitcoin.rpc ''' try: rpc = Proxy(settings.BITCOIN_API) return rpc._call(*args, **kwargs) except Exception as err: logging.error(err) return False
if sys.version_info.major < 3: sys.stderr.write("Sorry, Python 3.x required by this example.\n") sys.exit(1) import hashlib from bitcoin import SelectParams from bitcoin.core import b2x, b2lx, lx, COIN, COutPoint, CTxOut, CTxIn, CTxInWitness, CTxWitness, CScriptWitness, CMutableTransaction, Hash160 from bitcoin.core.script import CScript, OP_0, SignatureHash, SIGHASH_ALL, SIGVERSION_WITNESS_V0 from bitcoin.wallet import CBitcoinSecret, P2WPKHBitcoinAddress from bitcoin.rpc import Proxy SelectParams("regtest") connection = Proxy() if connection._call("getblockchaininfo")["chain"] != "regtest": sys.stderr.write("This example is intended for regtest only.\n") sys.exit(1) # Create the (in)famous correct brainwallet secret key. h = hashlib.sha256(b'correct horse battery staple').digest() seckey = CBitcoinSecret.from_secret_bytes(h) # Create an address from that private key. public_key = seckey.pub scriptPubKey = CScript([OP_0, Hash160(public_key)]) address = P2WPKHBitcoinAddress.from_scriptPubKey(scriptPubKey) # Give the private key to bitcoind (for ismine, listunspent, etc). connection._call("importprivkey", str(seckey))