def connect_utxo_provider( utxo_opts ): """ Set up and return a UTXO provider client. """ global SUPPORTED_UTXO_PROVIDERS if not utxo_opts.has_key("utxo_provider"): raise Exception("No UTXO provider given") utxo_provider = utxo_opts['utxo_provider'] if not utxo_provider in SUPPORTED_UTXO_PROVIDERS: raise Exception("Unsupported UTXO provider '%s'" % utxo_provider) if utxo_provider == "chain_com": return pybitcoin.ChainComClient( utxo_opts['api_key_id'], utxo_opts['api_key_secret'] ) elif utxo_provider == "blockcypher": return pybitcoin.BlockcypherClient( utxo_opts['api_token'] ) elif utxo_provider == "blockchain_info": return pybitcoin.BlockchainInfoClient( utxo_opts['api_token'] ) elif utxo_provider == "bitcoind_utxo": return pybitcoin.BitcoindClient( utxo_opts['rpc_username'], utxo_opts['rpc_password'], use_https=utxo_opts['use_https'], server=utxo_opts['server'], port=utxo_opts['port'], version_byte=utxo_opts['version_byte'] ) elif utxo_provider == "mock_utxo": # requires blockstack tests to be installed from ..tests import connect_mock_utxo_provider return connect_mock_utxo_provider( utxo_opts ) else: raise Exception("Unrecognized UTXO provider '%s'" % utxo_provider )
def tx_get_unspents(address, utxo_client, min_confirmations=TX_MIN_CONFIRMATIONS): """ Given an address get unspent outputs (UTXOs) Return array of UTXOs on success Raise UTXOException on error """ assert utxo_client is not None, "Utxo client is null" min_confirmations = 1 if utxo_client is None: utxo_opts = get_bitcoin_regtest_opts() utxo_client = pybitcoin.BitcoindClient( utxo_opts['bitcoind_user'], utxo_opts['bitcoind_passwd'], use_https=utxo_opts['bitcoind_use_https'], server=utxo_opts['bitcoind_server'], port=utxo_opts['bitcoind_port']) data = pybitcoin.get_unspents(address, utxo_client) try: assert type(data) == list, "No UTXO list returned" for d in data: assert isinstance(d, dict), 'Invalid UTXO information returned' assert 'value' in d, 'Missing value in UTXOs from {}'.format( address) except AssertionError, ae: log.exception(ae) raise
def get_tx_broadcaster(): utxo_opts = get_bitcoin_regtest_opts() return pybitcoin.BitcoindClient(utxo_opts['rpc_username'], utxo_opts['rpc_password'], use_https=utxo_opts['use_https'], server=utxo_opts['server'], port=utxo_opts['port'], version_byte=utxo_opts['version_byte'])
def get_utxo_client(): opts = get_bitcoin_regtest_opts() utxo_provider = pybitcoin.BitcoindClient(opts.get("bitcoind_user", None), opts.get("bitcoind_passwd"), \ use_https=opts.get("bitcoind_use_https", None),server=opts.get("bitcoind_server", None),port=opts.get("bitcoind_port"), version_byte=virtualchain.version_byte) return utxo_provider