|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/lightninglabs/loop/looprpc" |
| 7 | + "github.com/urfave/cli" |
| 8 | +) |
| 9 | + |
| 10 | +var ( |
| 11 | + assetDepositsCommands = cli.Command{ |
| 12 | + Name: "asset deposits", |
| 13 | + ShortName: "ad", |
| 14 | + Usage: "TAP asset deposit commands.", |
| 15 | + Subcommands: []cli.Command{ |
| 16 | + newAssetDepositCommand, |
| 17 | + listAssetDepositsCommand, |
| 18 | + withdrawAssetDepositCommand, |
| 19 | + testCoSignCommand, |
| 20 | + testKeyRevealCommand, |
| 21 | + }, |
| 22 | + } |
| 23 | + |
| 24 | + newAssetDepositCommand = cli.Command{ |
| 25 | + Name: "new", |
| 26 | + ShortName: "n", |
| 27 | + Usage: "Create a new TAP asset deposit.", |
| 28 | + Description: "Create a new TAP asset deposit.", |
| 29 | + Action: newAssetDeposit, |
| 30 | + Flags: []cli.Flag{ |
| 31 | + cli.StringFlag{ |
| 32 | + Name: "asset_id", |
| 33 | + Usage: "The asset id of the asset to deposit.", |
| 34 | + }, |
| 35 | + cli.Uint64Flag{ |
| 36 | + Name: "amt", |
| 37 | + Usage: "the amount to deposit (in asset " + |
| 38 | + "units).", |
| 39 | + }, |
| 40 | + cli.UintFlag{ |
| 41 | + Name: "expiry", |
| 42 | + Usage: "the deposit expiry in blocks.", |
| 43 | + }, |
| 44 | + }, |
| 45 | + } |
| 46 | + |
| 47 | + listAssetDepositsCommand = cli.Command{ |
| 48 | + Name: "list", |
| 49 | + ShortName: "l", |
| 50 | + Usage: "List TAP asset deposits.", |
| 51 | + Description: "List TAP asset deposits.", |
| 52 | + Flags: []cli.Flag{ |
| 53 | + cli.UintFlag{ |
| 54 | + Name: "min_confs", |
| 55 | + Usage: "The minimum amount of confirmations " + |
| 56 | + "an anchor output should have to be " + |
| 57 | + "listed.", |
| 58 | + }, |
| 59 | + cli.UintFlag{ |
| 60 | + Name: "max_confs", |
| 61 | + Usage: "The maximum number of confirmations " + |
| 62 | + "an anchor output could have to be " + |
| 63 | + "listed.", |
| 64 | + }, |
| 65 | + }, |
| 66 | + Action: listAssetDeposits, |
| 67 | + } |
| 68 | + |
| 69 | + withdrawAssetDepositCommand = cli.Command{ |
| 70 | + Name: "withdraw", |
| 71 | + ShortName: "w", |
| 72 | + Usage: "Withdraw TAP asset deposits.", |
| 73 | + Description: "Withdraw TAP asset deposits.", |
| 74 | + Action: withdrawAssetDeposit, |
| 75 | + Flags: []cli.Flag{ |
| 76 | + cli.StringSliceFlag{ |
| 77 | + Name: "deposit_ids", |
| 78 | + Usage: "The deposit ids of the asset " + |
| 79 | + "deposits to withdraw.", |
| 80 | + }, |
| 81 | + }, |
| 82 | + } |
| 83 | + |
| 84 | + testKeyRevealCommand = cli.Command{ |
| 85 | + Name: "testkeyreveal", |
| 86 | + ShortName: "tkr", |
| 87 | + Usage: "Test revealing the key of a deposit to the server.", |
| 88 | + Action: testKeyReveal, |
| 89 | + Flags: []cli.Flag{ |
| 90 | + cli.StringFlag{ |
| 91 | + Name: "deposit_id", |
| 92 | + Usage: "The deposit id of the asset deposit.", |
| 93 | + }, |
| 94 | + }, |
| 95 | + } |
| 96 | + |
| 97 | + testCoSignCommand = cli.Command{ |
| 98 | + Name: "testcosign", |
| 99 | + ShortName: "tcs", |
| 100 | + Usage: "Test co-signing a deposit to spend to an HTLC.", |
| 101 | + Action: testCoSign, |
| 102 | + Flags: []cli.Flag{ |
| 103 | + cli.StringFlag{ |
| 104 | + Name: "deposit_id", |
| 105 | + Usage: "The deposit id of the asset deposit.", |
| 106 | + }, |
| 107 | + }, |
| 108 | + } |
| 109 | +) |
| 110 | + |
| 111 | +func init() { |
| 112 | + commands = append(commands, assetDepositsCommands) |
| 113 | +} |
| 114 | + |
| 115 | +func newAssetDeposit(ctx *cli.Context) error { |
| 116 | + ctxb := context.Background() |
| 117 | + if ctx.NArg() > 0 { |
| 118 | + return cli.ShowCommandHelp(ctx, "newdeposit") |
| 119 | + } |
| 120 | + |
| 121 | + client, cleanup, err := getAssetDepositsClient(ctx) |
| 122 | + if err != nil { |
| 123 | + return err |
| 124 | + } |
| 125 | + defer cleanup() |
| 126 | + |
| 127 | + assetID := ctx.String("asset_id") |
| 128 | + amt := ctx.Uint64("amt") |
| 129 | + expiry := int32(ctx.Uint("expiry")) |
| 130 | + |
| 131 | + resp, err := client.NewAssetDeposit( |
| 132 | + ctxb, &looprpc.NewAssetDepositRequest{ |
| 133 | + AssetId: assetID, |
| 134 | + Amount: amt, |
| 135 | + CsvExpiry: expiry, |
| 136 | + }, |
| 137 | + ) |
| 138 | + if err != nil { |
| 139 | + return err |
| 140 | + } |
| 141 | + |
| 142 | + printJSON(resp) |
| 143 | + |
| 144 | + return nil |
| 145 | +} |
| 146 | + |
| 147 | +func listAssetDeposits(ctx *cli.Context) error { |
| 148 | + ctxb := context.Background() |
| 149 | + if ctx.NArg() > 0 { |
| 150 | + return cli.ShowCommandHelp(ctx, "list") |
| 151 | + } |
| 152 | + |
| 153 | + client, cleanup, err := getAssetDepositsClient(ctx) |
| 154 | + if err != nil { |
| 155 | + return err |
| 156 | + } |
| 157 | + defer cleanup() |
| 158 | + |
| 159 | + resp, err := client.ListAssetDeposits( |
| 160 | + ctxb, &looprpc.ListAssetDepositsRequest{ |
| 161 | + MinConfs: uint32(ctx.Int("min_confs")), |
| 162 | + MaxConfs: uint32(ctx.Int("max_confs")), |
| 163 | + }) |
| 164 | + if err != nil { |
| 165 | + return err |
| 166 | + } |
| 167 | + |
| 168 | + printRespJSON(resp) |
| 169 | + |
| 170 | + return nil |
| 171 | +} |
| 172 | + |
| 173 | +func withdrawAssetDeposit(ctx *cli.Context) error { |
| 174 | + ctxb := context.Background() |
| 175 | + if ctx.NArg() > 0 { |
| 176 | + return cli.ShowCommandHelp(ctx, "withdraw") |
| 177 | + } |
| 178 | + |
| 179 | + client, cleanup, err := getAssetDepositsClient(ctx) |
| 180 | + if err != nil { |
| 181 | + return err |
| 182 | + } |
| 183 | + defer cleanup() |
| 184 | + |
| 185 | + depositIDs := ctx.StringSlice("deposit_ids") |
| 186 | + |
| 187 | + resp, err := client.WithdrawAssetDeposits( |
| 188 | + ctxb, &looprpc.WithdrawAssetDepositsRequest{ |
| 189 | + DepositIds: depositIDs, |
| 190 | + }, |
| 191 | + ) |
| 192 | + if err != nil { |
| 193 | + return err |
| 194 | + } |
| 195 | + |
| 196 | + printRespJSON(resp) |
| 197 | + |
| 198 | + return nil |
| 199 | +} |
| 200 | + |
| 201 | +func testKeyReveal(ctx *cli.Context) error { |
| 202 | + ctxb := context.Background() |
| 203 | + if ctx.NArg() > 0 { |
| 204 | + return cli.ShowCommandHelp(ctx, "testkeyreveal") |
| 205 | + } |
| 206 | + |
| 207 | + client, cleanup, err := getAssetDepositsClient(ctx) |
| 208 | + if err != nil { |
| 209 | + return err |
| 210 | + } |
| 211 | + defer cleanup() |
| 212 | + |
| 213 | + depositID := ctx.String("deposit_id") |
| 214 | + |
| 215 | + resp, err := client.RevealAssetDepositKey( |
| 216 | + ctxb, &looprpc.RevealAssetDepositKeyRequest{ |
| 217 | + DepositId: depositID, |
| 218 | + }, |
| 219 | + ) |
| 220 | + if err != nil { |
| 221 | + return err |
| 222 | + } |
| 223 | + |
| 224 | + printRespJSON(resp) |
| 225 | + |
| 226 | + return nil |
| 227 | +} |
| 228 | + |
| 229 | +func testCoSign(ctx *cli.Context) error { |
| 230 | + ctxb := context.Background() |
| 231 | + if ctx.NArg() > 0 { |
| 232 | + return cli.ShowCommandHelp(ctx, "testcosign") |
| 233 | + } |
| 234 | + |
| 235 | + client, cleanup, err := getAssetDepositsClient(ctx) |
| 236 | + if err != nil { |
| 237 | + return err |
| 238 | + } |
| 239 | + defer cleanup() |
| 240 | + |
| 241 | + depositID := ctx.String("deposit_id") |
| 242 | + |
| 243 | + resp, err := client.TestCoSignAssetDepositHTLC( |
| 244 | + ctxb, &looprpc.TestCoSignAssetDepositHTLCRequest{ |
| 245 | + DepositId: depositID, |
| 246 | + }, |
| 247 | + ) |
| 248 | + if err != nil { |
| 249 | + return err |
| 250 | + } |
| 251 | + |
| 252 | + printRespJSON(resp) |
| 253 | + |
| 254 | + return nil |
| 255 | +} |
0 commit comments