MCPcopy Create free account
hub / github.com/ElementsProject/lightning / wallet_can_spend

Function wallet_can_spend

wallet/wallet.c:636–677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

634}
635
636bool wallet_can_spend(struct wallet *w, const u8 *script,
637 u32 *index, bool *output_is_p2sh)
638{
639 struct ext_key ext;
640 u64 bip32_max_index = db_get_intvar(w->db, "bip32_max_index", 0);
641 u32 i;
642
643 /* If not one of these, can't be for us. */
644 if (is_p2sh(script, NULL))
645 *output_is_p2sh = true;
646 else if (is_p2wpkh(script, NULL))
647 *output_is_p2sh = false;
648 else
649 return false;
650
651 for (i = 0; i <= bip32_max_index + w->keyscan_gap; i++) {
652 u8 *s;
653
654 if (bip32_key_from_parent(w->bip32_base, i,
655 BIP32_FLAG_KEY_PUBLIC, &ext)
656 != WALLY_OK) {
657 abort();
658 }
659 s = scriptpubkey_p2wpkh_derkey(w, ext.pub_key);
660 if (*output_is_p2sh) {
661 u8 *p2sh = scriptpubkey_p2sh(w, s);
662 tal_free(s);
663 s = p2sh;
664 }
665 if (scripteq(s, script)) {
666 /* If we found a used key in the keyscan_gap we should
667 * remember that. */
668 if (i > bip32_max_index)
669 db_set_intvar(w->db, "bip32_max_index", i);
670 tal_free(s);
671 *index = i;
672 return true;
673 }
674 tal_free(s);
675 }
676 return false;
677}
678
679s64 wallet_get_newindex(struct lightningd *ld)
680{

Callers 11

openchannel2_hook_cbFunction · 0.85
json_openchannel_initFunction · 0.85
json_queryratesFunction · 0.85
peer_restart_dualopendFunction · 0.85
peer_start_closingdFunction · 0.85
json_closeFunction · 0.85
openchannel_hook_finalFunction · 0.85
json_fundchannel_startFunction · 0.85

Calls 9

abortFunction · 0.85
scriptpubkey_p2shFunction · 0.85
tal_freeFunction · 0.85
scripteqFunction · 0.85
db_set_intvarFunction · 0.85
db_get_intvarFunction · 0.50
is_p2shFunction · 0.50
is_p2wpkhFunction · 0.50

Tested by

no test coverage detected