529 lines
22 KiB
C
529 lines
22 KiB
C
#include "config.h"
|
|
|
|
#include <common/setup.h>
|
|
#include <common/status_levels.h>
|
|
#include <common/utils.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
#include "lightningd/log.h"
|
|
|
|
struct node_id;
|
|
|
|
static void db_log_(struct logger *log UNUSED, enum log_level level UNUSED, const struct node_id *node_id UNUSED, bool call_notifier UNUSED, const char *fmt UNUSED, ...)
|
|
{
|
|
}
|
|
#define log_ db_log_
|
|
|
|
#include "wallet/wallet.c"
|
|
|
|
#include "db/bindings.c"
|
|
#include "db/db_sqlite3.c"
|
|
#include "db/exec.c"
|
|
#include "db/utils.c"
|
|
#include "wallet/datastore.c"
|
|
#include "wallet/db.c"
|
|
#include "wallet/migrations.c"
|
|
#include "common/coin_mvt.c"
|
|
|
|
/* AUTOGENERATED MOCKS START */
|
|
/* Generated stub for bip32_pubkey */
|
|
void bip32_pubkey(struct lightningd *ld UNNEEDED, struct pubkey *pubkey UNNEEDED, u32 index UNNEEDED)
|
|
{ fprintf(stderr, "bip32_pubkey called!\n"); abort(); }
|
|
/* Generated stub for bip86_pubkey */
|
|
void bip86_pubkey(struct lightningd *ld UNNEEDED, struct pubkey *pubkey UNNEEDED, u32 index UNNEEDED)
|
|
{ fprintf(stderr, "bip86_pubkey called!\n"); abort(); }
|
|
/* Generated stub for bitcoind_getrawblockbyheight_ */
|
|
void bitcoind_getrawblockbyheight_(const tal_t *ctx UNNEEDED,
|
|
struct bitcoind *bitcoind UNNEEDED,
|
|
u32 height UNNEEDED,
|
|
void (*cb)(struct bitcoind *bitcoind_ UNNEEDED,
|
|
u32 height_ UNNEEDED,
|
|
struct bitcoin_blkid *blkid UNNEEDED,
|
|
struct bitcoin_block *blk UNNEEDED,
|
|
void *arg) UNNEEDED,
|
|
void *arg UNNEEDED)
|
|
{ fprintf(stderr, "bitcoind_getrawblockbyheight_ called!\n"); abort(); }
|
|
/* Generated stub for channel_by_dbid */
|
|
struct channel *channel_by_dbid(struct lightningd *ld UNNEEDED, const u64 dbid UNNEEDED)
|
|
{ fprintf(stderr, "channel_by_dbid called!\n"); abort(); }
|
|
/* Generated stub for channel_gossip_get_remote_update */
|
|
const struct peer_update *channel_gossip_get_remote_update(const struct channel *channel UNNEEDED)
|
|
{ fprintf(stderr, "channel_gossip_get_remote_update called!\n"); abort(); }
|
|
/* Generated stub for channel_gossip_update */
|
|
void channel_gossip_update(struct channel *channel UNNEEDED)
|
|
{ fprintf(stderr, "channel_gossip_update called!\n"); abort(); }
|
|
/* Generated stub for channel_mvt_index_created */
|
|
u64 channel_mvt_index_created(struct lightningd *ld UNNEEDED,
|
|
struct db *db UNNEEDED,
|
|
const struct mvt_account_id *account UNNEEDED,
|
|
struct amount_msat credit UNNEEDED,
|
|
struct amount_msat debit UNNEEDED)
|
|
{ fprintf(stderr, "channel_mvt_index_created called!\n"); abort(); }
|
|
/* Generated stub for channel_scid_or_local_alias */
|
|
struct short_channel_id channel_scid_or_local_alias(const struct channel *chan UNNEEDED)
|
|
{ fprintf(stderr, "channel_scid_or_local_alias called!\n"); abort(); }
|
|
/* Generated stub for channel_state_name */
|
|
const char *channel_state_name(const struct channel *channel UNNEEDED)
|
|
{ fprintf(stderr, "channel_state_name called!\n"); abort(); }
|
|
/* Generated stub for connect_htlc_in */
|
|
void connect_htlc_in(struct htlc_in_map *map UNNEEDED, struct htlc_in *hin UNNEEDED)
|
|
{ fprintf(stderr, "connect_htlc_in called!\n"); abort(); }
|
|
/* Generated stub for connect_htlc_out */
|
|
void connect_htlc_out(struct htlc_out_map *map UNNEEDED, struct htlc_out *hout UNNEEDED)
|
|
{ fprintf(stderr, "connect_htlc_out called!\n"); abort(); }
|
|
/* Generated stub for fatal */
|
|
void fatal(const char *fmt UNNEEDED, ...)
|
|
{ fprintf(stderr, "fatal called!\n"); abort(); }
|
|
/* Generated stub for fatal_vfmt */
|
|
void fatal_vfmt(const char *fmt UNNEEDED, va_list ap UNNEEDED)
|
|
{ fprintf(stderr, "fatal_vfmt called!\n"); abort(); }
|
|
/* Generated stub for find_peer_by_dbid */
|
|
struct peer *find_peer_by_dbid(struct lightningd *ld UNNEEDED, u64 dbid UNNEEDED)
|
|
{ fprintf(stderr, "find_peer_by_dbid called!\n"); abort(); }
|
|
/* Generated stub for forward_index_created */
|
|
u64 forward_index_created(struct lightningd *ld UNNEEDED,
|
|
enum forward_status status UNNEEDED,
|
|
struct short_channel_id in_channel UNNEEDED,
|
|
u64 in_htlc_id UNNEEDED,
|
|
struct amount_msat in_amount UNNEEDED,
|
|
const struct short_channel_id *out_channel UNNEEDED)
|
|
{ fprintf(stderr, "forward_index_created called!\n"); abort(); }
|
|
/* Generated stub for forward_index_deleted */
|
|
void forward_index_deleted(struct lightningd *ld UNNEEDED,
|
|
enum forward_status status UNNEEDED,
|
|
struct short_channel_id in_channel UNNEEDED,
|
|
u64 in_htlc_id UNNEEDED,
|
|
const struct amount_msat *in_amount UNNEEDED,
|
|
const struct short_channel_id *out_channel UNNEEDED)
|
|
{ fprintf(stderr, "forward_index_deleted called!\n"); abort(); }
|
|
/* Generated stub for forward_index_update_status */
|
|
u64 forward_index_update_status(struct lightningd *ld UNNEEDED,
|
|
enum forward_status status UNNEEDED,
|
|
struct short_channel_id in_channel UNNEEDED,
|
|
u64 in_htlc_id UNNEEDED,
|
|
struct amount_msat in_amount UNNEEDED,
|
|
const struct short_channel_id *out_channel UNNEEDED)
|
|
{ fprintf(stderr, "forward_index_update_status called!\n"); abort(); }
|
|
/* Generated stub for fromwire_hsmd_get_channel_basepoints_reply */
|
|
bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED, struct basepoints *basepoints UNNEEDED, struct pubkey *funding_pubkey UNNEEDED)
|
|
{ fprintf(stderr, "fromwire_hsmd_get_channel_basepoints_reply called!\n"); abort(); }
|
|
/* Generated stub for fromwire_hsmd_get_output_scriptpubkey_reply */
|
|
bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **script UNNEEDED)
|
|
{ fprintf(stderr, "fromwire_hsmd_get_output_scriptpubkey_reply called!\n"); abort(); }
|
|
/* Generated stub for get_channel_basepoints */
|
|
void get_channel_basepoints(struct lightningd *ld UNNEEDED,
|
|
const struct node_id *peer_id UNNEEDED,
|
|
const u64 dbid UNNEEDED,
|
|
struct basepoints *local_basepoints UNNEEDED,
|
|
struct pubkey *local_funding_pubkey UNNEEDED)
|
|
{ fprintf(stderr, "get_channel_basepoints called!\n"); abort(); }
|
|
/* Generated stub for hash_cid */
|
|
size_t hash_cid(const struct channel_id *cid UNNEEDED)
|
|
{ fprintf(stderr, "hash_cid called!\n"); abort(); }
|
|
/* Generated stub for htlc_in_check */
|
|
struct htlc_in *htlc_in_check(const struct htlc_in *hin UNNEEDED, const char *abortstr UNNEEDED)
|
|
{ fprintf(stderr, "htlc_in_check called!\n"); abort(); }
|
|
/* Generated stub for htlc_out_connect_htlc_in */
|
|
void htlc_out_connect_htlc_in(struct htlc_out *hout UNNEEDED, struct htlc_in *hin UNNEEDED)
|
|
{ fprintf(stderr, "htlc_out_connect_htlc_in called!\n"); abort(); }
|
|
/* Generated stub for htlcs_index_created */
|
|
u64 htlcs_index_created(struct lightningd *ld UNNEEDED,
|
|
u64 htlc_id UNNEEDED,
|
|
const struct channel *channel UNNEEDED,
|
|
const struct sha256 *payment_hash UNNEEDED,
|
|
enum side owner UNNEEDED,
|
|
u32 expiry UNNEEDED,
|
|
struct amount_msat amount UNNEEDED,
|
|
enum htlc_state hstate UNNEEDED)
|
|
{ fprintf(stderr, "htlcs_index_created called!\n"); abort(); }
|
|
/* Generated stub for htlcs_index_deleted */
|
|
void htlcs_index_deleted(struct lightningd *ld UNNEEDED,
|
|
const struct channel *channel UNNEEDED,
|
|
u64 num_deleted UNNEEDED)
|
|
{ fprintf(stderr, "htlcs_index_deleted called!\n"); abort(); }
|
|
/* Generated stub for htlcs_index_update_status */
|
|
u64 htlcs_index_update_status(struct lightningd *ld UNNEEDED,
|
|
u64 htlc_id UNNEEDED,
|
|
const struct channel *channel UNNEEDED,
|
|
const struct sha256 *payment_hash UNNEEDED,
|
|
enum side owner UNNEEDED,
|
|
u32 expiry UNNEEDED,
|
|
struct amount_msat amount UNNEEDED,
|
|
enum htlc_state hstate UNNEEDED)
|
|
{ fprintf(stderr, "htlcs_index_update_status called!\n"); abort(); }
|
|
/* Generated stub for inflight_set_last_tx */
|
|
void inflight_set_last_tx(struct channel_inflight *inflight UNNEEDED,
|
|
struct bitcoin_tx *last_tx STEALS UNNEEDED,
|
|
const struct bitcoin_signature last_sig UNNEEDED)
|
|
{ fprintf(stderr, "inflight_set_last_tx called!\n"); abort(); }
|
|
/* Generated stub for invoices_new */
|
|
struct invoices *invoices_new(const tal_t *ctx UNNEEDED,
|
|
struct wallet *wallet UNNEEDED,
|
|
struct timers *timers UNNEEDED)
|
|
{ fprintf(stderr, "invoices_new called!\n"); abort(); }
|
|
/* Generated stub for new_channel */
|
|
struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
|
|
/* NULL or stolen */
|
|
struct wallet_shachain *their_shachain STEALS UNNEEDED,
|
|
enum channel_state state UNNEEDED,
|
|
enum side opener UNNEEDED,
|
|
/* NULL or stolen */
|
|
struct logger *log STEALS UNNEEDED,
|
|
const char *transient_billboard TAKES UNNEEDED,
|
|
u8 channel_flags UNNEEDED,
|
|
bool req_confirmed_ins_local UNNEEDED,
|
|
bool req_confirmed_ins_remote UNNEEDED,
|
|
const struct channel_config *our_config UNNEEDED,
|
|
u32 minimum_depth UNNEEDED,
|
|
u64 next_index_local UNNEEDED,
|
|
u64 next_index_remote UNNEEDED,
|
|
u64 next_htlc_id UNNEEDED,
|
|
const struct bitcoin_outpoint *funding UNNEEDED,
|
|
struct amount_sat funding_sats UNNEEDED,
|
|
struct amount_msat push UNNEEDED,
|
|
struct amount_sat our_funds UNNEEDED,
|
|
bool remote_channel_ready UNNEEDED,
|
|
/* NULL or stolen */
|
|
struct short_channel_id *scid TAKES UNNEEDED,
|
|
struct short_channel_id *old_scids TAKES UNNEEDED,
|
|
struct short_channel_id alias_local UNNEEDED,
|
|
struct short_channel_id *alias_remote STEALS UNNEEDED,
|
|
struct channel_id *cid UNNEEDED,
|
|
struct amount_msat our_msatoshi UNNEEDED,
|
|
struct amount_msat msatoshi_to_us_min UNNEEDED,
|
|
struct amount_msat msatoshi_to_us_max UNNEEDED,
|
|
struct bitcoin_tx *last_tx STEALS UNNEEDED,
|
|
const struct bitcoin_signature *last_sig UNNEEDED,
|
|
/* NULL or stolen */
|
|
const struct bitcoin_signature *last_htlc_sigs STEALS UNNEEDED,
|
|
const struct channel_info *channel_info UNNEEDED,
|
|
const struct fee_states *fee_states TAKES UNNEEDED,
|
|
/* NULL or stolen */
|
|
u8 *remote_shutdown_scriptpubkey STEALS UNNEEDED,
|
|
const u8 *local_shutdown_scriptpubkey UNNEEDED,
|
|
u64 final_key_idx UNNEEDED,
|
|
bool last_was_revoke UNNEEDED,
|
|
/* NULL or stolen */
|
|
struct changed_htlc *last_sent_commit STEALS UNNEEDED,
|
|
u32 first_blocknum UNNEEDED,
|
|
u32 min_possible_feerate UNNEEDED,
|
|
u32 max_possible_feerate UNNEEDED,
|
|
const struct basepoints *local_basepoints UNNEEDED,
|
|
const struct pubkey *local_funding_pubkey UNNEEDED,
|
|
bool has_future_per_commitment_point UNNEEDED,
|
|
u32 feerate_base UNNEEDED,
|
|
u32 feerate_ppm UNNEEDED,
|
|
/* NULL or stolen */
|
|
const u8 *remote_upfront_shutdown_script STEALS UNNEEDED,
|
|
u64 local_static_remotekey_start UNNEEDED,
|
|
u64 remote_static_remotekey_start UNNEEDED,
|
|
const struct channel_type *type STEALS UNNEEDED,
|
|
enum side closer UNNEEDED,
|
|
u32 close_attempt_height UNNEEDED,
|
|
enum state_change reason UNNEEDED,
|
|
/* NULL or stolen */
|
|
const struct bitcoin_outpoint *shutdown_wrong_funding STEALS UNNEEDED,
|
|
const struct height_states *height_states TAKES UNNEEDED,
|
|
u32 lease_expiry UNNEEDED,
|
|
secp256k1_ecdsa_signature *lease_commit_sig STEALS UNNEEDED,
|
|
u32 lease_chan_max_msat UNNEEDED,
|
|
u16 lease_chan_max_ppt UNNEEDED,
|
|
struct amount_msat htlc_minimum_msat UNNEEDED,
|
|
struct amount_msat htlc_maximum_msat UNNEEDED,
|
|
bool ignore_fee_limits UNNEEDED,
|
|
/* NULL or stolen */
|
|
struct peer_update *peer_update STEALS UNNEEDED,
|
|
u64 last_stable_connection UNNEEDED,
|
|
const struct channel_stats *stats UNNEEDED,
|
|
struct channel_state_change **state_changes STEALS UNNEEDED,
|
|
const struct wally_psbt *funding_psbt STEALS UNNEEDED,
|
|
bool withheld UNNEEDED)
|
|
{ fprintf(stderr, "new_channel called!\n"); abort(); }
|
|
/* Generated stub for new_channel_state_change */
|
|
struct channel_state_change *new_channel_state_change(const tal_t *ctx UNNEEDED,
|
|
struct timeabs timestamp UNNEEDED,
|
|
enum channel_state old_state UNNEEDED,
|
|
enum channel_state new_state UNNEEDED,
|
|
enum state_change cause UNNEEDED,
|
|
const char *message TAKES UNNEEDED)
|
|
{ fprintf(stderr, "new_channel_state_change called!\n"); abort(); }
|
|
/* Generated stub for new_inflight */
|
|
struct channel_inflight *new_inflight(struct channel *channel UNNEEDED,
|
|
struct pubkey *remote_funding STEALS UNNEEDED,
|
|
const struct bitcoin_outpoint *funding_outpoint UNNEEDED,
|
|
u32 funding_feerate UNNEEDED,
|
|
struct amount_sat funding_sat UNNEEDED,
|
|
struct amount_sat our_funds UNNEEDED,
|
|
struct wally_psbt *funding_psbt STEALS UNNEEDED,
|
|
const u32 lease_expiry UNNEEDED,
|
|
const secp256k1_ecdsa_signature *lease_commit_sig UNNEEDED,
|
|
const u32 lease_chan_max_msat UNNEEDED,
|
|
const u16 lease_chan_max_ppt UNNEEDED,
|
|
const u32 lease_blockheight_start UNNEEDED,
|
|
const struct amount_msat lease_fee UNNEEDED,
|
|
const struct amount_sat lease_amt UNNEEDED,
|
|
s64 splice_amnt UNNEEDED,
|
|
bool i_am_initiator UNNEEDED,
|
|
bool force_sign_first UNNEEDED,
|
|
bool i_sent_sigs UNNEEDED)
|
|
{ fprintf(stderr, "new_inflight called!\n"); abort(); }
|
|
/* Generated stub for new_logger */
|
|
struct logger *new_logger(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED,
|
|
const struct node_id *default_node_id UNNEEDED,
|
|
const char *fmt UNNEEDED, ...)
|
|
{ fprintf(stderr, "new_logger called!\n"); abort(); }
|
|
/* Generated stub for new_peer */
|
|
struct peer *new_peer(struct lightningd *ld UNNEEDED, u64 dbid UNNEEDED,
|
|
const struct node_id *id UNNEEDED,
|
|
const struct wireaddr_internal *addr UNNEEDED,
|
|
const struct wireaddr *last_known_addr UNNEEDED,
|
|
const u8 *their_features TAKES UNNEEDED,
|
|
bool connected_incoming UNNEEDED)
|
|
{ fprintf(stderr, "new_peer called!\n"); abort(); }
|
|
/* Generated stub for notify_channel_mvt */
|
|
void notify_channel_mvt(struct lightningd *ld UNNEEDED,
|
|
const struct channel_coin_mvt *chan_mvt UNNEEDED,
|
|
u64 id UNNEEDED)
|
|
{ fprintf(stderr, "notify_channel_mvt called!\n"); abort(); }
|
|
/* Generated stub for notify_forward_event */
|
|
void notify_forward_event(struct lightningd *ld UNNEEDED,
|
|
const struct htlc_in *in UNNEEDED,
|
|
/* May be NULL if we don't know. */
|
|
const struct short_channel_id *scid_out UNNEEDED,
|
|
/* May be NULL. */
|
|
const struct amount_msat *amount_out UNNEEDED,
|
|
enum forward_status state UNNEEDED,
|
|
enum onion_wire failcode UNNEEDED,
|
|
struct timeabs *resolved_time UNNEEDED,
|
|
enum forward_style forward_style UNNEEDED,
|
|
u64 created_index UNNEEDED,
|
|
u64 updated_index UNNEEDED)
|
|
{ fprintf(stderr, "notify_forward_event called!\n"); abort(); }
|
|
/* Generated stub for outpointfilter_add */
|
|
void outpointfilter_add(struct outpointfilter *of UNNEEDED,
|
|
const struct bitcoin_outpoint *outpoint UNNEEDED)
|
|
{ fprintf(stderr, "outpointfilter_add called!\n"); abort(); }
|
|
/* Generated stub for outpointfilter_matches */
|
|
bool outpointfilter_matches(struct outpointfilter *of UNNEEDED,
|
|
const struct bitcoin_outpoint *outpoint UNNEEDED)
|
|
{ fprintf(stderr, "outpointfilter_matches called!\n"); abort(); }
|
|
/* Generated stub for outpointfilter_new */
|
|
struct outpointfilter *outpointfilter_new(tal_t *ctx UNNEEDED)
|
|
{ fprintf(stderr, "outpointfilter_new called!\n"); abort(); }
|
|
/* Generated stub for outpointfilter_remove */
|
|
void outpointfilter_remove(struct outpointfilter *of UNNEEDED,
|
|
const struct bitcoin_outpoint *outpoint UNNEEDED)
|
|
{ fprintf(stderr, "outpointfilter_remove called!\n"); abort(); }
|
|
/* Generated stub for peer_set_dbid */
|
|
void peer_set_dbid(struct peer *peer UNNEEDED, u64 dbid UNNEEDED)
|
|
{ fprintf(stderr, "peer_set_dbid called!\n"); abort(); }
|
|
/* Generated stub for psbt_fixup */
|
|
const u8 *psbt_fixup(const tal_t *ctx UNNEEDED, const u8 *psbtblob UNNEEDED)
|
|
{ fprintf(stderr, "psbt_fixup called!\n"); abort(); }
|
|
/* Generated stub for remove_htlc_in_by_dbid */
|
|
struct htlc_in *remove_htlc_in_by_dbid(struct htlc_in_map *remaining_htlcs_in UNNEEDED,
|
|
u64 dbid UNNEEDED)
|
|
{ fprintf(stderr, "remove_htlc_in_by_dbid called!\n"); abort(); }
|
|
/* Generated stub for rune_unique_id */
|
|
u64 rune_unique_id(const struct rune *rune UNNEEDED)
|
|
{ fprintf(stderr, "rune_unique_id called!\n"); abort(); }
|
|
/* Generated stub for sendpay_index_created */
|
|
u64 sendpay_index_created(struct lightningd *ld UNNEEDED,
|
|
const struct sha256 *payment_hash UNNEEDED,
|
|
u64 partid UNNEEDED,
|
|
u64 groupid UNNEEDED,
|
|
enum payment_status status UNNEEDED)
|
|
{ fprintf(stderr, "sendpay_index_created called!\n"); abort(); }
|
|
/* Generated stub for sendpay_index_deleted */
|
|
void sendpay_index_deleted(struct lightningd *ld UNNEEDED,
|
|
const struct sha256 *payment_hash UNNEEDED,
|
|
u64 partid UNNEEDED,
|
|
u64 groupid UNNEEDED,
|
|
enum payment_status status UNNEEDED)
|
|
{ fprintf(stderr, "sendpay_index_deleted called!\n"); abort(); }
|
|
/* Generated stub for sendpay_index_update_status */
|
|
u64 sendpay_index_update_status(struct lightningd *ld UNNEEDED,
|
|
const struct sha256 *payment_hash UNNEEDED,
|
|
u64 partid UNNEEDED,
|
|
u64 groupid UNNEEDED,
|
|
enum payment_status status UNNEEDED)
|
|
{ fprintf(stderr, "sendpay_index_update_status called!\n"); abort(); }
|
|
/* Generated stub for towire_hsmd_get_channel_basepoints */
|
|
u8 *towire_hsmd_get_channel_basepoints(const tal_t *ctx UNNEEDED, const struct node_id *peerid UNNEEDED, u64 dbid UNNEEDED)
|
|
{ fprintf(stderr, "towire_hsmd_get_channel_basepoints called!\n"); abort(); }
|
|
/* Generated stub for towire_hsmd_get_output_scriptpubkey */
|
|
u8 *towire_hsmd_get_output_scriptpubkey(const tal_t *ctx UNNEEDED, u64 channel_id UNNEEDED, const struct node_id *peer_id UNNEEDED, const struct pubkey *commitment_point UNNEEDED)
|
|
{ fprintf(stderr, "towire_hsmd_get_output_scriptpubkey called!\n"); abort(); }
|
|
/* Generated stub for txfilter_add_scriptpubkey */
|
|
void txfilter_add_scriptpubkey(struct txfilter *filter UNNEEDED, const u8 *script TAKES UNNEEDED)
|
|
{ fprintf(stderr, "txfilter_add_scriptpubkey called!\n"); abort(); }
|
|
/* Generated stub for wait_index_increment */
|
|
u64 wait_index_increment(struct lightningd *ld UNNEEDED,
|
|
struct db *db UNNEEDED,
|
|
enum wait_subsystem subsystem UNNEEDED,
|
|
enum wait_index index UNNEEDED,
|
|
...)
|
|
{ fprintf(stderr, "wait_index_increment called!\n"); abort(); }
|
|
/* Generated stub for wait_index_name */
|
|
const char *wait_index_name(enum wait_index index UNNEEDED)
|
|
{ fprintf(stderr, "wait_index_name called!\n"); abort(); }
|
|
/* Generated stub for wait_subsystem_name */
|
|
const char *wait_subsystem_name(enum wait_subsystem subsystem UNNEEDED)
|
|
{ fprintf(stderr, "wait_subsystem_name called!\n"); abort(); }
|
|
/* AUTOGENERATED MOCKS END */
|
|
|
|
void plugin_hook_db_sync(struct db *db UNNEEDED)
|
|
{
|
|
}
|
|
|
|
void migrate_from_account_db(struct lightningd *ld UNNEEDED, struct db *db UNNEEDED)
|
|
{
|
|
}
|
|
|
|
u64 chain_mvt_index_created(struct lightningd *ld UNNEEDED,
|
|
struct db *db UNNEEDED,
|
|
const struct mvt_account_id *account UNNEEDED,
|
|
struct amount_msat credit UNNEEDED,
|
|
struct amount_msat debit UNNEEDED)
|
|
{
|
|
static u64 idx = 1;
|
|
return idx++;
|
|
}
|
|
|
|
void notify_chain_mvt(struct lightningd *ld UNNEEDED,
|
|
const struct chain_coin_mvt *chain_mvt UNNEEDED,
|
|
u64 id UNNEEDED)
|
|
{
|
|
}
|
|
|
|
void logv(struct logger *logger UNNEEDED, enum log_level level UNNEEDED, const struct node_id *node_id UNNEEDED,
|
|
bool call_notifier UNNEEDED, const char *fmt UNNEEDED, va_list ap UNNEEDED)
|
|
{
|
|
}
|
|
|
|
static size_t count_moves(struct db *db)
|
|
{
|
|
struct db_stmt *stmt;
|
|
size_t ret;
|
|
|
|
stmt = db_prepare_v2(db,
|
|
SQL("SELECT COUNT(*)"
|
|
" FROM chain_moves"));
|
|
db_query_prepared(stmt);
|
|
db_step(stmt);
|
|
|
|
ret = db_col_int(stmt, "COUNT(*)");
|
|
tal_free(stmt);
|
|
return ret;
|
|
}
|
|
|
|
int main(int argc, const char *argv[])
|
|
{
|
|
char *filename;
|
|
struct wallet *w;
|
|
struct lightningd *ld;
|
|
struct chain_coin_mvt *chain_mvt;
|
|
struct channel_id cid;
|
|
struct channel *channel;
|
|
const char *channel_cid_name;
|
|
struct bitcoin_txid txid, txid2;
|
|
struct bitcoin_outpoint outpoint, outpoint2;
|
|
struct db_stmt *stmt;
|
|
|
|
common_setup(argv[0]);
|
|
close(tmpdir_mkstemp(tmpctx, "ldb-XXXXXX", &filename));
|
|
|
|
ld = talz(tmpctx, struct lightningd);
|
|
|
|
chainparams = chainparams_for_network("bitcoin");
|
|
ld->wallet_dsn = tal_fmt(ld, "sqlite3://%s", filename);
|
|
ld->developer = false;
|
|
ld->wallet = w = tal(ld, struct wallet);
|
|
ld->wallet->db = db_setup(ld->wallet, ld, NULL);
|
|
|
|
memset(&cid, 1, sizeof(cid));
|
|
memset(&txid, 2, sizeof(txid));
|
|
txid2 = txid;
|
|
txid2.shad.sha.u.u8[0] = 0;
|
|
memset(&outpoint, 3, sizeof(outpoint));
|
|
outpoint2 = outpoint;
|
|
outpoint2.n++;
|
|
channel = tal(ld, struct channel);
|
|
channel->cid = cid;
|
|
channel->dbid = 1;
|
|
channel_cid_name = fmt_channel_id(tmpctx, &cid);
|
|
|
|
db_begin_transaction(w->db);
|
|
stmt = db_prepare_v2(
|
|
w->db, SQL("INSERT INTO channels ("
|
|
"id, full_channel_id"
|
|
") VALUES (?,?);"));
|
|
db_bind_u64(stmt, channel->dbid);
|
|
db_bind_channel_id(stmt, &cid);
|
|
db_exec_prepared_v2(take(stmt));
|
|
|
|
chain_mvt = new_coin_channel_close(tmpctx,
|
|
NULL,
|
|
channel_cid_name,
|
|
&txid,
|
|
&outpoint,
|
|
100,
|
|
AMOUNT_MSAT(100000),
|
|
AMOUNT_SAT(1000),
|
|
5, false);
|
|
wallet_save_chain_mvt(ld, chain_mvt);
|
|
assert(count_moves(w->db) == 1);
|
|
/* Exact duplicate: no */
|
|
wallet_save_chain_mvt(ld, chain_mvt);
|
|
assert(count_moves(w->db) == 1);
|
|
|
|
/* Different txid */
|
|
chain_mvt = new_coin_channel_close(tmpctx,
|
|
NULL,
|
|
channel_cid_name,
|
|
&txid2,
|
|
&outpoint,
|
|
100,
|
|
AMOUNT_MSAT(100000),
|
|
AMOUNT_SAT(1000),
|
|
5, false);
|
|
wallet_save_chain_mvt(ld, chain_mvt);
|
|
assert(count_moves(w->db) == 2);
|
|
|
|
/* Same one: channel by channel not name. */
|
|
chain_mvt = new_coin_channel_close(tmpctx,
|
|
NULL,
|
|
channel_cid_name,
|
|
&txid,
|
|
&outpoint2,
|
|
100,
|
|
AMOUNT_MSAT(100000),
|
|
AMOUNT_SAT(1000),
|
|
5, false);
|
|
wallet_save_chain_mvt(ld, chain_mvt);
|
|
assert(count_moves(w->db) == 3);
|
|
|
|
/* Same one: channel by channel not name. */
|
|
chain_mvt = new_coin_channel_close(tmpctx,
|
|
channel,
|
|
NULL,
|
|
&txid,
|
|
&outpoint,
|
|
100,
|
|
AMOUNT_MSAT(100000),
|
|
AMOUNT_SAT(1000),
|
|
5, false);
|
|
wallet_save_chain_mvt(ld, chain_mvt);
|
|
assert(count_moves(w->db) == 3);
|
|
|
|
/* Different tag */
|
|
chain_mvt->tags = mk_mvt_tags(MVT_DEPOSIT);
|
|
wallet_save_chain_mvt(ld, chain_mvt);
|
|
assert(count_moves(w->db) == 4);
|
|
db_commit_transaction(w->db);
|
|
unlink(filename);
|
|
common_shutdown();
|
|
trace_cleanup();
|
|
}
|