-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove print * feat: integrate FIL coin
- Loading branch information
1 parent
45baf5f
commit fc2ae81
Showing
12 changed files
with
189 additions
and
18 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters