mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 10:38:25 +01:00
sendpsbt: annotate transactions in wallet.
This is what txsend does, only we have a psbt so we have to change the db interface to take a wally_tx. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
6b39731c6a
commit
cf25ca11b8
9 changed files with 23 additions and 16 deletions
|
@ -83,7 +83,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
|
|||
txo = txowatch_hash_get(&topo->txowatches, &out);
|
||||
if (txo) {
|
||||
wallet_transaction_add(topo->ld->wallet,
|
||||
tx, b->height, i);
|
||||
tx->wtx, b->height, i);
|
||||
txowatch_fire(txo, tx, j, b);
|
||||
}
|
||||
}
|
||||
|
@ -93,14 +93,14 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
|
|||
if (txfilter_match(topo->bitcoind->ld->owned_txfilter, tx)) {
|
||||
wallet_extract_owned_outputs(topo->bitcoind->ld->wallet,
|
||||
tx->wtx, &b->height, &owned);
|
||||
wallet_transaction_add(topo->ld->wallet, tx, b->height,
|
||||
i);
|
||||
wallet_transaction_add(topo->ld->wallet, tx->wtx,
|
||||
b->height, i);
|
||||
}
|
||||
|
||||
/* We did spends first, in case that tells us to watch tx. */
|
||||
if (watching_txid(topo, &txid) || we_broadcast(topo, &txid)) {
|
||||
wallet_transaction_add(topo->ld->wallet,
|
||||
tx, b->height, i);
|
||||
tx->wtx, b->height, i);
|
||||
}
|
||||
|
||||
txwatch_inform(topo, &txid, tx);
|
||||
|
@ -235,7 +235,7 @@ void broadcast_tx(struct chain_topology *topo,
|
|||
log_debug(topo->log, "Broadcasting txid %s",
|
||||
type_to_string(tmpctx, struct bitcoin_txid, &otx->txid));
|
||||
|
||||
wallet_transaction_add(topo->ld->wallet, tx, 0, 0);
|
||||
wallet_transaction_add(topo->ld->wallet, tx->wtx, 0, 0);
|
||||
bitcoind_sendrawtx(topo->bitcoind, otx->hextx, broadcast_done, otx);
|
||||
}
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg)
|
|||
tx->chainparams = chainparams;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
wallet_transaction_add(w, tx, 0, 0);
|
||||
wallet_transaction_add(w, tx->wtx, 0, 0);
|
||||
wallet_transaction_annotate(w, &txid, type, channel->dbid);
|
||||
|
||||
/* We don't really care if it fails, we'll respond via watch. */
|
||||
|
|
|
@ -356,7 +356,7 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel,
|
|||
} else {
|
||||
sign_last_tx(channel);
|
||||
bitcoin_txid(channel->last_tx, &txid);
|
||||
wallet_transaction_add(ld->wallet, channel->last_tx, 0, 0);
|
||||
wallet_transaction_add(ld->wallet, channel->last_tx->wtx, 0, 0);
|
||||
wallet_transaction_annotate(ld->wallet, &txid, channel->last_tx_type, channel->dbid);
|
||||
|
||||
/* Keep broadcasting until we say stop (can fail due to dup,
|
||||
|
|
|
@ -620,7 +620,7 @@ void wallet_peer_delete(struct wallet *w UNNEEDED, u64 peer_dbid UNNEEDED)
|
|||
struct amount_msat wallet_total_forward_fees(struct wallet *w UNNEEDED)
|
||||
{ fprintf(stderr, "wallet_total_forward_fees called!\n"); abort(); }
|
||||
/* Generated stub for wallet_transaction_add */
|
||||
void wallet_transaction_add(struct wallet *w UNNEEDED, const struct bitcoin_tx *tx UNNEEDED,
|
||||
void wallet_transaction_add(struct wallet *w UNNEEDED, const struct wally_tx *tx UNNEEDED,
|
||||
const u32 blockheight UNNEEDED, const u32 txindex UNNEEDED)
|
||||
{ fprintf(stderr, "wallet_transaction_add called!\n"); abort(); }
|
||||
/* Generated stub for wallet_transaction_annotate */
|
||||
|
|
|
@ -1440,9 +1440,9 @@ void db_bind_timeabs(struct db_stmt *stmt, int col, struct timeabs t)
|
|||
db_bind_u64(stmt, col, timestamp);
|
||||
}
|
||||
|
||||
void db_bind_tx(struct db_stmt *stmt, int col, const struct bitcoin_tx *tx)
|
||||
void db_bind_tx(struct db_stmt *stmt, int col, const struct wally_tx *tx)
|
||||
{
|
||||
u8 *ser = linearize_tx(stmt, tx);
|
||||
u8 *ser = linearize_wtx(stmt, tx);
|
||||
assert(ser);
|
||||
db_bind_blob(stmt, col, ser, tal_count(ser));
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ void db_bind_short_channel_id_arr(struct db_stmt *stmt, int col,
|
|||
void db_bind_signature(struct db_stmt *stmt, int col,
|
||||
const secp256k1_ecdsa_signature *sig);
|
||||
void db_bind_timeabs(struct db_stmt *stmt, int col, struct timeabs t);
|
||||
void db_bind_tx(struct db_stmt *stmt, int col, const struct bitcoin_tx *tx);
|
||||
void db_bind_tx(struct db_stmt *stmt, int col, const struct wally_tx *tx);
|
||||
void db_bind_psbt(struct db_stmt *stmt, int col, const struct wally_psbt *psbt);
|
||||
void db_bind_amount_msat(struct db_stmt *stmt, int pos,
|
||||
const struct amount_msat *msat);
|
||||
|
|
|
@ -3380,14 +3380,14 @@ struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx,
|
|||
return op;
|
||||
}
|
||||
|
||||
void wallet_transaction_add(struct wallet *w, const struct bitcoin_tx *tx,
|
||||
void wallet_transaction_add(struct wallet *w, const struct wally_tx *tx,
|
||||
const u32 blockheight, const u32 txindex)
|
||||
{
|
||||
struct bitcoin_txid txid;
|
||||
struct db_stmt *stmt = db_prepare_v2(
|
||||
w->db, SQL("SELECT blockheight FROM transactions WHERE id=?"));
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
wally_txid(tx, &txid);
|
||||
db_bind_txid(stmt, 0, &txid);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
|
|
|
@ -1165,7 +1165,7 @@ void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx,
|
|||
const u32 txindex, const u8 *scriptpubkey,
|
||||
struct amount_sat sat);
|
||||
|
||||
void wallet_transaction_add(struct wallet *w, const struct bitcoin_tx *tx,
|
||||
void wallet_transaction_add(struct wallet *w, const struct wally_tx *tx,
|
||||
const u32 blockheight, const u32 txindex);
|
||||
|
||||
void wallet_annotate_txout(struct wallet *w, const struct bitcoin_txid *txid,
|
||||
|
|
|
@ -543,7 +543,7 @@ static struct command_result *json_txsend(struct command *cmd,
|
|||
/* We're the owning cmd now. */
|
||||
utx->wtx->cmd = cmd;
|
||||
|
||||
wallet_transaction_add(cmd->ld->wallet, utx->tx, 0, 0);
|
||||
wallet_transaction_add(cmd->ld->wallet, utx->tx->wtx, 0, 0);
|
||||
wallet_transaction_annotate(cmd->ld->wallet, &utx->txid,
|
||||
TX_UNKNOWN, 0);
|
||||
|
||||
|
@ -610,7 +610,7 @@ static struct command_result *json_withdraw(struct command *cmd,
|
|||
return res;
|
||||
|
||||
/* Store the transaction in the DB and annotate it as a withdrawal */
|
||||
wallet_transaction_add(cmd->ld->wallet, utx->tx, 0, 0);
|
||||
wallet_transaction_add(cmd->ld->wallet, utx->tx->wtx, 0, 0);
|
||||
wallet_transaction_annotate(cmd->ld->wallet, &utx->txid,
|
||||
TX_WALLET_WITHDRAWAL, 0);
|
||||
|
||||
|
@ -1309,6 +1309,7 @@ static struct command_result *json_sendpsbt(struct command *cmd,
|
|||
struct wally_tx *w_tx;
|
||||
struct tx_broadcast *txb;
|
||||
struct utxo **utxos;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("psbt", param_psbt, &psbt),
|
||||
|
@ -1336,6 +1337,12 @@ static struct command_result *json_sendpsbt(struct command *cmd,
|
|||
txb->cmd = cmd;
|
||||
txb->expected_change = NULL;
|
||||
|
||||
/* FIXME: Do this *after* successful broadcast! */
|
||||
wallet_transaction_add(cmd->ld->wallet, txb->wtx, 0, 0);
|
||||
wally_txid(txb->wtx, &txid);
|
||||
wallet_transaction_annotate(cmd->ld->wallet, &txid,
|
||||
TX_UNKNOWN, 0);
|
||||
|
||||
/* Now broadcast the transaction */
|
||||
bitcoind_sendrawtx(cmd->ld->topology->bitcoind,
|
||||
tal_hex(tmpctx, linearize_wtx(tmpctx, w_tx)),
|
||||
|
|
Loading…
Add table
Reference in a new issue