Browse Source

utils: add tal_hex() helper.

This is a shortcut when the data being dumped is a tal array.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
7b1a4fc765
  1. 2
      bitcoin/tx.c
  2. 2
      daemon/chaintopology.c
  3. 3
      daemon/commit_tx.c
  4. 16
      daemon/db.c
  5. 2
      daemon/netaddr.c
  6. 3
      daemon/peer.c
  7. 5
      utils.c
  8. 3
      utils.h

2
bitcoin/tx.c

@ -497,7 +497,7 @@ bool bitcoin_txid_to_hex(const struct sha256_double *txid,
static char *fmt_bitcoin_tx(const tal_t *ctx, const struct bitcoin_tx *tx)
{
u8 *lin = linearize_tx(ctx, tx);
char *s = tal_hexstr(ctx, lin, tal_count(lin));
char *s = tal_hex(ctx, lin);
tal_free(lin);
return s;
}

2
daemon/chaintopology.c

@ -324,7 +324,7 @@ void broadcast_tx(struct peer *peer, const struct bitcoin_tx *tx,
otx->peer = peer;
bitcoin_txid(tx, &otx->txid);
otx->hextx = tal_hexstr(otx, rawtx, tal_count(rawtx));
otx->hextx = tal_hex(otx, rawtx);
otx->failed = failed;
tal_free(rawtx);

3
daemon/commit_tx.c

@ -211,8 +211,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
log_add_struct(peer->log, " rhash %s", struct sha256,
&h->rhash);
log_debug(peer->log, "Script: %s",
tal_hexstr(tmpctx,
wscript, tal_count(wscript)));
tal_hex(tmpctx, wscript));
} else
log_debug(peer->log, "DOES NOT pay %"PRIu64" to htlc %"PRIu64,
h->msatoshi / 1000, h->id);

16
daemon/db.c

@ -772,7 +772,7 @@ static const char *linearize_shachain(const tal_t *ctx,
}
assert(tal_count(p) == SHACHAIN_SIZE);
str = tal_hexstr(ctx, p, tal_count(p));
str = tal_hex(ctx, p);
tal_free(p);
return str;
}
@ -1011,7 +1011,7 @@ static const char *pubkeys_to_hex(const tal_t *ctx, const struct pubkey *ids)
for (i = 0; i < tal_count(ids); i++)
pubkey_to_der(ders + i * PUBKEY_DER_LEN, &ids[i]);
return tal_hexstr(ctx, ders, tal_count(ders));
return tal_hex(ctx, ders);
}
static struct pubkey *pubkeys_from_arr(const tal_t *ctx,
const void *blob, size_t len)
@ -1518,7 +1518,7 @@ void db_new_htlc(struct peer *peer, const struct htlc *htlc)
htlc->msatoshi,
abs_locktime_to_blocks(&htlc->expiry),
tal_hexstr(ctx, &htlc->rhash, sizeof(htlc->rhash)),
tal_hexstr(ctx, htlc->routing, tal_count(htlc->routing)),
tal_hex(ctx, htlc->routing),
peerid,
htlc->src->id);
} else {
@ -1531,7 +1531,7 @@ void db_new_htlc(struct peer *peer, const struct htlc *htlc)
htlc->msatoshi,
abs_locktime_to_blocks(&htlc->expiry),
tal_hexstr(ctx, &htlc->rhash, sizeof(htlc->rhash)),
tal_hexstr(ctx, htlc->routing, tal_count(htlc->routing)));
tal_hex(ctx, htlc->routing));
}
tal_free(ctx);
@ -1798,8 +1798,7 @@ void db_set_our_closing_script(struct peer *peer)
assert(peer->dstate->db->in_transaction);
db_exec(__func__, peer->dstate, "UPDATE closing SET our_script=x'%s',shutdown_order=%"PRIu64" WHERE peer=x'%s';",
tal_hexstr(ctx, peer->closing.our_script,
tal_count(peer->closing.our_script)),
tal_hex(ctx, peer->closing.our_script),
peer->closing.shutdown_order,
peerid);
tal_free(ctx);
@ -1815,8 +1814,7 @@ void db_set_their_closing_script(struct peer *peer)
assert(peer->dstate->db->in_transaction);
db_exec(__func__, peer->dstate,
"UPDATE closing SET their_script=x'%s' WHERE peer=x'%s';",
tal_hexstr(ctx, peer->closing.their_script,
tal_count(peer->closing.their_script)),
tal_hex(ctx, peer->closing.their_script),
peerid);
tal_free(ctx);
}
@ -1923,7 +1921,7 @@ void db_complete_pay_command(struct lightningd_state *dstate,
else
db_exec(__func__, dstate,
"UPDATE pay SET fail=x'%s', htlc_peer=NULL WHERE rhash=x'%s';",
tal_hexstr(ctx, htlc->fail, tal_count(htlc->fail)),
tal_hex(ctx, htlc->fail),
tal_hexstr(ctx, &htlc->rhash, sizeof(htlc->rhash)));
tal_free(ctx);

2
daemon/netaddr.c

@ -61,7 +61,7 @@ char *netaddr_to_hex(const tal_t *ctx, const struct netaddr *a)
assert(a->addrlen <= sizeof(a->saddr));
push(&a->saddr, a->addrlen, &blob);
hex = tal_hexstr(ctx, blob, tal_count(blob));
hex = tal_hex(ctx, blob);
tal_free(blob);
return hex;
}

3
daemon/peer.c

@ -5156,8 +5156,7 @@ static void json_signcommit(struct command *cmd,
= tal_free(peer->local.commit->tx->input[0].witness);
json_object_start(response, NULL);
json_add_string(response, "tx",
tal_hexstr(cmd, linear, tal_count(linear)));
json_add_string(response, "tx", tal_hex(cmd, linear));
json_object_end(response);
command_success(cmd, response);
}

5
utils.c

@ -10,6 +10,11 @@ char *tal_hexstr(const tal_t *ctx, const void *data, size_t len)
return str;
}
char *tal_hex(const tal_t *ctx, const tal_t *data)
{
return tal_hexstr(ctx, data, tal_len(data));
}
u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len)
{
u8 *data = tal_arr(ctx, u8, hex_data_size(len));

3
utils.h

@ -10,6 +10,9 @@ extern secp256k1_context *secp256k1_ctx;
/* Allocate and fill in a hex-encoded string of this data. */
char *tal_hexstr(const tal_t *ctx, const void *data, size_t len);
/* Allocate and fill a hex-encoding of this tal pointer. */
char *tal_hex(const tal_t *ctx, const tal_t *data);
/* Allocate and fill a buffer with the data of this hex string. */
u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len);

Loading…
Cancel
Save