fix explorer searching debug issue and make correct_rpc official

pull/3/head
lance 5 years ago
parent acf2220301
commit 0c845aa4fe

@ -1,9 +1,12 @@
from logging import getLogger
from django.conf import settings from django.conf import settings
from monero.daemon import Daemon from monero.daemon import Daemon
from monero.wallet import Wallet from monero.wallet import Wallet
from monero.backends.jsonrpc import JSONRPCDaemon, JSONRPCWallet from monero.backends.jsonrpc import JSONRPCDaemon, JSONRPCWallet
logger = getLogger('django.server')
class AuctionDaemon(object): class AuctionDaemon(object):
def __init__(self): def __init__(self):
self.host = settings.DAEMON_HOST self.host = settings.DAEMON_HOST
@ -50,3 +53,17 @@ class AuctionWallet(object):
self.connected = False self.connected = False
except: except:
self.connected = False self.connected = False
def connect_rpc(rpc_type):
if rpc_type == "daemon":
rpc = AuctionDaemon()
elif rpc_type == "wallet":
rpc = AuctionWallet()
else:
logger.error('[ERROR] Invalid RPC type specified. Use "daemon" or "wallet"')
return False
if rpc.connected is False:
logger.error(f'[ERROR] Auction {rpc_type} is not connected. Stopping task.')
return False
return rpc

@ -4,25 +4,12 @@ from huey import crontab
from huey.contrib.djhuey import periodic_task from huey.contrib.djhuey import periodic_task
from django.conf import settings from django.conf import settings
from django.core.cache import cache from django.core.cache import cache
from core.monero import AuctionWallet, AuctionDaemon from core.monero import connect_rpc
from sales.models import ItemSale from sales.models import ItemSale
logger = logging.getLogger('django.server') logger = logging.getLogger('django.server')
def connect_rpc(rpc_type):
if rpc_type == "daemon":
rpc = AuctionDaemon()
elif rpc_type == "wallet":
rpc = AuctionWallet()
else:
logger.error('[ERROR] Invalid RPC type specified. Use "daemon" or "wallet"')
return False
if rpc.connected is False:
logging.error(f'[ERROR] Auction {rpc_type} is not connected. Stopping task.')
return False
return rpc
@periodic_task(crontab(minute='*/2')) @periodic_task(crontab(minute='*/2'))
def poll_for_buyer_escrow_payments(): def poll_for_buyer_escrow_payments():
wallet_rpc = connect_rpc("wallet") wallet_rpc = connect_rpc("wallet")

@ -1,10 +1,17 @@
from django import template from django import template
from django.conf import settings from django.conf import settings
from core.monero import connect_rpc
register = template.Library() register = template.Library()
@register.filter(is_safe=True) @register.filter(is_safe=True)
def search_block_explorer(param): def search_block_explorer(param):
search_url = f'{settings.BLOCK_EXPLORER}search?value={param}' daemon_rpc = connect_rpc('daemon')
return search_url if daemon_rpc:
net_type = daemon_rpc.daemon.info()['nettype']
explorer_url = settings.BLOCK_EXPLORER % net_type
search_url = f'{explorer_url}/tx/{param}/autorefresh'
return search_url
else:
return '#'

@ -22,7 +22,7 @@
<p class="sale-info"><strong>Network Fee (XMR)</strong>: {{ sale.network_fee_xmr }}</p> <p class="sale-info"><strong>Network Fee (XMR)</strong>: {{ sale.network_fee_xmr }}</p>
<p class="sale-info"><strong>Total Payout (XMR)</strong>: {{ total_seller_payout }}</p> <p class="sale-info"><strong>Total Payout (XMR)</strong>: {{ total_seller_payout }}</p>
<p class="sale-info"><strong>Payout Address</strong>: {{ sale.item.payout_address }}</p> <p class="sale-info"><strong>Payout Address</strong>: {{ sale.item.payout_address }}</p>
<p class="sale-info"><strong>Payout Transaction ID</strong>: <a href="{{ sale.seller_payout_transaction | search_block_explorer }}" target="_blank">{{ sale.seller_payout_transaction }}</a></p> <p class="sale-info"><strong>Payout Transaction ID</strong>: <a href="{{ sale.seller_payout_transaction | search_block_explorer }}">{{ sale.seller_payout_transaction }}</a></p>
<br> <br>
<p class="sale-info">If you found the site useful and had a good experience, please consider sending a tip to the developer address provided at the bottom of the page.</p> <p class="sale-info">If you found the site useful and had a good experience, please consider sending a tip to the developer address provided at the bottom of the page.</p>
<p class="sale-info">Thanks for using {{ site_meta.name }}!</p> <p class="sale-info">Thanks for using {{ site_meta.name }}!</p>

@ -28,11 +28,7 @@ ALLOWED_HOSTS = str(os.environ['ALLOWED_HOSTS']).split(',')
ESCROW_PERIOD_DAYS = os.environ.get('ESCROW_PERIOD_DAYS', 30) ESCROW_PERIOD_DAYS = os.environ.get('ESCROW_PERIOD_DAYS', 30)
PLATFORM_FEE_PERCENT = os.environ.get('PLATFORM_FEE_PERCENT', 0) PLATFORM_FEE_PERCENT = os.environ.get('PLATFORM_FEE_PERCENT', 0)
BLOCK_CONFIRMATIONS_RCV = os.environ.get('BLOCK_CONFIRMATIONS_RCV', 3) BLOCK_CONFIRMATIONS_RCV = os.environ.get('BLOCK_CONFIRMATIONS_RCV', 3)
BLOCK_EXPLORER = 'https://community.xmr.to/explorer/%s'
if DEBUG:
BLOCK_EXPLORER = 'https://community.xmr.to/explorer/stagenet/'
else:
BLOCK_EXPLORER = 'https://community.xmr.to/explorer/mainnet/'
# Application definition # Application definition