fix: crashes in CLN JSON RPC implementation

This commit is contained in:
fusion44 2023-04-02 12:58:04 +02:00
parent c73b8e9f15
commit d40790e5f4
No known key found for this signature in database
2 changed files with 17 additions and 7 deletions

View file

@ -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:

View file

@ -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,