Browse Source

lightningd: export bitcoin_pubkey as bip32_pubkey.

We're going to need it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
afc31cd68f
  1. 17
      lightningd/build_utxos.c
  2. 5
      lightningd/build_utxos.h
  3. 22
      lightningd/peer_control.c

17
lightningd/build_utxos.c

@ -246,3 +246,20 @@ const struct utxo **build_utxos(const tal_t *ctx,
return tal_free(utxos);
}
bool bip32_pubkey(const struct ext_key *bip32_base,
struct pubkey *pubkey, u32 index)
{
struct ext_key ext;
assert(index < BIP32_INITIAL_HARDENED_CHILD);
if (bip32_key_from_parent(bip32_base, index,
BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK)
return false;
if (!secp256k1_ec_pubkey_parse(secp256k1_ctx, &pubkey->pubkey,
ext.pub_key, sizeof(ext.pub_key)))
return false;
return true;
}

5
lightningd/build_utxos.h

@ -13,4 +13,9 @@ const struct utxo **build_utxos(const tal_t *ctx,
/* Once we've spent them, mark them confirmed. */
void confirm_utxos(struct lightningd *ld, const struct utxo **utxos);
struct ext_key;
bool bip32_pubkey(const struct ext_key *bip32_base,
struct pubkey *pubkey, u32 index);
#endif /* LIGHTNING_LIGHTNINGD_BUILD_UTXOS_H */

22
lightningd/peer_control.c

@ -36,22 +36,6 @@ static void destroy_peer(struct peer *peer)
peer->condition);
}
static void bitcoin_pubkey(struct lightningd *ld,
struct pubkey *pubkey, u32 index)
{
struct ext_key ext;
assert(index < BIP32_INITIAL_HARDENED_CHILD);
assert(index < ld->bip32_max_index);
if (bip32_key_from_parent(ld->bip32_base, index,
BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK)
fatal("BIP32 of %u failed", index);
if (!secp256k1_ec_pubkey_parse(secp256k1_ctx, &pubkey->pubkey,
ext.pub_key, sizeof(ext.pub_key)))
fatal("Parse of BIP32 child %u pubkey failed", index);
}
void peer_set_condition(struct peer *peer, const char *fmt, ...)
{
va_list ap;
@ -591,8 +575,10 @@ static void opening_gen_funding(struct subdaemon *opening, const u8 *resp,
return;
}
if (fc->change)
bitcoin_pubkey(fc->peer->ld, &changekey, fc->change_keyindex);
if (fc->change
&& !bip32_pubkey(fc->peer->ld->bip32_base,
&changekey, fc->change_keyindex))
fatal("Error deriving change key %u", fc->change_keyindex);
fc->funding_tx = funding_tx(fc, &outnum, fc->utxomap, fc->satoshi,
&fc->local_fundingkey,

Loading…
Cancel
Save