diff --git a/client.go b/client.go index 526c2a6..91aa82f 100644 --- a/client.go +++ b/client.go @@ -151,8 +151,8 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore, config := &clientConfig{ LndServices: cfg.Lnd, Server: swapServerClient, - Store: loopDB, Conn: swapServerClient.conn, + Store: loopDB, LsatStore: lsatStore, CreateExpiryTimer: func(d time.Duration) <-chan time.Time { return time.NewTimer(d).C diff --git a/cmd/loop/loopin.go b/cmd/loop/loopin.go index 52e8890..2d84a5e 100644 --- a/cmd/loop/loopin.go +++ b/cmd/loop/loopin.go @@ -52,6 +52,9 @@ var ( Name: "in", Usage: "perform an on-chain to off-chain swap (loop in)", ArgsUsage: "amt", + Subcommands: []cli.Command{ + staticAddressCommands, + }, Description: ` Send the amount in satoshis specified by the amt argument off-chain. diff --git a/cmd/loop/main.go b/cmd/loop/main.go index 0e970c2..44023da 100644 --- a/cmd/loop/main.go +++ b/cmd/loop/main.go @@ -148,7 +148,7 @@ func main() { listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand, setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand, getInfoCommand, abandonSwapCommand, reservationsCommands, - instantOutCommand, + instantOutCommand, staticAddressCommands, } err := app.Run(os.Args) diff --git a/cmd/loop/staticaddr.go b/cmd/loop/staticaddr.go new file mode 100644 index 0000000..394e5b1 --- /dev/null +++ b/cmd/loop/staticaddr.go @@ -0,0 +1,76 @@ +package main + +import ( + "context" + "fmt" + + "github.com/lightninglabs/loop/looprpc" + "github.com/urfave/cli" +) + +var staticAddressCommands = cli.Command{ + Name: "static", + ShortName: "s", + Usage: "manage static loop-in addresses", + Category: "StaticAddress", + Subcommands: []cli.Command{ + newStaticAddressCommand, + }, +} + +var newStaticAddressCommand = cli.Command{ + Name: "new", + ShortName: "n", + Usage: "Create a new static loop in address.", + Description: ` + Requests a new static loop in address from the server. Funds that are + sent to this address will be locked by a 2:2 multisig between us and the + loop server, or a timeout path that we can sweep once it opens up. The + funds can either be cooperatively spent with a signature from the server + or looped in. + `, + Action: newStaticAddress, +} + +func newStaticAddress(ctx *cli.Context) error { + ctxb := context.Background() + if ctx.NArg() > 0 { + return cli.ShowCommandHelp(ctx, "new") + } + + client, cleanup, err := getAddressClient(ctx) + if err != nil { + return err + } + defer cleanup() + + resp, err := client.NewAddress( + ctxb, &looprpc.NewAddressRequest{}, + ) + if err != nil { + return err + } + + fmt.Printf("Received a new static loop-in address from the server: "+ + "%s\n", resp.Address) + + 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 +}