Skip to content

Commit

Permalink
Fix #2232 - Adjust ENS hash txns to allow blank, switch to default em…
Browse files Browse the repository at this point in the history
…pty str, and catch if empty (#2233)
  • Loading branch information
Mark Beacom authored and SaptakS committed Sep 26, 2018
1 parent e408146 commit 1d74c9e
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 42 deletions.
23 changes: 13 additions & 10 deletions app/assets/ens/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
function signMsgAndCreateSubdomain(message, from) {
var msg = web3.toHex(message)
var params = [msg, from];
var msg = web3.toHex(message);
var params = [ msg, from ];
var method = 'personal_sign';

web3.currentProvider.sendAsync({
method,
params,
from,
}, function (err, result) {
if (err) return console.error(err)
if (result.error) return console.error(result.error)
$.post( "", { 'signedMsg' : result.result, 'signer': from }, function( data ) {
alert(data.msg);
location.reload();
});
from
}, function(err, result) {
if (err)
return console.error(err);
if (result.error)
return console.error(result.error);
$.post('', { 'signedMsg': result.result, 'signer': from }, function(data) {
alert(data.msg);
location.reload();
});
});
}

21 changes: 11 additions & 10 deletions app/assets/ens/register.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
window.onload = function () {
$("#register")[0].onclick = function (e) {
if ($("#tos")[0].checked === false) {
return alert('Please check the TOS checkbox.')
window.onload = function() {
$('#register')[0].onclick = function(e) {
if ($('#tos')[0].checked === false) {
return alert('Please check the TOS checkbox.');
}
if (typeof web3 == 'undefined') {
return alert('Please install metamask in your browser and try again.')
return alert('Please install metamask in your browser and try again.');
}
// Get the github handle
githubHandle = $("#githubHandle").text()
githubHandle = $('#githubHandle').text();
// Get the current account and call sign function:
web3.eth.getAccounts(function (err, accounts) {
if (!accounts) return
signMsgAndCreateSubdomain('Github Username : ' + $("#githubHandle").text(), accounts[0]);
web3.eth.getAccounts(function(err, accounts) {
if (!accounts)
return;
signMsgAndCreateSubdomain('Github Username : ' + $('#githubHandle').text(), accounts[0]);
});
};
}
};
28 changes: 28 additions & 0 deletions app/enssubdomain/migrations/0008_auto_20180917_2043.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.1.1 on 2018-09-17 20:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('enssubdomain', '0007_enssubdomainregistration_gas_cost_eth'),
]

operations = [
migrations.AlterField(
model_name='enssubdomainregistration',
name='txn_hash_1',
field=models.CharField(blank=True, max_length=255),
),
migrations.AlterField(
model_name='enssubdomainregistration',
name='txn_hash_2',
field=models.CharField(blank=True, max_length=255),
),
migrations.AlterField(
model_name='enssubdomainregistration',
name='txn_hash_3',
field=models.CharField(blank=True, max_length=255),
),
]
6 changes: 3 additions & 3 deletions app/enssubdomain/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class ENSSubdomainRegistration(SuperModel):
'dashboard.Profile', related_name='ens_registration', null=True, on_delete=models.SET_NULL
)
subdomain_wallet_address = models.CharField(max_length=50)
txn_hash_1 = models.CharField(max_length=255)
txn_hash_2 = models.CharField(max_length=255)
txn_hash_3 = models.CharField(max_length=255)
txn_hash_1 = models.CharField(max_length=255, blank=True)
txn_hash_2 = models.CharField(max_length=255, blank=True)
txn_hash_3 = models.CharField(max_length=255, blank=True)
pending = models.BooleanField()
signed_msg = models.TextField()
start_nonce = models.IntegerField(default=0)
Expand Down
34 changes: 18 additions & 16 deletions app/enssubdomain/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ def handle_subdomain_exists(request, github_handle):
'ens_domain': settings.ENS_TLD,
}
return TemplateResponse(request, 'ens/ens_pending.html', params)
elif request_reset_time > last_request.created_on:
if request_reset_time > last_request.created_on:
params = {
'owner': last_request.subdomain_wallet_address,
'github_handle': github_handle,
'ens_domain': settings.ENS_TLD,
}
return TemplateResponse(request, 'ens/ens_edit.html', params)
else:
params = {
'owner': last_request.subdomain_wallet_address,
'github_handle': github_handle,
'limit_reset_days': settings.ENS_LIMIT_RESET_DAYS,
'try_after': last_request.created_on + datetime.timedelta(days=settings.ENS_LIMIT_RESET_DAYS),
'ens_domain': settings.ENS_TLD,
}
return TemplateResponse(request, 'ens/ens_rate_limit.html', params)

params = {
'owner': last_request.subdomain_wallet_address,
'github_handle': github_handle,
'limit_reset_days': settings.ENS_LIMIT_RESET_DAYS,
'try_after': last_request.created_on + datetime.timedelta(days=settings.ENS_LIMIT_RESET_DAYS),
'ens_domain': settings.ENS_TLD,
}
return TemplateResponse(request, 'ens/ens_rate_limit.html', params)


def set_resolver(signer, github_handle, nonce, gas_multiplier=1.101):
Expand Down Expand Up @@ -162,7 +162,7 @@ def set_address_at_resolver(signer, github_handle, nonce, gas_multiplier=1.101):
ns = ENS.fromWeb3(w3)
resolver_addr = ns.address('resolver.eth')
signer = Web3.toChecksumAddress(signer)
txn_hash = None
txn_hash = ''
gas_price = get_gas_price(gas_multiplier)
subdomain = f"{github_handle}.{settings.ENS_TLD}"

Expand All @@ -180,7 +180,7 @@ def set_address_at_resolver(signer, github_handle, nonce, gas_multiplier=1.101):
try:
txn_hash = convert_txn(w3.eth.sendRawTransaction(signed_txn.rawTransaction))
except ValueError as e:
logger.warning(f'{e} - set_address_at_resolver')
logger.error(e)

return txn_hash

Expand Down Expand Up @@ -224,12 +224,12 @@ def helper_process_registration(signer, github_handle, signedMsg, gas_multiplier

def handle_subdomain_post_request(request, github_handle):
# setup
signedMsg = request.POST.get('signedMsg', '')
signed_msg = request.POST.get('signedMsg', '')
signer = request.POST.get('signer', '').lower()
if signedMsg and signer:
if signed_msg and signer:
# validation
message_hash = defunct_hash_message(text=f'Github Username : {github_handle}')
recovered_signer = w3.eth.account.recoverHash(message_hash, signature=signedMsg).lower()
recovered_signer = w3.eth.account.recoverHash(message_hash, signature=signed_msg).lower()
if recovered_signer != signer:
return JsonResponse({'success': False, 'msg': _('Sign Mismatch Error')})
if not request.user.profile.trust_profile and request.user.profile.github_created_on > (
Expand All @@ -256,14 +256,16 @@ def handle_subdomain_post_request(request, github_handle):
gas_price = get_gas_price()
gas_cost_eth = (RESOLVER_GAS_COST + OWNER_GAS_COST + SET_ADDRESS_GAS_COST) * gas_price / 10**18
profile = Profile.objects.filter(handle=github_handle).first()
if not txn_hash_1 or not txn_hash_2 or not txn_hash_3:
return JsonResponse({'success': False, 'msg': _('Your ENS request has failed. Please try again.')})
ENSSubdomainRegistration.objects.create(
profile=profile,
subdomain_wallet_address=signer,
txn_hash_1=txn_hash_1,
txn_hash_2=txn_hash_2,
txn_hash_3=txn_hash_3,
pending=True,
signed_msg=signedMsg,
signed_msg=signed_msg,
start_nonce=start_nonce,
end_nonce=nonce,
gas_cost_eth=gas_cost_eth,
Expand Down
9 changes: 8 additions & 1 deletion app/locale/pl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3765,7 +3765,14 @@ msgstr ""
"Skontaktuj się z pomocą techniczną, jeśli uważasz, że ta wiadomość jest "
"błędna."

#: enssubdomain/views.py:273
#: enssubdomain/views.py:260
#, fuzzy
#| msgid ""
#| "Your request has been submitted. Please wait for the transaction to mine!"
msgid "Your ENS request has failed. Please try again."
msgstr "Twoja prośba została wysłana. Proszę czekać na transakcję do kopalni!"

#: enssubdomain/views.py:275
msgid ""
"Your request has been submitted. Please wait for the transaction to mine!"
msgstr "Twoja prośba została wysłana. Proszę czekać na transakcję do kopalni!"
Expand Down
19 changes: 19 additions & 0 deletions app/marketing/migrations/0036_auto_20180917_2043.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.1.1 on 2018-09-17 20:43

import django.contrib.postgres.fields.jsonb
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('marketing', '0035_accountdeletionrequest'),
]

operations = [
migrations.AlterField(
model_name='accountdeletionrequest',
name='profile',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict),
),
]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Gitcoin is the easiest way to monetize or incentivize work in Open Source Software",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"eslint": "./node_modules/eslint/bin/eslint.js --quiet --config .eslintrc ./app/assets/v2/js/*.js ./app/assets/v2/js/**/*.js ./app/assets/legacy/v2/js/*.js ./app/assets/legacy/v2/js/**/*.js ./app/assets/onepager/*.js ./app/assets/onepager/js/*.js",
"eslint:fix": "./node_modules/eslint/bin/eslint.js --quiet --fix --config .eslintrc ./app/assets/v2/js/*.js ./app/assets/v2/js/**/*.js ./app/assets/legacy/v2/js/*.js ./app/assets/legacy/v2/js/**/*.js ./app/assets/onepager/*.js ./app/assets/onepager/js/*.js",
"eslint": "./node_modules/eslint/bin/eslint.js --quiet --config .eslintrc ./app/assets/v2/js/*.js ./app/assets/v2/js/**/*.js ./app/assets/legacy/v2/js/*.js ./app/assets/legacy/v2/js/**/*.js ./app/assets/onepager/*.js ./app/assets/onepager/js/*.js ./app/assets/ens/*.js",
"eslint:fix": "./node_modules/eslint/bin/eslint.js --quiet --fix --config .eslintrc ./app/assets/v2/js/*.js ./app/assets/v2/js/**/*.js ./app/assets/legacy/v2/js/*.js ./app/assets/legacy/v2/js/**/*.js ./app/assets/onepager/*.js ./app/assets/onepager/js/*.js ./app/assets/ens/*.js",
"stylelint": "stylelint ./app/assets/**/**/*.css",
"stylelint:fix": "stylelint --fix ./app/assets/**/**/*.css",
"build": "webpack --config webpack.config.js --progress --colors"
Expand Down

0 comments on commit 1d74c9e

Please sign in to comment.