Пример #1
0
def getrawtransaction( bitcoind_or_opts, txid, verbose=0 ):
   """
   Get a raw transaction by txid.
   Only call out to bitcoind if we need to.
   """
   
   exc_to_raise = None
   bitcoind = get_bitcoind( bitcoind_or_opts )

   if bitcoind is None and bitcoind_or_opts is None:
       raise Exception("No bitcoind or opts given")
   
   for i in xrange(0, MULTIPROCESS_RPC_RETRY):
      try:
         
         try:
            
            tx = bitcoind.getrawtransaction( txid, verbose )
            
         except JSONRPCException, je:
            log.error("\n\n[%s] Caught JSONRPCException from bitcoind: %s\n" % (os.getpid(), repr(je.error)))
            exc_to_raise = je
            
            bitcoind = multiprocess_bitcoind( bitcoind.opts, reset=True)
            continue

         except Exception, e:
            log.error("\n\n[%s] Caught Exception from bitcoind: %s" % (os.getpid(), repr(e)))
            exc_to_raise = e
        
            bitcoind = multiprocess_bitcoind( bitcoind.opts, reset=True)
            continue 
            
         return tx 
Пример #2
0
def getrawtransaction( bitcoind_or_opts, txid, verbose=0 ):
   """
   Get a raw transaction by txid.
   Only call out to bitcoind if we need to.
   """
   
   exc_to_raise = None
   bitcoind = get_bitcoind( bitcoind_or_opts )

   if bitcoind is None and bitcoind_or_opts is None:
       raise Exception("No bitcoind or opts given")
   
   for i in xrange(0, MULTIPROCESS_RPC_RETRY):
      try:
         
         try:
            
            tx = bitcoind.getrawtransaction( txid, verbose )
            
         except JSONRPCException, je:
            log.error("\n\n[%s] Caught JSONRPCException from bitcoind: %s\n" % (os.getpid(), repr(je.error)))
            exc_to_raise = je
            
            bitcoind = multiprocess_bitcoind( bitcoind.opts, reset=True)
            continue

         except Exception, e:
            log.error("\n\n[%s] Caught Exception from bitcoind: %s" % (os.getpid(), repr(e)))
            exc_to_raise = e
        
            bitcoind = multiprocess_bitcoind( bitcoind.opts, reset=True)
            continue 
            
         return tx 
def getblock(bitcoind_or_opts, block_hash):
    """
   Get a block's data, given its hash.
   """

    bitcoind = get_bitcoind(bitcoind_or_opts)
    if bitcoind is None and bitcoind_or_opts is None:
        raise Exception("No bitcoind or opts given")

    exc_to_raise = None
    bitcoind = get_bitcoind(bitcoind_or_opts)
    attempts = 0

    for i in xrange(0, MULTIPROCESS_RPC_RETRY):

        try:
            block_data = bitcoind.getblock(block_hash)

        except JSONRPCException, je:
            log.error("\n\n[%s] Caught JSONRPCException from bitcoind: %s\n" %
                      (os.getpid(), repr(je.error)))
            exc_to_raise = je

            attempts += 1

            # probably a transient bitcoind failure
            # exponential backof with jitter
            time.sleep(2**attempts + random.randint(0, 2**(attempts - 1)))

            bitcoind = multiprocess_bitcoind(bitcoind.opts, reset=True)
            continue

        except Exception, e:
            log.error("\n\n[%s] Caught Exception from bitcoind: %s" %
                      (os.getpid(), repr(e)))
            exc_to_raise = e

            attempts += 1

            # probably a transient network failure
            # exponential backoff with jitter
            time.sleep(2**attempts + random.randint(0, 2**(attempts - 1)))

            bitcoind = multiprocess_bitcoind(bitcoind.opts, reset=True)
            continue
Пример #4
0
def getblock( bitcoind_or_opts, block_hash ):
   """
   Get a block's data, given its hash.
   """
   
   bitcoind = get_bitcoind( bitcoind_or_opts )
   if bitcoind is None and bitcoind_or_opts is None:
       raise Exception("No bitcoind or opts given")
    
   exc_to_raise = None
   bitcoind = get_bitcoind( bitcoind_or_opts )
   attempts = 0
   
   for i in xrange(0, MULTIPROCESS_RPC_RETRY):
      
      try:
         block_data = bitcoind.getblock( block_hash )
         
      except JSONRPCException, je:
         log.error("\n\n[%s] Caught JSONRPCException from bitcoind: %s\n" % (os.getpid(), repr(je.error)))
         exc_to_raise = je
     
         attempts += 1
         
         # probably a transient bitcoind failure
         # exponential backof with jitter
         time.sleep(2**attempts + random.randint( 0, 2**(attempts - 1)) )
         
         bitcoind = multiprocess_bitcoind( bitcoind.opts, reset=True)
         continue
     
      except Exception, e:
         log.error("\n\n[%s] Caught Exception from bitcoind: %s" % (os.getpid(), repr(e)))
         exc_to_raise = e
     
         attempts += 1
         
         # probably a transient network failure
         # exponential backoff with jitter
         time.sleep(2**attempts + random.randint( 0, 2**(attempts - 1)) )
         
         bitcoind = multiprocess_bitcoind( bitcoind.opts, reset=True)
         continue
def getblockhash(bitcoind_or_opts, block_number, reset):
    """
   Get a block's hash, given its ID.
   Return None if there are no options
   """

    exc_to_raise = None  # exception to raise if we fail
    bitcoind = get_bitcoind(bitcoind_or_opts)

    if not reset and bitcoind is None and bitcoind_or_opts is None:
        raise Exception("No bitcoind or opts given")

    if reset:
        new_opts = get_bitcoind_opts(bitcoind_or_opts)
        bitcoind = multiprocess_bitcoind(new_opts, reset=True)

    for i in xrange(0, MULTIPROCESS_RPC_RETRY):
        try:

            try:

                block_hash = bitcoind.getblockhash(block_number)
            except JSONRPCException, je:
                log.error(
                    "\n\n[%s] Caught JSONRPCException from bitcoind: %s\n" %
                    (os.getpid(), repr(je.error)))
                exc_to_raise = je

                bitcoind = multiprocess_bitcoind(bitcoind.opts, reset=True)
                continue

            except Exception, e:
                log.error("\n\n[%s] Caught Exception from bitcoind: %s" %
                          (os.getpid(), repr(e)))
                exc_to_raise = e

                bitcoind = multiprocess_bitcoind(bitcoind.opts, reset=True)
                continue

            return block_hash
Пример #6
0
def getblockhash( bitcoind_or_opts, block_number, reset ):
   """
   Get a block's hash, given its ID.
   Return None if there are no options
   """
  

   exc_to_raise = None  # exception to raise if we fail
   bitcoind = get_bitcoind( bitcoind_or_opts )
   
   if not reset and bitcoind is None and bitcoind_or_opts is None:
       raise Exception("No bitcoind or opts given")
       
   if reset:
       new_opts = get_bitcoind_opts( bitcoind_or_opts )
       bitcoind = multiprocess_bitcoind( new_opts, reset=True )
   
   for i in xrange(0, MULTIPROCESS_RPC_RETRY):
      try:
         
         try:
         
            block_hash = bitcoind.getblockhash( block_number )
         except JSONRPCException, je:
            log.error("\n\n[%s] Caught JSONRPCException from bitcoind: %s\n" % (os.getpid(), repr(je.error)))
            exc_to_raise = je 
        
            bitcoind = multiprocess_bitcoind( bitcoind.opts, reset=True)
            continue
         
         except Exception, e:
            log.error("\n\n[%s] Caught Exception from bitcoind: %s" % (os.getpid(), repr(e)))
            exc_to_raise = e
            
            bitcoind = multiprocess_bitcoind( bitcoind.opts, reset=True)
            continue 
         
         return block_hash
def get_bitcoind(bitcoind_or_opts):
    """
   Given either a bitcoind API endpoint proxy, 
   or a dictionary of options to generate one in a
   process-local context, return a bitcoind API endpoint 
   proxy.
   """

    if type(bitcoind_or_opts) == types.DictType or bitcoind_or_opts is None:

        # instantiate from options
        if bitcoind_or_opts is None:
            bitcoind_or_opts = multiprocess_bitcoind_opts()

        return multiprocess_bitcoind(bitcoind_or_opts)

    else:
        # already an endpoint
        return bitcoind_or_opts
Пример #8
0
def get_bitcoind( bitcoind_or_opts ):
   """
   Given either a bitcoind API endpoint proxy, 
   or a dictionary of options to generate one in a
   process-local context, return a bitcoind API endpoint 
   proxy.
   """ 
   
   if type(bitcoind_or_opts) == types.DictType or bitcoind_or_opts is None:

      # instantiate from options
      if bitcoind_or_opts is None:
          bitcoind_or_opts = multiprocess_bitcoind_opts()

      return multiprocess_bitcoind( bitcoind_or_opts )
   
   else:
      # already an endpoint 
      return bitcoind_or_opts