@@ -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+ }
0 commit comments