Browse Source

cleanup: Make blockheights unsigned

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
ba7341ec87
  1. 4
      common/utxo.h
  2. 3
      lightningd/chaintopology.c
  3. 2
      lightningd/chaintopology.h
  4. 14
      wallet/wallet.c
  5. 2
      wallet/wallet.h

4
common/utxo.h

@ -28,10 +28,10 @@ struct utxo {
struct unilateral_close_info *close_info;
/* NULL if we haven't seen it in a block, otherwise the block it's in */
const int *blockheight;
const u32 *blockheight;
/* NULL if not spent yet, otherwise, the block the spending transaction is in */
const int *spendheight;
const u32 *spendheight;
};
void towire_utxo(u8 **pptr, const struct utxo *utxo);

3
lightningd/chaintopology.c

@ -77,7 +77,8 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
satoshi_owned = 0;
if (txfilter_match(topo->bitcoind->ld->owned_txfilter, tx)) {
wallet_extract_owned_outputs(topo->bitcoind->ld->wallet,
tx, b, &satoshi_owned);
tx, &b->height,
&satoshi_owned);
}
/* We did spends first, in case that tells us to watch tx. */

2
lightningd/chaintopology.h

@ -35,7 +35,7 @@ struct outgoing_tx {
};
struct block {
int height;
u32 height;
/* Actual header. */
struct bitcoin_block_hdr hdr;

14
wallet/wallet.c

@ -117,7 +117,7 @@ bool wallet_add_utxo(struct wallet *w, struct utxo *utxo,
*/
static bool wallet_stmt2output(sqlite3_stmt *stmt, struct utxo *utxo)
{
int *blockheight, *spendheight;
u32 *blockheight, *spendheight;
sqlite3_column_sha256_double(stmt, 0, &utxo->txid.shad);
utxo->outnum = sqlite3_column_int(stmt, 1);
utxo->amount = sqlite3_column_int64(stmt, 2);
@ -137,13 +137,13 @@ static bool wallet_stmt2output(sqlite3_stmt *stmt, struct utxo *utxo)
utxo->spendheight = NULL;
if (sqlite3_column_type(stmt, 9) != SQLITE_NULL) {
blockheight = tal(utxo, int);
blockheight = tal(utxo, u32);
*blockheight = sqlite3_column_int(stmt, 9);
utxo->blockheight = blockheight;
}
if (sqlite3_column_type(stmt, 10) != SQLITE_NULL) {
spendheight = tal(utxo, int);
spendheight = tal(utxo, u32);
*spendheight = sqlite3_column_int(stmt, 10);
utxo->spendheight = spendheight;
}
@ -1071,7 +1071,7 @@ static void wallet_output_confirm(struct wallet *w,
}
int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
const struct block *block, u64 *total_satoshi)
const u32 *blockheight, u64 *total_satoshi)
{
int num_utxos = 0;
for (size_t output = 0; output < tal_count(tx->output); output++) {
@ -1092,7 +1092,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
utxo->outnum = output;
utxo->close_info = NULL;
utxo->blockheight = block?&block->height:NULL;
utxo->blockheight = blockheight?blockheight:NULL;
utxo->spendheight = NULL;
log_debug(w->log, "Owning output %zu %"PRIu64" (%s) txid %s",
@ -1107,8 +1107,8 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
* blockheight. This can happen when we grab
* the output from a transaction we created
* ourselves. */
if (block)
wallet_output_confirm(w, &utxo->txid, utxo->outnum, block->height);
if (blockheight)
wallet_output_confirm(w, &utxo->txid, utxo->outnum, *blockheight);
tal_free(utxo);
continue;
}

2
wallet/wallet.h

@ -315,7 +315,7 @@ u32 wallet_first_blocknum(struct wallet *w, u32 first_possible);
* wallet_extract_owned_outputs - given a tx, extract all of our outputs
*/
int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
const struct block *block, u64 *total_satoshi);
const u32 *blockheight, u64 *total_satoshi);
/**
* wallet_htlc_save_in - store an htlc_in in the database

Loading…
Cancel
Save