Merge #920: Wallet creation time

79177945ada4803af409f963dd6185d436aa6e21 add timestamp field to getinfo (pythcoiner)

Pull request description:

  (partially) address #805
  - [x] daemon
  - [x] tests
  - [x] doc

ACKs for top commit:
  darosior:
    ACK 79177945ada4803af409f963dd6185d436aa6e21

Tree-SHA512: ee72761174a09871092fe13313e18180530c1a9c4ef5ddf63cb196760a67bc4bac3c9af134d4be5e464f1ac0e16fed726693340499d192eb9a4d68471bbc2ced
This commit is contained in:
Antoine Poinsot 2024-01-23 10:25:48 +01:00
commit e9b5a7ad22
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
5 changed files with 29 additions and 2 deletions

View File

@ -53,14 +53,15 @@ This command does not take any parameter for now.
#### Response
| Field | Type | Description |
| -------------------- | ------- | -------------------------------------------------------------------------------------------------- |
| Field | Type | Description |
| -------------------- | ------------- | -------------------------------------------------------------------------------------------- |
| `version` | string | Version following the [SimVer](http://www.simver.org/) format |
| `network` | string | Answer can be `mainnet`, `testnet`, `regtest` |
| `block_height` | integer | The block height we are synced at. |
| `sync` | float | The synchronization progress as percentage (`0 < sync < 1`) |
| `descriptors` | object | Object with the name of the descriptor as key and the descriptor string as value |
| `rescan_progress` | float or null | Progress of an ongoing rescan as a percentage (between 0 and 1) if there is any |
| `timestamp` | integer | Unix timestamp of wallet creation date |
### `getnewaddress`

View File

@ -294,6 +294,7 @@ impl DaemonControl {
main: self.config.main_descriptor.clone(),
},
rescan_progress,
timestamp: db_conn.timestamp(),
}
}
@ -1030,6 +1031,8 @@ pub struct GetInfoResult {
pub descriptors: GetInfoDescriptors,
/// The progress as a percentage (between 0 and 1) of an ongoing rescan if there is any
pub rescan_progress: Option<f64>,
/// Timestamp at wallet creation date
pub timestamp: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]

View File

@ -46,6 +46,9 @@ pub trait DatabaseConnection {
/// The network we are operating on.
fn network(&mut self) -> bitcoin::Network;
/// The timestamp at wallet creation time
fn timestamp(&mut self) -> u32;
/// Update our best chain seen.
fn update_tip(&mut self, tip: &BlockChainTip);
@ -161,6 +164,10 @@ impl DatabaseConnection for SqliteConn {
self.db_tip().network
}
fn timestamp(&mut self) -> u32 {
self.db_wallet().timestamp
}
fn update_tip(&mut self, tip: &BlockChainTip) {
self.update_tip(tip)
}

View File

@ -5,11 +5,13 @@ use crate::{
descriptors, DaemonHandle,
};
use std::convert::TryInto;
use std::{
collections::{HashMap, HashSet},
env, fs, io, path, process,
str::FromStr,
sync, thread, time,
time::{SystemTime, UNIX_EPOCH},
};
use miniscript::{
@ -129,6 +131,7 @@ struct DummyDbState {
curr_tip: Option<BlockChainTip>,
coins: HashMap<bitcoin::OutPoint, Coin>,
spend_txs: HashMap<bitcoin::Txid, (Psbt, Option<u32>)>,
timestamp: u32,
}
pub struct DummyDatabase {
@ -145,6 +148,13 @@ impl DatabaseInterface for DummyDatabase {
impl DummyDatabase {
pub fn new() -> DummyDatabase {
let now: u32 = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs()
.try_into()
.unwrap();
DummyDatabase {
db: sync::Arc::new(sync::RwLock::new(DummyDbState {
deposit_index: 0.into(),
@ -152,6 +162,7 @@ impl DummyDatabase {
curr_tip: None,
coins: HashMap::new(),
spend_txs: HashMap::new(),
timestamp: now,
})),
}
}
@ -172,6 +183,10 @@ impl DatabaseConnection for DummyDatabase {
self.db.read().unwrap().curr_tip
}
fn timestamp(&mut self) -> u32 {
self.db.read().unwrap().timestamp
}
fn update_tip(&mut self, tip: &BlockChainTip) {
self.db.write().unwrap().curr_tip = Some(*tip);
}

View File

@ -22,6 +22,7 @@ from test_framework.utils import (
def test_getinfo(lianad):
res = lianad.rpc.getinfo()
assert 'timestamp' in res.keys()
assert res["version"] == "4.0.0-dev"
assert res["network"] == "regtest"
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == 101)