Skip to content

Commit

Permalink
staticaddr: add swap client to cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
hieblmi committed Apr 22, 2024
1 parent 96f4625 commit 8ae63de
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions cmd/loop/staticaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func newStaticAddress(ctx *cli.Context) error {
return cli.ShowCommandHelp(ctx, "new")
}

client, cleanup, err := getAddressClient(ctx)
client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()

resp, err := client.NewAddress(
ctxb, &looprpc.NewAddressRequest{},
resp, err := client.NewStaticAddress(
ctxb, &looprpc.NewStaticAddressRequest{},
)
if err != nil {
return err
Expand Down Expand Up @@ -86,16 +86,17 @@ func listUnspent(ctx *cli.Context) error {
return cli.ShowCommandHelp(ctx, "listunspent")
}

client, cleanup, err := getAddressClient(ctx)
client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()

resp, err := client.ListUnspent(ctxb, &looprpc.ListUnspentRequest{
MinConfs: int32(ctx.Int("min_confs")),
MaxConfs: int32(ctx.Int("max_confs")),
})
resp, err := client.ListUnspentDeposits(
ctxb, &looprpc.ListUnspentDepositsRequest{
MinConfs: int32(ctx.Int("min_confs")),
MaxConfs: int32(ctx.Int("max_confs")),
})
if err != nil {
return err
}
Expand All @@ -104,21 +105,3 @@ func listUnspent(ctx *cli.Context) error {

return nil
}

func getAddressClient(ctx *cli.Context) (looprpc.StaticAddressClientClient,
func(), error) {

rpcServer := ctx.GlobalString("rpcserver")
tlsCertPath, macaroonPath, err := extractPathArgs(ctx)
if err != nil {
return nil, nil, err
}
conn, err := getClientConn(rpcServer, tlsCertPath, macaroonPath)
if err != nil {
return nil, nil, err
}
cleanup := func() { conn.Close() }

addressClient := looprpc.NewStaticAddressClientClient(conn)
return addressClient, cleanup, nil
}

0 comments on commit 8ae63de

Please sign in to comment.