lndg/gui/models.py

328 lines
13 KiB
Python
Raw Normal View History

2021-03-13 18:06:59 -05:00
from django.db import models
2021-03-31 23:59:22 -04:00
from django.utils import timezone
2021-03-13 18:06:59 -05:00
# Create your models here.
class Payments(models.Model):
creation_date = models.DateTimeField()
payment_hash = models.CharField(max_length=64, primary_key=True)
value = models.FloatField()
fee = models.FloatField()
status = models.IntegerField()
index = models.IntegerField()
2022-03-07 21:57:20 -05:00
chan_out = models.CharField(max_length=20, null=True)
chan_out_alias = models.CharField(null=True, max_length=32)
keysend_preimage = models.CharField(null=True, max_length=64)
2022-03-07 21:57:20 -05:00
message = models.CharField(null=True, max_length=1000)
2022-02-13 16:23:28 -05:00
cleaned = models.BooleanField(default=False)
2022-03-07 21:57:20 -05:00
rebal_chan = models.CharField(max_length=20, null=True)
class Meta:
app_label = 'gui'
class PaymentHops(models.Model):
payment_hash = models.ForeignKey('Payments', on_delete=models.CASCADE)
attempt_id = models.IntegerField()
step = models.IntegerField()
2022-03-07 21:57:20 -05:00
chan_id = models.CharField(max_length=20)
alias = models.CharField(max_length=32)
chan_capacity = models.BigIntegerField()
node_pubkey = models.CharField(max_length=66)
amt = models.FloatField()
fee = models.FloatField()
cost_to = models.FloatField()
class Meta:
app_label = 'gui'
unique_together = (('payment_hash', 'attempt_id', 'step'),)
class Invoices(models.Model):
creation_date = models.DateTimeField()
settle_date = models.DateTimeField(null=True, default=None)
r_hash = models.CharField(max_length=64, primary_key=True)
value = models.FloatField()
amt_paid = models.BigIntegerField()
state = models.IntegerField()
2022-03-07 21:57:20 -05:00
chan_in = models.CharField(max_length=20, null=True)
2021-05-06 11:41:37 -04:00
chan_in_alias = models.CharField(null=True, max_length=32)
keysend_preimage = models.CharField(null=True, max_length=64)
2022-03-07 21:57:20 -05:00
message = models.CharField(null=True, max_length=1000)
sender = models.CharField(null=True, max_length=66)
sender_alias = models.CharField(null=True, max_length=32)
index = models.IntegerField()
is_revenue = models.BooleanField(default=False)
class Meta:
app_label = 'gui'
class Forwards(models.Model):
forward_date = models.DateTimeField()
2022-03-07 21:57:20 -05:00
chan_id_in = models.CharField(max_length=20)
chan_id_out = models.CharField(max_length=20)
chan_in_alias = models.CharField(null=True, max_length=32)
chan_out_alias = models.CharField(null=True, max_length=32)
amt_in_msat = models.BigIntegerField()
amt_out_msat = models.BigIntegerField()
fee = models.FloatField()
class Meta:
app_label = 'gui'
class Channels(models.Model):
remote_pubkey = models.CharField(max_length=66)
2022-03-07 21:57:20 -05:00
chan_id = models.CharField(max_length=20, primary_key=True)
short_chan_id = models.CharField(max_length=20)
funding_txid = models.CharField(max_length=64)
output_index = models.IntegerField()
capacity = models.BigIntegerField()
local_balance = models.BigIntegerField()
remote_balance = models.BigIntegerField()
2021-03-24 18:38:40 -04:00
unsettled_balance = models.BigIntegerField()
local_commit = models.IntegerField()
local_chan_reserve = models.IntegerField()
num_updates = models.IntegerField()
initiator = models.BooleanField()
alias = models.CharField(max_length=32)
2022-03-07 21:57:20 -05:00
total_sent = models.BigIntegerField()
total_received = models.BigIntegerField()
private = models.BooleanField()
pending_outbound = models.BigIntegerField()
pending_inbound = models.BigIntegerField()
htlc_count = models.IntegerField()
local_base_fee = models.IntegerField()
local_fee_rate = models.IntegerField()
2022-02-13 16:23:28 -05:00
local_disabled = models.BooleanField()
2022-04-30 11:09:47 -04:00
local_cltv = models.IntegerField()
2022-09-28 08:47:33 -04:00
local_min_htlc_msat = models.BigIntegerField()
local_max_htlc_msat = models.BigIntegerField()
remote_base_fee = models.IntegerField()
remote_fee_rate = models.IntegerField()
2022-02-13 16:23:28 -05:00
remote_disabled = models.BooleanField()
2022-04-30 11:09:47 -04:00
remote_cltv = models.IntegerField()
2022-09-28 08:47:33 -04:00
remote_min_htlc_msat = models.BigIntegerField()
remote_max_htlc_msat = models.BigIntegerField()
push_amt = models.BigIntegerField()
close_address = models.CharField(max_length=100)
is_active = models.BooleanField()
2021-03-17 15:31:51 -04:00
is_open = models.BooleanField()
2022-02-13 16:23:28 -05:00
last_update = models.DateTimeField()
auto_rebalance = models.BooleanField(default=False)
ar_amt_target = models.BigIntegerField()
2022-08-26 20:56:46 -04:00
ar_in_target = models.IntegerField()
ar_out_target = models.IntegerField()
2022-02-13 16:23:28 -05:00
ar_max_cost = models.IntegerField()
2022-03-28 15:14:02 -04:00
fees_updated = models.DateTimeField(default=timezone.now)
2022-08-26 20:56:46 -04:00
auto_fees = models.BooleanField()
notes = models.TextField(default='', blank=True)
2022-01-21 11:43:37 -05:00
def save(self, *args, **kwargs):
2022-08-26 20:56:46 -04:00
if self.auto_fees is None:
if LocalSettings.objects.filter(key='AF-Enabled').exists():
enabled = int(LocalSettings.objects.filter(key='AF-Enabled')[0].value)
else:
LocalSettings(key='AF-Enabled', value='0').save()
enabled = 0
self.auto_fees = False if enabled == 0 else True
2022-01-21 11:43:37 -05:00
if not self.ar_out_target:
if LocalSettings.objects.filter(key='AR-Outbound%').exists():
2022-07-09 22:25:32 -04:00
outbound_setting = int(LocalSettings.objects.filter(key='AR-Outbound%')[0].value)
2022-01-21 11:43:37 -05:00
else:
2022-07-09 22:25:32 -04:00
LocalSettings(key='AR-Outbound%', value='75').save()
outbound_setting = 75
2022-07-11 11:10:01 -04:00
self.ar_out_target = outbound_setting
2022-08-26 20:56:46 -04:00
if not self.ar_in_target:
if LocalSettings.objects.filter(key='AR-Inbound%').exists():
inbound_setting = int(LocalSettings.objects.filter(key='AR-Inbound%')[0].value)
else:
LocalSettings(key='AR-Inbound%', value='100').save()
inbound_setting = 100
self.ar_in_target = inbound_setting
2022-01-21 11:43:37 -05:00
if not self.ar_amt_target:
if LocalSettings.objects.filter(key='AR-Target%').exists():
2022-07-11 11:10:01 -04:00
amt_setting = float(LocalSettings.objects.filter(key='AR-Target%')[0].value)
2022-01-21 11:43:37 -05:00
else:
2022-07-09 22:25:32 -04:00
LocalSettings(key='AR-Target%', value='5').save()
amt_setting = 5
self.ar_amt_target = int((amt_setting/100) * self.capacity)
2022-02-13 16:23:28 -05:00
if not self.ar_max_cost:
if LocalSettings.objects.filter(key='AR-MaxCost%').exists():
2022-07-09 22:25:32 -04:00
cost_setting = int(LocalSettings.objects.filter(key='AR-MaxCost%')[0].value)
2022-02-13 16:23:28 -05:00
else:
2022-07-09 22:25:32 -04:00
LocalSettings(key='AR-MaxCost%', value='65').save()
cost_setting = 65
2022-07-11 11:10:01 -04:00
self.ar_max_cost = cost_setting
2022-01-21 11:43:37 -05:00
super(Channels, self).save(*args, **kwargs)
2021-03-31 23:59:22 -04:00
class Meta:
app_label = 'gui'
class Peers(models.Model):
pubkey = models.CharField(max_length=66, primary_key=True)
2022-03-07 21:57:20 -05:00
alias = models.CharField(null=True, max_length=32)
address = models.CharField(max_length=100)
sat_sent = models.BigIntegerField()
sat_recv = models.BigIntegerField()
inbound = models.BooleanField()
connected = models.BooleanField()
last_reconnected = models.DateTimeField(null=True, default=None)
ping_time = models.BigIntegerField(default=0)
class Meta:
app_label = 'gui'
2021-03-31 23:59:22 -04:00
class Rebalancer(models.Model):
requested = models.DateTimeField(default=timezone.now)
value = models.IntegerField()
2022-07-09 22:25:32 -04:00
fee_limit = models.FloatField()
2021-04-05 08:25:32 -04:00
outgoing_chan_ids = models.TextField(default='[]')
last_hop_pubkey = models.CharField(default='', max_length=66)
target_alias = models.CharField(default='', max_length=32)
duration = models.IntegerField()
start = models.DateTimeField(null=True, default=None)
stop = models.DateTimeField(null=True, default=None)
2021-03-31 23:59:22 -04:00
status = models.IntegerField(default=0)
payment_hash = models.CharField(max_length=64, null=True, default=None)
2022-05-09 10:35:03 -04:00
manual = models.BooleanField(default=False)
2022-08-26 20:56:46 -04:00
fees_paid = models.FloatField(null=True, default=None)
class Meta:
app_label = 'gui'
class LocalSettings(models.Model):
key = models.CharField(primary_key=True, default=None, max_length=20)
value = models.CharField(default=None, max_length=50)
class Meta:
app_label = 'gui'
class Onchain(models.Model):
tx_hash = models.CharField(max_length=64, primary_key=True)
amount = models.BigIntegerField()
block_hash = models.CharField(max_length=64)
block_height = models.IntegerField()
time_stamp = models.DateTimeField()
fee = models.IntegerField()
label = models.CharField(max_length=100)
class Meta:
app_label = 'gui'
2022-03-07 21:57:20 -05:00
class Closures(models.Model):
2022-03-28 15:14:02 -04:00
chan_id = models.CharField(max_length=20)
funding_txid = models.CharField(max_length=64)
funding_index = models.IntegerField()
2022-03-07 21:57:20 -05:00
closing_tx = models.CharField(max_length=64)
remote_pubkey = models.CharField(max_length=66)
capacity = models.BigIntegerField()
close_height = models.IntegerField()
settled_balance = models.BigIntegerField()
time_locked_balance = models.BigIntegerField()
close_type = models.IntegerField()
open_initiator = models.IntegerField()
close_initiator = models.IntegerField()
resolution_count = models.IntegerField()
closing_costs = models.IntegerField(default=0)
2022-03-07 21:57:20 -05:00
class Meta:
app_label = 'gui'
2022-03-28 15:14:02 -04:00
unique_together = (('funding_txid', 'funding_index'),)
2022-03-07 21:57:20 -05:00
class Resolutions(models.Model):
2022-03-28 15:14:02 -04:00
chan_id = models.CharField(max_length=20)
2022-03-07 21:57:20 -05:00
resolution_type = models.IntegerField()
outcome = models.IntegerField()
outpoint_tx = models.CharField(max_length=64)
outpoint_index = models.IntegerField()
amount_sat = models.BigIntegerField()
sweep_txid = models.CharField(max_length=64)
class Meta:
app_label = 'gui'
class PendingHTLCs(models.Model):
2022-03-07 21:57:20 -05:00
chan_id = models.CharField(max_length=20)
2021-10-18 16:42:04 -04:00
alias = models.CharField(max_length=32)
incoming = models.BooleanField()
amount = models.BigIntegerField()
hash_lock = models.CharField(max_length=64)
expiration_height = models.IntegerField()
2022-07-09 22:25:32 -04:00
forwarding_channel = models.CharField(max_length=20)
2021-10-18 16:42:04 -04:00
forwarding_alias = models.CharField(max_length=32)
class Meta:
app_label = 'gui'
class FailedHTLCs(models.Model):
timestamp = models.DateTimeField(default=timezone.now)
amount = models.IntegerField()
2022-03-07 21:57:20 -05:00
chan_id_in = models.CharField(max_length=20)
chan_id_out = models.CharField(max_length=20)
chan_in_alias = models.CharField(null=True, max_length=32)
chan_out_alias = models.CharField(null=True, max_length=32)
2022-03-07 21:57:20 -05:00
chan_out_liq = models.BigIntegerField(null=True)
chan_out_pending = models.BigIntegerField(null=True)
wire_failure = models.IntegerField()
failure_detail = models.IntegerField()
missed_fee = models.FloatField()
class Meta:
app_label = 'gui'
class Autopilot(models.Model):
2022-03-28 15:14:02 -04:00
timestamp = models.DateTimeField(default=timezone.now)
chan_id = models.CharField(max_length=20)
peer_alias = models.CharField(max_length=32)
setting = models.CharField(max_length=20)
old_value = models.IntegerField()
new_value = models.IntegerField()
class Meta:
app_label = 'gui'
class Autofees(models.Model):
timestamp = models.DateTimeField(default=timezone.now)
2022-03-07 21:57:20 -05:00
chan_id = models.CharField(max_length=20)
peer_alias = models.CharField(max_length=32)
setting = models.CharField(max_length=20)
old_value = models.IntegerField()
new_value = models.IntegerField()
2021-03-17 15:31:51 -04:00
class Meta:
2022-08-26 20:56:46 -04:00
app_label = 'gui'
class PendingChannels(models.Model):
funding_txid = models.CharField(max_length=64)
output_index = models.IntegerField()
local_base_fee = models.IntegerField(null=True, default=None)
local_fee_rate = models.IntegerField(null=True, default=None)
local_cltv = models.IntegerField(null=True, default=None)
auto_rebalance = models.BooleanField(null=True, default=None)
ar_amt_target = models.BigIntegerField(null=True, default=None)
ar_in_target = models.IntegerField(null=True, default=None)
ar_out_target = models.IntegerField(null=True, default=None)
ar_max_cost = models.IntegerField(null=True, default=None)
auto_fees = models.BooleanField(null=True, default=None)
class Meta:
app_label = 'gui'
unique_together = (('funding_txid', 'output_index'),)
class AvoidNodes(models.Model):
pubkey = models.CharField(max_length=66, primary_key=True)
notes = models.CharField(null=True, max_length=1000)
updated = models.DateTimeField(default=timezone.now)
class Meta:
app_label = 'gui'
class PeerEvents(models.Model):
timestamp = models.DateTimeField(default=timezone.now)
chan_id = models.CharField(max_length=20)
peer_alias = models.CharField(max_length=32)
event = models.CharField(max_length=20)
old_value = models.BigIntegerField(null=True)
new_value = models.BigIntegerField()
out_liq = models.BigIntegerField()
class Meta:
2023-03-12 18:08:26 -04:00
app_label = 'gui'
class HistFailedHTLC(models.Model):
date = models.DateField(default=timezone.now)
chan_id_in = models.CharField(max_length=20)
chan_id_out = models.CharField(max_length=20)
chan_in_alias = models.CharField(null=True, max_length=32)
chan_out_alias = models.CharField(null=True, max_length=32)
htlc_count = models.IntegerField()
amount_sum = models.BigIntegerField()
fee_sum = models.BigIntegerField()
liq_avg = models.BigIntegerField()
pending_avg = models.BigIntegerField()
balance_count = models.IntegerField()
downstream_count = models.IntegerField()
other_count = models.IntegerField()
class Meta:
app_label = 'gui'
unique_together = (('date', 'chan_id_in', 'chan_id_out'),)