adding new management commands for viewing sales and wallet balances

pull/3/head
lalanza808 5 years ago
parent 5142d3ee1d
commit 059da3bcf6

@ -0,0 +1,36 @@
import json
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from core.monero import AuctionWallet
from sales.models import ItemSale
class Command(BaseCommand):
help = 'Shows mempool'
def handle(self, *args, **kwargs):
aw = AuctionWallet()
if aw.connected is False:
raise Exception('Unable to connect to auction wallet RPC endpoint.')
msg = {'sales': []}
item_sales = ItemSale.objects.all()
for sale in item_sales:
ew = aw.wallet.accounts[sale.escrow_account_index]
msg['sales'].append({
'account_index': sale.escrow_account_index,
'sale_id': sale.id,
'platform_paid': sale.platform_paid,
'expected_payment_xmr': sale.expected_payment_xmr,
'received_payment_xmr': sale.received_payment_xmr,
'item_shipped': sale.item_shipped,
'item_received': sale.item_received,
'escrow_complete': sale.escrow_complete,
'sale_finalized': sale.sale_finalized,
'escrow_wallet_balances': {
'locked': float(ew.balances()[0]),
'unlocked': float(ew.balances()[1])
}
})
self.stdout.write(json.dumps(msg))

@ -16,31 +16,24 @@ class Command(BaseCommand):
if aw.connected is False:
raise Exception('Unable to connect to auction wallet RPC endpoint.')
msg = []
msg = {'balances': []}
if kwargs.get('all', False):
self.stdout.write(self.style.SUCCESS(len(aw.wallet.accounts)))
for index,account in enumerate(aw.wallet.accounts):
msg.append({
msg['balances'].append({
"index": index,
"address": str(account.address()),
"locked_balance": str(account.balances()[0]),
"unlocked_balance": str(account.balances()[1]),
"outgoing": account.outgoing(),
"incoming": account.incoming(),
"outgoing": [str(i) for i in account.outgoing()],
"incoming": [str(i) for i in account.incoming()],
})
else:
item_sales = ItemSale.objects.all()
for sale in item_sales:
w = aw.wallet.accounts[sale.escrow_account_index]
msg.append({
msg['balances'].append({
"sale_id": sale.id,
"address": str(w.address()),
"locked_balance": str(w.balances()[0]),
"unlocked_balance": str(w.balances()[1]),
"outgoing": w.outgoing(),
"incoming": w.incoming(),
"outgoing": [str(i) for i in w.outgoing()],
"incoming": [str(i) for i in w.incoming()],
})
for i in msg:
self.stdout.write(self.style.SUCCESS(i))
self.stdout.write(json.dumps(msg))