Skip to content

Commit 2c77329

Browse files
committed
Rename ConfirmationTime to BlockTime
1 parent 3e5bb07 commit 2c77329

File tree

12 files changed

+51
-44
lines changed

12 files changed

+51
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- BIP39 implementation dependency, in `keys::bip39` changed from tiny-bip39 to rust-bip39.
1010
- Add new method on the `TxBuilder` to embed data in the transaction via `OP_RETURN`. To allow that a fix to check the dust only on spendable output has been introduced.
1111
- Update the `Database` trait to store the last sync timestamp and block height
12+
- Rename `ConfirmationTime` to `BlockTime`
1213

1314
## [v0.13.0] - [v0.12.0]
1415

src/blockchain/compact_filters/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use super::{Blockchain, Capability, ConfigurableBlockchain, Progress};
7171
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
7272
use crate::error::Error;
7373
use crate::types::{KeychainKind, LocalUtxo, TransactionDetails};
74-
use crate::{ConfirmationTime, FeeRate};
74+
use crate::{BlockTime, FeeRate};
7575

7676
use peer::*;
7777
use store::*;
@@ -206,7 +206,7 @@ impl CompactFiltersBlockchain {
206206
transaction: Some(tx.clone()),
207207
received: incoming,
208208
sent: outgoing,
209-
confirmation_time: ConfirmationTime::new(height, timestamp),
209+
confirmation_time: BlockTime::new(height, timestamp),
210210
verified: height.is_some(),
211211
fee: Some(inputs_sum.saturating_sub(outputs_sum)),
212212
};

