Skip to content

Commit 47bf510

Browse files
committed
loopd: add RPC method to list tokens
1 parent a23dfe3 commit 47bf510

File tree

7 files changed

+617
-156
lines changed

7 files changed

+617
-156
lines changed

client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func NewClient(dbDir string, serverAddress string, insecure bool,
9595
LndServices: lnd,
9696
Server: swapServerClient,
9797
Store: store,
98+
LsatStore: lsatStore,
9899
CreateExpiryTimer: func(d time.Duration) <-chan time.Time {
99100
return time.NewTimer(d).C
100101
},

cmd/loopd/swapclient_server.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,40 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
346346
}, nil
347347
}
348348

349+
// GetLsatTokens returns all tokens that are contained in the LSAT token store.
350+
func (s *swapClientServer) GetLsatTokens(ctx context.Context,
351+
_ *looprpc.TokensRequest) (*looprpc.TokensResponse, error) {
352+
353+
log.Infof("Get LSAT tokens request received")
354+
355+
tokens, err := s.impl.LsatStore.AllTokens()
356+
if err != nil {
357+
return nil, err
358+
}
359+
360+
rpcTokens := make([]*looprpc.LsatToken, len(tokens))
361+
idx := 0
362+
for key, token := range tokens {
363+
macBytes, err := token.BaseMacaroon().MarshalBinary()
364+
if err != nil {
365+
return nil, err
366+
}
367+
rpcTokens[idx] = &looprpc.LsatToken{
368+
BaseMacaroon: macBytes,
369+
PaymentHash: token.PaymentHash[:],
370+
PaymentPreimage: token.Preimage[:],
371+
AmountPaidMsat: int64(token.AmountPaid),
372+
RoutingFeePaidMsat: int64(token.RoutingFeePaid),
373+
TimeCreated: token.TimeCreated.Unix(),
374+
Expired: !token.IsValid(),
375+
StorageName: key,
376+
}
377+
idx++
378+
}
379+
380+
return &looprpc.TokensResponse{Tokens: rpcTokens}, nil
381+
}
382+
349383
// validateConfTarget ensures the given confirmation target is valid. If one
350384
// isn't specified (0 value), then the default target is used.
351385
func validateConfTarget(target, defaultTarget int32) (int32, error) {

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import (
55

66
"github.com/lightninglabs/loop/lndclient"
77
"github.com/lightninglabs/loop/loopdb"
8+
"github.com/lightninglabs/loop/lsat"
89
)
910

1011
// clientConfig contains config items for the swap client.
1112
type clientConfig struct {
1213
LndServices *lndclient.LndServices
1314
Server swapServerClient
1415
Store loopdb.SwapStore
16+
LsatStore lsat.Store
1517
CreateExpiryTimer func(expiry time.Duration) <-chan time.Time
1618
}

looprpc/client.pb.go

Lines changed: 309 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.pb.gw.go

Lines changed: 61 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)