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

Ks contract versioning #2951

Merged
merged 12 commits into from
Nov 27, 2018
6 changes: 6 additions & 0 deletions app/assets/v2/js/grants/cancel_subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ window.onload = function() {

// need to delete subscription from miner so it isn't checked every 15 seconds.

let compiledSubscription;

if (data.contract_version == 0) {
compiledSubscription = compiledSubscription0;
}

let deployedSubscription = new web3.eth.Contract(compiledSubscription.abi, data.contract_address);

let deployedToken = new web3.eth.Contract(
Expand Down
6,344 changes: 3,279 additions & 3,065 deletions app/assets/v2/js/grants/compiledSubscriptionContract.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions app/assets/v2/js/grants/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ $(document).ready(function() {
data[this.name] = this.value;
});

let compiledSubscription;

if (data.contract_version == 0) {
compiledSubscription = compiledSubscription0;
}

let deployedSubscription = new web3.eth.Contract(compiledSubscription.abi, data.contract_address);

web3.eth.getAccounts(function(err, accounts) {
Expand Down
6 changes: 6 additions & 0 deletions app/assets/v2/js/grants/fund.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ $(document).ready(function() {
}
}

let compiledSubscription;

if (data.contract_version == 0) {
compiledSubscription = compiledSubscription0;
}

let deployedSubscription = new web3.eth.Contract(compiledSubscription.abi, data.contract_address);
let deployedToken;

Expand Down
2 changes: 2 additions & 0 deletions app/assets/v2/js/grants/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ $(document).ready(function() {
// data.frequency
web3.utils.toTwosComplement(0),
// data.gas_price
web3.utils.toTwosComplement(0),
// contract version
web3.utils.toTwosComplement(0)
];

Expand Down
14 changes: 14 additions & 0 deletions app/dashboard/migrations/0117_merge_20181126_1652.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.1.2 on 2018-11-26 16:52

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0112_auto_20181107_1809'),
('dashboard', '0116_merge_20181115_2252'),
]

operations = [
]
19 changes: 10 additions & 9 deletions app/grants/migrations/0005_grant_slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import django_extensions.db.fields


def update_grants(apps, schema_editor):
"""Handle the data migration for grant.slug."""
Grant = apps.get_model('grants', 'Grant')

grants = Grant.objects.all()
for grant in grants:
grant.save()
# def update_grants(apps, schema_editor):
# """Handle the data migration for grant.slug."""
captnseagraves marked this conversation as resolved.
Show resolved Hide resolved
# Grant = apps.get_model('grants', 'Grant')
#
# grants = Grant.objects.all()
# for grant in grants:
# grant.save()


class Migration(migrations.Migration):
Expand All @@ -24,6 +24,7 @@ class Migration(migrations.Migration):
model_name='grant',
name='slug',
field=django_extensions.db.fields.AutoSlugField(blank=True, editable=False, populate_from='title'),
),
migrations.RunPython(update_grants),
)
# ,
# migrations.RunPython(update_grants),
captnseagraves marked this conversation as resolved.
Show resolved Hide resolved
]
17 changes: 17 additions & 0 deletions app/grants/migrations/0007_auto_20181126_1652.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.1.2 on 2018-11-26 16:52

from django.db import migrations


class Migration(migrations.Migration):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SaptakS @thelostone-mc do these migrations look ok to you?


dependencies = [
('grants', '0006_auto_20181121_1646'),
]

operations = [
migrations.AlterModelOptions(
name='grant',
options={'ordering': ['-created_on']},
),
]
18 changes: 18 additions & 0 deletions app/grants/migrations/0008_grant_contract_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.2 on 2018-11-26 20:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grants', '0007_auto_20181126_1652'),
]

