@@ -46,6 +46,12 @@ pub struct RPCNakamotoBlockRequestHandler {
46
46
pub block_id : Option < StacksBlockId > ,
47
47
}
48
48
49
+ impl RPCNakamotoBlockRequestHandler {
50
+ pub fn new ( ) -> Self {
51
+ Self { block_id : None }
52
+ }
53
+ }
54
+
49
55
pub struct NakamotoBlockStream {
50
56
/// index block hash of the block to download
51
57
pub index_block_hash : StacksBlockId ,
@@ -63,27 +69,6 @@ pub struct NakamotoBlockStream {
63
69
pub rowid : i64 ,
64
70
}
65
71
66
- impl RPCNakamotoBlockRequestHandler {
67
- pub fn new ( ) -> Self {
68
- Self { block_id : None }
69
- }
70
-
71
- pub fn get_stream_by_node (
72
- block_id : & StacksBlockId ,
73
- node : & mut StacksNodeState ,
74
- ) -> Result < NakamotoBlockStream , ChainError > {
75
- node. with_node_state ( |_network, _sortdb, chainstate, _mempool, _rpc_args| {
76
- let Some ( ( tenure_id, parent_block_id) ) = chainstate
77
- . nakamoto_blocks_db ( )
78
- . get_tenure_and_parent_block_id ( & block_id) ?
79
- else {
80
- return Err ( ChainError :: NoSuchBlockError ) ;
81
- } ;
82
- NakamotoBlockStream :: new ( chainstate, block_id. clone ( ) , tenure_id, parent_block_id)
83
- } )
84
- }
85
- }
86
-
87
72
impl NakamotoBlockStream {
88
73
pub fn new (
89
74
chainstate : & StacksChainState ,
@@ -194,8 +179,19 @@ impl RPCRequestHandler for RPCNakamotoBlockRequestHandler {
194
179
. take ( )
195
180
. ok_or ( NetError :: SendError ( "Missing `block_id`" . into ( ) ) ) ?;
196
181
182
+ let stream_res =
183
+ node. with_node_state ( |_network, _sortdb, chainstate, _mempool, _rpc_args| {
184
+ let Some ( ( tenure_id, parent_block_id) ) = chainstate
185
+ . nakamoto_blocks_db ( )
186
+ . get_tenure_and_parent_block_id ( & block_id) ?
187
+ else {
188
+ return Err ( ChainError :: NoSuchBlockError ) ;
189
+ } ;
190
+ NakamotoBlockStream :: new ( chainstate, block_id. clone ( ) , tenure_id, parent_block_id)
191
+ } ) ;
192
+
197
193
// start loading up the block
198
- let stream = match Self :: get_stream_by_node ( & block_id , node ) {
194
+ let stream = match stream_res {
199
195
Ok ( stream) => stream,
200
196
Err ( ChainError :: NoSuchBlockError ) => {
201
197
return StacksHttpResponse :: new_error (
0 commit comments