-
Notifications
You must be signed in to change notification settings - Fork 0
/
moneropos.py
66 lines (50 loc) · 2.49 KB
/
moneropos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from monero.wallet import Wallet
from monero.backends.jsonrpc import JSONRPCWallet
from threading import Thread
from time import sleep
class MoneroPoS:
def __init__(self, host='127.0.0.1', port=28088, foundIncomingTransactionFunction=None, findConfirmedTransactionAutomatically=False):
self.host = host
self.port = port
self.foundIncomingTransactionFunction = foundIncomingTransactionFunction
self.findConfirmedIncomingTransactionsAutomatically = findConfirmedTransactionAutomatically
self.wallet = Wallet(JSONRPCWallet(host=self.host, port=self.port))
if findConfirmedTransactionAutomatically:
Thread(
target=self._loopForConfirmedIncomingTransactions,
)
def _loopForConfirmedIncomingTransactions(self):
while True:
txHistory = self.wallet.incoming()
for tx in txHistory:
print(tx)
sleep(5)
continue
def mainWalletAddress(self):
return {'success': True, 'address': self.wallet.address()}
def generateNewPayment(self, paymentId, usdAmount=None, xmrAmount=None, processingFunction=None, **kwargs):
self.newAddress = self.wallet.address().with_payment_id(paymentId)
if processingFunction:
processingFunction(
newAddress=self.newAddress,
usdAmount=usdAmount,
xmrAmount=xmrAmount,
**kwargs,
)
return {'success': True, 'address': self.newAddress}
def findConfirmedIncomingTransactions(self, paymentId, xmrAmount, integratedAddress=None):
txHistory = self.wallet.incoming(payment_id=paymentId)
txList = list(txHistory)
foundAConfirmedTransaction = bool(txList)
sumAmount = sum(transaction.amount for transaction in txList)
transactionSumAmountIsCorrect = float(sumAmount) >= float(xmrAmount)
print(sumAmount)
print(transactionSumAmountIsCorrect)
return {
'success': True,
'txList': txList,
'paymentId': paymentId,
'integratedAddress': integratedAddress,
'foundAConfirmedTransaction': foundAConfirmedTransaction,
'transactionSumAmountIsCorrect': transactionSumAmountIsCorrect,
}