From 1e267bb57f257bf179bf030f57e1782959aa2ff8 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 6 Sep 2021 13:58:00 +0200 Subject: [PATCH] cmd/pool: use DecodeSidecarTicket RPC for printticket --- cmd/pool/sidecar.go | 63 ++++++++------------------------------------- 1 file changed, 11 insertions(+), 52 deletions(-) diff --git a/cmd/pool/sidecar.go b/cmd/pool/sidecar.go index a66bb8151..477fd6a5b 100644 --- a/cmd/pool/sidecar.go +++ b/cmd/pool/sidecar.go @@ -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" ) @@ -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"}, @@ -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 }