Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LN Address payments must use millisat amounts #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ExampleWallet_PayLightningAddress() {
panic(err)
}

payment, err := wallet.PayLightningAddress(ctx, lnAddress, "", 0.00000001)
payment, err := wallet.PayLightningAddress(ctx, lnAddress, "", 1000)
if err != nil {
panic(err)
}
Expand Down
20 changes: 11 additions & 9 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,10 @@ func (wallet *Wallet) PayInvoice(ctx context.Context, invoice, description strin
})
}

// PayLightningAddress executes a payment of the given BTC amount to a
// PayLightningAddress executes a payment of the given millisat amount to a
// given lightning address. The description is stored in the WoS payment history.
// Note the amount is in millisats (thousandths of a sat). To pay 5 sats, pass
// 5000 as the amount.
//
// Returns ErrOutsideSendableRange if the amount to be sent is outside the receiver's
// acceptable min/max sendable range.
Expand All @@ -423,7 +425,7 @@ func (wallet *Wallet) PayLightningAddress(
ctx context.Context,
lnAddress LightningAddress,
description string,
amount float64,
amountMillisat uint64,
) (*Payment, error) {
respData, err := wallet.PostRequest(ctx, "/api/v1/wallet/lnurl", map[string]any{
"address": lnAddress.LNURL(),
Expand All @@ -442,20 +444,20 @@ func (wallet *Wallet) PayLightningAddress(
return nil, fmt.Errorf("PayLightningAddress: invalid response JSON: %w", err)
}

if maxSendable := fromMillisat(lnPayResponseBody.MaxSendable); amount > maxSendable {
if amountMillisat > lnPayResponseBody.MaxSendable {
return nil, fmt.Errorf(
"PayLightningAddress: %w: exceeds maxSendable (%f BTC)",
ErrOutsideSendableRange, maxSendable,
"PayLightningAddress: %w: exceeds maxSendable (%d msat)",
ErrOutsideSendableRange, lnPayResponseBody.MaxSendable,
)
} else if minSendable := fromMillisat(lnPayResponseBody.MinSendable); amount < minSendable {
} else if amountMillisat < lnPayResponseBody.MinSendable {
return nil, fmt.Errorf(
"PayLightningAddress: %w: exceeds minSendable (%f BTC)",
ErrOutsideSendableRange, minSendable,
"PayLightningAddress: %w: exceeds minSendable (%d msat)",
ErrOutsideSendableRange, lnPayResponseBody.MinSendable,
)
}

respData, err = wallet.PostRequest(ctx, "/api/v1/wallet/lnPay", map[string]any{
"amount": toMillisat(amount),
"amount": amountMillisat,
"callback": lnPayResponseBody.Callback,
})
if err != nil {
Expand Down