From 8d5faea971e3bc18d14353c81e8ce6de6322a70a Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 7 Mar 2019 11:51:16 +0100 Subject: [PATCH] loop: move commands to separate files --- cmd/loop/{commands.go => loopout.go} | 80 ---------------------------- cmd/loop/monitor.go | 38 +++++++++++++ cmd/loop/terms.go | 61 +++++++++++++++++++++ 3 files changed, 99 insertions(+), 80 deletions(-) rename cmd/loop/{commands.go => loopout.go} (56%) create mode 100644 cmd/loop/monitor.go create mode 100644 cmd/loop/terms.go diff --git a/cmd/loop/commands.go b/cmd/loop/loopout.go similarity index 56% rename from cmd/loop/commands.go rename to cmd/loop/loopout.go index 6c216a1..6767a84 100644 --- a/cmd/loop/commands.go +++ b/cmd/loop/loopout.go @@ -4,9 +4,7 @@ import ( "context" "fmt" - "github.com/btcsuite/btcutil" "github.com/lightninglabs/loop/looprpc" - "github.com/lightninglabs/loop/swap" "github.com/urfave/cli" ) @@ -97,81 +95,3 @@ func loopOut(ctx *cli.Context) error { return nil } - -var termsCommand = cli.Command{ - Name: "terms", - Usage: "show current server swap terms", - Action: terms, -} - -func terms(ctx *cli.Context) error { - client, cleanup, err := getClient(ctx) - if err != nil { - return err - } - defer cleanup() - - terms, err := client.GetLoopOutTerms( - context.Background(), &looprpc.TermsRequest{}, - ) - if err != nil { - return err - } - - fmt.Printf("Amount: %d - %d\n", - btcutil.Amount(terms.MinSwapAmount), - btcutil.Amount(terms.MaxSwapAmount), - ) - if err != nil { - return err - } - - printTerms := func(terms *looprpc.TermsResponse) { - fmt.Printf("Amount: %d - %d\n", - btcutil.Amount(terms.MinSwapAmount), - btcutil.Amount(terms.MaxSwapAmount), - ) - fmt.Printf("Fee: %d + %.4f %% (%d prepaid)\n", - btcutil.Amount(terms.SwapFeeBase), - swap.FeeRateAsPercentage(terms.SwapFeeRate), - btcutil.Amount(terms.PrepayAmt), - ) - - fmt.Printf("Cltv delta: %v blocks\n", terms.CltvDelta) - } - - fmt.Println("Loop Out") - fmt.Println("--------") - printTerms(terms) - - return nil -} - -var monitorCommand = cli.Command{ - Name: "monitor", - Usage: "monitor progress of any active swaps", - Description: "Allows the user to monitor progress of any active swaps", - Action: monitor, -} - -func monitor(ctx *cli.Context) error { - client, cleanup, err := getClient(ctx) - if err != nil { - return err - } - defer cleanup() - - stream, err := client.Monitor( - context.Background(), &looprpc.MonitorRequest{}) - if err != nil { - return err - } - - for { - swap, err := stream.Recv() - if err != nil { - return fmt.Errorf("recv: %v", err) - } - logSwap(swap) - } -} diff --git a/cmd/loop/monitor.go b/cmd/loop/monitor.go new file mode 100644 index 0000000..8f51fcf --- /dev/null +++ b/cmd/loop/monitor.go @@ -0,0 +1,38 @@ +package main + +import ( + "context" + "fmt" + + "github.com/lightninglabs/loop/looprpc" + "github.com/urfave/cli" +) + +var monitorCommand = cli.Command{ + Name: "monitor", + Usage: "monitor progress of any active swaps", + Description: "Allows the user to monitor progress of any active swaps", + Action: monitor, +} + +func monitor(ctx *cli.Context) error { + client, cleanup, err := getClient(ctx) + if err != nil { + return err + } + defer cleanup() + + stream, err := client.Monitor( + context.Background(), &looprpc.MonitorRequest{}) + if err != nil { + return err + } + + for { + swap, err := stream.Recv() + if err != nil { + return fmt.Errorf("recv: %v", err) + } + logSwap(swap) + } +} diff --git a/cmd/loop/terms.go b/cmd/loop/terms.go new file mode 100644 index 0000000..960779b --- /dev/null +++ b/cmd/loop/terms.go @@ -0,0 +1,61 @@ +package main + +import ( + "context" + "fmt" + + "github.com/btcsuite/btcutil" + "github.com/lightninglabs/loop/swap" + + "github.com/lightninglabs/loop/looprpc" + "github.com/urfave/cli" +) + +var termsCommand = cli.Command{ + Name: "terms", + Usage: "show current server swap terms", + Action: terms, +} + +func terms(ctx *cli.Context) error { + client, cleanup, err := getClient(ctx) + if err != nil { + return err + } + defer cleanup() + + terms, err := client.GetLoopOutTerms( + context.Background(), &looprpc.TermsRequest{}, + ) + if err != nil { + return err + } + + fmt.Printf("Amount: %d - %d\n", + btcutil.Amount(terms.MinSwapAmount), + btcutil.Amount(terms.MaxSwapAmount), + ) + if err != nil { + return err + } + + printTerms := func(terms *looprpc.TermsResponse) { + fmt.Printf("Amount: %d - %d\n", + btcutil.Amount(terms.MinSwapAmount), + btcutil.Amount(terms.MaxSwapAmount), + ) + fmt.Printf("Fee: %d + %.4f %% (%d prepaid)\n", + btcutil.Amount(terms.SwapFeeBase), + swap.FeeRateAsPercentage(terms.SwapFeeRate), + btcutil.Amount(terms.PrepayAmt), + ) + + fmt.Printf("Cltv delta: %v blocks\n", terms.CltvDelta) + } + + fmt.Println("Loop Out") + fmt.Println("--------") + printTerms(terms) + + return nil +}