# Generated by Django 3.1.14 on 2022-02-20 09:00

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import fernet_fields.fields
import picklefield.fields
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Account',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(blank=True, max_length=100, null=True)),
                ('description', models.TextField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
                ('updated_at', models.DateTimeField(auto_now=True, null=True)),
                ('address', models.CharField(blank=True, max_length=255, null=True)),
                ('balance', models.DecimalField(blank=True, decimal_places=18, default=0, editable=False, max_digits=80)),
                ('secret_key', fernet_fields.fields.EncryptedTextField()),
                ('revealed', models.BooleanField(default=False)),
                ('counter', models.PositiveIntegerField(null=True)),
                ('last_level', models.PositiveIntegerField(null=True)),
            ],
        ),
        migrations.CreateModel(
            name='Blockchain',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('provider_class', models.CharField(choices=[('djwebdapp_tezos.provider.TezosProvider', 'Tezos'), ('djwebdapp_ethereum.provider.EthereumProvider', 'Ethereum'), ('djwebdapp.provider.Success', 'Test that always succeeds'), ('djwebdapp.provider.FailDeploy', 'Test that fails deploy'), ('djwebdapp.provider.FailWatch', 'Test that fails watch')], max_length=255)),
                ('is_active', models.BooleanField(default=True, help_text='Check to activate this blockchain')),
                ('description', models.TextField(blank=True, help_text='Free text to describe the blockchain to users')),
                ('unit', models.CharField(help_text='Unit name, ie. btc, xtz...', max_length=15)),
                ('unit_micro', models.CharField(help_text='Unit name, ie. satoshi, mutez...', max_length=15)),
                ('max_level', models.PositiveIntegerField(blank=True, default=None, help_text='Highest indexed level', null=True)),
                ('min_level', models.PositiveIntegerField(blank=True, default=None, help_text='Lowest indexed level', null=True)),
                ('configuration', models.JSONField(blank=True, default=dict)),
            ],
        ),
        migrations.CreateModel(
            name='Transaction',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, null=True)),
                ('updated_at', models.DateTimeField(auto_now=True, null=True)),
                ('name', models.CharField(blank=True, help_text='Free label', max_length=100, null=True)),
                ('description', models.TextField(blank=True, help_text='Free description text', null=True)),
                ('hash', models.CharField(blank=True, max_length=255, null=True, unique=True)),
                ('gasprice', models.BigIntegerField(blank=True, null=True)),
                ('gas', models.BigIntegerField(blank=True, null=True)),
                ('level', models.PositiveIntegerField(blank=True, db_index=True, null=True)),
                ('last_fail', models.DateTimeField(blank=True, null=True)),
                ('max_fails', models.PositiveIntegerField(default=10, help_text='Number of failures to retry before aborting transaction')),
                ('has_code', models.BooleanField(default=True, help_text='Check to activate this blockchain')),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('state', models.CharField(choices=[('held', 'Held'), ('deleted', 'Deleted during reorg'), ('aborted', 'Aborted'), ('deploy', 'To deploy'), ('deploying', 'Deploying'), ('retrying', 'Retrying'), ('confirm', 'To confirm'), ('confirming', 'Confirming'), ('done', 'Finished')], db_index=True, default='held', max_length=200)),
                ('history', models.JSONField(default=list)),
                ('amount', models.PositiveIntegerField(blank=True, db_index=True, null=True)),
                ('args', picklefield.fields.PickledObjectField(blank=True, default=None, editable=False, help_text='Arguments, appliable to deployments or method calls', null=True)),
                ('address', models.CharField(blank=True, db_index=True, help_text='Contract address, appliable to method calls', max_length=255, null=True)),
                ('function', models.CharField(blank=True, db_index=True, help_text='Function name, if this is a method call', max_length=100, null=True)),
                ('kind', models.CharField(blank=True, choices=[('contract', 'Contract'), ('function', 'Function call'), ('transfer', 'Transfer')], db_index=True, max_length=8, null=True)),
                ('error', models.TextField(blank=True, null=True)),
                ('blockchain', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='djwebdapp.blockchain')),
                ('receiver', models.ForeignKey(blank=True, help_text='Receiver address, if this is a transfer', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='transaction_received', to='djwebdapp.account')),
                ('sender', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='transaction_sent', to='djwebdapp.account')),
            ],
        ),
        migrations.CreateModel(
            name='Node',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(help_text='Node name, generated from endpoint if empty', max_length=100)),
                ('endpoint', models.URLField(help_text='Node endpoint to query')),
                ('is_active', models.BooleanField(default=True, help_text='Check to activate this node')),
                ('priority', models.IntegerField(default=0, help_text='Nodes with the highest priority will be used first')),
                ('blockchain', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='djwebdapp.blockchain')),
            ],
        ),
        migrations.CreateModel(
            name='Explorer',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(help_text='Explorer name, generated from url template if empty', max_length=100)),
                ('url_template', models.CharField(blank=True, max_length=255, null=True)),
                ('is_active', models.BooleanField(default=True, help_text='Check to activate this explorer')),
                ('blockchain', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='djwebdapp.blockchain')),
            ],
        ),
        migrations.AddField(
            model_name='account',
            name='blockchain',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='djwebdapp.blockchain'),
        ),
        migrations.AddField(
            model_name='account',
            name='owner',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
        ),
    ]
