Browse Source

lightningd/utxo: helpers to translate from utxo * <-> utxo **

We need the former for marshalling, the latter for build_utxos and funding_tx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
7bfd282319
  1. 6
      lightningd/hsm/hsm.c
  2. 8
      lightningd/peer_control.c
  3. 21
      lightningd/utxo.c
  4. 5
      lightningd/utxo.h

6
lightningd/hsm/hsm.c

@ -16,6 +16,7 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <lightningd/build_utxos.h>
#include <lightningd/daemon_conn.h>
#include <lightningd/funding_tx.h>
#include <lightningd/hsm/client.h>
@ -474,10 +475,7 @@ static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
&remote_pubkey, &inputs))
status_failed(WIRE_HSMSTATUS_BAD_REQUEST, "Bad SIGN_FUNDING");
/* FIXME: unmarshall gives array, not array of pointers. */
utxomap = tal_arr(tmpctx, const struct utxo *, tal_count(inputs));
for (i = 0; i < tal_count(inputs); i++)
utxomap[i] = &inputs[i];
utxomap = to_utxoptr_arr(tmpctx, inputs);
if (change_out)
bitcoin_pubkey(&changekey, change_keyindex);

8
lightningd/peer_control.c

@ -1377,14 +1377,12 @@ static bool opening_release_tx(struct subd *opening, const u8 *resp,
struct funding_channel *fc)
{
u8 *msg;
size_t i;
struct channel_config their_config;
secp256k1_ecdsa_signature commit_sig;
struct pubkey their_per_commit_point;
struct basepoints theirbase;
struct config *cfg = &fc->peer->ld->dstate.config;
/* FIXME: marshal code wants array, not array of pointers. */
struct utxo *utxos = tal_arr(fc, struct utxo, tal_count(fc->utxomap));
struct utxo *utxos;
assert(tal_count(fds) == 1);
fc->peer->fd = fds[0];
@ -1407,9 +1405,7 @@ static bool opening_release_tx(struct subd *opening, const u8 *resp,
log_debug(fc->peer->log, "Getting HSM to sign funding tx");
/* Get HSM to sign the funding tx. */
for (i = 0; i < tal_count(fc->utxomap); i++)
utxos[i] = *fc->utxomap[i];
utxos = from_utxoptr_arr(fc, fc->utxomap);
msg = towire_hsmctl_sign_funding(fc, fc->satoshi, fc->change,
fc->change_keyindex,
&fc->local_fundingkey,

21
lightningd/utxo.c

@ -18,3 +18,24 @@ void fromwire_utxo(const u8 **ptr, size_t *max, struct utxo *utxo)
utxo->keyindex = fromwire_u32(ptr, max);
utxo->is_p2sh = fromwire_bool(ptr, max);
}
struct utxo *from_utxoptr_arr(const tal_t *ctx, const struct utxo **utxos)
{
size_t i, n = tal_count(utxos);
struct utxo *utxo = tal_arr(ctx, struct utxo, n);
for (i = 0; i < n; i++)
utxo[i] = *utxos[i];
return utxo;
}
const struct utxo **to_utxoptr_arr(const tal_t *ctx, const struct utxo *utxos)
{
size_t i, n = tal_count(utxos);
const struct utxo **utxo = tal_arr(ctx, const struct utxo *, n);
for (i = 0; i < n; i++)
utxo[i] = &utxos[i];
return utxo;
}

5
lightningd/utxo.h

@ -16,4 +16,9 @@ struct utxo {
void towire_utxo(u8 **pptr, const struct utxo *utxo);
void fromwire_utxo(const u8 **ptr, size_t *max, struct utxo *utxo);
/* build_utxos/funding_tx use array of pointers, but marshall code
* wants arr of structs */
struct utxo *from_utxoptr_arr(const tal_t *ctx, const struct utxo **utxos);
const struct utxo **to_utxoptr_arr(const tal_t *ctx, const struct utxo *utxos);
#endif /* LIGHTNING_LIGHTNINGD_UTXO_H */

Loading…
Cancel
Save