Skip to content

Commit 378d817

Browse files
committed
cmd: abandon api support
1 parent c0b4193 commit 378d817

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

cmd/loop/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func main() {
147147
monitorCommand, quoteCommand, listAuthCommand,
148148
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
149149
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
150-
getInfoCommand,
150+
getInfoCommand, abandonSwapCommand,
151151
}
152152

153153
err := app.Run(os.Args)

cmd/loop/swaps.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,73 @@ func swapInfo(ctx *cli.Context) error {
9090
printRespJSON(resp)
9191
return nil
9292
}
93+
94+
var abandonSwapCommand = cli.Command{
95+
Name: "abandonswap",
96+
Usage: "abandon a swap with a given swap hash",
97+
Description: "This command overrides the database and abandons a " +
98+
"swap with a given swap hash.\n\n" +
99+
"!!! This command might potentially lead to loss of funds if " +
100+
"it is applied to swaps that are still waiting for pending " +
101+
"user funds. Before executing this command make sure that " +
102+
"no funds are locked by the swap.",
103+
ArgsUsage: "ID",
104+
Flags: []cli.Flag{
105+
cli.BoolFlag{
106+
Name: "i_know_what_i_am_doing",
107+
Usage: "Specify this flag if you made sure that you " +
108+
"read and understood the following " +
109+
"consequence of applying this command.",
110+
},
111+
},
112+
Action: abandonSwap,
113+
}
114+
115+
func abandonSwap(ctx *cli.Context) error {
116+
args := ctx.Args()
117+
118+
var id string
119+
switch {
120+
case ctx.IsSet("id"):
121+
id = ctx.String("id")
122+
123+
case ctx.NArg() > 0:
124+
id = args[0]
125+
args = args.Tail() // nolint:wastedassign
126+
127+
default:
128+
// Show command help if no arguments and flags were provided.
129+
return cli.ShowCommandHelp(ctx, "abandonswap")
130+
}
131+
132+
if len(id) != hex.EncodedLen(lntypes.HashSize) {
133+
return fmt.Errorf("invalid swap ID")
134+
}
135+
idBytes, err := hex.DecodeString(id)
136+
if err != nil {
137+
return fmt.Errorf("cannot hex decode id: %v", err)
138+
}
139+
140+
client, cleanup, err := getClient(ctx)
141+
if err != nil {
142+
return err
143+
}
144+
defer cleanup()
145+
146+
if !ctx.Bool("i_know_what_i_am_doing") {
147+
return cli.ShowCommandHelp(ctx, "abandonswap")
148+
}
149+
150+
resp, err := client.AbandonSwap(
151+
context.Background(), &looprpc.AbandonSwapRequest{
152+
Id: idBytes,
153+
IKnowWhatIAmDoing: ctx.Bool("i_know_what_i_am_doing"),
154+
},
155+
)
156+
if err != nil {
157+
return err
158+
}
159+
160+
printRespJSON(resp)
161+
return nil
162+
}

loopd/perms/perms.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ var RequiredPermissions = map[string][]bakery.Op{
3131
Entity: "swap",
3232
Action: "read",
3333
}},
34+
"/looprpc.SwapClient/AbandonSwap": {{
35+
Entity: "swap",
36+
Action: "execute",
37+
}, {
38+
Entity: "loop",
39+
Action: "in",
40+
}, {
41+
Entity: "loop",
42+
Action: "out",
43+
}},
3444
"/looprpc.SwapClient/LoopOutTerms": {{
3545
Entity: "terms",
3646
Action: "read",

0 commit comments

Comments
 (0)