Exemple #1
0
def GetUserIDFromPaymentID(paymentid):
    if not redis_hexists("paymentid", paymentid):
        log_log('PaymentID %s not found' % paymentid)
        return None
    identity = redis_hget("paymentid", paymentid)
    log_log('PaymentID %s => %s' % (paymentid, str(identity)))
    return identity
Exemple #2
0
def GetUserIDFromPaymentID(paymentid):
    if not redis_hexists("paymentid", paymentid):
        log_log("PaymentID %s not found" % paymentid)
        return None
    identity = redis_hget("paymentid", paymentid)
    log_log("PaymentID %s => %s" % (paymentid, str(identity)))
    return identity
Exemple #3
0
def RetrieveWalletBalance(wallet_host, wallet_port, force_refresh=False):
    global cached_wallet_balance, cached_wallet_unlocked_balance, cached_wallet_balance_timestamp
    if not force_refresh and cached_wallet_balance_timestamp and time.time() - cached_wallet_balance_timestamp < 35:
        return cached_wallet_balance, cached_wallet_unlocked_balance

    j = SendJSONRPCCommand(wallet_host, wallet_port, "getbalance", None)
    if not "result" in j:
        log_error("RetrieveWalletBalance: result not found in reply")
        raise RuntimeError("")
        return
    result = j["result"]
    if not "balance" in result:
        log_error("RetrieveWalletBalance: balance not found in result")
        raise RuntimeError("")
        return
    if not "unlocked_balance" in result:
        log_error("RetrieveWalletBalance: unlocked_balance not found in result")
        raise RuntimeError("")
        return
    balance = result["balance"]
    unlocked_balance = result["unlocked_balance"]
    log_log("RetrieveWalletBalance: balance: %s" % str(balance))
    log_log("RetrieveWalletBalance: unlocked_balance: %s" % str(unlocked_balance))
    pending = long(balance) - long(unlocked_balance)
    if pending < 0:
        log_error(
            "RetrieveWalletBalance: Negative pending balance! balance %s, unlocked %s"
            % (str(balance), str(unlocked_balance))
        )
        raise RuntimeError("")
        return
    cached_wallet_balance_timestamp = time.time()
    cached_wallet_balance = balance
    cached_wallet_unlocked_balance = unlocked_balance
    return balance, unlocked_balance
Exemple #4
0
def RetrieveWalletBalance(wallet_host, wallet_port, force_refresh=False):
    global cached_wallet_balance, cached_wallet_unlocked_balance, cached_wallet_balance_timestamp
    if not force_refresh and cached_wallet_balance_timestamp and time.time(
    ) - cached_wallet_balance_timestamp < 35:
        return cached_wallet_balance, cached_wallet_unlocked_balance

    j = SendJSONRPCCommand(wallet_host, wallet_port, "getbalance", None)
    if not "result" in j:
        log_error('RetrieveWalletBalance: result not found in reply')
        raise RuntimeError("")
        return
    result = j["result"]
    if not "balance" in result:
        log_error('RetrieveWalletBalance: balance not found in result')
        raise RuntimeError("")
        return
    if not "unlocked_balance" in result:
        log_error(
            'RetrieveWalletBalance: unlocked_balance not found in result')
        raise RuntimeError("")
        return
    balance = result["balance"]
    unlocked_balance = result["unlocked_balance"]
    log_log('RetrieveWalletBalance: balance: %s' % str(balance))
    log_log('RetrieveWalletBalance: unlocked_balance: %s' %
            str(unlocked_balance))
    pending = long(balance) - long(unlocked_balance)
    if pending < 0:
        log_error(
            'RetrieveWalletBalance: Negative pending balance! balance %s, unlocked %s'
            % (str(balance), str(unlocked_balance)))
        raise RuntimeError("")
        return
    cached_wallet_balance_timestamp = time.time()
    cached_wallet_balance = balance
    cached_wallet_unlocked_balance = unlocked_balance
    return balance, unlocked_balance
