From 5bc84dd8b3ea845e3e04757967f588b0508c3d63 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Wed, 1 Apr 2020 23:18:49 +0530 Subject: [PATCH] celo: update to support cUSD and cGLD --- app/assets/v2/js/pages/create_bounty/token.js | 2 +- app/assets/v2/js/pages/new_bounty.js | 2 +- .../management/commands/sync_etc_payouts.py | 10 +++++--- app/dashboard/sync/celo.py | 25 ++++++++----------- app/dashboard/sync/etc.py | 6 +++-- app/dashboard/sync/zil.py | 6 +++-- app/dashboard/utils.py | 2 +- 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/app/assets/v2/js/pages/create_bounty/token.js b/app/assets/v2/js/pages/create_bounty/token.js index 02b815a4976..2209d39c775 100644 --- a/app/assets/v2/js/pages/create_bounty/token.js +++ b/app/assets/v2/js/pages/create_bounty/token.js @@ -76,7 +76,7 @@ createBounty = data => { 'eventTag': metadata.eventTag, 'auto_approve_workers': data.auto_approve_workers ? 'True' : 'False', 'web3_type': 'qr', - 'activity': data.activity + 'activity': data.activity, 'bounty_owner_address': data.funderAddress }; diff --git a/app/assets/v2/js/pages/new_bounty.js b/app/assets/v2/js/pages/new_bounty.js index 7bebd74b813..2df871f8fa2 100644 --- a/app/assets/v2/js/pages/new_bounty.js +++ b/app/assets/v2/js/pages/new_bounty.js @@ -4,7 +4,7 @@ document.web3network = 'mainnet'; load_tokens(); -const qr_tokens = [ 'ETC', 'CELO', 'ZIL' ]; +const qr_tokens = [ 'ETC', 'cGLD', 'cUSD', 'ZIL' ]; const updateOnNetworkOrTokenChange = () => { const tokenName = $('select[name=denomination]').select2('data')[0] && diff --git a/app/dashboard/management/commands/sync_etc_payouts.py b/app/dashboard/management/commands/sync_etc_payouts.py index 530f75074d4..a14f5402f0d 100644 --- a/app/dashboard/management/commands/sync_etc_payouts.py +++ b/app/dashboard/management/commands/sync_etc_payouts.py @@ -17,9 +17,10 @@ ''' -from datetime import datetime, timedelta +from datetime import timedelta from django.core.management.base import BaseCommand +from django.utils import timezone from dashboard.models import BountyFulfillment from dashboard.utils import sync_payout @@ -34,10 +35,11 @@ def handle(self, *args, **options): payout_status='pending' ) - timeout_period = datetime.now() - timedelta(minutes=5) - pending_fulfillments.filter(created__gt=timeout_period).update(payout_status='expired') + timeout_period = timezone.now() - timedelta(minutes=5) - fulfillments = pending_fulfillments.filter(created__lte=timeout_period) + pending_fulfillments.filter(created_on__lt=timeout_period).update(payout_status='expired') + + fulfillments = pending_fulfillments.filter(created_on__lte=timeout_period) for fulfillment in fulfillments.all(): sync_payout(fulfillment) diff --git a/app/dashboard/sync/celo.py b/app/dashboard/sync/celo.py index 7b2d10be166..8618899bed8 100644 --- a/app/dashboard/sync/celo.py +++ b/app/dashboard/sync/celo.py @@ -6,18 +6,15 @@ def find_txn_on_celo_explorer(fulfillment, network='mainnet'): token_name = fulfillment.token_name - if token_name != 'CELO': + if token_name != 'cGLD' and token_name != 'cUSD': return None funderAddress = fulfillment.bounty.bounty_owner_address amount = fulfillment.payout_amount payeeAddress = fulfillment.fulfiller_address - if network == 'alfajores': - blockscout_url = f'https://alfajores-blockscout.celo-testnet.org/api?module=account&action=txlist&address={funderAddress}' - else: - # TODO: validate mainnet URL - blockscout_url = f'https://blockscout.com/celo/mainnet/api?module=account&action=txlist&address={funderAddress}' + # TODO: UPDATE WITH MAINNET URL. Using alfajores until then + blockscout_url = f'https://alfajores-blockscout.celo-testnet.org/api?module=account&action=txlist&address={funderAddress}' blockscout_response = requests.get(blockscout_url).json() if blockscout_response['message'] and blockscout_response['result']: @@ -36,11 +33,8 @@ def get_celo_txn_status(txnid, network='mainnet'): if not txnid: return None - if network == 'alfajores': - blockscout_url = f'https://alfajores-blockscout.celo-testnet.org/api?module=transaction&action=gettxinfo&txhash={txnid}' - else: - # TODO: validate mainnet URL - blockscout_url = f'https://blockscout.com/etc/{network}/api?module=transaction&action=gettxinfo&txhash={txnid}' + # TODO: UPDATE WITH MAINNET URL. Using alfajores until then + blockscout_url = f'https://alfajores-blockscout.celo-testnet.org/api?module=transaction&action=gettxinfo&txhash={txnid}' blockscout_response = requests.get(blockscout_url).json() @@ -61,13 +55,14 @@ def get_celo_txn_status(txnid, network='mainnet'): def sync_celo_payout(fulfillment): - network = 'alfajores' # TODO: decide where network will be obtained from if not fulfillment.payout_tx_id: - txn = find_txn_on_celo_explorer(fulfillment, network) - fulfillment.payout_tx_id = txn['hash'] + txn = find_txn_on_celo_explorer(fulfillment) + if txn: + fulfillment.payout_tx_id = txn['hash'] if fulfillment.payout_tx_id: - if get_celo_txn_status(fulfillment.payout_tx_id, network).get('has_mined'): + txn_status = get_celo_txn_status(fulfillment.payout_tx_id) + if txn_status and txn_status.get('has_mined'): fulfillment.payout_status = 'done' fulfillment.accepted_on = timezone.now() fulfillment.accepted = True diff --git a/app/dashboard/sync/etc.py b/app/dashboard/sync/etc.py index 20bc1b602be..84bd5d4cda0 100644 --- a/app/dashboard/sync/etc.py +++ b/app/dashboard/sync/etc.py @@ -53,9 +53,11 @@ def get_etc_txn_status(txnid, network='mainnet'): def sync_etc_payout(fulfillment): if not fulfillment.payout_tx_id: txn = find_txn_on_etc_explorer(fulfillment) - fulfillment.payout_tx_id = txn['hash'] + if txn: + fulfillment.payout_tx_id = txn['hash'] if fulfillment.payout_tx_id: - if get_etc_txn_status(fulfillment.payout_tx_id).get('has_mined'): + txn_status = get_etc_txn_status(fulfillment.payout_tx_id) + if txn_status and txn_status.get('has_mined'): fulfillment.payout_status = 'done' fulfillment.accepted_on = timezone.now() fulfillment.accepted = True diff --git a/app/dashboard/sync/zil.py b/app/dashboard/sync/zil.py index 14e97122da3..4f6b58a0b8e 100644 --- a/app/dashboard/sync/zil.py +++ b/app/dashboard/sync/zil.py @@ -61,10 +61,12 @@ def get_zil_txn_status(txnid, network='mainnet'): def sync_zil_payout(fulfillment): if not fulfillment.payout_tx_id: txn = find_txn_on_zil_explorer(fulfillment) - fulfillment.payout_tx_id = txn['hash'] + if txn: + fulfillment.payout_tx_id = txn['hash'] if fulfillment.payout_tx_id: - if get_zil_txn_status(fulfillment.payout_tx_id).get('has_mined'): + txn_status = get_zil_txn_status(fulfillment.payout_tx_id) + if txn_status and txn_status.get('has_mined'): fulfillment.payout_status = 'done' fulfillment.accepted_on = timezone.now() fulfillment.accepted = True diff --git a/app/dashboard/utils.py b/app/dashboard/utils.py index abc78f151f5..f6bc5e6064a 100644 --- a/app/dashboard/utils.py +++ b/app/dashboard/utils.py @@ -481,7 +481,7 @@ def sync_payout(fulfillment): if token_name == 'ETC': sync_etc_payout(fulfillment) - elif token_name == 'CELO': + elif token_name == 'cUSD' or token_name == 'cGLD': sync_celo_payout(fulfillment) elif token_name == 'ZIL': sync_zil_payout(fulfillment)