-
Notifications
You must be signed in to change notification settings - Fork 14
/
fee.go
146 lines (128 loc) · 3.1 KB
/
fee.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"context"
daemonv2 "github.com/tdex-network/tdex-daemon/api-spec/protobuf/gen/tdex-daemon/v2"
"github.com/urfave/cli/v2"
)
var (
feeAccount = cli.Command{
Name: "fee",
Usage: "manage the fee account of the daemon's wallet",
Subcommands: []*cli.Command{
feeBalanceCmd, feeDepositCmd, feeListAddressesCmd, feeWithdrawCmd,
},
}
feeBalanceCmd = &cli.Command{
Name: "balance",
Usage: "check the balance of the fee account",
Action: feeBalanceAction,
}
feeDepositCmd = &cli.Command{
Name: "deposit",
Usage: "generate some address(es) to receive funds",
Flags: []cli.Flag{
&cli.UintFlag{
Name: "num-of-addresses",
Usage: "the number of addresses to generate",
},
},
Action: feeDepositAction,
}
feeListAddressesCmd = &cli.Command{
Name: "addresses",
Usage: "list all the derived deposit addresses of the fee account",
Action: feeListAddressesAction,
}
feeWithdrawCmd = &cli.Command{
Name: "withdraw",
Usage: "withdraw funds from fee account",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "receivers",
Usage: "list of withdrawal receivers as {asset, amount, address}",
Required: true,
},
&cli.Uint64Flag{
Name: "millisats-per-byte",
Usage: "the mSat/byte to pay for the transaction",
Value: 100,
},
&cli.StringFlag{
Name: "password",
Usage: "the wallet unlocking password as security measure",
Required: true,
},
},
Action: feeWithdrawAction,
}
)
func feeBalanceAction(ctx *cli.Context) error {
client, cleanup, err := getOperatorClient(ctx)
if err != nil {
return err
}
defer cleanup()
reply, err := client.GetFeeBalance(context.Background(), &daemonv2.GetFeeBalanceRequest{})
if err != nil {
return err
}
printRespJSON(reply)
return nil
}
func feeDepositAction(ctx *cli.Context) error {
client, cleanup, err := getOperatorClient(ctx)
if err != nil {
return err
}
defer cleanup()
numOfAddresses := ctx.Int64("num-of-addresses")
reply, err := client.DeriveFeeAddresses(
context.Background(), &daemonv2.DeriveFeeAddressesRequest{
NumOfAddresses: numOfAddresses,
},
)
if err != nil {
return err
}
printRespJSON(reply)
return nil
}
func feeListAddressesAction(ctx *cli.Context) error {
client, cleanup, err := getOperatorClient(ctx)
if err != nil {
return err
}
defer cleanup()
reply, err := client.ListFeeAddresses(
context.Background(), &daemonv2.ListFeeAddressesRequest{},
)
if err != nil {
return err
}
printRespJSON(reply)
return nil
}
func feeWithdrawAction(ctx *cli.Context) error {
client, cleanup, err := getOperatorClient(ctx)
if err != nil {
return err
}
defer cleanup()
receivers := ctx.StringSlice("receivers")
password := ctx.String("password")
mSatsPerByte := ctx.Uint64("millisats-per-byte")
outputs, err := parseOutputs(receivers)
if err != nil {
return err
}
reply, err := client.WithdrawFee(context.Background(), &daemonv2.WithdrawFeeRequest{
Outputs: outputs,
MillisatsPerByte: mSatsPerByte,
Password: password,
})
if err != nil {
return err
}
printRespJSON(reply)
return nil
}