mirror of
https://git.wownero.com/wownero/tippero.git
synced 2024-08-15 00:33:14 +00:00
New randompid command, to allow avoiding payment id reuse
This commit is contained in:
parent
e387fa67ab
commit
921212d217
2 changed files with 20 additions and 2 deletions
|
@ -161,6 +161,9 @@ def UpdateCoin(data):
|
||||||
def Deposit(link,cmd):
|
def Deposit(link,cmd):
|
||||||
Help(link)
|
Help(link)
|
||||||
|
|
||||||
|
def RandomPaymentID(link,cmd):
|
||||||
|
link.send_private(" New payment ID: %s" % GetRandomPaymentID(link))
|
||||||
|
|
||||||
def Help(link):
|
def Help(link):
|
||||||
GetAccount(link.identity())
|
GetAccount(link.identity())
|
||||||
link.send_private("You can send %s to your account:" % coinspecs.name);
|
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)
|
link.send_private(" Address: %s" % address)
|
||||||
if config.openalias_address != None:
|
if config.openalias_address != None:
|
||||||
link.send_private(" (or %s when using OpenAlias)" % config.openalias_address)
|
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)
|
link.send_private("Incoming transactions are credited after %d confirmations" % config.payment_confirmations)
|
||||||
|
|
||||||
RegisterModule({
|
RegisterModule({
|
||||||
|
@ -182,4 +186,11 @@ RegisterCommand({
|
||||||
'function': Deposit,
|
'function': Deposit,
|
||||||
'help': "Show instructions about depositing %s" % coinspecs.name
|
'help': "Show instructions about depositing %s" % coinspecs.name
|
||||||
})
|
})
|
||||||
|
RegisterCommand({
|
||||||
|
'module': __name__,
|
||||||
|
'name': 'randompid',
|
||||||
|
'function': RandomPaymentID,
|
||||||
|
'registered': True,
|
||||||
|
'help': "Generate a new random payment ID"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ import time
|
||||||
import threading
|
import threading
|
||||||
import math
|
import math
|
||||||
import string
|
import string
|
||||||
|
import random
|
||||||
|
from Crypto.Random.random import getrandbits
|
||||||
from decimal import *
|
from decimal import *
|
||||||
import tipbot.config as config
|
import tipbot.config as config
|
||||||
import tipbot.coinspecs as coinspecs
|
import tipbot.coinspecs as coinspecs
|
||||||
|
@ -55,8 +57,10 @@ def GetParam(parms,idx):
|
||||||
return parms[idx]
|
return parms[idx]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def GetPaymentID(link):
|
def GetPaymentID(link,random=False):
|
||||||
salt="2u3g55bkwrui32fi3g4bGR$j5g4ugnujb-"+coinspecs.name+"-";
|
salt="2u3g55bkwrui32fi3g4bGR$j5g4ugnujb-"+coinspecs.name+"-";
|
||||||
|
if random:
|
||||||
|
salt = salt + "-" + str(time.time()) + "-" + str(getrandbits(128))
|
||||||
p = hashlib.sha256(salt+link.identity()).hexdigest();
|
p = hashlib.sha256(salt+link.identity()).hexdigest();
|
||||||
try:
|
try:
|
||||||
redis_hset("paymentid",p,link.identity())
|
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)))
|
log_error('GetPaymentID: failed to set payment ID for %s to redis: %s' % (link.identity(),str(e)))
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
def GetRandomPaymentID(link):
|
||||||
|
return GetPaymentID(link, True)
|
||||||
|
|
||||||
def GetIdentityFromPaymentID(p):
|
def GetIdentityFromPaymentID(p):
|
||||||
if not redis_hexists("paymentid",p):
|
if not redis_hexists("paymentid",p):
|
||||||
log_log('PaymentID %s not found' % p)
|
log_log('PaymentID %s not found' % p)
|
||||||
|
|
Loading…
Reference in a new issue