Skip to content

Commit

Permalink
multi: expose l402 id in grpc interface
Browse files Browse the repository at this point in the history
This commit adds an additional field to the tokens in order to fetch the
relevant l402 ids for the users tokens.
  • Loading branch information
sputn1ck committed Jun 22, 2023
1 parent eaad220 commit e97b5be
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
10 changes: 2 additions & 8 deletions cmd/loop/lsat.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package main

import (
"bytes"
"context"
"encoding/hex"
"fmt"
"time"

"github.com/lightninglabs/aperture/lsat"
"github.com/lightninglabs/loop/looprpc"
"github.com/urfave/cli"
"gopkg.in/macaroon.v2"
Expand Down Expand Up @@ -55,13 +53,9 @@ func listAuth(ctx *cli.Context) error {
return fmt.Errorf("unable to unmarshal macaroon: %v",
err)
}
id, err := lsat.DecodeIdentifier(bytes.NewReader(mac.Id()))
if err != nil {
return fmt.Errorf("unable to decode macaroon ID: %v",
err)
}

tokens[i] = &printableToken{
ID: hex.EncodeToString(id.TokenID[:]),
ID: t.Id,
ValidUntil: "",
BaseMacaroon: hex.EncodeToString(t.BaseMacaroon),
PaymentHash: hex.EncodeToString(t.PaymentHash),
Expand Down
12 changes: 12 additions & 0 deletions loopd/swapclient_server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loopd

import (
"bytes"
"context"
"encoding/hex"
"errors"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/lightninglabs/aperture/lsat"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/labels"
Expand Down Expand Up @@ -723,6 +725,13 @@ func (s *swapClientServer) GetLsatTokens(ctx context.Context,
if err != nil {
return nil, err
}

id, err := lsat.DecodeIdentifier(
bytes.NewReader(token.BaseMacaroon().Id()),
)
if err != nil {
return nil, err
}
rpcTokens[idx] = &clientrpc.LsatToken{
BaseMacaroon: macBytes,
PaymentHash: token.PaymentHash[:],
Expand All @@ -732,6 +741,9 @@ func (s *swapClientServer) GetLsatTokens(ctx context.Context,
TimeCreated: token.TimeCreated.Unix(),
Expired: !token.IsValid(),
StorageName: key,
Id: hex.EncodeToString(
id.TokenID[:],
),
}
idx++
}
Expand Down
15 changes: 13 additions & 2 deletions looprpc/client.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions looprpc/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ message LsatToken {
file name of the token where it's stored on the file system.
*/
string storage_name = 8;

/*
The l402 Id of the token.
*/
string id = 9;
}

message LoopStats {
Expand Down
4 changes: 4 additions & 0 deletions looprpc/client.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,10 @@
"storage_name": {
"type": "string",
"description": "Identifying attribute of this token in the store. Currently represents the\nfile name of the token where it's stored on the file system."
},
"id": {
"type": "string",
"description": "The l402 Id of the token."
}
}
},
Expand Down

0 comments on commit e97b5be

Please sign in to comment.