-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf36613
commit 570be29
Showing
4 changed files
with
104 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package challenger | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/lightninglabs/aperture/lnc" | ||
"github.com/lightningnetwork/lnd/lnrpc" | ||
"github.com/lightningnetwork/lnd/lntypes" | ||
) | ||
|
||
// LndChallenger is a challenger that uses an lnd backend to create new LSAT | ||
// payment challenges. | ||
type LNCChallenger struct { | ||
lndChallenger *LndChallenger | ||
nodeConn *lnc.NodeConn | ||
} | ||
|
||
// NewLndChallenger creates a new challenger that uses the given connection 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 LSAT 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters