mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
cmd/loop: add cli clock and hook
This commit is contained in:
parent
3e9a99dd55
commit
cdec0cacef
3 changed files with 18 additions and 4 deletions
|
|
@ -248,9 +248,9 @@ func loopOut(ctx context.Context, cmd *cli.Command) error {
|
|||
// Set our maximum swap wait time. If a fast swap is requested we set
|
||||
// it to now, otherwise to 30 minutes in the future.
|
||||
fast := cmd.Bool("fast")
|
||||
swapDeadline := time.Now()
|
||||
swapDeadline := cliClock.Now()
|
||||
if !fast {
|
||||
swapDeadline = time.Now().Add(defaultSwapWaitTime)
|
||||
swapDeadline = cliClock.Now().Add(defaultSwapWaitTime)
|
||||
}
|
||||
|
||||
sweepConfTarget := int32(cmd.Uint64("conf_target"))
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/lightninglabs/loop/loopd"
|
||||
"github.com/lightninglabs/loop/looprpc"
|
||||
"github.com/lightninglabs/loop/swap"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/lncfg"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/macaroons"
|
||||
|
|
@ -99,6 +100,9 @@ var (
|
|||
instantOutCommand, listInstantOutsCommand, stopCommand,
|
||||
printManCommand, printMarkdownCommand,
|
||||
}
|
||||
|
||||
// cliClock provides the time source used by CLI commands.
|
||||
cliClock clock.Clock = clock.NewDefaultClock()
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -264,6 +268,16 @@ func getClientWithConn(cmd *cli.Command) (looprpc.SwapClientClient,
|
|||
return loopClient, conn, cleanup, nil
|
||||
}
|
||||
|
||||
// hookClock overrides cliClock until the returned callback is called.
|
||||
func hookClock(c clock.Clock) func() {
|
||||
prev := cliClock
|
||||
cliClock = c
|
||||
|
||||
return func() {
|
||||
cliClock = prev
|
||||
}
|
||||
}
|
||||
|
||||
func getMaxRoutingFee(amt btcutil.Amount) btcutil.Amount {
|
||||
return swap.CalcFee(amt, maxRoutingFeeBase, maxRoutingFeeRate)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,9 +206,9 @@ func quoteOut(ctx context.Context, cmd *cli.Command) error {
|
|||
defer cleanup()
|
||||
|
||||
fast := cmd.Bool("fast")
|
||||
swapDeadline := time.Now()
|
||||
swapDeadline := cliClock.Now()
|
||||
if !fast {
|
||||
swapDeadline = time.Now().Add(defaultSwapWaitTime)
|
||||
swapDeadline = cliClock.Now().Add(defaultSwapWaitTime)
|
||||
}
|
||||
|
||||
quoteReq := &looprpc.QuoteRequest{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue