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

Function wallet_can_spend

wallet/wallet.c:1026–1062  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1024}
1025
1026bool wallet_can_spend(struct wallet *w, const u8 *script, size_t script_len,
1027 u32 *index, enum addrtype *addrtype)
1028{
1029 u64 bip32_max_index, bip86_max_index;
1030 const struct wallet_address *waddr;
1031 struct script_with_len scriptwl = {script, script_len};
1032
1033 /* Update hash table if we need to */
1034 bip32_max_index = db_get_intvar(w->db, "bip32_max_index", 0);
1035 bip86_max_index = db_get_intvar(w->db, "bip86_max_index", 0);
1036
1037 /* Scan both BIP32 and BIP86 addresses */
1038 u64 max_index = (bip32_max_index > bip86_max_index) ? bip32_max_index : bip86_max_index;
1039 while (w->our_addresses_maxindex < max_index + w->keyscan_gap)
1040 our_addresses_add_for_index(w, ++w->our_addresses_maxindex);
1041
1042 waddr = wallet_address_htable_get(w->our_addresses, &scriptwl);
1043 if (!waddr)
1044 return false;
1045
1046 /* If we found a used key in the keyscan_gap we should
1047 * remember that. */
1048 if (w->ld->bip86_base) {
1049 /* BIP86-based wallet: all addresses use BIP86 derivation */
1050 if (waddr->index > bip86_max_index)
1051 db_set_intvar(w->db, "bip86_max_index", waddr->index);
1052 } else {
1053 /* Legacy wallet: all addresses use BIP32 derivation */
1054 if (waddr->index > bip32_max_index)
1055 db_set_intvar(w->db, "bip32_max_index", waddr->index);
1056 }
1057
1058 *index = waddr->index;
1059 if (addrtype)
1060 *addrtype = waddr->addrtype;
1061 return true;
1062}
1063
1064s64 wallet_get_newindex(struct lightningd *ld, enum addrtype addrtype)
1065{

Callers 12

json_signmessagewithkeyFunction · 0.85
openchannel2_hook_cbFunction · 0.85
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 3

db_set_intvarFunction · 0.85
db_get_intvarFunction · 0.50

Tested by

no test coverage detected