Skip to content

Commit

Permalink
feat: filecoin integrate (#7656)
Browse files Browse the repository at this point in the history
* remove print

* feat: integrate FIL coin
  • Loading branch information
thelostone-mc authored Oct 14, 2020
1 parent 45baf5f commit fc2ae81
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 18 deletions.
1 change: 1 addition & 0 deletions app/assets/v2/images/chains/filecoin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions app/assets/v2/js/pages/bounty_details2.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Vue.mixin({
url = `https://kusama.subscan.io/extrinsic/${txn}`;
break;

case 'FIL':
url = `https://filscan.io/#/tipset/message-detail?cid=${txn}`;
break;

default:
url = `https://etherscan.io/tx/${txn}`;

Expand Down Expand Up @@ -109,6 +113,10 @@ Vue.mixin({
url = `https://kusama.subscan.io/account/${address}`;
break;

case 'FIL':
url = `https://filscan.io/#/tipset/address-detail?address=${address}`;
break;

default:
url = `https://etherscan.io/address/${address}`;
}
Expand Down Expand Up @@ -144,6 +152,12 @@ Vue.mixin({
`zilliqa://${address}?amount=${value}` :
`zilliqa://${address}`;
break;

case 'FIL':
qr_string = value ?
`filecoin://${address}?amount=${value}` :
`filecoin://${address}`;
break;
}

return qr_string;
Expand Down Expand Up @@ -305,6 +319,10 @@ Vue.mixin({
tenant = 'POLKADOT';
break;

case 'FIL':
tenant = 'FILECOIN';
break;

default:
tenant = 'ETH';
}
Expand Down
1 change: 1 addition & 0 deletions app/assets/v2/js/pages/hackathon_new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Vue.mixin({
case '0': // bitcoin
case '61': // ethereum classic
case '102': // zilliqa
case '600': // filecoin
case '42220': // celo mainnet
case '44786': // celo alfajores tesnet
type = 'qr';
Expand Down
1 change: 1 addition & 0 deletions app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Vue.mixin({
case '0': // bitcoin
case '61': // ethereum classic
case '102': // zilliqa
case '600': // filecoin
case '42220': // celo mainnet
case '44786': // celo alfajores tesnet
case '717171': // other
Expand Down
33 changes: 33 additions & 0 deletions app/dashboard/migrations/0154_auto_20201012_1044.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 2.2.4 on 2020-10-12 10:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0153_hackathonevent_use_circle'),
]

operations = [
migrations.AlterField(
model_name='bounty',
name='bounty_owner_address',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AlterField(
model_name='bountyfulfillment',
name='fulfiller_address',
field=models.CharField(blank=True, help_text='address to which amount is credited', max_length=100, null=True),
),
migrations.AlterField(
model_name='bountyfulfillment',
name='funder_address',
field=models.CharField(blank=True, help_text='address from which amount is deducted', max_length=100, null=True),
),
migrations.AlterField(
model_name='bountyfulfillment',
name='tenant',
field=models.CharField(blank=True, choices=[('BTC', 'BTC'), ('ETH', 'ETH'), ('ETC', 'ETC'), ('ZIL', 'ZIL'), ('CELO', 'CELO'), ('PYPL', 'PYPL'), ('POLKADOT', 'POLKADOT'), ('FILECOIN', 'FILECOIN'), ('OTHERS', 'OTHERS')], help_text='specific tenant type under the payout_type', max_length=10, null=True),
),
]
15 changes: 4 additions & 11 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class Bounty(SuperModel):
github_url = models.URLField(db_index=True)
github_issue_details = JSONField(default=dict, blank=True, null=True)
github_comments = models.IntegerField(default=0)
bounty_owner_address = models.CharField(max_length=50, blank=True, null=True)
bounty_owner_address = models.CharField(max_length=100, blank=True, null=True)
bounty_owner_email = models.CharField(max_length=255, blank=True)
bounty_owner_github_username = models.CharField(max_length=255, blank=True, db_index=True)
bounty_owner_name = models.CharField(max_length=255, blank=True)
Expand Down Expand Up @@ -1092,21 +1092,13 @@ def is_notification_eligible(self, var_to_check=True):
bool: Whether or not the Bounty is eligible for outbound notifications.
"""
print(f'### GITCOIN BOT A2 network {self.network}')
print(f'### GITCOIN BOT A2 settings.DEBUG {settings.DEBUG}')
print(f'### GITCOIN BOT A2 settings.ENV {settings.ENV}')

if self.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK:
return False

print(f'### GITCOIN BOT A3')

if self.network == 'mainnet' and (settings.DEBUG or settings.ENV != 'prod'):
return False

print(f'### GITCOIN BOT A4')

print(f'### GITCOIN BOT A5 - Is Eligible')
return True

@property
Expand Down Expand Up @@ -1418,6 +1410,7 @@ class BountyFulfillment(SuperModel):
('CELO', 'CELO'),
('PYPL', 'PYPL'),
('POLKADOT', 'POLKADOT'),
('FILECOIN', 'FILECOIN'),
('OTHERS', 'OTHERS')
]

Expand All @@ -1429,8 +1422,8 @@ class BountyFulfillment(SuperModel):
# TODO: RETIRE
fulfiller_metadata = JSONField(default=dict, blank=True)

fulfiller_address = models.CharField(max_length=50, null=True, blank=True, help_text="address to which amount is credited")
funder_address = models.CharField(max_length=50, null=True, blank=True, help_text="address from which amount is deducted")
fulfiller_address = models.CharField(max_length=100, null=True, blank=True, help_text="address to which amount is credited")
funder_address = models.CharField(max_length=100, null=True, blank=True, help_text="address from which amount is deducted")

# TODO: rename to fulfiller_profile
profile = models.ForeignKey('dashboard.Profile', related_name='fulfilled', on_delete=models.CASCADE, null=True, help_text="fulfillers's profile")
Expand Down
4 changes: 0 additions & 4 deletions app/dashboard/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,9 @@ def maybe_market_to_github(bounty, event_name, profile_pairs=None):
bool: Whether or not the Github comment was posted successfully.
"""
print('### GITCOIN BOT A1')
if not bounty.is_notification_eligible(var_to_check=settings.GITHUB_CLIENT_ID):
print(f'### GITCOIN BOT A6 NOT POSTING')
return False

print(f'### GITCOIN BOT A6')
# Define posting specific variables.
comment_id = None
url = bounty.github_url
Expand All @@ -617,7 +614,6 @@ def maybe_market_to_github(bounty, event_name, profile_pairs=None):

# Prepare the comment message string.
msg = build_github_notification(bounty, event_name, profile_pairs)
print(f'### GITCOIN BOT A7 {msg}')
if not msg:
return False

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

from django.conf import settings
from django.utils import timezone

import requests
from dashboard.sync.helpers import record_payout_activity, txn_already_used

headers = {
'Host': 'gitcoin.co'
}

def find_txn_on_filecoin_explorer(fulfillment):
token_name = fulfillment.token_name
payeeAddress = fulfillment.fulfiller_address

if token_name != 'FIL':
return None

url = 'https://api.filscan.io:8700/rpc/v1'

data = {
"id": 1,
"jsonrpc": "2.0",
"params": [
{
"address": payeeAddress,
"offset_range": {
"start": 0,
"count": 25
}
}
],
"method": "filscan.MessageByAddress"
}

response = requests.post(url, headers=headers, data=json.dumps(data)).json()
if (
response and
'result' in response and
'data' in response['result']
):
for txn in response['result']['data']:
if (
isValidTxn(fulfillment, txn) == 'success' and
not txn_already_used(txn['cid'], token_name)
):
return txn
return None


def get_filecoin_txn_status(fulfillment):

txnid = fulfillment.payout_tx_id
token_name = fulfillment.token_name

if token_name != 'FIL':
return None

if not txnid or txnid == "0x0":
return None

url = 'https://api.filscan.io:8700/rpc/v1'

data = {
"id": 1,
"jsonrpc": "2.0",
"params": [ txnid ],
"method": "filscan.MessageDetails"
}

filscan_response = requests.post(url, headers=headers, data=json.dumps(data)).json()
if filscan_response and 'result' in filscan_response:
txn = filscan_response['result']
if 'exit_code' in txn:
return 'expired'
elif isValidTxn(fulfillment, txn):
return 'success'

return None


def sync_filecoin_payout(fulfillment):
if not fulfillment.payout_tx_id or fulfillment.payout_tx_id == "0x0":
txn = find_txn_on_filecoin_explorer(fulfillment)
if txn:
fulfillment.payout_tx_id = txn['cid']
fulfillment.save()

if fulfillment.payout_tx_id:
txn_status = get_filecoin_txn_status(fulfillment)

if txn_status == 'success':
fulfillment.payout_status = 'done'
fulfillment.accepted_on = timezone.now()
fulfillment.accepted = True
record_payout_activity(fulfillment)

elif txn_status == 'expired':
fulfillment.payout_status = 'expired'

fulfillment.save()


def isValidTxn(fulfillment, txn):
funderAddress = fulfillment.bounty.bounty_owner_address
amount = fulfillment.payout_amount
payeeAddress = fulfillment.fulfiller_address

if (
txn['from'] == funderAddress.lower() and
txn['to'] == payeeAddress.lower() and
float(txn['value']) == float(amount) and
txn['method_name'] == 'transfer'
):
return True

return False
6 changes: 5 additions & 1 deletion app/dashboard/templates/bounty/new_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ <h1 class="text-center">Fund Issue</h1>

{% if is_staff %}
<label class="btn btn-radio chain-btn d-flex align-items-center mr-2 mb-2 font-weight-bold py-2 px-4" :class="{'active': chainId === '0'}">
<input type="radio" name="bounty_chain" id="0_chain" value="0" v-model="chainId"><img class="mr-2" src="{% static 'v2/images/chains/bitcoin.svg' %}" alt="" width="16"> BTC
<input type="radio" name="bounty_chain" id="0_chain" value="0" v-model="chainId"><img class="mr-2" src="{% static 'v2/images/chains/bitcoin.svg' %}" alt="" width="20"> BTC
</label>

<label class="btn btn-radio chain-btn d-flex align-items-center mr-2 mb-2 font-weight-bold py-2 px-4" :class="{'active': chainId === '600'}">
<input type="radio" name="bounty_chain" id="600_chain" value="600" v-model="chainId"><img class="mr-2" src="{% static 'v2/images/chains/filecoin.svg' %}" alt="" width="20"> Filecoin
</label>

<label class="btn btn-radio chain-btn d-flex align-items-center mr-2 mb-2 font-weight-bold py-2 px-4" :class="{'active': chainId === '666'}">
Expand Down
6 changes: 5 additions & 1 deletion app/dashboard/templates/dashboard/hackathon/new_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ <h1 class="text-center">Fund Prize</h1>
{% if is_staff %}

<label class="btn btn-radio chain-btn d-flex align-items-center mr-2 mb-2 font-weight-bold py-2 px-4" :class="{'active': chainId === '0'}">
<input type="radio" name="bounty_chain" id="0_chain" value="0" v-model="chainId"><img class="mr-2" src="{% static 'v2/images/chains/bitcoin.svg' %}" alt="" width="16"> BTC
<input type="radio" name="bounty_chain" id="0_chain" value="0" v-model="chainId"><img class="mr-2" src="{% static 'v2/images/chains/bitcoin.svg' %}" alt="" width="20"> BTC
</label>

<label class="btn btn-radio chain-btn d-flex align-items-center mr-2 mb-2 font-weight-bold py-2 px-4" :class="{'active': chainId === '600'}">
<input type="radio" name="bounty_chain" id="600_chain" value="600" v-model="chainId"><img class="mr-2" src="{% static 'v2/images/chains/filecoin.svg' %}" alt="" width="20"> Filecoin
</label>

<label class="btn btn-radio chain-btn d-flex align-items-center mr-2 mb-2 font-weight-bold py-2 px-4" :class="{'active': chainId === '666'}">
Expand Down
3 changes: 3 additions & 0 deletions app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from dashboard.sync.celo import sync_celo_payout
from dashboard.sync.etc import sync_etc_payout
from dashboard.sync.eth import sync_eth_payout
from dashboard.sync.filecoin import sync_filecoin_payout
from dashboard.sync.polkadot import sync_polkadot_payout
from dashboard.sync.zil import sync_zil_payout
from eth_abi import decode_single, encode_single
Expand Down Expand Up @@ -506,6 +507,8 @@ def sync_payout(fulfillment):
sync_celo_payout(fulfillment)
elif token_name == 'ZIL':
sync_zil_payout(fulfillment)
elif token_name == 'FIL':
sync_filecoin_payout(fulfillment)

elif fulfillment.payout_type == 'polkadot_ext':
sync_polkadot_payout(fulfillment)
Expand Down
1 change: 0 additions & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5417,7 +5417,6 @@ def create_bounty_v1(request):
event_name = 'new_bounty'
record_bounty_activity(bounty, user, event_name)
maybe_market_to_email(bounty, event_name)
print('### GITCOIN BOT A0')
maybe_market_to_github(bounty, event_name)

response = {
Expand Down

0 comments on commit fc2ae81

Please sign in to comment.