Skip to content

Commit

Permalink
cmd/pool: use DecodeSidecarTicket RPC for printticket
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Sep 22, 2021
1 parent a5cf85a commit 3d015ec
Showing 1 changed file with 11 additions and 52 deletions.
63 changes: 11 additions & 52 deletions cmd/pool/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package main

import (
"context"
"encoding/hex"
"fmt"
"strconv"

"github.com/btcsuite/btcutil"
"github.com/lightninglabs/pool/order"
"github.com/lightninglabs/pool/poolrpc"
"github.com/lightninglabs/pool/sidecar"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -179,20 +177,6 @@ func sidecarOffer(ctx *cli.Context) error {
return nil
}

type jsonTicket struct {
ID string
Version uint8
State string
Capacity uint64
PushAmount uint64
LeaseDurationBlocks uint32
OfferSigningPubKey string
RecipientNodePubKey string
RecipientMultiSigPubKey string
RecipientMultiSigKeyIndex uint32
OrderNonce string
}

var sidecarPrintTicketCommand = cli.Command{
Name: "printticket",
Aliases: []string{"p"},
Expand All @@ -211,47 +195,22 @@ func sidecarPrintTicket(ctx *cli.Context) error {
return nil
}

ticketStr := ctx.Args().First()

ticket, err := sidecar.DecodeString(ticketStr)
client, cleanup, err := getClient(ctx)
if err != nil {
return fmt.Errorf("error decoding base64 ticket: %v", err)
}

jsonTicket := &jsonTicket{
ID: hex.EncodeToString(ticket.ID[:]),
Version: uint8(ticket.Version),
State: ticket.State.String(),
Capacity: uint64(ticket.Offer.Capacity),
PushAmount: uint64(ticket.Offer.PushAmt),
LeaseDurationBlocks: ticket.Offer.LeaseDurationBlocks,
return err
}
defer cleanup()

if ticket.Offer.SignPubKey != nil {
jsonTicket.OfferSigningPubKey = hex.EncodeToString(
ticket.Offer.SignPubKey.SerializeCompressed(),
)
}
if ticket.Recipient != nil {
if ticket.Recipient.NodePubKey != nil {
jsonTicket.RecipientNodePubKey = hex.EncodeToString(
ticket.Recipient.NodePubKey.SerializeCompressed(),
)
}
if ticket.Recipient.MultiSigPubKey != nil {
jsonTicket.RecipientMultiSigPubKey = hex.EncodeToString(
ticket.Recipient.MultiSigPubKey.SerializeCompressed(),
)
}
jsonTicket.RecipientMultiSigKeyIndex = ticket.Recipient.MultiSigKeyIndex
}
if ticket.Order != nil {
jsonTicket.OrderNonce = hex.EncodeToString(
ticket.Order.BidNonce[:],
)
resp, err := client.DecodeSidecarTicket(
context.Background(), &poolrpc.SidecarTicket{
Ticket: ctx.Args().First(),
},
)
if err != nil {
return err
}

printJSON(jsonTicket)
printRespJSON(resp)

return nil
}
Expand Down

0 comments on commit 3d015ec

Please sign in to comment.