diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index b80d2b93e..7dd1ad88d 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -358,6 +358,15 @@ void json_add_pubkey(struct json_result *response, json_add_hex(response, fieldname, der, sizeof(der)); } +void json_add_txid(struct json_result *result, const char *fieldname, + const struct sha256_double *txid) +{ + char hex[hex_str_size(sizeof(*txid))]; + + bitcoin_txid_to_hex(txid, hex, sizeof(hex)); + json_add_string(result, fieldname, hex); +} + bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok, struct pubkey *pubkey) { diff --git a/lightningd/jsonrpc.h b/lightningd/jsonrpc.h index 9989f5dbd..6187e0652 100644 --- a/lightningd/jsonrpc.h +++ b/lightningd/jsonrpc.h @@ -5,6 +5,7 @@ #include #include +struct sha256_double; struct wireaddr; /* Context for a command (from JSON, but might outlive the connection!) @@ -66,6 +67,10 @@ void json_add_pubkey(struct json_result *response, const char *fieldname, const struct pubkey *key); +/* '"fieldname" : ' or "" if fieldname is NULL */ +void json_add_txid(struct json_result *result, const char *fieldname, + const struct sha256_double *txid); + /* Extract a pubkey from this */ bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok, struct pubkey *pubkey); diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 9c4982066..d3dab05d8 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -456,8 +456,7 @@ static void json_listfunds(struct command *cmd, const char *buffer, json_array_start(response, "outputs"); for (int i = 0; i < tal_count(utxos); i++) { json_object_start(response, NULL); - json_add_hex_reversed(response, "txid", &utxos[i]->txid, - sizeof(struct sha256_double)); + json_add_txid(response, "txid", &utxos[i]->txid); json_add_num(response, "output", utxos[i]->outnum); json_add_u64(response, "value", utxos[i]->amount); json_object_end(response);