mirror of
https://github.com/lightninglabs/pool.git
synced 2026-08-13 12:33:04 +02:00
client: expose LSAT identity
This commit is contained in:
parent
9111b99f0b
commit
afa03d728b
1 changed files with 28 additions and 0 deletions
28
server.go
28
server.go
|
|
@ -1,6 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
|
|
@ -30,6 +31,10 @@ type Server struct {
|
|||
// restarted.
|
||||
AuctioneerClient *auctioneer.Client
|
||||
|
||||
// GetIdentity returns the current LSAT identification of the trader
|
||||
// client or an error if none has been established yet.
|
||||
GetIdentity func() (*lsat.TokenID, error)
|
||||
|
||||
cfg *Config
|
||||
lndServices *lndclient.GrpcLndServices
|
||||
traderServer *rpcServer
|
||||
|
|
@ -93,10 +98,32 @@ func NewServer(cfg *Config) (*Server, error) {
|
|||
&lndServices.LndServices, fileStore, defaultRPCTimeout,
|
||||
defaultLsatMaxCost, defaultLsatMaxFee,
|
||||
)
|
||||
|
||||
// getIdentity can be used to determine the current LSAT identification
|
||||
// of the trader.
|
||||
getIdentity := func() (*lsat.TokenID, error) {
|
||||
token, err := fileStore.CurrentToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
macID, err := lsat.DecodeIdentifier(
|
||||
bytes.NewBuffer(token.BaseMacaroon().Id()),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &macID.TokenID, nil
|
||||
}
|
||||
|
||||
// For regtest, we create a fixed identity now that is used for the
|
||||
// whole runtime of the trader.
|
||||
if cfg.Network == "regtest" {
|
||||
var tokenID lsat.TokenID
|
||||
_, _ = rand.Read(tokenID[:])
|
||||
interceptor = ®testInterceptor{id: tokenID}
|
||||
getIdentity = func() (*lsat.TokenID, error) {
|
||||
return &tokenID, nil
|
||||
}
|
||||
}
|
||||
cfg.AuctioneerDialOpts = append(
|
||||
cfg.AuctioneerDialOpts,
|
||||
|
|
@ -123,6 +150,7 @@ func NewServer(cfg *Config) (*Server, error) {
|
|||
cfg: cfg,
|
||||
lndServices: lndServices,
|
||||
AuctioneerClient: auctioneerClient,
|
||||
GetIdentity: getIdentity,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue