switching to "whereabouts" for locations and making some new mgmt commands

pull/3/head
lalanza808 5 years ago
parent 8af3788b7f
commit 9ae4832c2d

@ -0,0 +1,46 @@
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 balances of all sale items'
def add_arguments(self, parser):
parser.add_argument('-a', '--all', action='store_true', help='Whether or not to scan whole wallet vs item sales', default=False)
def handle(self, *args, **kwargs):
aw = AuctionWallet()
if aw.connected is False:
raise Exception('Unable to connect to auction wallet RPC endpoint.')
msg = []
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({
"index": index,
"address": str(account.address()),
"locked_balance": str(account.balances()[0]),
"unlocked_balance": str(account.balances()[1]),
"outgoing": account.outgoing(),
"incoming": account.incoming(),
})
else:
item_sales = ItemSale.objects.all()
for sale in item_sales:
w = aw.wallet.accounts[sale.escrow_account_index]
msg.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(),
})
for i in msg:
self.stdout.write(self.style.SUCCESS(i))

@ -0,0 +1,17 @@
import json
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from core.monero import AuctionDaemon
from sales.models import ItemSale
class Command(BaseCommand):
help = 'Shows mempool'
def handle(self, *args, **kwargs):
ad = AuctionDaemon()
if ad.connected is False:
raise Exception('Unable to connect to auction daemon RPC endpoint.')
msg = str(ad.daemon.mempool())
self.stdout.write(self.style.SUCCESS(msg))

@ -7,11 +7,12 @@ class CreateItemForm(forms.ModelForm):
class Meta: class Meta:
model = Item model = Item
fields = ['name', 'description', 'ask_price_xmr', 'payout_address'] fields = ['name', 'description', 'whereabouts', 'ask_price_xmr', 'payout_address']
labels = { labels = {
'ask_price_xmr': 'Asking Price (XMR)', 'ask_price_xmr': 'Asking Price (XMR)',
'payout_address': 'Payout Wallet Address' 'payout_address': 'Payout Wallet Address'
} }
help_texts = { help_texts = {
'payout_address': 'Monero address where funds will be sent after sale is confirmed' 'payout_address': 'Monero address where funds will be sent after sale is confirmed',
'whereabouts': 'A simple pointer to your general region - a nearby ZIP code would be perfect.'
} }

@ -0,0 +1,19 @@
# Generated by Django 2.2.8 on 2020-01-10 16:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('items', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='item',
name='whereabouts',
field=models.CharField(default=0, max_length=100),
preserve_default=False,
),
]

@ -19,6 +19,7 @@ class Item(models.Model):
ask_price_xmr = models.FloatField() ask_price_xmr = models.FloatField()
available = models.BooleanField(default=True) available = models.BooleanField(default=True)
payout_address = models.CharField(max_length=100, validators=[address_is_valid_monero]) payout_address = models.CharField(max_length=100, validators=[address_is_valid_monero])
whereabouts = models.CharField(max_length=100)
def __str__(self): def __str__(self):
return f"{self.id} - {self.owner} - {self.name}" return f"{self.id} - {self.owner} - {self.name}"

