-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e52f2d9
commit f6745dc
Showing
14 changed files
with
230 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 5.0.4 on 2024-07-15 18:23 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("accounts", "0003_alter_account_options"), | ||
("chains", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="account", | ||
name="chain", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="Blockchain this account is located on.", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="accounts", | ||
related_query_name="account", | ||
to="chains.chain", | ||
), | ||
), | ||
] |
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,26 @@ | ||
# Generated by Django 5.0.4 on 2024-07-15 18:26 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("accounts", "0004_account_chain"), | ||
("chains", "0002_add_near_chain"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="account", | ||
name="chain", | ||
field=models.ForeignKey( | ||
help_text="Blockchain this account is located on.", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="accounts", | ||
related_query_name="account", | ||
to="chains.chain", | ||
), | ||
), | ||
] |
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
Empty file.
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,18 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Chain | ||
|
||
|
||
@admin.register(Chain) | ||
class ChainAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
"name", | ||
"name_slug", | ||
"rpc_url", | ||
"explorer_url", | ||
"evm_compat", | ||
"evm_chain_id", | ||
) | ||
search_fields = ("name", "name_slug", "rpc_url", "explorer_url", "evm_chain_id") | ||
list_filter = ("evm_compat",) | ||
ordering = ("name",) |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ChainsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "chains" |
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,60 @@ | ||
# Generated by Django 5.0.4 on 2024-07-15 18:23 | ||
|
||
import django_extensions.db.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Chain", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(db_index=True, max_length=32, unique=True)), | ||
( | ||
"name_slug", | ||
django_extensions.db.fields.AutoSlugField( | ||
blank=True, | ||
editable=False, | ||
max_length=32, | ||
populate_from=("name",), | ||
unique=True, | ||
), | ||
), | ||
("rpc_url", models.URLField()), | ||
("explorer_url", models.URLField()), | ||
("evm_compat", models.BooleanField()), | ||
( | ||
"evm_chain_id", | ||
models.IntegerField(blank=True, db_index=True, null=True), | ||
), | ||
], | ||
options={ | ||
"ordering": ("name",), | ||
}, | ||
), | ||
migrations.AddConstraint( | ||
model_name="chain", | ||
constraint=models.CheckConstraint( | ||
check=models.Q( | ||
models.Q(("evm_chain_id__isnull", False), ("evm_compat", True)), | ||
models.Q(("evm_chain_id__isnull", True), ("evm_compat", False)), | ||
_connector="OR", | ||
), | ||
name="evm_chain_id_check", | ||
), | ||
), | ||
] |
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,25 @@ | ||
# Generated by Django 5.0.4 on 2024-07-15 18:24 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def create_near_chain(apps, schema_editor): | ||
Chain = apps.get_model("chains", "Chain") | ||
# Create the "near" chain | ||
near_chain, created = Chain.objects.get_or_create( | ||
name="NEAR", defaults={"evm_compat": False} | ||
) | ||
|
||
# Set "near" chain as the default for all existing accounts | ||
Account = apps.get_model("accounts", "Account") | ||
Account.objects.update(chain=near_chain) | ||
print("Updated all accounts to use NEAR chain") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("chains", "0001_initial"), ("accounts", "0004_account_chain")] | ||
|
||
operations = [ | ||
migrations.RunPython(create_near_chain), | ||
] |
Empty file.
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,48 @@ | ||
from django.db import models | ||
from django_extensions.db.fields import AutoSlugField | ||
|
||
|
||
class Chain(models.Model): | ||
############################ | ||
# BLOCKCHAIN MODEL FIELDS | ||
############################ | ||
|
||
# GENERAL | ||
name = models.CharField( | ||
max_length=32, unique=True, blank=False, null=False, db_index=True | ||
) | ||
name_slug = AutoSlugField( | ||
populate_from=("name",), | ||
max_length=32, | ||
unique=True, | ||
blank=False, | ||
null=False, | ||
db_index=True, | ||
) | ||
|
||
# URLS | ||
rpc_url = models.URLField() | ||
explorer_url = models.URLField() | ||
|
||
# EVM | ||
evm_compat = models.BooleanField(null=False, blank=False) | ||
evm_chain_id = models.IntegerField(null=True, blank=True, db_index=True) | ||
|
||
############################ | ||
# META | ||
############################ | ||
class Meta: | ||
# default record ordering | ||
ordering = ("name",) | ||
|
||
constraints = [ | ||
# if an evm then the evm_chain_id id must be set otherwise should be null | ||
models.CheckConstraint( | ||
name="evm_chain_id_check", | ||
check=models.Q(evm_compat=True, evm_chain_id__isnull=False) | ||
| models.Q(evm_compat=False, evm_chain_id__isnull=True), | ||
), | ||
] | ||
|
||
def __str__(self): | ||
return self.name |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
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