operations = [
migrations.AddField(
model_name='grant',
name='contract_version',
field=models.DecimalField(decimal_places=0, default=0, help_text='The contract version the Grant.', max_digits=3),
),
]
6 changes: 6 additions & 0 deletions app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class Meta:
default='0x0',
help_text=_('The contract address of the Grant.'),
)
contract_version = models.DecimalField(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@captnseagraves
cc @owocki

Should we include a process for handling the ABI based on contract version, so it outputs the appropriate static URL or a given contract version..?

Also, we are we using a decimalfield if decimal_places=0 with max_digits=3?

Can we switch this to a charfield? If we're going by semantic versioning, decimalfield won't make sense: 0.1.0 for example. If we're using integers like: 0 or 1, we should use positiveintegerfield here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we switch this to a charfield? If we're going by semantic versioning, decimalfield won't make sense: 0.1.0 for example. If we're using integers like: 0 or 1, we should use positiveintegerfield here.

this makes sense to me

Should we include a process for handling the ABI based on contract version, so it outputs the appropriate static URL or a given contract version..?

as does this

default=0,
decimal_places=0,
max_digits=3,
help_text=_('The contract version the Grant.'),
)
transaction_hash = models.CharField(
max_length=255,
default='0x0',
Expand Down
1 change: 1 addition & 0 deletions app/grants/templates/grants/cancel.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ <h2 class="font-title-lg my-4">{% trans "Cancel Contribution" %}</h2>
<button class="button button--primary button--warning button--full">{% trans "Cancel Contribution" %}
</button>
<input type="hidden" id="contract_address" name="contract_address" value="{{ grant.contract_address }}">
<input type="hidden" id="contract_version" name="contract_version" value="{{ grant.contract_version }}">
<input type="hidden" id="admin_address" name="admin_address" value="{{ grant.admin_address }}">
<input type="hidden" id="token_address" name="token_address" value="{{ subscription.token_address }}">
<input type="hidden" id="amount_per_period" name="amount_per_period" value="{{ subscription.amount_per_period }}">
Expand Down
1 change: 1 addition & 0 deletions app/grants/templates/grants/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ <h4 class="my-4" >{% trans "This grant has ended. You can find all active grants
<button class="button button--primary button--warning" id="cancel_grant">{% trans "Cancel this Grant" %}
</button>
<input type="hidden" id="contract_address" name="contract_address" value="{{ grant.contract_address }}">
<input type="hidden" id="contract_version" name="contract_version" value="{{ grant.contract_version }}">
</form>
{% elif user_subscription %}
<a href="{% url 'grants:subscription_cancel' grant.id grant.slug user_subscription.id %}">
Expand Down
1 change: 1 addition & 0 deletions app/grants/templates/grants/fund.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ <h2 class="font-title-lg my-4">{% trans "Fund Grant" %}</h2>
<input type="hidden" id="admin_address" name="admin_address" value="{{ grant.admin_address }}">
<input type="hidden" id="token_address" name="token_address" value="{{ grant.token_address }}">
<input type="hidden" id="contract_address" name="contract_address" value="{{ grant.contract_address }}">
<input type="hidden" id="contract_version" name="contract_version" value="{{ grant.contract_version }}">
<input type="hidden" id="network" name="network" value="{{ grant.network }}">
<input type="hidden" id="subscription_hash" name="subscription_hash" value="">
<input type="hidden" id="signature" name="signature" value="">
Expand Down
1 change: 1 addition & 0 deletions app/grants/templates/grants/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ <h1>{% trans "Create a Grant" %}</h1>
<div>
<input type="hidden" class="form__input form__input-lg " id="transaction_hash" name="transaction_hash" />
<input type="hidden" class="form__input form__input-lg " id="contract_address" name="contract_address" />
<input type="hidden" id="contract_version" name="contract_version" value="0">
<input type="hidden" class="form__input form__input-lg " id="network" name="network" />
<input type="hidden" id="receipt" name="receipt" value="{}">
<input type="hidden" id="token_symbol" name="token_symbol" value="">
Expand Down
1 change: 1 addition & 0 deletions app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def grant_new(request):
'token_address': request.POST.get('denomination', ''),
'token_symbol': request.POST.get('token_symbol', ''),
'amount_goal': request.POST.get('amount_goal', 1),
'contract_version': request.POST.get('contract_version', ''),
'transaction_hash': request.POST.get('transaction_hash', ''),
'contract_address': request.POST.get('contract_address', ''),
'network': request.POST.get('network', 'mainnet'),
Expand Down