@ -121,7 +121,7 @@ def notify_seller_of_funds_received():
else: else:
return False return False
@periodic_task(crontab(minute='*/30')) @periodic_task(crontab(minute='*/1'))
def pay_sellers_on_sold_items(): def pay_sellers_on_sold_items():
aw = AuctionWallet() aw = AuctionWallet()
if aw.connected is False: if aw.connected is False:
@ -129,33 +129,35 @@ def pay_sellers_on_sold_items():
item_sales = ItemSale.objects.filter(item_received=True, payment_received=True).filter(seller_paid=False) item_sales = ItemSale.objects.filter(item_received=True, payment_received=True).filter(seller_paid=False)
for sale in item_sales: for sale in item_sales:
email_template = EmailTemplate(
item=sale,
scenario='sale_completed',
role='seller'
)
if sale.seller_notified_of_payout is False:
sent = email_template.send()
sale.seller_notified_of_payout = True
sale.save()
try: try:
txs = aw.wallet.accounts[sale.escrow_account_index].transfer( print(f'sending agreed payment, {sale.agreed_price_xmr} XMR, from account index #{sale.escrow_account_index} to {sale.item.owner.username} for sale #{sale.id} ({sale.item.name})')
sale_account = aw.wallet.accounts[sale.escrow_account_index]
if sale_account.balances()[1] > Decimal(0.0):
aw.wallet.accounts[sale.escrow_account_index].transfer(
sale.item.payout_address, sale.agreed_price_xmr, relay=True sale.item.payout_address, sale.agreed_price_xmr, relay=True
) )
if txs:
sale.seller_paid = True sale.seller_paid = True
sale.escrow_complete = True sale.escrow_complete = True
sale.save() sale.save()
return True
else: else:
print('not enough funds here to transfer. try later')
return False return False
except Exception as e: except Exception as e:
print('unable to make payment: ', e) print('unable to make payment: ', e)
return False return False
@periodic_task(crontab(hour='*/6')) email_template = EmailTemplate(
item=sale,
scenario='sale_completed',
role='seller'
)
if sale.seller_notified_of_payout is False:
sent = email_template.send()
sale.seller_notified_of_payout = True
sale.save()
@periodic_task(crontab(minute='*'))
def pay_platform_on_sold_items(): def pay_platform_on_sold_items():
aw = AuctionWallet() aw = AuctionWallet()
if aw.connected is False: if aw.connected is False:
@ -163,17 +165,22 @@ def pay_platform_on_sold_items():
aof = settings.PLATFORM_WALLET_ADDRESS aof = settings.PLATFORM_WALLET_ADDRESS
if aof is None: if aof is None:
aof = aw.wallet.accounts[0].address() aof = str(aw.wallet.accounts[0].address())
item_sales = ItemSale.objects.filter(escrow_complete=True, seller_paid=True, item_received=True).filter(platform_paid=False) item_sales = ItemSale.objects.filter(escrow_complete=True, seller_paid=True, item_received=True).filter(platform_paid=False)
for sale in item_sales: for sale in item_sales:
sale_account = aw.wallet.accounts[sale.escrow_account_index]
try: try:
txs = aw.wallet.accounts[sale.escrow_account_index].sweep_all(aof) if sale_account.balances()[1] >= Decimal(0.0):
if txs: print(f'paying out platform wallet, {aof}, remaining funds in account #{sale.escrow_account_index} for sale #{sale.id}')
aw.wallet.accounts[sale.escrow_account_index].sweep_all(aof)
sale.platform_paid = True sale.platform_paid = True
sale.sale_finalized = True sale.sale_finalized = True
sale.save() sale.save()
return True return True
else:
print('not enough funds here to sweep. try later')
return False
except Exception as e: except Exception as e:
print('unable to sweep funds: ', e) print('unable to sweep funds: ', e)
return False return False

@ -10,7 +10,7 @@
</header> </header>
<section> <section>
{% if not item.available %}<p>This item is currently pending sale. Bidding is temporarily closed.</p>{% endif %} {% if not item.available %}<p>This item is currently pending sale. Bidding is temporarily closed.</p>{% endif %}
<p class="sale-info"><strong>Whereabouts</strong>: Whereabouts</p> <p class="sale-info"><strong>Whereabouts</strong>: <a href="https://duckduckgo.com/?q={{ item.whereabouts }}" target="_blank">{{ item.whereabouts }}</a></p>
<p class="sale-info"><strong>Creation</strong>: {{ item.list_date | date:"d M Y H:i:s" }}</p> <p class="sale-info"><strong>Creation</strong>: {{ item.list_date | date:"d M Y H:i:s" }}</p>
<p class="sale-info"><strong>Last Updated</strong>: {{ item.last_updated | date:"d M Y H:i:s" }}</p> <p class="sale-info"><strong>Last Updated</strong>: {{ item.last_updated | date:"d M Y H:i:s" }}</p>
<p class="sale-info"><strong>Description</strong>: {{ item.description }}</p> <p class="sale-info"><strong>Description</strong>: {{ item.description }}</p>