lib: rename and use existing structs (Db)SpendBlock
This commit is contained in:
parent
4cb6d2dc69
commit
b519c8d185
@ -868,11 +868,7 @@ pub struct CreateRecoveryResult {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
bitcoin::Block,
|
||||
database::{BlockInfo, SpendBlock},
|
||||
testutils::*,
|
||||
};
|
||||
use crate::{bitcoin::Block, database::BlockInfo, testutils::*};
|
||||
|
||||
use bitcoin::{
|
||||
blockdata::transaction::{TxIn, TxOut},
|
||||
@ -1296,7 +1292,7 @@ mod tests {
|
||||
vout: 0,
|
||||
},
|
||||
block_info: Some(BlockInfo { height: 1, time: 1 }),
|
||||
spend_block: Some(SpendBlock { time: 3, height: 3 }),
|
||||
spend_block: Some(BlockInfo { time: 3, height: 3 }),
|
||||
derivation_index: ChildNumber::from(0),
|
||||
amount: bitcoin::Amount::from_sat(100_000_000),
|
||||
spend_txid: Some(spend_tx.txid()),
|
||||
|
||||
@ -6,7 +6,7 @@ pub mod sqlite;
|
||||
use crate::{
|
||||
bitcoin::BlockChainTip,
|
||||
database::sqlite::{
|
||||
schema::{DbBlockInfo, DbCoin, DbSpendBlock, DbTip},
|
||||
schema::{DbBlockInfo, DbCoin, DbTip},
|
||||
SqliteConn, SqliteDb,
|
||||
},
|
||||
};
|
||||
@ -261,21 +261,6 @@ impl DatabaseConnection for SqliteConn {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct SpendBlock {
|
||||
pub height: i32,
|
||||
pub time: u32,
|
||||
}
|
||||
|
||||
impl From<DbSpendBlock> for SpendBlock {
|
||||
fn from(b: DbSpendBlock) -> SpendBlock {
|
||||
SpendBlock {
|
||||
height: b.height,
|
||||
time: b.time,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct BlockInfo {
|
||||
pub height: i32,
|
||||
@ -299,7 +284,7 @@ pub struct Coin {
|
||||
pub derivation_index: bip32::ChildNumber,
|
||||
pub is_change: bool,
|
||||
pub spend_txid: Option<bitcoin::Txid>,
|
||||
pub spend_block: Option<SpendBlock>,
|
||||
pub spend_block: Option<BlockInfo>,
|
||||
}
|
||||
|
||||
impl std::convert::From<DbCoin> for Coin {
|
||||
@ -321,7 +306,7 @@ impl std::convert::From<DbCoin> for Coin {
|
||||
derivation_index,
|
||||
is_change,
|
||||
spend_txid,
|
||||
spend_block: spend_block.map(SpendBlock::from),
|
||||
spend_block: spend_block.map(BlockInfo::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -585,7 +585,7 @@ impl SqliteConn {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::database::{BlockInfo, DbBlockInfo, SpendBlock};
|
||||
use crate::database::{BlockInfo, DbBlockInfo};
|
||||
use crate::testutils::*;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
@ -1005,7 +1005,7 @@ mod tests {
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
spend_block: Some(SpendBlock {
|
||||
spend_block: Some(BlockInfo {
|
||||
height: 101_199,
|
||||
time: 1_231_678,
|
||||
}),
|
||||
@ -1043,7 +1043,7 @@ mod tests {
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
spend_block: Some(SpendBlock {
|
||||
spend_block: Some(BlockInfo {
|
||||
height: 101_105,
|
||||
time: 1_201_678,
|
||||
}),
|
||||
@ -1218,7 +1218,7 @@ mod tests {
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
spend_block: Some(SpendBlock {
|
||||
spend_block: Some(BlockInfo {
|
||||
height: 101_199,
|
||||
time: 1_123_000,
|
||||
}),
|
||||
@ -1256,7 +1256,7 @@ mod tests {
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
spend_block: Some(SpendBlock {
|
||||
spend_block: Some(BlockInfo {
|
||||
height: 101_105,
|
||||
time: 1_126_000,
|
||||
}),
|
||||
|
||||
@ -147,12 +147,6 @@ impl TryFrom<&rusqlite::Row<'_>> for DbWallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct DbSpendBlock {
|
||||
pub height: i32,
|
||||
pub time: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct DbBlockInfo {
|
||||
pub height: i32,
|
||||
@ -169,7 +163,7 @@ pub struct DbCoin {
|
||||
pub derivation_index: bip32::ChildNumber,
|
||||
pub is_change: bool,
|
||||
pub spend_txid: Option<bitcoin::Txid>,
|
||||
pub spend_block: Option<DbSpendBlock>,
|
||||
pub spend_block: Option<DbBlockInfo>,
|
||||
}
|
||||
|
||||
impl TryFrom<&rusqlite::Row<'_>> for DbCoin {
|
||||
@ -203,7 +197,7 @@ impl TryFrom<&rusqlite::Row<'_>> for DbCoin {
|
||||
let spend_height: Option<i32> = row.get(10)?;
|
||||
let spend_time: Option<u32> = row.get(11)?;
|
||||
assert_eq!(spend_height.is_none(), spend_time.is_none());
|
||||
let spend_block = spend_height.map(|height| DbSpendBlock {
|
||||
let spend_block = spend_height.map(|height| DbBlockInfo {
|
||||
height,
|
||||
time: spend_time.expect("Must be there if height is"),
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
bitcoin::{BitcoinInterface, Block, BlockChainTip, UTxO},
|
||||
config::{BitcoinConfig, Config},
|
||||
database::{BlockInfo, Coin, CoinType, DatabaseConnection, DatabaseInterface, SpendBlock},
|
||||
database::{BlockInfo, Coin, CoinType, DatabaseConnection, DatabaseInterface},
|
||||
descriptors, DaemonHandle,
|
||||
};
|
||||
|
||||
@ -258,7 +258,7 @@ impl DatabaseConnection for DummyDatabase {
|
||||
assert!(spent.spend_txid.is_some());
|
||||
assert!(spent.spend_block.is_none());
|
||||
spent.spend_txid = Some(*spend_txid);
|
||||
spent.spend_block = Some(SpendBlock {
|
||||
spent.spend_block = Some(BlockInfo {
|
||||
height: *height,
|
||||
time: *time,
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user