Skip to content

Commit 7917794

Browse files
author
pythcoiner
committed
add timestamp field to getinfo
1 parent 501dce4 commit 7917794

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

doc/API.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ This command does not take any parameter for now.
5353

5454
#### Response
5555

56-
| Field | Type | Description |
57-
| -------------------- | ------- | -------------------------------------------------------------------------------------------------- |
56+
| Field | Type | Description |
57+
| -------------------- | ------------- | -------------------------------------------------------------------------------------------- |
5858
| `version` | string | Version following the [SimVer](http://www.simver.org/) format |
5959
| `network` | string | Answer can be `mainnet`, `testnet`, `regtest` |
6060
| `block_height` | integer | The block height we are synced at. |
6161
| `sync` | float | The synchronization progress as percentage (`0 < sync < 1`) |
6262
| `descriptors` | object | Object with the name of the descriptor as key and the descriptor string as value |
6363
| `rescan_progress` | float or null | Progress of an ongoing rescan as a percentage (between 0 and 1) if there is any |
64+
| `timestamp` | integer | Unix timestamp of wallet creation date |
6465

6566
### `getnewaddress`
6667

src/commands/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ impl DaemonControl {
294294
main: self.config.main_descriptor.clone(),
295295
},
296296
rescan_progress,
297+
timestamp: db_conn.timestamp(),
297298
}
298299
}
299300

@@ -1030,6 +1031,8 @@ pub struct GetInfoResult {
10301031
pub descriptors: GetInfoDescriptors,
10311032
/// The progress as a percentage (between 0 and 1) of an ongoing rescan if there is any
10321033
pub rescan_progress: Option<f64>,
1034+
/// Timestamp at wallet creation date
1035+
pub timestamp: u32,
10331036
}
10341037

10351038
#[derive(Debug, Clone, Serialize, Deserialize)]

src/database/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub trait DatabaseConnection {
4646
/// The network we are operating on.
4747
fn network(&mut self) -> bitcoin::Network;
4848

49+
/// The timestamp at wallet creation time
50+
fn timestamp(&mut self) -> u32;
51+
4952
/// Update our best chain seen.
5053
fn update_tip(&mut self, tip: &BlockChainTip);
5154

@@ -161,6 +164,10 @@ impl DatabaseConnection for SqliteConn {
161164
self.db_tip().network
162165
}
163166

167+
fn timestamp(&mut self) -> u32 {
168+
self.db_wallet().timestamp
169+
}
170+
164171
fn update_tip(&mut self, tip: &BlockChainTip) {
165172
self.update_tip(tip)
166173
}

src/testutils.rs

+15
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use crate::{
55
descriptors, DaemonHandle,
66
};
77

8+
use std::convert::TryInto;
89
use std::{
910
collections::{HashMap, HashSet},
1011
env, fs, io, path, process,
1112
str::FromStr,
1213
sync, thread, time,
14+
time::{SystemTime, UNIX_EPOCH},
1315
};
1416

1517
use miniscript::{
@@ -129,6 +131,7 @@ struct DummyDbState {
129131
curr_tip: Option<BlockChainTip>,
130132
coins: HashMap<bitcoin::OutPoint, Coin>,
131133
spend_txs: HashMap<bitcoin::Txid, (Psbt, Option<u32>)>,
134+
timestamp: u32,
132135
}
133136

134137
pub struct DummyDatabase {
@@ -145,13 +148,21 @@ impl DatabaseInterface for DummyDatabase {
145148

146149
impl DummyDatabase {
147150
pub fn new() -> DummyDatabase {
151+
let now: u32 = SystemTime::now()
152+
.duration_since(UNIX_EPOCH)
153+
.unwrap()
154+
.as_secs()
155+
.try_into()
156+
.unwrap();
157+
148158
DummyDatabase {
149159
db: sync::Arc::new(sync::RwLock::new(DummyDbState {
150160
deposit_index: 0.into(),
151161
change_index: 0.into(),
152162
curr_tip: None,
153163
coins: HashMap::new(),
154164
spend_txs: HashMap::new(),
165+
timestamp: now,
155166
})),
156167
}
157168
}
@@ -172,6 +183,10 @@ impl DatabaseConnection for DummyDatabase {
172183
self.db.read().unwrap().curr_tip
173184
}
174185

186+
fn timestamp(&mut self) -> u32 {
187+
self.db.read().unwrap().timestamp
188+
}
189+
175190
fn update_tip(&mut self, tip: &BlockChainTip) {
176191
self.db.write().unwrap().curr_tip = Some(*tip);
177192
}

tests/test_rpc.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
def test_getinfo(lianad):
2424
res = lianad.rpc.getinfo()
25+
assert 'timestamp' in res.keys()
2526
assert res["version"] == "4.0.0-dev"
2627
assert res["network"] == "regtest"
2728
wait_for(lambda: lianad.rpc.getinfo()["block_height"] == 101)

0 commit comments

Comments
 (0)