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

Function wallet_has_funds

wallet/wallet.c:903–954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

901
902
903bool wallet_has_funds(struct wallet *w,
904 const struct utxo **excludes,
905 u32 current_blockheight,
906 struct amount_sat *needed)
907{
908 struct db_stmt *stmt;
909
910 stmt = db_prepare_v2(w->db, SQL("SELECT"
911 " prev_out_tx"
912 ", prev_out_index"
913 ", value"
914 ", type"
915 ", status"
916 ", keyindex"
917 ", channel_id"
918 ", peer_id"
919 ", commitment_point"
920 ", option_anchor_outputs"
921 ", confirmation_height"
922 ", spend_height"
923 ", scriptpubkey "
924 ", reserved_til"
925 ", csv_lock"
926 ", is_in_coinbase"
927 " FROM outputs"
928 " WHERE status = ?"
929 " OR (status = ? AND reserved_til <= ?)"));
930 db_bind_int(stmt, output_status_in_db(OUTPUT_STATE_AVAILABLE));
931 db_bind_int(stmt, output_status_in_db(OUTPUT_STATE_RESERVED));
932 db_bind_u64(stmt, current_blockheight);
933
934 db_query_prepared(stmt);
935 while (db_step(stmt)) {
936 struct utxo *utxo = wallet_stmt2output(tmpctx, stmt);
937
938 if (excluded(excludes, utxo)
939 || !deep_enough(-1U, utxo, current_blockheight)) {
940 continue;
941 }
942
943 /* If we've found enough, answer is yes. */
944 if (!amount_sat_sub(needed, *needed, utxo->amount)) {
945 *needed = AMOUNT_SAT(0);
946 tal_free(stmt);
947 return true;
948 }
949 }
950
951 /* Insufficient funds! */
952 tal_free(stmt);
953 return false;
954}
955
956bool wallet_add_onchaind_utxo(struct wallet *w,
957 const struct bitcoin_outpoint *outpoint,

Callers 2

change_for_emergencyFunction · 0.85
json_addpsbtinputFunction · 0.85

Calls 10

db_bind_intFunction · 0.85
output_status_in_dbFunction · 0.85
db_bind_u64Function · 0.85
db_query_preparedFunction · 0.85
db_stepFunction · 0.85
wallet_stmt2outputFunction · 0.85
excludedFunction · 0.85
deep_enoughFunction · 0.85
tal_freeFunction · 0.85
amount_sat_subFunction · 0.50

Tested by

no test coverage detected