src/blockchain/rpc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::blockchain::{Blockchain, Capability, ConfigurableBlockchain, Progress
3737
use crate::database::{BatchDatabase, DatabaseUtils};
3838
use crate::descriptor::{get_checksum, IntoWalletDescriptor};
3939
use crate::wallet::utils::SecpCtx;
40-
use crate::{ConfirmationTime, Error, FeeRate, KeychainKind, LocalUtxo, TransactionDetails};
40+
use crate::{BlockTime, Error, FeeRate, KeychainKind, LocalUtxo, TransactionDetails};
4141
use bitcoincore_rpc::json::{
4242
GetAddressInfoResultLabel, ImportMultiOptions, ImportMultiRequest,
4343
ImportMultiRequestScriptPubkey, ImportMultiRescanSince,
@@ -230,7 +230,7 @@ impl Blockchain for RpcBlockchain {
230230
list_txs_ids.insert(txid);
231231
if let Some(mut known_tx) = known_txs.get_mut(&txid) {
232232
let confirmation_time =
233-
ConfirmationTime::new(tx_result.info.blockheight, tx_result.info.blocktime);
233+
BlockTime::new(tx_result.info.blockheight, tx_result.info.blocktime);
234234
if confirmation_time != known_tx.confirmation_time {
235235
// reorg may change tx height
236236
debug!(
@@ -266,7 +266,7 @@ impl Blockchain for RpcBlockchain {
266266
let td = TransactionDetails {
267267
transaction: Some(tx),
268268
txid: tx_result.info.txid,
269-
confirmation_time: ConfirmationTime::new(
269+
confirmation_time: BlockTime::new(
270270
tx_result.info.blockheight,
271271
tx_result.info.blocktime,
272272
),

src/blockchain/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use bitcoin::{BlockHeader, OutPoint, Script, Transaction, Txid};
2121
use super::*;
2222
use crate::database::{BatchDatabase, BatchOperations, DatabaseUtils};
2323
use crate::error::Error;
24-
use crate::types::{ConfirmationTime, KeychainKind, LocalUtxo, TransactionDetails};
24+
use crate::types::{BlockTime, KeychainKind, LocalUtxo, TransactionDetails};
2525
use crate::wallet::time::Instant;
2626
use crate::wallet::utils::ChunksIterator;
2727

@@ -151,7 +151,7 @@ pub trait ElectrumLikeSync {
151151
// check if tx height matches, otherwise updates it. timestamp is not in the if clause
152152
// because we are not asking headers for confirmed tx we know about
153153
if tx_details.confirmation_time.as_ref().map(|c| c.height) != height {
154-
let confirmation_time = ConfirmationTime::new(height, timestamp);
154+
let confirmation_time = BlockTime::new(height, timestamp);
155155
let mut new_tx_details = tx_details.clone();
156156
new_tx_details.confirmation_time = confirmation_time;
157157
batch.set_tx(&new_tx_details)?;
@@ -359,7 +359,7 @@ fn save_transaction_details_and_utxos<D: BatchDatabase>(
359359
transaction: Some(tx),
360360
received: incoming,
361361
sent: outgoing,
362-
confirmation_time: ConfirmationTime::new(height, timestamp),
362+
confirmation_time: BlockTime::new(height, timestamp),
363363
fee: Some(inputs_sum.saturating_sub(outputs_sum)), /* if the tx is a coinbase, fees would be negative */
364364
verified: height.is_some(),
365365
};

src/database/any.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl BatchOperations for AnyDatabase {
144144
fn set_last_index(&mut self, keychain: KeychainKind, value: u32) -> Result<(), Error> {
145145
impl_inner_method!(AnyDatabase, self, set_last_index, keychain, value)
146146
}
147-
fn set_last_sync_time(&mut self, last_sync_time: ConfirmationTime) -> Result<(), Error> {
147+
fn set_last_sync_time(&mut self, last_sync_time: BlockTime) -> Result<(), Error> {
148148
impl_inner_method!(AnyDatabase, self, set_last_sync_time, last_sync_time)
149149
}
150150

@@ -183,7 +183,7 @@ impl BatchOperations for AnyDatabase {
183183
fn del_last_index(&mut self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
184184
impl_inner_method!(AnyDatabase, self, del_last_index, keychain)
185185
}
186-
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
186+
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
187187
impl_inner_method!(AnyDatabase, self, del_last_sync_time)
188188
}
189189
}
@@ -247,7 +247,7 @@ impl Database for AnyDatabase {
247247
fn get_last_index(&self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
248248
impl_inner_method!(AnyDatabase, self, get_last_index, keychain)
249249
}
250-
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
250+
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
251251
impl_inner_method!(AnyDatabase, self, get_last_sync_time)
252252
}
253253

@@ -281,7 +281,7 @@ impl BatchOperations for AnyBatch {
281281
fn set_last_index(&mut self, keychain: KeychainKind, value: u32) -> Result<(), Error> {
282282
impl_inner_method!(AnyBatch, self, set_last_index, keychain, value)
283283
}
284-
fn set_last_sync_time(&mut self, last_sync_time: ConfirmationTime) -> Result<(), Error> {
284+
fn set_last_sync_time(&mut self, last_sync_time: BlockTime) -> Result<(), Error> {
285285
impl_inner_method!(AnyBatch, self, set_last_sync_time, last_sync_time)
286286
}
287287

@@ -314,7 +314,7 @@ impl BatchOperations for AnyBatch {
314314
fn del_last_index(&mut self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
315315
impl_inner_method!(AnyBatch, self, del_last_index, keychain)
316316
}
317-
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
317+
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
318318
impl_inner_method!(AnyBatch, self, del_last_sync_time)
319319
}
320320
}

src/database/keyvalue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ macro_rules! impl_batch_operations {
8282
Ok(())
8383
}
8484

85-
fn set_last_sync_time(&mut self, ct: ConfirmationTime) -> Result<(), Error> {
85+
fn set_last_sync_time(&mut self, ct: BlockTime) -> Result<(), Error> {
8686
let key = MapKey::LastSyncTime.as_map_key();
8787
self.insert(key, serde_json::to_vec(&ct)?)$($after_insert)*;
8888

@@ -176,7 +176,7 @@ macro_rules! impl_batch_operations {
176176
}
177177
}
178178

179-
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
179+
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
180180
let key = MapKey::LastSyncTime.as_map_key();
181181
let res = self.remove(key);
182182
let res = $process_delete!(res);
@@ -357,7 +357,7 @@ impl Database for Tree {
357357
.transpose()
358358
}
359359

360-
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
360+
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
361361
let key = MapKey::LastSyncTime.as_map_key();
362362
Ok(self
363363
.get(key)?

src/database/memory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl BatchOperations for MemoryDatabase {
183183

184184
Ok(())
185185
}
186-
fn set_last_sync_time(&mut self, ct: ConfirmationTime) -> Result<(), Error> {
186+
fn set_last_sync_time(&mut self, ct: BlockTime) -> Result<(), Error> {
187187
let key = MapKey::LastSyncTime.as_map_key();
188188
self.map.insert(key, Box::new(ct));
189189

@@ -279,7 +279,7 @@ impl BatchOperations for MemoryDatabase {
279279
Some(b) => Ok(Some(*b.downcast_ref().unwrap())),
280280
}
281281
}
282-
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
282+
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
283283
let key = MapKey::LastSyncTime.as_map_key();
284284
let res = self.map.remove(&key);
285285
self.deleted_keys.push(key);
@@ -423,7 +423,7 @@ impl Database for MemoryDatabase {
423423
Ok(self.map.get(&key).map(|b| *b.downcast_ref().unwrap()))
424424
}
425425

426-
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
426+
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
427427
let key = MapKey::LastSyncTime.as_map_key();
428428
Ok(self
429429
.map
@@ -505,7 +505,7 @@ macro_rules! populate_test_db {
505505
let txid = tx.txid();
506506
let confirmation_time = tx_meta
507507
.min_confirmations
508-
.map(|conf| $crate::ConfirmationTime {
508+
.map(|conf| $crate::BlockTime {
509509
height: current_height.unwrap().checked_sub(conf as u32).unwrap(),
510510
timestamp: 0,
511511
});

src/database/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub trait BatchOperations {
6565
/// Store the last derivation index for a given keychain.
6666
fn set_last_index(&mut self, keychain: KeychainKind, value: u32) -> Result<(), Error>;
6767
/// Store the sync time in terms of block height and timestamp
68-
fn set_last_sync_time(&mut self, last_sync_time: ConfirmationTime) -> Result<(), Error>;
68+
fn set_last_sync_time(&mut self, last_sync_time: BlockTime) -> Result<(), Error>;
6969

7070
/// Delete a script_pubkey given the keychain and its child number.
7171
fn del_script_pubkey_from_path(
@@ -94,7 +94,7 @@ pub trait BatchOperations {
9494
/// Reset the last sync time to `None`
9595
///
9696
/// Returns the removed value
97-
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error>;
97+
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error>;
9898
}
9999

100100
/// Trait for reading data from a database
@@ -141,7 +141,7 @@ pub trait Database: BatchOperations {
141141
/// Return the last defivation index for a keychain.
142142
fn get_last_index(&self, keychain: KeychainKind) -> Result<Option<u32>, Error>;
143143
/// Return the last sync time, if present
144-
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error>;
144+
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error>;
145145

146146
/// Increment the last derivation index for a keychain and return it
147147
///
@@ -333,7 +333,7 @@ pub mod test {
333333
received: 1337,
334334
sent: 420420,
335335
fee: Some(140),
336-
confirmation_time: Some(ConfirmationTime {
336+
confirmation_time: Some(BlockTime {
337337
timestamp: 123456,
338338
height: 1000,
339339
}),
@@ -388,7 +388,7 @@ pub mod test {
388388
pub fn test_last_sync_time<D: Database>(mut tree: D) {
389389
assert!(tree.get_last_sync_time().unwrap().is_none());
390390

391-
tree.set_last_sync_time(ConfirmationTime {
391+
tree.set_last_sync_time(BlockTime {
392392
height: 100,
393393
timestamp: 1000,
394394
})

src/database/sqlite.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl SqliteDatabase {
206206
Ok(())
207207
}
208208

209-
fn update_last_sync_time(&self, ct: ConfirmationTime) -> Result<i64, Error> {
209+
fn update_last_sync_time(&self, ct: BlockTime) -> Result<i64, Error> {
210210
let mut statement = self.connection.prepare_cached(
211211
"INSERT INTO last_sync_time (id, height, timestamp) VALUES (0, :height, :timestamp) ON CONFLICT(id) DO UPDATE SET height=:height, timestamp=:timestamp WHERE id = 0",
212212
)?;
@@ -389,7 +389,7 @@ impl SqliteDatabase {
389389
};
390390

391391
let confirmation_time = match (height, timestamp) {
392-
(Some(height), Some(timestamp)) => Some(ConfirmationTime { height, timestamp }),
392+
(Some(height), Some(timestamp)) => Some(BlockTime { height, timestamp }),
393393
_ => None,
394394
};
395395

@@ -423,7 +423,7 @@ impl SqliteDatabase {
423423
let verified: bool = row.get(6)?;
424424

425425
let confirmation_time = match (height, timestamp) {
426-
(Some(height), Some(timestamp)) => Some(ConfirmationTime { height, timestamp }),
426+
(Some(height), Some(timestamp)) => Some(BlockTime { height, timestamp }),
427427
_ => None,
428428
};
429429

@@ -466,7 +466,7 @@ impl SqliteDatabase {
466466
};
467467

468468
let confirmation_time = match (height, timestamp) {
469-
(Some(height), Some(timestamp)) => Some(ConfirmationTime { height, timestamp }),
469+
(Some(height), Some(timestamp)) => Some(BlockTime { height, timestamp }),
470470
_ => None,
471471
};
472472

@@ -501,12 +501,12 @@ impl SqliteDatabase {
501501
}
502502
}
503503

504-
fn select_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
504+
fn select_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
505505
let mut statement = self
506506
.connection
507507
.prepare_cached("SELECT height, timestamp FROM last_sync_time WHERE id = 0")?;
508508
let mut rows = statement.query_map([], |row| {
509-
Ok(ConfirmationTime {
509+
Ok(BlockTime {
510510
height: row.get(0)?,
511511
timestamp: row.get(1)?,
512512
})
@@ -658,7 +658,7 @@ impl BatchOperations for SqliteDatabase {
658658
Ok(())
659659
}
660660

661-
fn set_last_sync_time(&mut self, ct: ConfirmationTime) -> Result<(), Error> {
661+
fn set_last_sync_time(&mut self, ct: BlockTime) -> Result<(), Error> {
662662
self.update_last_sync_time(ct)?;
663663
Ok(())
664664
}
@@ -749,7 +749,7 @@ impl BatchOperations for SqliteDatabase {
749749
}
750750
}
751751

752-
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
752+
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
753753
match self.select_last_sync_time()? {
754754
Some(value) => {
755755
self.delete_last_sync_time()?;
@@ -870,7 +870,7 @@ impl Database for SqliteDatabase {
870870
Ok(value)
871871
}
872872

873-
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
873+
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
874874
self.select_last_sync_time()
875875
}
876876

src/types.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub struct TransactionDetails {
210210
pub fee: Option<u64>,
211211
/// If the transaction is confirmed, contains height and timestamp of the block containing the
212212
/// transaction, unconfirmed transaction contains `None`.
213-
pub confirmation_time: Option<ConfirmationTime>,
213+
pub confirmation_time: Option<BlockTime>,
214214
/// Whether the tx has been verified against the consensus rules
215215
///
216216
/// Confirmed txs are considered "verified" by default, while unconfirmed txs are checked to
@@ -222,20 +222,26 @@ pub struct TransactionDetails {
222222
pub verified: bool,
223223
}
224224

225-
/// Block height and timestamp of the block containing the confirmed transaction
225+
/// Block height and timestamp of a block
226226
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
227-
pub struct ConfirmationTime {
227+
pub struct BlockTime {
228228
/// confirmation block height
229229
pub height: u32,
230230
/// confirmation block timestamp
231231
pub timestamp: u64,
232232
}
233233

234-
impl ConfirmationTime {
235-
/// Returns `Some` `ConfirmationTime` if both `height` and `timestamp` are `Some`
234+
/// **DEPRECATED**: Confirmation time of a transaction
235+
///
236+
/// The structure has been renamed to `BlockTime`
237+
#[deprecated(note = "This structure has been renamed to `BlockTime`")]
238+
pub type ConfirmationTime = BlockTime;
239+
240+
impl BlockTime {
241+
/// Returns `Some` `BlockTime` if both `height` and `timestamp` are `Some`
236242
pub fn new(height: Option<u32>, timestamp: Option<u64>) -> Option<Self> {
237243
match (height, timestamp) {
238-
(Some(height), Some(timestamp)) => Some(ConfirmationTime { height, timestamp }),
244+
(Some(height), Some(timestamp)) => Some(BlockTime { height, timestamp }),
239245
_ => None,
240246
}
241247
}

0 commit comments

Comments
 (0)