11mod error;
22mod types;
33
4+ use bitcoincore_rpc:: bitcoin:: ScriptBuf ;
45pub use error:: Error ;
56pub use types:: * ;
67
78use crate :: {
89 deserialize, opcodes, serialize, Address , Block , BlockHash , BlockHeader , Builder as ScriptBuilder , FromHex ,
9- Network , OutPoint , Script , SignedAmount , ToHex , Transaction , Txid , H256 ,
10+ Network , OutPoint , SignedAmount , Transaction , Txid , H256 ,
1011} ;
1112use futures:: future:: { join_all, try_join} ;
1213use reqwest:: { Client , Url } ;
@@ -185,7 +186,7 @@ impl ElectrsClient {
185186 . collect :: < Result < Vec < _ > , Error > > ( )
186187 }
187188
188- pub ( crate ) async fn get_script_pubkey ( & self , outpoint : OutPoint ) -> Result < Script , Error > {
189+ pub ( crate ) async fn get_script_pubkey ( & self , outpoint : OutPoint ) -> Result < ScriptBuf , Error > {
189190 let tx: TransactionValue = self
190191 . get_and_decode ( & format ! ( "/tx/{txid}" , txid = outpoint. txid) )
191192 . await ?;
@@ -215,7 +216,7 @@ impl ElectrsClient {
215216 let txid = self
216217 . cli
217218 . post ( url)
218- . body ( serialize ( & tx) . to_hex ( ) )
219+ . body ( hex :: encode ( serialize ( & tx) ) )
219220 . send ( )
220221 . await ?
221222 . error_for_status ( ) ?
@@ -232,7 +233,7 @@ impl ElectrsClient {
232233 let mut transactions: Vec < TransactionValue > = self
233234 . get_and_decode ( & format ! (
234235 "/scripthash/{scripthash}/txs/chain/{last_seen_txid}" ,
235- scripthash = script_hash . to_hex ( )
236+ scripthash = hex :: encode ( & script_hash )
236237 ) )
237238 . await ?;
238239 let page_size = transactions. len ( ) ;
@@ -257,7 +258,7 @@ impl ElectrsClient {
257258 ) -> Result < Option < Txid > , Error > {
258259 let script = ScriptBuilder :: new ( )
259260 . push_opcode ( opcodes:: OP_RETURN )
260- . push_slice ( data. as_bytes ( ) )
261+ . push_slice ( & data. as_fixed_bytes ( ) )
261262 . into_script ( ) ;
262263
263264 let script_hash = {
@@ -302,11 +303,11 @@ mod tests {
302303 async fn test_electrs ( url : & str , script_hex : & str , expected_txid : & str ) {
303304 let script_bytes = Vec :: from_hex ( script_hex) . unwrap ( ) ;
304305 let script_hash = Sha256Hash :: hash ( & script_bytes) ;
305- let expected_txid = Txid :: from_hex ( expected_txid) . unwrap ( ) ;
306+ let expected_txid = Txid :: from_str ( expected_txid) . unwrap ( ) ;
306307
307308 let electrs_client = ElectrsClient :: new ( Some ( url. to_owned ( ) ) , Network :: Bitcoin ) . unwrap ( ) ;
308309 let txs = electrs_client
309- . get_txs_by_scripthash ( script_hash. to_vec ( ) )
310+ . get_txs_by_scripthash ( script_hash. to_byte_array ( ) . to_vec ( ) )
310311 . await
311312 . unwrap ( ) ;
312313 assert ! ( txs. iter( ) . any( |tx| tx. txid. eq( & expected_txid) ) ) ;
0 commit comments