Keep track of funds awaiting confirmation

This commit is contained in:
moneromooo 2015-01-26 17:52:39 +00:00
parent d270ca14f9
commit 50455a0d08
3 changed files with 23 additions and 8 deletions

View file

@ -90,15 +90,18 @@ for modulename in modulenames:
def GetBalance(link,cmd): def GetBalance(link,cmd):
nick=link.user.nick nick=link.user.nick
try: try:
balance = RetrieveBalance(link) balance,confirming = RetrieveBalance(link)
sbalance = AmountToString(balance) sbalance = AmountToString(balance)
if balance < coinspecs.atomic_units: if balance < coinspecs.atomic_units:
if balance == 0: if balance == 0:
link.send("%s's balance is %s" % (nick, sbalance)) msg="%s's balance is %s" % (nick, sbalance)
else: else:
link.send("%s's balance is %s (%.16g %s)" % (nick, sbalance, float(balance) / coinspecs.atomic_units, coinspecs.name)) msg="%s's balance is %s (%.16g %s)" % (nick, sbalance, float(balance) / coinspecs.atomic_units, coinspecs.name)
else: else:
link.send("%s's balance is %s" % (nick, sbalance)) msg="%s's balance is %s" % (nick, sbalance)
if confirming > 0:
msg = msg + " (%s awaiting confirmation)" % (AmountToString(confirming))
link.send(msg)
except Exception, e: except Exception, e:
log_error('GetBalance: exception: %s' % str(e)) log_error('GetBalance: exception: %s' % str(e))
link.send("An error has occured") link.send("An error has occured")

View file

@ -80,15 +80,19 @@ def UpdateCoin(data):
#print 'Got j: %s' % str(j) #print 'Got j: %s' % str(j)
if "result" in j: if "result" in j:
result = j["result"] result = j["result"]
cp = redis_pipeline()
cp.delete('confirming_payments')
if "payments" in result: if "payments" in result:
payments = result["payments"] payments = result["payments"]
new_payments = [] new_payments = []
n_confirming = 0 n_confirming = 0
new_scan_block_height = scan_block_height new_scan_block_height = scan_block_height
for p in payments: for p in payments:
payment_id=p["payment_id"]
tx_hash = p["tx_hash"] tx_hash = p["tx_hash"]
bh = p["block_height"] bh = p["block_height"]
ut = p["block_height"] ut = p["block_height"]
amount=p["amount"]
if redis_sismember("processed_txs",tx_hash): if redis_sismember("processed_txs",tx_hash):
continue continue
log_log('UpdateCoin: Looking at payment %s' % str(p)) log_log('UpdateCoin: Looking at payment %s' % str(p))
@ -103,6 +107,14 @@ def UpdateCoin(data):
log_info('Payment %s has %d/%d confirmations' % (str(p),confirmations,confirmations_needed)) log_info('Payment %s has %d/%d confirmations' % (str(p),confirmations,confirmations_needed))
n_confirming += 1 n_confirming += 1
new_scan_block_height = None new_scan_block_height = None
try:
recipient = GetIdentityFromPaymentID(payment_id)
if not recipient:
raise RuntimeError('Payment ID %s not found' % payment_id)
log_info('UpdateCoin: Found payment %s to %s for %s' % (tx_hash,recipient, AmountToString(amount)))
cp.hincrby('confirming_payments',recipient,amount)
except Exception,e:
log_error('UpdateCoin: No identity found for payment id %s, tx hash %s, amount %s: %s' % (payment_id, tx_hash, amount, str(e)))
payments=new_payments payments=new_payments
log_info('UpdateCoin: Got %d mature payments and %d confirming payments' % (len(payments),n_confirming)) log_info('UpdateCoin: Got %d mature payments and %d confirming payments' % (len(payments),n_confirming))
if len(payments) > 0: if len(payments) > 0:
@ -132,6 +144,7 @@ def UpdateCoin(data):
pipe.execute() pipe.execute()
except Exception,e: except Exception,e:
log_error('UpdateCoin: failed to set scan_block_height: %s' % str(e)) log_error('UpdateCoin: failed to set scan_block_height: %s' % str(e))
cp.execute()
else: else:
log_error('UpdateCoin: No results in get_bulk_payments reply') log_error('UpdateCoin: No results in get_bulk_payments reply')
except Exception,e: except Exception,e:

View file

@ -223,10 +223,9 @@ def RetrieveTipbotBalance(force_refresh=False):
def RetrieveBalance(link): def RetrieveBalance(link):
try: try:
balance = redis_hget("balances",link.identity()) balance = redis_hget("balances",link.identity()) or 0
if balance == None: confirming = redis_hget("confirming_payments",link.identity()) or 0
balance = 0 return long(balance), long(confirming)
return long(balance)
except Exception, e: except Exception, e:
log_error('RetrieveBalance: exception: %s' % str(e)) log_error('RetrieveBalance: exception: %s' % str(e))
raise raise