Browse Source

lightningd: add json_add_tx helper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
htlc_accepted_hook
Rusty Russell 6 years ago
parent
commit
7e02fbe6ec
  1. 7
      lightningd/json.c
  2. 5
      lightningd/json.h
  3. 5
      lightningd/opening_control.c
  4. 12
      lightningd/peer_control.c
  5. 5
      lightningd/test/run-invoice-select-inchan.c
  6. 5
      wallet/test/run-wallet.c

7
lightningd/json.c

@ -372,6 +372,13 @@ void json_add_hex_talarr(struct json_stream *result,
json_add_hex(result, fieldname, data, tal_bytelen(data));
}
void json_add_tx(struct json_stream *result,
const char *fieldname,
const struct bitcoin_tx *tx)
{
json_add_hex_talarr(result, fieldname, linearize_tx(tmpctx, tx));
}
void json_add_escaped_string(struct json_stream *result, const char *fieldname,
const struct json_escaped *esc TAKES)
{

5
lightningd/json.h

@ -16,6 +16,7 @@
#define JSMN_STRICT 1
# include <external/jsmn/jsmn.h>
struct bitcoin_tx;
struct bitcoin_txid;
struct chainparams;
struct channel_id;
@ -153,6 +154,10 @@ void json_add_hex(struct json_stream *result, const char *fieldname,
void json_add_hex_talarr(struct json_stream *result,
const char *fieldname,
const tal_t *data);
/* '"fieldname" : "010000000001..."' or "010000000001..." if fieldname is NULL */
void json_add_tx(struct json_stream *result,
const char *fieldname,
const struct bitcoin_tx *tx);
/* Adds both a 'raw' number field and an 'amount_msat' field */
void json_add_amount_msat_compat(struct json_stream *result,

5
lightningd/opening_control.c

@ -758,9 +758,8 @@ openchannel_hook_serialize(struct openchannel_hook_payload *payload,
json_add_num(stream, "max_accepted_htlcs", payload->max_accepted_htlcs);
json_add_num(stream, "channel_flags", payload->channel_flags);
if (tal_count(payload->shutdown_scriptpubkey) != 0)
json_add_hex(stream, "shutdown_scriptpubkey",
payload->shutdown_scriptpubkey,
tal_count(payload->shutdown_scriptpubkey));
json_add_hex_talarr(stream, "shutdown_scriptpubkey",
payload->shutdown_scriptpubkey);
json_object_end(stream); /* .openchannel */
}

12
lightningd/peer_control.c

@ -237,13 +237,12 @@ static void
resolve_one_close_command(struct close_command *cc, bool cooperative)
{
struct json_stream *result = json_stream_success(cc->cmd);
u8 *tx = linearize_tx(result, cc->channel->last_tx);
struct bitcoin_txid txid;
bitcoin_txid(cc->channel->last_tx, &txid);
json_object_start(result, NULL);
json_add_hex_talarr(result, "tx", tx);
json_add_tx(result, "tx", cc->channel->last_tx);
json_add_txid(result, "txid", &txid);
if (cooperative)
json_add_string(result, "type", "mutual");
@ -1501,7 +1500,6 @@ static struct command_result *json_sign_last_tx(struct command *cmd,
struct node_id *peerid;
struct peer *peer;
struct json_stream *response;
u8 *linear;
struct channel *channel;
if (!param(cmd, buffer, params,
@ -1523,13 +1521,13 @@ static struct command_result *json_sign_last_tx(struct command *cmd,
response = json_stream_success(cmd);
log_debug(channel->log, "dev-sign-last-tx: signing tx with %zu outputs",
channel->last_tx->wtx->num_outputs);
sign_last_tx(channel);
linear = linearize_tx(cmd, channel->last_tx);
remove_sig(channel->last_tx);
sign_last_tx(channel);
json_object_start(response, NULL);
json_add_hex_talarr(response, "tx", linear);
json_add_tx(response, "tx", channel->last_tx);
json_object_end(response);
remove_sig(channel->last_tx);
return command_success(cmd, response);
}

5
lightningd/test/run-invoice-select-inchan.c

@ -183,6 +183,11 @@ void json_add_short_channel_id(struct json_stream *response UNNEEDED,
/* Generated stub for json_add_string */
void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const char *value UNNEEDED)
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
/* Generated stub for json_add_tx */
void json_add_tx(struct json_stream *result UNNEEDED,
const char *fieldname UNNEEDED,
const struct bitcoin_tx *tx UNNEEDED)
{ fprintf(stderr, "json_add_tx called!\n"); abort(); }
/* Generated stub for json_add_txid */
void json_add_txid(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED)

5
wallet/test/run-wallet.c

@ -266,6 +266,11 @@ void json_add_string(struct json_stream *result UNNEEDED, const char *fieldname
void json_add_timeabs(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
struct timeabs t UNNEEDED)
{ fprintf(stderr, "json_add_timeabs called!\n"); abort(); }
/* Generated stub for json_add_tx */
void json_add_tx(struct json_stream *result UNNEEDED,
const char *fieldname UNNEEDED,
const struct bitcoin_tx *tx UNNEEDED)
{ fprintf(stderr, "json_add_tx called!\n"); abort(); }
/* Generated stub for json_add_txid */
void json_add_txid(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED)

Loading…
Cancel
Save