database: rename coins' spent_at in spend_block_time
This commit is contained in:
parent
cce227f80f
commit
6038843d33
@ -43,7 +43,7 @@ fn update_coins(
|
||||
block_height: None,
|
||||
block_time: None,
|
||||
spend_txid: None,
|
||||
spent_at: None,
|
||||
spend_block_time: None,
|
||||
};
|
||||
received.push(coin);
|
||||
}
|
||||
|
||||
@ -572,7 +572,7 @@ mod tests {
|
||||
amount: bitcoin::Amount::from_sat(100_000),
|
||||
derivation_index: bip32::ChildNumber::from(13),
|
||||
spend_txid: None,
|
||||
spent_at: None,
|
||||
spend_block_time: None,
|
||||
}]);
|
||||
let res = control.create_spend(&[dummy_op], &destinations, 1).unwrap();
|
||||
let tx = res.psbt.global.unsigned_tx;
|
||||
@ -666,7 +666,7 @@ mod tests {
|
||||
amount: bitcoin::Amount::from_sat(100_000),
|
||||
derivation_index: bip32::ChildNumber::from(13),
|
||||
spend_txid: None,
|
||||
spent_at: None,
|
||||
spend_block_time: None,
|
||||
},
|
||||
Coin {
|
||||
outpoint: dummy_op_b,
|
||||
@ -675,7 +675,7 @@ mod tests {
|
||||
amount: bitcoin::Amount::from_sat(115_680),
|
||||
derivation_index: bip32::ChildNumber::from(34),
|
||||
spend_txid: None,
|
||||
spent_at: None,
|
||||
spend_block_time: None,
|
||||
},
|
||||
]);
|
||||
|
||||
|
||||
@ -194,7 +194,7 @@ pub struct Coin {
|
||||
pub amount: bitcoin::Amount,
|
||||
pub derivation_index: bip32::ChildNumber,
|
||||
pub spend_txid: Option<bitcoin::Txid>,
|
||||
pub spent_at: Option<u32>,
|
||||
pub spend_block_time: Option<u32>,
|
||||
}
|
||||
|
||||
impl std::convert::From<DbCoin> for Coin {
|
||||
@ -206,7 +206,7 @@ impl std::convert::From<DbCoin> for Coin {
|
||||
amount,
|
||||
derivation_index,
|
||||
spend_txid,
|
||||
spent_at,
|
||||
spend_block_time,
|
||||
..
|
||||
} = db_coin;
|
||||
Coin {
|
||||
@ -216,7 +216,7 @@ impl std::convert::From<DbCoin> for Coin {
|
||||
amount,
|
||||
derivation_index,
|
||||
spend_txid,
|
||||
spent_at,
|
||||
spend_block_time,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ impl SqliteConn {
|
||||
pub fn list_spending_coins(&mut self) -> Vec<DbCoin> {
|
||||
db_query(
|
||||
&mut self.conn,
|
||||
"SELECT * FROM coins WHERE spend_txid IS NOT NULL AND spent_at IS NULL",
|
||||
"SELECT * FROM coins WHERE spend_txid IS NOT NULL AND spend_block_time IS NULL",
|
||||
rusqlite::params![],
|
||||
|row| row.try_into(),
|
||||
)
|
||||
@ -342,7 +342,7 @@ impl SqliteConn {
|
||||
db_exec(&mut self.conn, |db_tx| {
|
||||
for (outpoint, spend_txid, time) in outpoints {
|
||||
db_tx.execute(
|
||||
"UPDATE coins SET spend_txid = ?1, spent_at = ?2 WHERE txid = ?3 AND vout = ?4",
|
||||
"UPDATE coins SET spend_txid = ?1, spend_block_time = ?2 WHERE txid = ?3 AND vout = ?4",
|
||||
rusqlite::params![
|
||||
spend_txid.to_vec(),
|
||||
time,
|
||||
@ -566,7 +566,7 @@ mod tests {
|
||||
amount: bitcoin::Amount::from_sat(98765),
|
||||
derivation_index: bip32::ChildNumber::from_normal_idx(10).unwrap(),
|
||||
spend_txid: None,
|
||||
spent_at: None,
|
||||
spend_block_time: None,
|
||||
};
|
||||
conn.new_unspent_coins(&[coin_a.clone()]); // On 1.48, arrays aren't IntoIterator
|
||||
assert_eq!(conn.unspent_coins()[0].outpoint, coin_a.outpoint);
|
||||
@ -587,7 +587,7 @@ mod tests {
|
||||
amount: bitcoin::Amount::from_sat(1111),
|
||||
derivation_index: bip32::ChildNumber::from_normal_idx(103).unwrap(),
|
||||
spend_txid: None,
|
||||
spent_at: None,
|
||||
spend_block_time: None,
|
||||
};
|
||||
conn.new_unspent_coins(&[coin_b.clone()]);
|
||||
let outpoints: HashSet<bitcoin::OutPoint> = conn
|
||||
|
||||
@ -42,7 +42,7 @@ CREATE TABLE coins (
|
||||
derivation_index INTEGER NOT NULL,
|
||||
spend_txid BLOB,
|
||||
/* Time of the block containing the transaction spending the coin, NULL if not confirmed */
|
||||
spent_at INTEGER,
|
||||
spend_block_time INTEGER,
|
||||
UNIQUE (txid, vout),
|
||||
FOREIGN KEY (wallet_id) REFERENCES wallets (id)
|
||||
ON UPDATE RESTRICT
|
||||
@ -136,7 +136,7 @@ pub struct DbCoin {
|
||||
pub amount: bitcoin::Amount,
|
||||
pub derivation_index: bip32::ChildNumber,
|
||||
pub spend_txid: Option<bitcoin::Txid>,
|
||||
pub spent_at: Option<u32>,
|
||||
pub spend_block_time: Option<u32>,
|
||||
}
|
||||
|
||||
impl TryFrom<&rusqlite::Row<'_>> for DbCoin {
|
||||
@ -161,7 +161,7 @@ impl TryFrom<&rusqlite::Row<'_>> for DbCoin {
|
||||
let spend_txid: Option<Vec<u8>> = row.get(8)?;
|
||||
let spend_txid =
|
||||
spend_txid.map(|txid| encode::deserialize(&txid).expect("We only store valid txids"));
|
||||
let spent_at = row.get(9)?;
|
||||
let spend_block_time = row.get(9)?;
|
||||
|
||||
Ok(DbCoin {
|
||||
id,
|
||||
@ -172,7 +172,7 @@ impl TryFrom<&rusqlite::Row<'_>> for DbCoin {
|
||||
amount,
|
||||
derivation_index,
|
||||
spend_txid,
|
||||
spent_at,
|
||||
spend_block_time,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ impl DatabaseConnection for DummyDbConn {
|
||||
let mut db = self.db.write().unwrap();
|
||||
let spent = &mut db.coins.get_mut(op).unwrap();
|
||||
assert!(spent.spend_txid.is_none());
|
||||
assert!(spent.spent_at.is_none());
|
||||
assert!(spent.spend_block_time.is_none());
|
||||
spent.spend_txid = Some(*spend_txid);
|
||||
}
|
||||
}
|
||||
@ -174,9 +174,9 @@ impl DatabaseConnection for DummyDbConn {
|
||||
let mut db = self.db.write().unwrap();
|
||||
let spent = &mut db.coins.get_mut(op).unwrap();
|
||||
assert!(spent.spend_txid.is_some());
|
||||
assert!(spent.spent_at.is_none());
|
||||
assert!(spent.spend_block_time.is_none());
|
||||
spent.spend_txid = Some(*spend_txid);
|
||||
spent.spent_at = Some(*time);
|
||||
spent.spend_block_time = Some(*time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user