Wait for some number of confirmations before acting on a deposit

This commit is contained in:
moneromooo 2015-01-25 18:36:17 +00:00
parent 1ad4474315
commit 55ec6907d3
2 changed files with 54 additions and 22 deletions

View file

@ -34,6 +34,7 @@ withdrawal_fee=None # None defaults to the network default fee
min_withdraw_amount = None # None defaults to the withdrawal fee min_withdraw_amount = None # None defaults to the withdrawal fee
withdrawal_mixin=0 withdrawal_mixin=0
disable_withdraw_on_error = True disable_withdraw_on_error = True
payment_confirmations = 6
admins = ["freenode:moneromooo", "freenode:moneromoo"] admins = ["freenode:moneromooo", "freenode:moneromoo"]

View file

@ -52,6 +52,20 @@ def UpdateCoin(data):
last_wallet_update_time = time.time() last_wallet_update_time = time.time()
return return
try:
j = SendDaemonHTMLCommand("getheight")
except Exception,e:
log_error('UpdateCoin: error getting height: %s' % str(e))
return
if not "height" in j:
log_error('UpdateCoin: error getting height: height not found in %s' % str(j))
return
try:
height=long(j["height"])
except Exception,e:
log_error('UpdateCoin: error getting height: %s' % str(e))
return
full_payment_ids = redis_hgetall("paymentid") full_payment_ids = redis_hgetall("paymentid")
#print 'Got full payment ids: %s' % str(full_payment_ids) #print 'Got full payment ids: %s' % str(full_payment_ids)
payment_ids = [] payment_ids = []
@ -69,32 +83,49 @@ def UpdateCoin(data):
if "payments" in result: if "payments" in result:
payments = result["payments"] payments = result["payments"]
log_info('UpdateCoin: Got %d payments' % len(payments)) log_info('UpdateCoin: Got %d payments' % len(payments))
new_payments = []
n_confirming = 0
for p in payments: for p in payments:
log_log('UpdateCoin: Looking at payment %s' % str(p)) log_log('UpdateCoin: Looking at payment %s' % str(p))
bh = p["block_height"] bh = p["block_height"]
if bh > scan_block_height: confirmations = height-1-bh
scan_block_height = bh if confirmations >= config.payment_confirmations:
log_log('UpdateCoin: seen payments up to block %d' % scan_block_height) log_info('Payment %s is now confirmed' % str(p))
try: new_payments.append(p)
pipe = redis_pipeline() else:
pipe.set("scan_block_height", scan_block_height) log_info('Payment %s has %d/%d confirmations' % (str(p),confirmations,config.payment_confirmations))
log_log('UpdateCoin: processing payments') n_confirming += 1
payments=new_payments
if len(payments) > 0:
for p in payments: for p in payments:
payment_id=p["payment_id"] if bh > scan_block_height:
tx_hash=p["tx_hash"] scan_block_height = bh
amount=p["amount"] log_info('UpdateCoin: Got %d mature payments and %d confirming payments' % (len(payments),n_confirming))
try: log_log('UpdateCoin: updated payments up to block %d' % scan_block_height)
recipient = GetIdentityFromPaymentID(payment_id) try:
if not recipient: pipe = redis_pipeline()
raise RuntimeError('Payment ID %s not found' % payment_id) pipe.set("scan_block_height", scan_block_height)
log_info('UpdateCoin: Found payment %s to %s for %s' % (tx_hash,recipient, AmountToString(amount))) log_log('UpdateCoin: processing payments')
pipe.hincrby("balances",recipient,amount); for p in payments:
except Exception,e: payment_id=p["payment_id"]
log_error('UpdateCoin: No identity found for payment id %s, tx hash %s, amount %s: %s' % (payment_id, tx_hash, amount, str(e))) tx_hash=p["tx_hash"]
log_log('UpdateCoin: Executing received payments pipeline') amount=p["amount"]
pipe.execute() bh = p["block_height"]
except Exception,e: try:
log_error('UpdateCoin: failed to set scan_block_height: %s' % str(e)) 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)))
if bh < height-config.payment_confirmations:
pipe.hincrby("balances",recipient,amount)
else:
log_log('%d/%d confirmations' % (height-1-bh,config.payment_confirmations))
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)))
log_log('UpdateCoin: Executing received payments pipeline')
pipe.execute()
except Exception,e:
log_error('UpdateCoin: failed to set scan_block_height: %s' % str(e))
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: