# Generated by Django 4.0 on 2022-01-28 23:27

import django.contrib.postgres.fields
import django.contrib.postgres.fields.hstore
import django.db.models.deletion
from django.contrib.postgres.operations import HStoreExtension
from django.db import migrations, models

import hub20.apps.blockchain.fields


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        HStoreExtension(),
        migrations.CreateModel(
            name="Block",
            fields=[
                (
                    "hash",
                    hub20.apps.blockchain.fields.HexField(
                        max_length=64, primary_key=True, serialize=False
                    ),
                ),
                ("number", models.PositiveIntegerField(db_index=True)),
                ("base_fee_per_gas", models.PositiveBigIntegerField(null=True)),
                ("timestamp", models.DateTimeField()),
                ("parent_hash", hub20.apps.blockchain.fields.HexField(max_length=64)),
                (
                    "uncle_hashes",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=hub20.apps.blockchain.fields.HexField(max_length=64), size=None
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Chain",
            fields=[
                ("id", models.PositiveBigIntegerField(primary_key=True, serialize=False)),
                ("name", models.CharField(default="EVM-compatible network", max_length=128)),
                ("is_mainnet", models.BooleanField(default=True)),
                ("highest_block", models.PositiveIntegerField()),
            ],
            options={
                "ordering": ("id",),
            },
        ),
        migrations.CreateModel(
            name="Web3Provider",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("url", hub20.apps.blockchain.fields.Web3ProviderURLField()),
                ("client_version", models.CharField(max_length=300, null=True)),
                ("requires_geth_poa_middleware", models.BooleanField(default=False)),
                ("supports_pending_filters", models.BooleanField(default=False)),
                ("supports_eip1559", models.BooleanField(default=False)),
                ("is_active", models.BooleanField(default=True)),
                ("synced", models.BooleanField(default=False)),
                ("connected", models.BooleanField(default=False)),
                (
                    "chain",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="providers",
                        to="blockchain.chain",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Transaction",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("hash", hub20.apps.blockchain.fields.HexField(db_index=True, max_length=64)),
                ("from_address", hub20.apps.blockchain.fields.EthereumAddressField(db_index=True)),
                ("to_address", hub20.apps.blockchain.fields.EthereumAddressField(db_index=True)),
                ("receipt", django.contrib.postgres.fields.hstore.HStoreField()),
                (
                    "block",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="transactions",
                        to="blockchain.block",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="NativeToken",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("name", models.CharField(max_length=500)),
                ("symbol", models.CharField(max_length=16)),
                ("decimals", models.PositiveIntegerField(default=18)),
                (
                    "chain",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="native_token",
                        to="blockchain.chain",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Explorer",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("name", models.CharField(max_length=200, null=True)),
                ("url", models.URLField()),
                ("standard", models.CharField(max_length=200, null=True)),
                (
                    "chain",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="explorers",
                        to="blockchain.chain",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="EventIndexer",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("name", models.CharField(max_length=200)),
                ("last_block", models.PositiveBigIntegerField(default=1)),
                (
                    "chain",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="indexers",
                        to="blockchain.chain",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="block",
            name="chain",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="blocks",
                to="blockchain.chain",
            ),
        ),
        migrations.CreateModel(
            name="BaseEthereumAccount",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "address",
                    hub20.apps.blockchain.fields.EthereumAddressField(db_index=True, unique=True),
                ),
                ("transactions", models.ManyToManyField(to="blockchain.Transaction")),
            ],
        ),
        migrations.CreateModel(
            name="TransactionDataRecord",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("hash", hub20.apps.blockchain.fields.HexField(db_index=True, max_length=64)),
                ("from_address", hub20.apps.blockchain.fields.EthereumAddressField(db_index=True)),
                ("to_address", hub20.apps.blockchain.fields.EthereumAddressField(db_index=True)),
                ("data", django.contrib.postgres.fields.hstore.HStoreField()),
                (
                    "chain",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="transaction_data",
                        to="blockchain.chain",
                    ),
                ),
            ],
            options={
                "unique_together": {("hash", "chain")},
            },
        ),
        migrations.AddConstraint(
            model_name="transaction",
            constraint=models.UniqueConstraint(
                fields=("hash", "block"), name="unique_tx_per_block"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="explorer",
            unique_together={("url", "chain")},
        ),
        migrations.AddConstraint(
            model_name="eventindexer",
            constraint=models.UniqueConstraint(
                fields=("chain", "name"), name="unique_name_per_chain"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="block",
            unique_together={("chain", "hash", "number")},
        ),
    ]
