mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
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>
This commit is contained in:
parent
805228b939
commit
7bfd282319
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user