diff --git a/app/lightning/impl/cln_utils.py b/app/lightning/impl/cln_utils.py index fcfade0..df601fe 100644 --- a/app/lightning/impl/cln_utils.py +++ b/app/lightning/impl/cln_utils.py @@ -23,8 +23,11 @@ def calc_fee_rate_str(sat_per_vbyte, target_conf) -> str: return fee_rate -def parse_cln_msat(msat: str) -> int: - return int(msat.replace("msat", "")) +def parse_cln_msat(msat) -> int: + if isinstance(msat, str): + return int(msat.replace("msat", "")) + + return msat def cln_classify_fee_revenue(forwards: list): @@ -39,8 +42,14 @@ def cln_classify_fee_revenue(forwards: list): # TODO: performance: cache this in redis for f in forwards: - received_time = f.received_time - fee = f.fee_msat.msat + received_time = fee = 0 + if isinstance(f, dict): + received_time = f["received_time"] + fee = parse_cln_msat(f["fee_msat"]) + else: + received_time = f.received_time + fee = f.fee_msat.msat + total += fee if received_time > t_day: diff --git a/app/lightning/models.py b/app/lightning/models.py index eb52d02..acb398a 100644 --- a/app/lightning/models.py +++ b/app/lightning/models.py @@ -157,7 +157,7 @@ class ForwardSuccessEvent(BaseModel): @classmethod def from_lnd_grpc(cls, evt) -> "ForwardSuccessEvent": return cls( - timestamp=int(evt.timestamp), + timestamp_ns=int(evt.timestamp), chan_id_in=int(evt.chan_id_in), chan_id_out=int(evt.chan_id_out), amt_in_msat=int(evt.amt_in_msat), @@ -646,13 +646,14 @@ If generated by some other method, it'll be the string supplied by the user at t @classmethod def from_cln_json(cls, i) -> "Invoice": + amt = parse_cln_msat(i["amount_msat"]) return cls( add_index=i["label"], memo=i["description"], r_preimage=i["payment_preimage"] if "payment_preimage" in i else None, r_hash=i["payment_hash"], - value=i["msatoshi"] / 1000, - value_msat=i["msatoshi"], + value=amt / 1000, + value_msat=amt, settled=True if i["status"] == "paid" else False, expiry_date=i["expires_at"], settle_date=i["paid_at"] if "paid_at" in i else None,