Skip to content

Commit f879c52

Browse files
authored
Merge pull request #1150 from hieblmi/show-static-details
looprpc: populate static address swap timing and cost fields
2 parents 5818b98 + 63affee commit f879c52

13 files changed

Lines changed: 413 additions & 12 deletions

File tree

cmd/loop/staticaddr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func listWithdrawals(ctx context.Context, cmd *cli.Command) error {
349349

350350
var listStaticAddressSwapsCommand = &cli.Command{
351351
Name: "listswaps",
352-
Usage: "Shows a list of finalized static address swaps.",
352+
Usage: "Shows a list of static address swaps.",
353353
Description: `
354354
`,
355355
Action: listStaticAddressSwaps,

cmd/loop/testdata/sessions/static-loop-in/04_loop-static.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
" listunspent, l List unspent static address outputs.\n",
2929
" listdeposits Displays static address deposits. A filter can be applied to only show deposits in a specific state.\n",
3030
" listwithdrawals Display a summary of past withdrawals.\n",
31-
" listswaps Shows a list of finalized static address swaps.\n",
31+
" listswaps Shows a list of static address swaps.\n",
3232
" withdraw, w Withdraw from static address deposits.\n",
3333
" summary, s Display a summary of static address related information.\n",
3434
" in Loop in funds from static address deposits.\n",

docs/loop.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ Display a summary of past withdrawals.
511511

512512
.SS listswaps
513513
.PP
514-
Shows a list of finalized static address swaps.
514+
Shows a list of static address swaps.
515515

516516
.PP
517517
\fB--help, -h\fP: show help

docs/loop.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ The following flags are supported:
601601

602602
### `static listswaps` subcommand
603603

604-
Shows a list of finalized static address swaps.
604+
Shows a list of static address swaps.
605605

606606
Usage:
607607

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,8 @@ replace gonum.org/v1/gonum => github.com/gonum/gonum v0.11.0
238238

239239
replace gonum.org/v1/plot => github.com/gonum/plot v0.10.1
240240

241+
// the replaced domain disappeared and package moved to new location. Worth
242+
// checking later if the domain reappears and replace can be removed.
243+
replace dario.cat/mergo => github.com/darccio/mergo v1.0.1
244+
241245
go 1.25.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,6 @@ cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoIS
592592
cloud.google.com/go/workflows v1.8.0/go.mod h1:ysGhmEajwZxGn1OhGOGKsTXc5PyxOc0vfKf5Af+to4M=
593593
cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT3ujaO/WwSA=
594594
cloud.google.com/go/workflows v1.10.0/go.mod h1:fZ8LmRmZQWacon9UCX1r/g/DfAXx5VcPALq2CxzdePw=
595-
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
596-
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
597595
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
598596
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
599597
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
@@ -747,6 +745,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
747745
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
748746
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
749747
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
748+
github.com/darccio/mergo v1.0.1 h1:xYD7+aWQRjjQuN2qd0DjhRavXPuEnm8pMIRJMY1AAiU=
749+
github.com/darccio/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
750750
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
751751
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
752752
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

loopd/swapclient_server.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,10 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
19661966

19671967
var clientSwaps []*looprpc.StaticAddressLoopInSwap
19681968
for _, swp := range swaps {
1969+
if swp == nil {
1970+
continue
1971+
}
1972+
19691973
chainParams, err := s.network.ChainParams()
19701974
if err != nil {
19711975
return nil, fmt.Errorf("error getting chain params")
@@ -2005,13 +2009,19 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
20052009
if swp.SelectedAmount > 0 {
20062010
swapAmount = swp.SelectedAmount
20072011
}
2012+
costServer := staticAddressLoopInSwapServerCost(swp)
2013+
initiationTime := staticAddressLoopInTimestamp(swp.InitiationTime)
2014+
lastUpdateTime := staticAddressLoopInTimestamp(swp.LastUpdateTime)
20082015
swap := &looprpc.StaticAddressLoopInSwap{
20092016
SwapHash: swp.SwapHash[:],
20102017
DepositOutpoints: swp.DepositOutpoints,
20112018
State: state,
20122019
SwapAmountSatoshis: int64(swapAmount),
20132020
PaymentRequestAmountSatoshis: payReqAmount,
20142021
Deposits: protoDeposits,
2022+
InitiationTime: initiationTime,
2023+
LastUpdateTime: lastUpdateTime,
2024+
CostServer: costServer,
20152025
}
20162026

20172027
clientSwaps = append(clientSwaps, swap)
@@ -2022,6 +2032,31 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
20222032
}, nil
20232033
}
20242034

2035+
func staticAddressLoopInTimestamp(t time.Time) int64 {
2036+
if t.IsZero() {
2037+
return 0
2038+
}
2039+
2040+
return t.UnixNano()
2041+
}
2042+
2043+
// staticAddressLoopInSwapServerCost returns the paid server cost using the
2044+
// legacy ListSwaps cost semantics. Static loop-ins currently only persist the
2045+
// accepted quote fee, and that fee is paid once the swap invoice settles.
2046+
// Timeout-path miner fees are not persisted, so cost_onchain and cost_offchain
2047+
// remain zero instead of returning an estimate as an actual cost.
2048+
func staticAddressLoopInSwapServerCost(swp *loopin.StaticAddressLoopIn) int64 {
2049+
switch swp.GetState() {
2050+
case loopin.PaymentReceived, loopin.Succeeded,
2051+
loopin.SucceededTransitioningFailed:
2052+
2053+
return int64(swp.QuotedSwapFee)
2054+
2055+
default:
2056+
return 0
2057+
}
2058+
}
2059+
20252060
// GetStaticAddressSummary returns a summary of static address-related
20262061
// information. Amongst deposits and withdrawals and their total values, it also
20272062
// includes a list of detailed deposit information filtered by their state.

0 commit comments

Comments
 (0)