Exemple #5
0
 if not full_history:
   cp.delete('confirming_payments')
 if "payments" in result:
   payments = result["payments"]
   new_payments = []
   n_confirming = 0
   new_scan_block_height = scan_block_height
   for p in payments:
     payment_id=p["payment_id"]
     tx_hash = p["tx_hash"]
     bh = p["block_height"]
     ut = p["block_height"]
     amount=p["amount"]
     if not full_history and redis_sismember("processed_txs",tx_hash):
       continue
     log_log('UpdateCoin: Looking at payment %s' % str(p))
     confirmations = height-1-bh
     confirmations_needed = max(config_confirmations,ut-height)
     if confirmations >= confirmations_needed:
       log_info('Payment %s is now confirmed' % str(p))
       new_payments.append(p)
       if new_scan_block_height and bh > new_scan_block_height:
         new_scan_block_height = bh
     else:
       log_info('Payment %s has %d/%d confirmations' % (str(p),confirmations,confirmations_needed))
       n_confirming += 1
       new_scan_block_height = None
       try:
         recipient = GetUserIDFromPaymentID(payment_id)
         if not recipient:
           raise RuntimeError('Payment ID %s not found' % payment_id)
     cp.delete('confirming_payments')
 if "payments" in result:
     payments = result["payments"]
     new_payments = []
     n_confirming = 0
     new_scan_block_height = scan_block_height
     for p in payments:
         payment_id = p["payment_id"]
         tx_hash = p["tx_hash"]
         bh = p["block_height"]
         ut = p["block_height"]
         amount = p["amount"]
         if not full_history and redis_sismember(
                 "processed_txs", tx_hash):
             continue
         log_log('UpdateCoin: Looking at payment %s' % str(p))
         confirmations = height - 1 - bh
         confirmations_needed = max(config_confirmations,
                                    ut - height)
         if confirmations >= confirmations_needed:
             log_info('Payment %s is now confirmed' % str(p))
             new_payments.append(p)
             if new_scan_block_height and bh > new_scan_block_height:
                 new_scan_block_height = bh
         else:
             log_info('Payment %s has %d/%d confirmations' %
                      (str(p), confirmations, confirmations_needed))
             n_confirming += 1
             new_scan_block_height = None
             try:
                 recipient = GetUserIDFromPaymentID(payment_id)
Exemple #7
0
def SendJSONRPCCommand(host, port, method, params):
    try:
        http = httplib.HTTPConnection(host, port, timeout=20)
    except Exception, e:
        log_error('SendJSONRPCCommand: Error connecting to %s:%u: %s' %
                  (host, port, str(e)))
        raise
    d = dict(id="0", jsonrpc="2.0", method=method, params=params)
    try:
        j = json.dumps(d).encode()
    except Exception, e:
        log_error('SendJSONRPCCommand: Failed to encode JSON: %s' % str(e))
        http.close()
        raise
    log_log('SendJSONRPCCommand: Sending json as body: %s' % j)
    headers = None
    try:
        http.request("POST", "/json_rpc", body=j)
    except Exception, e:
        log_error('SendJSONRPCCommand: Failed to post request: %s' % str(e))
        http.close()
        raise
    response = http.getresponse()
    if response.status != 200:
        log_error('SendJSONRPCCommand: Error, received reply status %s' %
                  str(response.status))
        http.close()
        raise RuntimeError("Error " + response.status)
    s = response.read()
    log_log('SendJSONRPCCommand: Received reply status %s: %s' %
Exemple #8
0

def SendJSONRPCCommand(host, port, method, params):
    try:
        http = httplib.HTTPConnection(host, port, timeout=20)
    except Exception, e:
        log_error("SendJSONRPCCommand: Error connecting to %s:%u: %s" % (host, port, str(e)))
        raise
    d = dict(id="0", jsonrpc="2.0", method=method, params=params)
    try:
        j = json.dumps(d).encode()
    except Exception, e:
        log_error("SendJSONRPCCommand: Failed to encode JSON: %s" % str(e))
        http.close()
        raise
    log_log("SendJSONRPCCommand: Sending json as body: %s" % j)
    headers = None
    try:
        http.request("POST", "/json_rpc", body=j)
    except Exception, e:
        log_error("SendJSONRPCCommand: Failed to post request: %s" % str(e))
        http.close()
        raise
    response = http.getresponse()
    if response.status != 200:
        log_error("SendJSONRPCCommand: Error, received reply status %s" % str(response.status))
        http.close()
        raise RuntimeError("Error " + response.status)
    s = response.read()
    log_log(
        "SendJSONRPCCommand: Received reply status %s: %s"