diff --git a/app/lightning/impl/cln_grpc.py b/app/lightning/impl/cln_grpc.py index 1c8ff20..0c608a2 100644 --- a/app/lightning/impl/cln_grpc.py +++ b/app/lightning/impl/cln_grpc.py @@ -595,7 +595,7 @@ class LnNodeCLNgRPC(LightningNodeBase): max_amt = 0 for o in funds.outputs: utxos.append(lnp.Outpoint(txid=o.txid, outnum=o.output)) - max_amt += o.amount_msat.msat + max_amt += o.amount_msat.msat / 1000 if not input.send_all and max_amt <= input.amount: raise HTTPException( @@ -603,12 +603,13 @@ class LnNodeCLNgRPC(LightningNodeBase): detail=f"Could not afford {input.amount}sat. Not enough funds available", ) + amt = lnp.AmountOrAll(amount=lnp.Amount(msat=input.amount * 1000)) + if input.send_all: + amt = lnp.AmountOrAll(all=True) + req = ln.WithdrawRequest( destination=input.address, - satoshi=lnp.AmountOrAll( - amount=lnp.Amount(msat=input.amount), - all=input.send_all, - ), + satoshi=amt, minconf=input.min_confs, feerate=fee_rate, utxos=utxos, diff --git a/app/lightning/impl/cln_jrpc.py b/app/lightning/impl/cln_jrpc.py index 7b89768..dab9c46 100644 --- a/app/lightning/impl/cln_jrpc.py +++ b/app/lightning/impl/cln_jrpc.py @@ -520,12 +520,35 @@ class LnNodeCLNjRPC(LightningNodeBase): return r - m = res["error"]["message"] - logger.error(m) + if not "message" in res["error"]: + raise HTTPException( + status.HTTP_500_INTERNAL_SERVER_ERROR, + detail=f"Unknown error: {res}", + ) + + details = res["error"]["message"] + logger.error(details) + + if details and details.find("Could not parse destination address") > -1: + raise HTTPException( + status.HTTP_400_BAD_REQUEST, + detail="Could not parse destination address, destination should be a valid address.", + ) + elif ( + details + and details.find("UTXO") > -1 + and details.find("already reserved") > -1 + ): + raise HTTPException( + status.HTTP_500_INTERNAL_SERVER_ERROR, + detail="Server tried to use a reserved UTXO. Please submit an issue to the BlitzAPI repository.", + ) + elif details and details.find("Could not afford ") > -1: + raise HTTPException(status.HTTP_412_PRECONDITION_FAILED, detail=details) raise HTTPException( status.HTTP_500_INTERNAL_SERVER_ERROR, - detail=f"Unknown error: {m}", + detail=f"Unknown error: {details}", ) @logger.catch(exclude=(HTTPException,)) diff --git a/app/lightning/models.py b/app/lightning/models.py index 8f6d742..ac385f0 100644 --- a/app/lightning/models.py +++ b/app/lightning/models.py @@ -1248,7 +1248,7 @@ class SendCoinsResponse(BaseModel): ..., description="The base58 or bech32 encoded bitcoin address where the onchain funds where sent to", ) - amount: conint(gt=0) = Query( + amount: conint(ge=0) = Query( ..., description="The number of bitcoin denominated in satoshis which where sent", ) @@ -1259,6 +1259,10 @@ class SendCoinsResponse(BaseModel): label: str = Query( "", description="The label used for the transaction. Ignored by CLN backend." ) + send_all: bool = Query( + False, + description="If this transaction was a `send_all` transaction.", + ) @classmethod def from_lnd_grpc(cls, r, input: SendCoinsInput): @@ -1269,15 +1273,17 @@ class SendCoinsResponse(BaseModel): amount=abs(amount), fees=r.total_fees, label=input.label, + send_all=input.send_all, ) @classmethod def from_cln_grpc(cls, r, input: SendCoinsInput): return cls( - txid=r.txid, + txid=r.txid.hex(), address=input.address, amount=input.amount, label=input.label, + send_all=input.send_all, ) @classmethod @@ -1287,6 +1293,7 @@ class SendCoinsResponse(BaseModel): address=input.address, amount=input.amount, label=input.label, + send_all=input.send_all, )