Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/binance chain integration #7738

Merged
merged 31 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
35633ae
include binance_ext in models
chibie Oct 21, 2020
ca0b76e
feat(sync): get binance tx status; sync payout
chibie Oct 22, 2020
e3441a4
feat(binance): sync payouts via management command
chibie Oct 22, 2020
00be2e9
remove handling of replaced tx
chibie Oct 22, 2020
71f0816
fix(sync): optimize use of .get
chibie Oct 22, 2020
a7e74f8
feat(views): + binance_ext in bounty payout/fulfill
chibie Oct 22, 2020
1297511
fix(sync): some optimizations
chibie Oct 22, 2020
50c63d2
fix typo
chibie Oct 22, 2020
b0fe173
fix(binance): set host to gitcoin.co in headers
chibie Oct 23, 2020
bbdf704
feat: update bounty details
chibie Oct 26, 2020
27a5e0c
add placeholders for binance wallet connections
chibie Oct 27, 2020
c890fc7
fix(bounty): fix active class for polkadot selection
chibie Oct 27, 2020
2be26ce
Add BNB svg icon and include BNB token in bounties payable coins.
amustapha Oct 27, 2020
a0367fe
fix active class for polkadot selection
chibie Oct 27, 2020
af6fd71
Merge branch 'feature/binance-chain-integration' of github.com:gitcoi…
amustapha Oct 27, 2020
f68240c
setup binance sync test
chibie Oct 28, 2020
cfa0351
Change to Binance coin
amustapha Oct 28, 2020
191483c
Merge branch 'feature/binance-chain-integration' of github.com:gitcoi…
amustapha Oct 28, 2020
153ad92
feat(binance): add util to get wallet address balance
chibie Oct 30, 2020
d188bc3
feat(binance): handle chainChanged and connection events
chibie Oct 30, 2020
d9cc09c
feat(binance): fetch connected accounts
chibie Oct 30, 2020
9cc376d
feat(binance): add util to transfer token via extension
chibie Oct 30, 2020
28c19b3
feat(binance): add binance_extension.js; refactor
chibie Oct 30, 2020
6e7e0b7
fix(model): add binance tenant
chibie Oct 30, 2020
4c2e773
feat(binance): add missing svg
chibie Oct 30, 2020
fcae00f
feat(binance): select binance in hackathon new bounty
chibie Oct 30, 2020
9a985f1
Merge branch 'master' into feature/binance-chain-integration
chibie Nov 26, 2020
c1762f6
feat(sync): save pending transactions; celo/etc
chibie Nov 26, 2020
504d1c6
remove binance init comment
chibie Nov 26, 2020
c95d5cd
compress binance.svg with svgo
chibie Dec 2, 2020
aab9609
Merge branch 'master' into feature/binance-chain-integration
chibie Dec 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def handle(self, *args, **options):
for fulfillment in polkadot_pending_fulfillments.all():
sync_payout(fulfillment)

# binance extension
binance_pending_fulfillments = pending_fulfillments.filter(payout_type='binance_ext')
if binance_pending_fulfillments:
for fulfillment in binance_pending_fulfillments.all():
sync_payout(fulfillment)

# QR
qr_pending_fulfillments = pending_fulfillments.filter(payout_type='qr')
Expand Down
23 changes: 23 additions & 0 deletions app/dashboard/migrations/0157_auto_20201021_2319.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.4 on 2020-10-21 23:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0156_auto_20201015_1742'),
]

operations = [
migrations.AlterField(
model_name='bounty',
name='web3_type',
field=models.CharField(choices=[('legacy_gitcoin', 'Legacy Bounty'), ('bounties_network', 'Bounties Network'), ('qr', 'QR Code'), ('web3_modal', 'Web3 Modal'), ('polkadot_ext', 'Polkadot Ext'), ('binance_ext', 'Binance Ext'), ('fiat', 'Fiat'), ('manual', 'Manual')], default='bounties_network', max_length=50),
),
migrations.AlterField(
model_name='bountyfulfillment',
name='payout_type',
field=models.CharField(blank=True, choices=[('bounties_network', 'bounties_network'), ('qr', 'qr'), ('fiat', 'fiat'), ('web3_modal', 'web3_modal'), ('polkadot_ext', 'polkadot_ext'), ('binance_ext', 'binance_ext'), ('manual', 'manual')], help_text='payment type used to make the payment', max_length=20, null=True),
),
]
2 changes: 2 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ class Bounty(SuperModel):
('qr', 'QR Code'),
('web3_modal', 'Web3 Modal'),
('polkadot_ext', 'Polkadot Ext'),
('binance_ext', 'Binance Ext'),
('fiat', 'Fiat'),
('manual', 'Manual')
)
Expand Down Expand Up @@ -1399,6 +1400,7 @@ class BountyFulfillment(SuperModel):
('fiat', 'fiat'),
('web3_modal', 'web3_modal'),
('polkadot_ext', 'polkadot_ext'),
('binance_ext', 'binance_ext'),
('manual', 'manual')
]

Expand Down
69 changes: 69 additions & 0 deletions app/dashboard/sync/binance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import logging

from django.utils import timezone

import requests
from dashboard.sync.helpers import record_payout_activity

logger = logging.getLogger(__name__)

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0. 2272.118 Safari/537.36.'}
chibie marked this conversation as resolved.
Show resolved Hide resolved


def get_binance_txn_status(fulfillment):

txnid = fulfillment.payout_tx_id
network = fulfillment.bounty.network if fulfillment.bounty.network else None

if not txnid:
return None

response = { 'status': 'pending' }

try:
if network == 'mainnet':
binance_url = f'https://bsc-dataseed.binance.org'
else:
binance_url = f'https://data-seed-prebsc-1-s1.binance.org:8545'

data = {
'jsonrpc': '2.0',
'method': 'eth_getTransactionReceipt',
'params': [ txnid ],
'id': 0
}

binance_response = requests.post(binance_url, json=data, headers=headers).json()

result = binance_response['result']

response = { 'status': 'pending' }

if result:
tx_status = int(result.get('status'), 16) # convert hex to decimal

if tx_status == '1':
response = { 'status': 'done' }
elif tx_status == '0':
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved
response = { 'status': 'expired' }

except Exception as e:
logger.error(f'error: get_binance_txn_status - {e}')

finally:
return response


def sync_binance_payout(fulfillment):
if fulfillment.payout_tx_id:
txn_status = get_binance_txn_status(fulfillment)
if txn_status:
chibie marked this conversation as resolved.
Show resolved Hide resolved
if txn_status.get('status') == 'done':
fulfillment.payout_status = 'done'
fulfillment.accepted_on = timezone.now()
fulfillment.accepted = True
record_payout_activity(fulfillment)
elif txn_status.get('status') == 'expired':
fulfillment.payout_status = 'expired'

fulfillment.save()
chibie marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from dashboard.models import (
Activity, BlockedUser, Bounty, BountyFulfillment, HackathonRegistration, Profile, UserAction,
)
from dashboard.sync.binance import sync_binance_payout
from dashboard.sync.btc import sync_btc_payout
from dashboard.sync.celo import sync_celo_payout
from dashboard.sync.etc import sync_etc_payout
Expand Down Expand Up @@ -511,7 +512,10 @@ def sync_payout(fulfillment):
sync_filecoin_payout(fulfillment)

elif fulfillment.payout_type == 'polkadot_ext':
sync_polkadot_payout(fulfillment)
sync_polkadot_payout(fulfillment)

elif fulfillment.payout_type == 'binance_ext':
sync_binance_payout(fulfillment)


def get_bounty_id(issue_url, network):
Expand Down