Skip to content

Commit

Permalink
tapcliutil: wrap getinfo command with RPC client targeting
Browse files Browse the repository at this point in the history
Apply the new RPC client targeting functionality to the `getinfo`
command, allowing it to directly target (call into) a specific RPC
client.
  • Loading branch information
ffranr committed Jan 20, 2025
1 parent 499abeb commit 11f762d
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions tapcliutil/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ func NewApp() cli.App {
}

// Add all the available commands.
//
// TODO(ffranr): Replace with a call to `Commands`.
app.Commands = []cli.Command{
stopCommand,
debugLevelCommand,
profileSubCommand,
getInfoCommand,
NewGetInfoCommand(nil),
}
app.Commands = append(app.Commands, assetsCommands...)
app.Commands = append(app.Commands, addrCommands...)
Expand All @@ -121,6 +123,18 @@ type ClientInterfaceBundle interface {
tapdevrpc.TapDevClient
}

// Commands returns all the available commands for the tapcli.
//
// TODO(ffranr): Add all the available commands.
func Commands(rpcClientHarness *RpcClientHarness) []cli.Command {
// Add all the available commands.
commands := []cli.Command{
NewGetInfoCommand(rpcClientHarness),
}

return commands
}

func getContext() context.Context {
shutdownInterceptor, err := signal.Intercept()
if err != nil {
Expand Down Expand Up @@ -219,26 +233,29 @@ func stopDaemon(ctx *cli.Context) error {
return nil
}

var getInfoCommand = cli.Command{
Name: "getinfo",
Usage: "Get daemon info.",
Description: "Returns basic information related to the active daemon.",
Action: getInfo,
// NewGetInfoCommand creates a new command to get daemon info.
func NewGetInfoCommand(clientSpecifier *RpcClientHarness) cli.Command {
return cli.Command{
Name: "getinfo",
Usage: "Get daemon info.",
Description: "Returns basic information related to the " +
"active daemon.",
Action: NewWrappedAction(clientSpecifier, getInfo),
}
}

func getInfo(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
// getInfo is the action function for the `getinfo` command.
func getInfo(_ *cli.Context, ctx context.Context,
client taprpc.TaprootAssetsClient) (proto.Message, error) {

req := &taprpc.GetInfoRequest{}
resp, err := client.GetInfo(ctxc, req)
resp, err := client.GetInfo(ctx, req)
if err != nil {
return err
return nil, err
}

printRespJSON(resp)
return nil
return resp, nil
}

// RpcClientHarness is a struct that contains the necessary information to
Expand Down

0 comments on commit 11f762d

Please sign in to comment.