-
-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
casper crosschain | bounties/hackathons (#9291)
* update models * update views * update utils/mgmt cmd * sync function * update new bounty pages * fetch browserify casper + svg logo * fix casper chain id * start casper extension * + usable casper js sdk * extension wip * validate cspr addresses * add address + tx urls * finish casper extension * minify svg & js sdk * serialize deploy to / fro * add payout forwarder endpoint * handle rpc error * final fixes * review fixes * less complexity * restore tx expiry in tezos * review update
- Loading branch information
Showing
17 changed files
with
247 additions
and
13 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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,93 @@ | ||
const payWithCasperExtension = async(fulfillment_id, to_address, vm, modal) => { | ||
|
||
const amount = vm.fulfillment_context.amount; | ||
const token_name = vm.bounty.token_name; | ||
const tenant = vm.getTenant(token_name, vm.bounty.web3_type); | ||
|
||
const { CasperClient, DeployUtil, PublicKey, Signer } = casper; | ||
const casperClient = new CasperClient(`/api/v1/reverse-proxy/${tenant}`); | ||
|
||
const isConnected = await Signer.isConnected(); | ||
|
||
if (!isConnected) { | ||
try { | ||
Signer.sendConnectionRequest(); | ||
} catch (e) { | ||
_alert({ message: gettext('Please download or enable CasperLabs Signer extension.') }, 'danger'); | ||
return; | ||
} | ||
} | ||
|
||
const selectedAddress = await Signer.getActivePublicKey(); | ||
|
||
const paymentAmount = 10000; // for native-transfers the payment price is fixed | ||
const id = fulfillment_id; | ||
const gasPrice = 1; // gasPrice for native transfers can be set to 1 | ||
|
||
// time that the deploy will remain valid for, in milliseconds | ||
// the default value is 1800000 ms (30 minutes) | ||
const ttl = 1800000; | ||
|
||
const fromPublicKey = PublicKey.fromHex(selectedAddress); | ||
const toPublicKey = PublicKey.fromHex(to_address); | ||
|
||
let deployParams = new DeployUtil.DeployParams(fromPublicKey, 'casper', gasPrice, ttl); | ||
|
||
const session = DeployUtil.ExecutableDeployItem.newTransfer( | ||
amount * 10 ** vm.decimals, | ||
toPublicKey, | ||
null, | ||
id | ||
); | ||
|
||
const payment = DeployUtil.standardPayment(paymentAmount); | ||
const deploy = DeployUtil.makeDeploy(deployParams, session, payment); | ||
const deployJson = DeployUtil.deployToJson(deploy); | ||
|
||
const signedDeployJson = await Signer.sign(deployJson, selectedAddress, to_address); | ||
const signedDeploy = DeployUtil.deployFromJson(signedDeployJson); | ||
|
||
try { | ||
const deployHash = await casperClient.putDeploy(signedDeploy); | ||
|
||
callback(null, selectedAddress, deployHash); | ||
} catch (e) { | ||
modal.closeModal(); | ||
callback(e); | ||
} | ||
|
||
function callback(error, from_address, txn) { | ||
if (error) { | ||
_alert({ message: gettext('Unable to payout bounty due to: ' + error) }, 'danger'); | ||
console.log(error); | ||
} else { | ||
|
||
const payload = { | ||
payout_type: 'casper_ext', | ||
tenant: 'CASPER', | ||
amount: amount, | ||
token_name: token_name, | ||
funder_address: from_address, | ||
payout_tx_id: txn | ||
}; | ||
|
||
modal.closeModal(); | ||
const apiUrlBounty = `/api/v1/bounty/payout/${fulfillment_id}`; | ||
|
||
fetchData(apiUrlBounty, 'POST', payload).then(response => { | ||
if (200 <= response.status && response.status <= 204) { | ||
vm.fetchBounty(); | ||
_alert('Payment Successful', 'success'); | ||
|
||
} else { | ||
_alert('Unable to make payout bounty. Please try again later', 'danger'); | ||
console.error(`error: bounty payment failed with status: ${response.status} and message: ${response.message}`); | ||
} | ||
}).catch(function(error) { | ||
_alert('Unable to make payout bounty. Please try again later', 'danger'); | ||
console.log(error); | ||
}); | ||
} | ||
} | ||
}; | ||
|
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
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,63 @@ | ||
import logging | ||
|
||
from django.utils import timezone | ||
|
||
import requests | ||
from dashboard.sync.helpers import record_payout_activity | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_casper_txn_status(fulfillment): | ||
txnid = fulfillment.payout_tx_id | ||
token_name = fulfillment.token_name | ||
funderAddress = fulfillment.funder_address | ||
amount = fulfillment.payout_amount | ||
|
||
if token_name != 'CSPR' or not txnid: | ||
return None | ||
|
||
try: | ||
data = { | ||
'id': 0, | ||
'jsonrpc': '2.0', | ||
'method': 'info_get_deploy', | ||
'params': [ txnid ] | ||
} | ||
casper_rpc_url = 'http://3.142.224.108:7777/rpc' | ||
casper_response = requests.post(casper_rpc_url, json=data).json() | ||
|
||
result = casper_response['result'] | ||
|
||
if result: | ||
transfer_args = result["deploy"]["session"]["Transfer"]["args"] | ||
if ( | ||
result["deploy"]["hash"] == txnid | ||
and result["deploy"]["header"]["account"] == funderAddress | ||
and float([ | ||
arg for arg in transfer_args if arg[0] == 'amount' | ||
][0][1]['parsed']) == float(amount) * 10 ** 9 | ||
): | ||
if result["execution_results"][0]["result"].get("Success", False) != False: | ||
return 'success' | ||
return 'expired' | ||
|
||
except Exception as e: | ||
logger.error(f'error: get_casper_txn_status - {e}') | ||
|
||
return None | ||
|
||
|
||
def sync_casper_payout(fulfillment): | ||
if fulfillment.payout_tx_id: | ||
txn_status = get_casper_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() |
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
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
Oops, something went wrong.