Skip to content

Commit aab693b

Browse files
committed
all info stuff
1 parent 8160efa commit aab693b

18 files changed

+1367
-620
lines changed

cmd/loop/staticaddr.go

+33
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var staticAddressCommands = cli.Command{
3030
newStaticAddressCommand,
3131
listUnspentCommand,
3232
listDepositsCommand,
33+
listWithdrawalsCommand,
3334
listStaticAddressSwapsCommand,
3435
withdrawalCommand,
3536
summaryCommand,
@@ -247,6 +248,14 @@ var listDepositsCommand = cli.Command{
247248
Action: listDeposits,
248249
}
249250

251+
var listWithdrawalsCommand = cli.Command{
252+
Name: "listwithdrawals",
253+
Usage: "Display a summary of past withdrawals.",
254+
Description: `
255+
`,
256+
Action: listWithdrawals,
257+
}
258+
250259
var listStaticAddressSwapsCommand = cli.Command{
251260
Name: "listswaps",
252261
Usage: "Display a summary of static address related information.",
@@ -345,6 +354,30 @@ func listDeposits(ctx *cli.Context) error {
345354
return nil
346355
}
347356

357+
func listWithdrawals(ctx *cli.Context) error {
358+
ctxb := context.Background()
359+
if ctx.NArg() > 0 {
360+
return cli.ShowCommandHelp(ctx, "withdrawals")
361+
}
362+
363+
client, cleanup, err := getClient(ctx)
364+
if err != nil {
365+
return err
366+
}
367+
defer cleanup()
368+
369+
resp, err := client.ListStaticAddressWithdrawals(
370+
ctxb, &looprpc.ListStaticAddressWithdrawalRequest{},
371+
)
372+
if err != nil {
373+
return err
374+
}
375+
376+
printRespJSON(resp)
377+
378+
return nil
379+
}
380+
348381
func listStaticAddressSwaps(ctx *cli.Context) error {
349382
ctxb := context.Background()
350383
if ctx.NArg() > 0 {

loopd/daemon.go

+2
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
604604
depositManager = deposit.NewManager(depoCfg)
605605

606606
// Static address deposit withdrawal manager setup.
607+
withdrawalStore := withdraw.NewSqlStore(baseDb)
607608
withdrawalCfg := &withdraw.ManagerConfig{
608609
StaticAddressServerClient: staticAddressClient,
609610
AddressManager: staticAddressManager,
@@ -612,6 +613,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
612613
ChainParams: d.lnd.ChainParams,
613614
ChainNotifier: d.lnd.ChainNotifier,
614615
Signer: d.lnd.Signer,
616+
Store: withdrawalStore,
615617
}
616618
withdrawalManager = withdraw.NewManager(withdrawalCfg, blockHeight)
617619

loopd/swapclient_server.go

+32
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,38 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
16651665
}, nil
16661666
}
16671667

1668+
// ListStaticAddressWithdrawals ...
1669+
func (s *swapClientServer) ListStaticAddressWithdrawals(ctx context.Context,
1670+
_ *looprpc.ListStaticAddressWithdrawalRequest) (
1671+
*looprpc.ListStaticAddressWithdrawalResponse, error) {
1672+
1673+
withdrawals, err := s.withdrawalManager.GetAllWithdrawals(ctx)
1674+
if err != nil {
1675+
return nil, err
1676+
}
1677+
1678+
if len(withdrawals) == 0 {
1679+
return &looprpc.ListStaticAddressWithdrawalResponse{}, nil
1680+
}
1681+
1682+
clientWithdrawals := make([]*looprpc.StaticAddressWithdrawal, 0, len(withdrawals))
1683+
for _, w := range withdrawals {
1684+
withdrawal := &looprpc.StaticAddressWithdrawal{
1685+
TxId: w.TxID.String(),
1686+
Outpoints: w.DepositOutpoints,
1687+
TotalDepositAmountSatoshis: int64(w.TotalDepositAmount),
1688+
WithdrawnAmountSatoshis: int64(w.WithdrawnAmount),
1689+
ChangeAmountSatoshis: int64(w.ChangeAmount),
1690+
ConfirmationHeight: w.ConfirmationHeight,
1691+
}
1692+
clientWithdrawals = append(clientWithdrawals, withdrawal)
1693+
}
1694+
1695+
return &looprpc.ListStaticAddressWithdrawalResponse{
1696+
Withdrawals: clientWithdrawals,
1697+
}, nil
1698+
}
1699+
16681700
// ListStaticAddressSwaps returns a list of all swaps that are currently pending
16691701
// or previously succeeded.
16701702
func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS withdrawals;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE TABLE IF NOT EXISTS withdrawals (
2+
-- id is the auto-incrementing primary key for a withdrawal.
3+
id INTEGER PRIMARY KEY,
4+
5+
withdrawal_tx_id TEXT NOT NULL UNIQUE,
6+
7+
deposit_outpoints TEXT NOT NULL,
8+
9+
total_deposit_amount BIGINT NOT NULL,
10+
11+
withdrawn_amount BIGINT NOT NULL,
12+
13+
change_amount BIGINT NOT NULL,
14+
15+
confirmation_height BIGINT NOT NULL
16+
);

loopdb/sqlc/models.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/querier.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- name: CreateWithdrawal :exec
2+
INSERT INTO withdrawals (
3+
withdrawal_tx_id,
4+
deposit_outpoints,
5+
total_deposit_amount,
6+
withdrawn_amount,
7+
change_amount,
8+
confirmation_height
9+
) VALUES (
10+
$1,
11+
$2,
12+
$3,
13+
$4,
14+
$5,
15+
$6
16+
);
17+
18+
-- name: AllWithdrawals :many
19+
SELECT
20+
*
21+
FROM
22+
withdrawals
23+
ORDER BY
24+
id ASC;

loopdb/sqlc/static_address_withdrawals.sql.go

+89
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)