mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
utxo: add scriptSig + scriptPubkey field
Allow the utxo object to bear the scriptSig and scriptPubKey
This commit is contained in:
parent
c110f3662c
commit
39d5117210
5 changed files with 48 additions and 3 deletions
|
@ -37,6 +37,13 @@ void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct n
|
|||
/* Generated stub for fromwire_pubkey */
|
||||
void fromwire_pubkey(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct pubkey *pubkey UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_pubkey called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_tal_arrn */
|
||||
u8 *fromwire_tal_arrn(const tal_t *ctx UNNEEDED,
|
||||
const u8 **cursor UNNEEDED, size_t *max UNNEEDED, size_t num UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_tal_arrn called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_u16 */
|
||||
u16 fromwire_u16(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_u16 called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_u32 */
|
||||
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
|
||||
|
@ -58,12 +65,18 @@ void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
|
|||
/* Generated stub for towire_pubkey */
|
||||
void towire_pubkey(u8 **pptr UNNEEDED, const struct pubkey *pubkey UNNEEDED)
|
||||
{ fprintf(stderr, "towire_pubkey called!\n"); abort(); }
|
||||
/* Generated stub for towire_u16 */
|
||||
void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED)
|
||||
{ fprintf(stderr, "towire_u16 called!\n"); abort(); }
|
||||
/* Generated stub for towire_u32 */
|
||||
void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
|
||||
{ fprintf(stderr, "towire_u32 called!\n"); abort(); }
|
||||
/* Generated stub for towire_u64 */
|
||||
void towire_u64(u8 **pptr UNNEEDED, u64 v UNNEEDED)
|
||||
{ fprintf(stderr, "towire_u64 called!\n"); abort(); }
|
||||
/* Generated stub for towire_u8_array */
|
||||
void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNEEDED)
|
||||
{ fprintf(stderr, "towire_u8_array called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -16,6 +16,11 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo)
|
|||
towire_u32(pptr, utxo->keyindex);
|
||||
towire_bool(pptr, utxo->is_p2sh);
|
||||
|
||||
towire_u16(pptr, tal_count(utxo->scriptPubkey));
|
||||
towire_u8_array(pptr, utxo->scriptPubkey, tal_count(utxo->scriptPubkey));
|
||||
towire_u16(pptr, tal_count(utxo->scriptSig));
|
||||
towire_u8_array(pptr, utxo->scriptSig, tal_count(utxo->scriptSig));
|
||||
|
||||
towire_bool(pptr, is_unilateral_close);
|
||||
if (is_unilateral_close) {
|
||||
towire_u64(pptr, utxo->close_info->channel_id);
|
||||
|
@ -36,9 +41,8 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
|
|||
utxo->keyindex = fromwire_u32(ptr, max);
|
||||
utxo->is_p2sh = fromwire_bool(ptr, max);
|
||||
|
||||
/* No need to tell hsmd about the scriptPubkey, it has all the info to
|
||||
* derive it from the rest. */
|
||||
utxo->scriptPubkey = NULL;
|
||||
utxo->scriptPubkey = fromwire_tal_arrn(utxo, ptr, max, fromwire_u16(ptr, max));
|
||||
utxo->scriptSig = fromwire_tal_arrn(utxo, ptr, max, fromwire_u16(ptr, max));
|
||||
|
||||
if (fromwire_bool(ptr, max)) {
|
||||
utxo->close_info = tal(utxo, struct unilateral_close_info);
|
||||
|
|
|
@ -41,6 +41,9 @@ struct utxo {
|
|||
|
||||
/* The scriptPubkey if it is known */
|
||||
u8 *scriptPubkey;
|
||||
|
||||
/* scriptSig. Only for P2SH outputs */
|
||||
u8 *scriptSig;
|
||||
};
|
||||
|
||||
void towire_utxo(u8 **pptr, const struct utxo *utxo);
|
||||
|
|
|
@ -175,6 +175,7 @@ static struct utxo *wallet_stmt2output(const tal_t *ctx, struct db_stmt *stmt)
|
|||
utxo->blockheight = NULL;
|
||||
utxo->spendheight = NULL;
|
||||
utxo->scriptPubkey = NULL;
|
||||
utxo->scriptSig = NULL;
|
||||
|
||||
if (!db_column_is_null(stmt, 9)) {
|
||||
blockheight = tal(utxo, u32);
|
||||
|
@ -537,6 +538,22 @@ const struct utxo **wallet_select_all(const tal_t *ctx, struct wallet *w,
|
|||
return utxo;
|
||||
}
|
||||
|
||||
u8 *derive_redeem_scriptsig(const tal_t *ctx, struct wallet *w, u32 keyindex)
|
||||
{
|
||||
struct ext_key ext;
|
||||
struct pubkey key;
|
||||
|
||||
if (bip32_key_from_parent(w->bip32_base, keyindex,
|
||||
BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK) {
|
||||
fatal("Unable to derive pubkey");
|
||||
}
|
||||
|
||||
if (!pubkey_from_der(ext.pub_key, PUBKEY_CMPR_LEN, &key))
|
||||
fatal("Unble to derive pubkey from DER");
|
||||
|
||||
return bitcoin_scriptsig_p2sh_p2wpkh(ctx, &key);
|
||||
}
|
||||
|
||||
bool wallet_can_spend(struct wallet *w, const u8 *script,
|
||||
u32 *index, bool *output_is_p2sh)
|
||||
{
|
||||
|
|
|
@ -399,6 +399,14 @@ const struct utxo **wallet_select_all(const tal_t *ctx, struct wallet *w,
|
|||
struct amount_sat *sat,
|
||||
struct amount_sat *fee_estimate);
|
||||
|
||||
/* derive_redeem_scriptsig - Compute the scriptSig for a P2SH-P2WPKH
|
||||
*
|
||||
* @ctx - allocation context
|
||||
* @w - wallet
|
||||
* @keyindex - index of the internal BIP32 key
|
||||
*/
|
||||
u8 *derive_redeem_scriptsig(const tal_t *ctx, struct wallet *w, u32 keyindex);
|
||||
|
||||
/**
|
||||
* wallet_select_specific - Select utxos given an array of txids and an array of outputs index
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue