1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
crate::ix!();

pub trait InitLogging {

    /**
      | Init logging.
      |
      */
    fn init_logging(&mut self);
}

pub trait InitParameterInteraction {

    /**
      | Init parameter interaction.
      |
      */
    fn init_parameter_interaction(&mut self);
}

pub trait GetWarnings {

    /**
      | Get warnings.
      |
      */
    fn get_warnings(&mut self) -> BilingualStr;
}

pub trait GetLogCategories {

    /**
      | Get log flags.
      |
      */
    fn get_log_categories(&mut self) -> u32;
}

pub trait BaseInitialize {

    /**
      | Initialize app dependencies.
      |
      */
    fn base_initialize(&mut self) -> bool;
}

pub trait AppInitMain {

    /**
      | Start node.
      |
      */
    fn app_init_main(&mut self, tip_info: *mut BlockAndHeaderTipInfo) -> bool;
}

pub trait AppShutdown {

    /**
      | Stop node.
      |
      */
    fn app_shutdown(&mut self);
}

pub trait StartShutdown {

    /**
      | Start shutdown.
      |
      */
    fn start_shutdown(&mut self);
}

pub trait ShutdownRequested {

    /**
      | Return whether shutdown was requested.
      |
      */
    fn shutdown_requested(&mut self) -> bool;
}

pub trait MapPort {

    fn map_port(&mut self, 
            use_upnp:   bool,
            use_natpmp: bool);
}

pub trait GetProxy {

    fn get_proxy(&mut self, 
        net:        Network,
        proxy_info: &mut ProxyType) -> bool;
}

pub trait GetNodeCount {

    /**
      | Get number of connections.
      |
      */
    fn get_node_count(&mut self, flags: ConnectionDirection) -> usize;
}

pub trait GetNodesStats {

    /**
      | Get stats for connected nodes.
      |
      */
    fn get_nodes_stats(&mut self, stats: &mut NodesStats) -> bool;
}

pub trait GetBanned {

    /**
      | Get ban map entries.
      |
      */
    fn get_banned(&mut self, banmap: &mut BanMap) -> bool;
}

pub trait Ban {

    /**
      | Ban node.
      |
      */
    fn ban(&mut self, 
            net_addr:        &NetAddr,
            ban_time_offset: i64) -> bool;
}

pub trait UnBan {

    /**
      | Unban node.
      |
      */
    fn unban(&mut self, ip: &SubNet) -> bool;
}

pub trait DisconnectByAddress {

    /**
      | Disconnect node by address.
      |
      */
    fn disconnect_by_address(&mut self, net_addr: &NetAddr) -> bool;
}

pub trait DisconnectById {

    /**
      | Disconnect node by id.
      |
      */
    fn disconnect_by_id(&mut self, id: NodeId) -> bool;
}

pub trait DisconnectOnStall {

    fn disconnect_on_stall(&self);
}

pub trait ExternalSigners {

    /**
      | List external signers
      |
      */
    fn external_signers(&mut self) -> Vec<ExternalSigner>;
}

pub trait GetTotalBytesRecv {

    /**
      | Get total bytes recv.
      |
      */
    fn get_total_bytes_recv(&mut self) -> i64;
}

pub trait GetTotalBytesSent {

    /**
      | Get total bytes sent.
      |
      */
    fn get_total_bytes_sent(&mut self) -> i64;
}

pub trait GetMempoolSize {

    fn get_mempool_size(&mut self) -> usize;
}

pub trait GetMempoolDynamicUsage {

    fn get_mempool_dynamic_usage(&mut self) -> usize;
}

pub trait GetHeaderTip {

    /**
      | Get header tip height and time.
      |
      */
    fn get_header_tip(&mut self, 
            height:     &mut i32,
            block_time: &mut i64) -> bool;
}

pub trait GetNumBlocks {

    fn get_num_blocks(&mut self) -> i32;
}

pub trait GetBestBlockHash {

    fn get_best_block_hash(&mut self) -> u256;
}

pub trait GetLastBlockTime {

    fn get_last_block_time(&mut self) -> i64;
}

pub trait GetVerificationProgress {

    fn get_verification_progress(&mut self) -> f64;
}

pub trait GetReindex {

    fn get_reindex(&mut self) -> bool;
}

pub trait GetImporting {

    fn get_importing(&mut self) -> bool;
}

pub trait SetNetworkActive {

    fn set_network_active(&mut self, active: bool);
}

pub trait GetNetworkActive {

    fn get_network_active(&mut self) -> bool;
}

pub trait GetDustRelayFee {
    fn get_dust_relay_fee(&mut self) -> FeeRate;
}

pub trait ExecuteRpc {

    fn execute_rpc(&mut self, 
            command: &String,
            params:  &UniValue,
            uri:     &String) -> UniValue;
}

pub trait ListRpcCommands {

    fn list_rpc_commands(&mut self) -> Vec<String>;
}

pub trait RpcSetTimerInterfaceIfUnset {

    fn rpc_set_timer_interface_if_unset<'a>(&mut self, iface: &'a mut dyn RPCTimerInterface);
}

pub trait RpcunsetTimerInterface {

    fn rpc_unset_timer_interface<'a>(&mut self, iface: &'a mut dyn RPCTimerInterface);
}

pub trait GetUnspentOutput {

    /**
      | Get unspent outputs associated with
      | a transaction.
      |
      */
    fn get_unspent_output(&mut self, 
            output: &OutPoint,
            coin:   &mut Coin) -> bool;
}

pub trait HandleInitMessage {

    /**
      | Register handler for init messages.
      |
      */
    fn handle_init_message(&mut self, fn_: NodeInitMessageFn) -> Box<dyn Handler>;
}

pub trait HandleMessageBox {

    /**
      | Register handler for message box messages.
      |
      */
    fn handle_message_box(&mut self, fn_: NodeMessageBoxFn) -> Box<dyn Handler>;
}

pub trait NodeHandleQuestion {

    /**
      | Register handler for question messages.
      |
      */
    fn handle_question(&mut self, fn_: NodeQuestionFn) -> Box<dyn Handler>;
}

pub trait HandleNotifyNumConnectionsChanged {

    /**
      | Register handler for number of connections
      | changed messages.
      |
      */
    fn handle_notify_num_connections_changed(&mut self, fn_: NodeNotifyNumConnectionsChangedFn) -> Box<dyn Handler>;
}

pub trait HandleNotifyNetworkActiveChanged {

    /**
      | Register handler for network active
      | messages.
      |
      */
    fn handle_notify_network_active_changed(&mut self, fn_: NodeNotifyNetworkActiveChangedFn) -> Box<dyn Handler>;
}

pub trait HandleNotifyAlertChanged {

    /**
      | Register handler for notify alert messages.
      |
      */
    fn handle_notify_alert_changed(&mut self, fn_: NodeNotifyAlertChangedFn) -> Box<dyn Handler>;
}

pub trait HandleBannedListChanged {

    /**
      | Register handler for ban list messages.
      |
      */
    fn handle_banned_list_changed(&mut self, fn_: NodeBannedListChangedFn) -> Box<dyn Handler>;
}

pub trait HandleNotifyBlockTip {

    /**
      | Register handler for block tip messages.
      |
      */
    fn handle_notify_block_tip(&mut self, fn_: NodeNotifyBlockTipFn) -> Box<dyn Handler>;
}

pub trait HandleNotifyHeaderTip {

    /**
      | Register handler for header tip messages.
      |
      */
    fn handle_notify_header_tip(&mut self, fn_: NodeNotifyHeaderTipFn) -> Box<dyn Handler>;
}

pub trait GetNodeContext {

    /**
      | Get and set internal node context. Useful
      | for testing, but not accessible across
      | processes.
      |
      */
    fn context(&mut self) -> *mut dyn NodeContextInterface {
        
        todo!();
        /*
            return nullptr;
        */
    }
}

pub trait SetNodeContext {

    fn set_context(&mut self, context: *mut dyn NodeContextInterface)  {
        
        todo!();
        /*
        
        */
    }
}

pub trait GetNodeId {

    fn get_id(&self) -> NodeId;
}

pub trait IsBlockOnlyConn {

    fn is_block_only_conn(&self) -> bool;
}

pub trait IsInboundConn {

    fn is_inbound_conn(&self) -> bool;
}

pub trait GetNTimeConnected {

    fn get_n_time_connected(&self) -> OffsetDateTime;
}

pub trait IsOutboundOrBlockRelayConn {

    fn is_outbound_or_block_relay_conn(&self) -> bool;
}

pub trait IsFullOutboundConn {

    fn is_full_outbound_conn(&self) -> bool;
}

pub trait IsManualConn {

    fn is_manual_conn(&self) -> bool;
}

pub trait IsFeelerConn {

    fn is_feeler_conn(&self) -> bool;
}

pub trait IsAddrFetchConn {

    fn is_addr_fetch_conn(&self) -> bool;
}

pub trait MarkForDisconnect {

    /**
      | Disconnect the handler.
      |
      */
    fn mark_for_disconnect(&self);
}

pub trait GetLocalServices {

    fn get_local_services(&self) -> ServiceFlags;
}

pub trait GetLocalNonce {

    fn get_local_nonce(&self) -> u64;
}

pub trait GetCommonVersion {

    fn get_common_version(&self) -> i32;
}

pub trait MarkedForDisconnect {

    fn marked_for_disconnect(&self) -> bool;
}

pub trait HasPermission {

    fn has_permission(&self, permission: NetPermissionFlags) -> bool;
}

pub trait ExpectServicesFromConn {

    fn expect_services_from_conn(&self) -> bool;
}

pub trait SetSuccessfullyConnected {

    fn set_successfully_connected(&self, val: bool);
}

pub trait IsSuccessfullyConnected {

    fn is_successfully_connected(&self) -> bool;
}

pub trait NVersion {

    fn n_version(&self) -> i32;
}

pub trait GetTxRelay {

    fn get_tx_relay(&self) -> AmoReadGuard<NodeTxRelay>;
}

pub trait GetTxRelayMut {

    fn get_tx_relay_mut(&self) -> AmoWriteGuard<NodeTxRelay>;
}

pub trait HasTxRelay {

    fn has_tx_relay(&self) -> bool;
}

pub trait AddKnownTx {

    fn add_known_tx(&mut self, hash: &u256);
}

pub trait PongReceived {

    fn pong_received(&mut self, ping_time: Duration /* micros */);
}

pub trait SetCommonVersion {

    fn set_common_version(&mut self, greatest_common_version: i32);
}

pub trait SetAddrLocal {

    fn set_addr_local(&mut self, addr_local_in: &Service);
}

pub trait SetNLastBlockTime {

    fn set_n_last_block_time(&mut self, x: Option<OffsetDateTime>);
}

pub trait SendPaused {

    fn send_paused(&self) -> bool;
}

pub trait IsClient {

    fn is_client(&self) -> bool;
}

pub trait SetIsClient {

    fn set_is_client(&mut self, x: bool);
}

pub trait IsLimitedNode {

    fn is_limited_node(&self) -> bool;
}

pub trait SetLimitedNode {

    fn set_limited_node(&mut self, x: bool);
}

pub trait SetNTimeOffset {

    fn set_n_time_offset(&mut self, x: Option<Duration>);
}

pub trait SetNServices {

    fn set_n_services(&mut self, x: ServiceFlags);
}

pub trait SetCleanSubVer {

    fn set_clean_sub_ver(&mut self, x: &str);
}

pub trait SetNVersion {

    fn set_n_version(&mut self, x: i32);
}

pub trait SetNLastTxTime {

    fn set_n_last_tx_time(&mut self, x: Option<OffsetDateTime>);
}

pub trait SetBip152HighBandwidthFrom {

    fn set_bip152_highbandwidth_from(&mut self, x: bool);
}

pub trait SetBip152HighBandwidthTo {

    fn set_bip152_highbandwidth_to(&mut self, x: bool);
}

pub trait DecrementNProcessQueueSize {

    fn decrement_n_process_queue_size(&self, val: usize);
}

pub trait GetNProcessQueueSize {

    fn get_n_process_queue_size(&self) -> usize;
}

pub trait SetPauseRecv {

    fn set_pause_recv(&self, x: bool);
}

pub trait LockVProcessMsg {

    fn lock_v_process_msg(&self) -> MutexGuard<NodeVProcessMsg>;
}

//-------------------------------------
pub trait ConnType {

    fn conn_type(&self) -> Option<ConnectionType>;
}

pub trait NTimeConnected {

    fn n_time_connected(&self) -> Option<OffsetDateTime>;
}

pub trait MinPingTime {

    fn min_ping_time(&self) -> Option<Duration>;
}

pub trait NLastBlockTime { 

    fn n_last_block_time(&self) -> Option<OffsetDateTime>; 
}

pub trait NLastTxTime {

    fn n_last_tx_time(&self) -> Option<OffsetDateTime>; 
}

pub trait NServices { 

    fn n_services(&self) -> ServiceFlags; 
}

pub trait NKeyedNetGroup { 

    fn n_keyed_net_group(&self) -> u64; 
}

pub trait PreferEvict { 

    fn prefer_evict(&self) -> bool; 
}

pub trait ConnectedThroughNetwork { 

    fn connected_through_network(&self) -> Network;
}

pub trait SuccessfullyConnected { 

    fn successfully_connected(&self) -> bool; 
}

pub trait NodeInterfaceAddRef { 

    fn add_ref(&mut self) -> *mut dyn NodeInterface;
}

pub trait SetPermissionFlags { 

    fn set_permission_flags(&mut self, x: NetPermissionFlags); 
}

pub trait SetPreferEvict { 

    fn set_prefer_evict(&mut self, x: bool); 
}

pub trait ReleaseGrantOutbound { 

    fn release_grant_outbound(&mut self); 
}

pub trait CloseSocketDisconnect { 

    fn close_socket_disconnect(&mut self);
}

pub trait Release { 

    fn release(&mut self); 
}

pub trait GetRefCount { 

    fn get_ref_count(&self) -> i32;
}

pub trait AddrName { 

    fn addr_name(&self) -> &str; 
}

pub trait PauseRecv { 

    fn pause_recv(&self) -> bool; 
}

pub trait LockVSend { 

    fn lock_v_send(&self) -> MutexGuard<NodeVSend>; 
}

pub trait LockHSocket { 

    fn lock_h_socket(&self) -> MutexGuard<NodeHSocket>; 
}

pub trait CopyStats { 

    fn copy_stats(&mut self, stats: &mut NodeStats);
}

pub trait AddrBind { 

    fn addr_bind(&self) -> &Address; 
}

pub trait NLastRecv { 

    fn n_last_recv(&self) -> Option<OffsetDateTime>; 
}

pub trait NLastSend { 

    fn n_last_send(&self) -> Option<OffsetDateTime>; 
}

pub trait GrantOutbound { 

    fn grant_outbound(&self) -> SemaphoreGrant; 
}

pub trait GetTransportSerializer { 

    fn get_transport_serializer(&self) -> &Box<dyn TransportSerializer>; 
}

pub trait GetTransportSerializerMut { 

    fn get_transport_serializer_mut(&mut self) -> &mut Box<dyn TransportSerializer>; 
}

pub trait SetPauseSend { 

    fn set_pause_send(&self, x: bool); 
}

pub trait ReceiveMsgBytes { 

    fn receive_msg_bytes(&mut self, 
        msg_bytes: &[u8],
        complete:  &mut bool) -> bool;
}

pub trait LockRecvMsg { 

    fn lock_recv_msg(&self) -> MutexGuard<Vec<NetMessage>>; 
}

pub trait IncrementNProcessQueueSize { 

    fn increment_n_process_queue_size(&self, x: usize); 
}

pub trait NProcessQueueSize { 

    fn n_process_queue_size(&self) -> usize; 
}

pub trait LockSendProcessing { 

    unsafe fn lock_send_processing(&self); 
}

pub trait UnlockSendProcessing { 

    unsafe fn unlock_send_processing(&self); 
}

pub trait PushTxInventory {

    fn push_tx_inventory(&mut self, hash: &u256);
}