• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 15280118615

27 May 2025 04:01PM UTC coverage: 73.59% (+0.4%) from 73.233%
15280118615

push

github

web-flow
feat: add base node HTTP wallet service (#7061)

Description
---
Added a new HTTP server for base node that exposes some wallet related
query functionality.

Current new endpoints (examples on **esmeralda** network):
 - http://127.0.0.1:9005/get_tip_info
 - http://127.0.0.1:9005/get_header_by_height?height=6994
 - http://127.0.0.1:9005/get_height_at_time?time=1747739959

Default ports for http service (by network):
```
MainNet: 9000,
StageNet: 9001,
NextNet: 9002,
LocalNet: 9003,
Igor: 9004,
Esmeralda: 9005,
```

New configuration needs to be set in base node:
```toml
[base_node.http_wallet_query_service]
port = 9000
external_address = "http://127.0.0.1:9000" # this is optional, but if not set, when someone requests for the external address, just returns a None, so wallets can't contact base node
```

Motivation and Context
---


How Has This Been Tested?
---
### Manually

#### Basic test
1. Build new base node
2. Set base node configuration by adding the following:
```toml
[base_node.http_wallet_query_service]
port = 9000
external_address = "http://127.0.0.1:9000"
```
This way we set the port and external address (which is sent to wallet
client when requesting, so in real world it must be public)
3. Set logging level of base node logs to DEBUG
4. Start base node
5. Build and start console wallet
6. See that it is still able to synchronize
7. Check logs of base node (with `tail -f ...` command for instance) and
see that the HTTP endpoints are used

#### Use RPC fallback test
1. Build new base node
2. Set base node configuration by adding the following:
```toml
[base_node.http_wallet_query_service]
port = 9000
external_address = "http://127.0.0.1:9001"
```
This way we set the port and external address (which is sent to wallet
client when requesting, so in real world it must be public)
3. Set logging level of base node logs to DEBUG
4. Start base node
5. Build and start console wallet
6. See that it is still able to synchronize
7. Check logs of base nod... (continued)

9 of 114 new or added lines in 4 files covered. (7.89%)

1592 existing lines in 62 files now uncovered.

82227 of 111736 relevant lines covered (73.59%)

272070.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.42
/base_layer/core/src/base_node/sync/hooks.rs
1
//  Copyright 2020, The Tari Project
2
//
3
//  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
//  following conditions are met:
5
//
6
//  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
//  disclaimer.
8
//
9
//  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
//  following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
//  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
//  products derived from this software without specific prior written permission.
14
//
15
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
//  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
//  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
//  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
//  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
//  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22

23
#![allow(clippy::type_complexity)]
24

25
use std::sync::Arc;
26

27
use crate::{
28
    base_node::sync::{horizon_state_sync::HorizonSyncInfo, SyncPeer},
29
    blocks::ChainBlock,
30
};
31

32
#[derive(Default)]
33
pub(super) struct Hooks {
34
    on_starting: Vec<Box<dyn FnOnce(&SyncPeer) + Send + Sync>>,
35
    on_progress_header: Vec<Box<dyn Fn(u64, u64, &SyncPeer) + Send + Sync>>,
36
    on_progress_block: Vec<Box<dyn Fn(Arc<ChainBlock>, u64, &SyncPeer) + Send + Sync>>,
37
    on_progress_horizon_sync: Vec<Box<dyn Fn(HorizonSyncInfo) + Send + Sync>>,
38
    on_complete: Vec<Box<dyn Fn(Arc<ChainBlock>, u64) + Send + Sync>>,
39
    on_rewind: Vec<Box<dyn Fn(Vec<Arc<ChainBlock>>) + Send + Sync>>,
40
}
41

42
impl Hooks {
43
    pub fn add_on_starting_hook<H>(&mut self, hook: H)
18✔
44
    where H: FnOnce(&SyncPeer) + Send + Sync + 'static {
18✔
45
        self.on_starting.push(Box::new(hook));
18✔
46
    }
18✔
47

48
    pub fn call_on_starting_hook(&mut self, sync_peer: &SyncPeer) {
18✔
49
        self.on_starting.drain(..).for_each(|f| (f)(sync_peer));
18✔
50
    }
18✔
51

52
    pub fn add_on_progress_header_hook<H>(&mut self, hook: H)
14✔
53
    where H: Fn(u64, u64, &SyncPeer) + Send + Sync + 'static {
14✔
54
        self.on_progress_header.push(Box::new(hook));
14✔
55
    }
14✔
56

57
    pub fn call_on_progress_header_hooks(&self, local_height: u64, remote_height: u64, sync_peer: &SyncPeer) {
6✔
58
        self.on_progress_header
6✔
59
            .iter()
6✔
60
            .for_each(|f| (*f)(local_height, remote_height, sync_peer));
6✔
61
    }
6✔
62

63
    pub fn add_on_progress_block_hook<H>(&mut self, hook: H)
4✔
64
    where H: Fn(Arc<ChainBlock>, u64, &SyncPeer) + Send + Sync + 'static {
4✔
65
        self.on_progress_block.push(Box::new(hook));
4✔
66
    }
4✔
67

68
    pub fn call_on_progress_block_hooks(&self, block: Arc<ChainBlock>, remote_tip_height: u64, sync_peer: &SyncPeer) {
5✔
69
        self.on_progress_block
5✔
70
            .iter()
5✔
71
            .for_each(|f| (*f)(block.clone(), remote_tip_height, sync_peer));
5✔
72
    }
5✔
73

UNCOV
74
    pub fn add_on_progress_horizon_hook<H>(&mut self, hook: H)
×
UNCOV
75
    where H: Fn(HorizonSyncInfo) + Send + Sync + 'static {
×
UNCOV
76
        self.on_progress_horizon_sync.push(Box::new(hook));
×
UNCOV
77
    }
×
78

UNCOV
79
    pub fn call_on_progress_horizon_hooks(&self, info: HorizonSyncInfo) {
×
UNCOV
80
        self.on_progress_horizon_sync.iter().for_each(|f| (*f)(info.clone()));
×
UNCOV
81
    }
×
82

83
    pub fn add_on_complete_hook<H>(&mut self, hook: H)
4✔
84
    where H: Fn(Arc<ChainBlock>, u64) + Send + Sync + 'static {
4✔
85
        self.on_complete.push(Box::new(hook));
4✔
86
    }
4✔
87

88
    pub fn call_on_complete_hooks(&self, final_block: Arc<ChainBlock>, starting_height: u64) {
1✔
89
        self.on_complete
1✔
90
            .iter()
1✔
91
            .for_each(|f| (*f)(final_block.clone(), starting_height));
1✔
92
    }
1✔
93

94
    pub fn add_on_rewind_hook<H>(&mut self, hook: H)
14✔
95
    where H: Fn(Vec<Arc<ChainBlock>>) + Send + Sync + 'static {
14✔
96
        self.on_rewind.push(Box::new(hook));
14✔
97
    }
14✔
98

99
    pub fn call_on_rewind_hooks(&mut self, blocks: Vec<Arc<ChainBlock>>) {
1✔
100
        self.on_rewind.iter().for_each(|f| (*f)(blocks.clone()));
1✔
101
    }
1✔
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc