mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
daemon: dev-signcommit command to sign the current commit tx.
Do not use this! We use it to test stealing. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
effcb73a48
commit
e1c6f2d630
@ -261,6 +261,7 @@ static const struct json_command *cmdlist[] = {
|
||||
&mocktime_command,
|
||||
&crash_command,
|
||||
&disconnect_command,
|
||||
&signcommit_command,
|
||||
};
|
||||
|
||||
static void json_help(struct command *cmd,
|
||||
|
@ -66,4 +66,5 @@ extern const struct json_command mocktime_command;
|
||||
extern const struct json_command close_command;
|
||||
extern const struct json_command newaddr_command;
|
||||
extern const struct json_command disconnect_command;
|
||||
extern const struct json_command signcommit_command;
|
||||
#endif /* LIGHTNING_DAEMON_JSONRPC_H */
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "secrets.h"
|
||||
#include "state.h"
|
||||
#include "timeout.h"
|
||||
#include "utils.h"
|
||||
#include "wallet.h"
|
||||
#include <bitcoin/base58.h>
|
||||
#include <bitcoin/script.h>
|
||||
@ -2320,9 +2321,56 @@ static void json_disconnect(struct command *cmd,
|
||||
command_success(cmd, null_response(cmd));
|
||||
}
|
||||
|
||||
static void json_signcommit(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
struct peer *peer;
|
||||
jsmntok_t *peeridtok;
|
||||
u8 *linear;
|
||||
const struct bitcoin_tx *tx;
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
|
||||
if (!json_get_params(buffer, params,
|
||||
"peerid", &peeridtok,
|
||||
NULL)) {
|
||||
command_fail(cmd, "Need peerid");
|
||||
return;
|
||||
}
|
||||
|
||||
peer = find_peer(cmd->dstate, buffer, peeridtok);
|
||||
if (!peer) {
|
||||
command_fail(cmd, "Could not find peer with that peerid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!peer->us.commit->sig) {
|
||||
command_fail(cmd, "Peer has not given us a signature");
|
||||
return;
|
||||
}
|
||||
|
||||
tx = bitcoin_commit(peer);
|
||||
linear = linearize_tx(cmd, tx);
|
||||
|
||||
/* Clear witness for potential future uses. */
|
||||
tx->input[0].witness = tal_free(tx->input[0].witness);
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "tx",
|
||||
tal_hexstr(cmd, linear, tal_count(linear)));
|
||||
json_object_end(response);
|
||||
command_success(cmd, response);
|
||||
}
|
||||
|
||||
const struct json_command disconnect_command = {
|
||||
"dev-disconnect",
|
||||
json_disconnect,
|
||||
"Force a disconned with peer {peerid}",
|
||||
"Returns an empty result on success"
|
||||
};
|
||||
|
||||
const struct json_command signcommit_command = {
|
||||
"dev-signcommit",
|
||||
json_signcommit,
|
||||
"Sign and return the current commit with peer {peerid}",
|
||||
"Returns a hex string on success"
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user