Skip to content

Commit

Permalink
celo: update to support cUSD and cGLD
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Apr 2, 2020
1 parent ca4112c commit 5bc84dd
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/create_bounty/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] &&
Expand Down
10 changes: 6 additions & 4 deletions app/dashboard/management/commands/sync_etc_payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
25 changes: 10 additions & 15 deletions app/dashboard/sync/celo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand All @@ -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()

Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/dashboard/sync/etc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/dashboard/sync/zil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5bc84dd

Please sign in to comment.