From 921212d217a092680df56cabe83c3843175149f1 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Thu, 22 Dec 2016 11:50:32 +0000 Subject: [PATCH] New randompid command, to allow avoiding payment id reuse --- tipbot/modules/payment.py | 13 ++++++++++++- tipbot/utils.py | 9 ++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tipbot/modules/payment.py b/tipbot/modules/payment.py index f6d91e8..432624f 100644 --- a/tipbot/modules/payment.py +++ b/tipbot/modules/payment.py @@ -161,6 +161,9 @@ def UpdateCoin(data): def Deposit(link,cmd): Help(link) +def RandomPaymentID(link,cmd): + link.send_private(" New payment ID: %s" % GetRandomPaymentID(link)) + def Help(link): GetAccount(link.identity()) link.send_private("You can send %s to your account:" % coinspecs.name); @@ -168,7 +171,8 @@ def Help(link): link.send_private(" Address: %s" % address) if config.openalias_address != None: link.send_private(" (or %s when using OpenAlias)" % config.openalias_address) - link.send_private(" Payment ID: %s" % GetPaymentID(link)) + link.send_private(" Main payment ID: %s" % GetPaymentID(link)) + link.send_private(" OR generate random payment ids at will with: !randompid") link.send_private("Incoming transactions are credited after %d confirmations" % config.payment_confirmations) RegisterModule({ @@ -182,4 +186,11 @@ RegisterCommand({ 'function': Deposit, 'help': "Show instructions about depositing %s" % coinspecs.name }) +RegisterCommand({ + 'module': __name__, + 'name': 'randompid', + 'function': RandomPaymentID, + 'registered': True, + 'help': "Generate a new random payment ID" +}) diff --git a/tipbot/utils.py b/tipbot/utils.py index b1f3ec0..8e74e37 100644 --- a/tipbot/utils.py +++ b/tipbot/utils.py @@ -17,6 +17,8 @@ import time import threading import math import string +import random +from Crypto.Random.random import getrandbits from decimal import * import tipbot.config as config import tipbot.coinspecs as coinspecs @@ -55,8 +57,10 @@ def GetParam(parms,idx): return parms[idx] return None -def GetPaymentID(link): +def GetPaymentID(link,random=False): salt="2u3g55bkwrui32fi3g4bGR$j5g4ugnujb-"+coinspecs.name+"-"; + if random: + salt = salt + "-" + str(time.time()) + "-" + str(getrandbits(128)) p = hashlib.sha256(salt+link.identity()).hexdigest(); try: redis_hset("paymentid",p,link.identity()) @@ -64,6 +68,9 @@ def GetPaymentID(link): log_error('GetPaymentID: failed to set payment ID for %s to redis: %s' % (link.identity(),str(e))) return p +def GetRandomPaymentID(link): + return GetPaymentID(link, True) + def GetIdentityFromPaymentID(p): if not redis_hexists("paymentid",p): log_log('PaymentID %s not found' % p)