Пример #1
0
def get_utxo_provider_client():
   """
   Get or instantiate our blockchain UTXO provider's client (i.e. chain.com; falling back to bitcoind otherwise).
   Return None if we were unable to connect
   """
   
   global blockchain_client 
   global chaincom_opts
   global blockchain_opts
   
   # acquire configuration (which we should already have)
   bitcoin_opts, chaincom_opts = configure( interactive=False )
   
   chaincom_id = chaincom_opts['api_key_id']
   chaincom_secret = chaincom_opts['api_key_secret']
   
   try:
      blockchain_client = pybitcoin.ChainComClient( chaincom_id, chaincom_secret )
      return blockchain_client
      
   except Exception, e:
      log.exception(e)
      
      # try bitcoind...
      try:
         blockchain_client = BitcoindClient( blockchain_opts['bitcoind_user'], blockchain_opts['bitcoind_passwd'],
                                             server=blockchain_opts['bitcoind_server'], port=str(blockchain_opts['bitcoind_port']), use_https=blockchain_opts.get('bitcoind_use_https', False) )
         
         return blockchain_client
         
      except Exception, e:
         log.exception(e)
         return None 
Пример #2
0
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 )
Пример #3
0
    privkey_str = None
    pp = pprint.PrettyPrinter()

    if len(sys.argv) != 4:
        print >> sys.stderr, "Usage: %s [json_file] [namespace_id] [private_key]"
        sys.exit(1)

    # try to connect to our broadcast provider
    try:
        chaincom_id, chaincom_secret = get_chaincom_api_keys()
    except Exception, e:
        traceback.print_exc()
        print >> sys.stderr, "Failed to get Chain.com API keys"
        sys.exit(1)

    chaincom_client = pybitcoin.ChainComClient(chaincom_id, chaincom_secret)

    # get our namespace's names
    try:
        with open(sys.argv[1], "r") as f:
            names_json = f.read()

    except Exception, e:
        traceback.print_exc()
        print >> sys.stderr, "Failed to read '%s'" % sys.argv[1]
        sys.exit(1)

    privkey_str = sys.argv[3]
    namespace_id = sys.argv[2]

    print "--------------------------------------------------------------"