mirror of
https://github.com/fusion44/blitz_api.git
synced 2026-08-19 12:37:30 +02:00
feat: improvements and fixes for send-coins
both: feat: add send_all field to SendCoinsResponse CLN_gRPC only: feat: improve error handling fix: return a status 412 when no funds are available to send CLN_gRPC only: fix: send-coins sending incorrect amount
This commit is contained in:
parent
fa474976da
commit
467d23a2c3
3 changed files with 41 additions and 10 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,))
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue