cmd/llm: add new auction snapshot command
In this commit, we add a new CLI command that allows a client to
"browse" the prior outcome of batches.
@@ -2,6 +2,8 @@ package main
import (
"context"
+ "encoding/hex"
+ "fmt"
"github.com/lightninglabs/llm/clmrpc"
"github.com/urfave/cli"
@@ -15,6 +17,7 @@ var auctionCommands = []cli.Command{
Category: "Auction",
Subcommands: []cli.Command{
auctionFeeCommand,
+ batchSnapshotCommand,
},
},
}
@@ -48,3 +51,61 @@ func auctionFee(ctx *cli.Context) error {
return nil
}
+
+var batchSnapshotCommand = cli.Command{
+ Name: "snapshot",
+ ShortName: "s",
+ Usage: "return information about a prior cleared auction batch",
+ Description: `
+ Returns information about a prior batch such as the clearing
+ price and the set of orders included in the batch. The
+ prev_batch_id field can be used to explore prior batches in the
+ sequence, similar to a block chain.
+ `,
+ Flags: []cli.Flag{
+ cli.StringFlag{
+ Name: "batch_id",
+ Usage: "the target batch ID to obtain a snapshot " +
+ "for, if left blank, information about the " +
+ "latest batch is returned",
+ },
+ },
+ Action: batchSnapshot,
+}
+
+func batchSnapshot(ctx *cli.Context) error {
+ client, cleanup, err := getClient(ctx)
+ if err != nil {
+ return err
+ }
+ defer cleanup()
+
+ var batchIDStr string
+ switch {
+ case ctx.Args().Present():
+ batchIDStr = ctx.Args().First()
+
+ case ctx.IsSet("batch_id"):
+ batchIDStr = ctx.String("batch_id")
+ }
+
+ batchID, err := hex.DecodeString(batchIDStr)
+ if err != nil {
+ return fmt.Errorf("unable to decode batch ID: %v", err)
+ }
+
+ ctxb := context.Background()
+ batchSnapshot, err := client.BatchSnapshot(
+ ctxb,
+ &clmrpc.BatchSnapshotRequest{
+ BatchId: batchID,
+ },
+ )
+ if err != nil {
+ return err
+ }
+
+ printRespJSON(batchSnapshot)
+
+ return nil
+}
