@@ -2,9 +2,11 @@ extern crate bitcoin;
2
2
extern crate lightning;
3
3
extern crate secp256k1;
4
4
5
- use bitcoin:: network:: constants:: Network ;
5
+ use bitcoin:: util:: hash:: Sha256dHash ;
6
+ use bitcoin:: blockdata:: script:: { Script , Builder } ;
7
+ use bitcoin:: blockdata:: opcodes;
6
8
7
- use lightning:: chain:: chaininterface;
9
+ use lightning:: chain:: chaininterface:: { ChainError , ChainWatchInterface , ChainListener } ;
8
10
use lightning:: ln:: channelmanager:: ChannelDetails ;
9
11
use lightning:: ln:: msgs;
10
12
use lightning:: ln:: msgs:: { MsgDecodable , RoutingMessageHandler } ;
@@ -19,7 +21,8 @@ mod utils;
19
21
20
22
use utils:: test_logger;
21
23
22
- use std:: sync:: Arc ;
24
+ use std:: sync:: { Weak , Arc } ;
25
+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
23
26
24
27
#[ inline]
25
28
pub fn slice_to_be16 ( v : & [ u8 ] ) -> u16 {
@@ -47,6 +50,46 @@ pub fn slice_to_be64(v: &[u8]) -> u64 {
47
50
( ( v[ 7 ] as u64 ) << 8 * 0 )
48
51
}
49
52
53
+
54
+ struct InputData {
55
+ data : Vec < u8 > ,
56
+ read_pos : AtomicUsize ,
57
+ }
58
+ impl InputData {
59
+ fn get_slice ( & self , len : usize ) -> Option < & [ u8 ] > {
60
+ let old_pos = self . read_pos . fetch_add ( len, Ordering :: AcqRel ) ;
61
+ if self . data . len ( ) < old_pos + len {
62
+ return None ;
63
+ }
64
+ Some ( & self . data [ old_pos..old_pos + len] )
65
+ }
66
+ }
67
+
68
+ struct DummyChainWatcher {
69
+ input : Arc < InputData > ,
70
+ }
71
+
72
+ impl ChainWatchInterface for DummyChainWatcher {
73
+ fn install_watch_script ( & self , _script_pub_key : & Script ) {
74
+ }
75
+
76
+ fn install_watch_outpoint ( & self , _outpoint : ( Sha256dHash , u32 ) , _out_script : & Script ) {
77
+ }
78
+
79
+ fn watch_all_txn ( & self ) {
80
+ }
81
+
82
+ fn register_listener ( & self , _listener : Weak < ChainListener > ) {
83
+ }
84
+
85
+ fn get_chain_utxo ( & self , _genesis_hash : Sha256dHash , _unspent_tx_output_identifier : u64 ) -> Result < ( Script , u64 ) , ChainError > {
86
+ match self . input . get_slice ( 1 ) {
87
+ Some ( slice) => Ok ( ( Builder :: new ( ) . push_opcode ( opcodes:: All :: OP_PUSHBYTES_0 ) . into_script ( ) . to_v0_p2wsh ( ) , 0 ) ) ,
88
+ None => Err ( ChainError :: UnknownTx ) ,
89
+ }
90
+ }
91
+ }
92
+
50
93
#[ inline]
51
94
pub fn do_test ( data : & [ u8 ] ) {
52
95
reset_rng_state ( ) ;
@@ -110,7 +153,13 @@ pub fn do_test(data: &[u8]) {
110
153
}
111
154
112
155
let logger: Arc < Logger > = Arc :: new ( test_logger:: TestLogger { } ) ;
113
- let chain_monitor = Arc :: new ( chaininterface:: ChainWatchInterfaceUtil :: new ( Network :: Bitcoin , Arc :: clone ( & logger) ) ) ;
156
+ let input = Arc :: new ( InputData {
157
+ data : data. to_vec ( ) ,
158
+ read_pos : AtomicUsize :: new ( 0 ) ,
159
+ } ) ;
160
+ let chain_monitor = Arc :: new ( DummyChainWatcher {
161
+ input : input,
162
+ } ) ;
114
163
115
164
let our_pubkey = get_pubkey ! ( ) ;
116
165
let router = Router :: new ( our_pubkey. clone ( ) , chain_monitor, Arc :: clone ( & logger) ) ;
0 commit comments