nip60: fixes to pay and stuff because it was very broken.
This commit is contained in:
16
nip60/pay.go
16
nip60/pay.go
@@ -28,9 +28,10 @@ func (w *Wallet) PayBolt11(ctx context.Context, invoice string, opts ...SendOpti
|
|||||||
var meltQuote string
|
var meltQuote string
|
||||||
var meltAmount uint64
|
var meltAmount uint64
|
||||||
|
|
||||||
invoicePct := uint64(99)
|
feeReservePct := uint64(1)
|
||||||
|
feeReserveAbs := uint64(1)
|
||||||
for range 10 {
|
for range 10 {
|
||||||
amount := invoiceAmount * invoicePct / 100
|
amount := invoiceAmount*(100+feeReservePct)/100 + feeReserveAbs
|
||||||
var fee uint64
|
var fee uint64
|
||||||
chosen, fee, err = w.getProofsForSending(ctx, amount, ss.specificMint)
|
chosen, fee, err = w.getProofsForSending(ctx, amount, ss.specificMint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,16 +49,17 @@ func (w *Wallet) PayBolt11(ctx context.Context, invoice string, opts ...SendOpti
|
|||||||
|
|
||||||
// if amount in proofs is not sufficient to pay for the melt request,
|
// if amount in proofs is not sufficient to pay for the melt request,
|
||||||
// increase the amount and get proofs again (because of lighting fees)
|
// increase the amount and get proofs again (because of lighting fees)
|
||||||
if meltResp.Amount+meltResp.FeeReserve+fee > chosen.proofs.Amount() {
|
|
||||||
invoicePct--
|
|
||||||
} else {
|
|
||||||
meltQuote = meltResp.Quote
|
meltQuote = meltResp.Quote
|
||||||
meltAmount = meltResp.Amount
|
meltAmount = meltResp.Amount + meltResp.FeeReserve + fee
|
||||||
|
|
||||||
|
if meltAmount > chosen.proofs.Amount() {
|
||||||
|
feeReserveAbs++
|
||||||
|
} else {
|
||||||
goto meltworked
|
goto meltworked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("stop trying to do the melt because the mint part is too expensive")
|
return "", fmt.Errorf("stop trying to do the melt because the invoice is too expensive")
|
||||||
|
|
||||||
meltworked:
|
meltworked:
|
||||||
// swap our proofs so we get the exact amount for paying the invoice
|
// swap our proofs so we get the exact amount for paying the invoice
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ func (w *Wallet) getProofsForSending(
|
|||||||
part.tokens = make([]Token, 0, 3)
|
part.tokens = make([]Token, 0, 3)
|
||||||
part.tokenIndexes = make([]int, 0, 3)
|
part.tokenIndexes = make([]int, 0, 3)
|
||||||
part.proofs = make(cashu.Proofs, 0, 7)
|
part.proofs = make(cashu.Proofs, 0, 7)
|
||||||
|
part.mint = token.Mint
|
||||||
}
|
}
|
||||||
|
|
||||||
part.tokens = append(part.tokens, token)
|
part.tokens = append(part.tokens, token)
|
||||||
@@ -193,6 +194,8 @@ func (w *Wallet) getProofsForSending(
|
|||||||
return part, fee, nil
|
return part, fee, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byMint[token.Mint] = part
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we got here it's because we didn't get enough proofs from the same mint
|
// if we got here it's because we didn't get enough proofs from the same mint
|
||||||
|
|||||||
Reference in New Issue
Block a user