Files
aperture/challenger/lnc.go
Boris Nagaev a4431801ef multi: replace LSAT with L402
auth: LsatAuthenticator -> L402Authenticator
sed -i 's/LsatAuthenticator/L402Authenticator/g' aperture.go auth/authenticator.go auth/authenticator_test.go

rename package lsat to l402
git mv lsat/ l402
sed 's@aperture/lsat@aperture/l402@g' -i `git grep -l aperture/lsat`
sed -i 's@package lsat@package l402@' `git grep -l 'package lsat'`
sed -i 's@lsat\.@l402.@g' -i `git grep -l 'lsat\.'`
sed 's@l402.Id@lsat.Id@' -i mint/mint_test.go

replace lsat with l402 in the code
sed 's@lsat@l402@' -i mint/mint_test.go
sed 's@Lsat@L402@' -i l402/client_interceptor.go
sed 's@lsatstore@l402store@' -i l402/store_test.go

replace LSAT to L402 in comments
sed '/\/\//s@LSAT@L402@g' -i `git grep -l '//.*LSAT'`

replace LSAT -> L402 in the code, skip when a string starts with it
sed 's@\([^"/]\)LSAT@\1L402@g' -i `git grep -l LSAT`
2024-04-16 19:33:03 -03:00

85 lines
2.2 KiB
Go

package challenger
import (
"fmt"
"time"
"github.com/lightninglabs/aperture/lnc"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntypes"
)
// LNCChallenger is a challenger that uses LNC to connect to an lnd backend to
// create new L402 payment challenges.
type LNCChallenger struct {
lndChallenger *LndChallenger
nodeConn *lnc.NodeConn
}
// NewLNCChallenger creates a new challenger that uses the given LNC session to
// connect to an lnd backend to create payment challenges.
func NewLNCChallenger(session *lnc.Session, lncStore lnc.Store,
genInvoiceReq InvoiceRequestGenerator,
errChan chan<- error) (*LNCChallenger, error) {
nodeConn, err := lnc.NewNodeConn(session, lncStore)
if err != nil {
return nil, fmt.Errorf("unable to connect to lnd using lnc: %w",
err)
}
client, err := nodeConn.Client()
if err != nil {
return nil, err
}
lndChallenger, err := NewLndChallenger(
client, genInvoiceReq, nodeConn.CtxFunc, errChan,
)
if err != nil {
return nil, err
}
err = lndChallenger.Start()
if err != nil {
return nil, err
}
return &LNCChallenger{
lndChallenger: lndChallenger,
nodeConn: nodeConn,
}, nil
}
// Stop stops the challenger.
func (l *LNCChallenger) Stop() {
err := l.nodeConn.Stop()
if err != nil {
log.Errorf("unable to stop lnc node conn: %v", err)
}
l.lndChallenger.Stop()
}
// NewChallenge creates a new L402 payment challenge, returning a payment
// request (invoice) and the corresponding payment hash.
//
// NOTE: This is part of the mint.Challenger interface.
func (l *LNCChallenger) NewChallenge(price int64) (string, lntypes.Hash,
error) {
return l.lndChallenger.NewChallenge(price)
}
// VerifyInvoiceStatus checks that an invoice identified by a payment
// hash has the desired status. To make sure we don't fail while the
// invoice update is still on its way, we try several times until either
// the desired status is set or the given timeout is reached.
//
// NOTE: This is part of the auth.InvoiceChecker interface.
func (l *LNCChallenger) VerifyInvoiceStatus(hash lntypes.Hash,
state lnrpc.Invoice_InvoiceState, timeout time.Duration) error {
return l.lndChallenger.VerifyInvoiceStatus(hash, state, timeout)
}