@@ -4,7 +4,7 @@ use base58::FromBase58;
44use bitcoin:: blockdata:: opcodes;
55use bitcoin:: blockdata:: script:: Builder ;
66use bitcoin:: consensus:: encode;
7- use bitcoin:: { OutPoint , Script , Transaction , TxIn , TxOut , Txid , Witness } ;
7+ use bitcoin:: { OutPoint , Script , Transaction , TxIn , TxOut , Txid , Witness , PubkeyHash , WPubkeyHash } ;
88use bitcoincore_rpc:: bitcoin:: secp256k1:: { Message , PublicKey , Secp256k1 , SecretKey } ;
99use bitcoincore_rpc:: bitcoin:: Address ;
1010use bitcoincore_rpc:: Client ;
@@ -61,20 +61,19 @@ pub fn build_transaction_spec(
6161 selected_utxos. push ( utxo) ;
6262 }
6363
64+
6465 // Prepare Recipient output
65- let recipient_pub_key_hash = tx_spec
66- . recipient
67- . from_base58 ( )
68- . expect ( "Unable to get bytes recipient btc address" ) ;
66+ let address = {
67+ use bitcoin:: Address ;
68+ match Address :: from_str ( & tx_spec. recipient ) {
69+ Ok ( address) => address,
70+ Err ( e) => panic ! ( "{:?}" , e) ,
71+ }
72+ } ;
73+
6974 let txout = TxOut {
7075 value : tx_spec. sats_amount ,
71- script_pubkey : Builder :: new ( )
72- . push_opcode ( opcodes:: all:: OP_DUP )
73- . push_opcode ( opcodes:: all:: OP_HASH160 )
74- . push_slice ( & recipient_pub_key_hash[ 1 ..21 ] )
75- . push_opcode ( opcodes:: all:: OP_EQUALVERIFY )
76- . push_opcode ( opcodes:: all:: OP_CHECKSIG )
77- . into_script ( ) ,
76+ script_pubkey : address. script_pubkey ( )
7877 } ;
7978 transaction. output . push ( txout) ;
8079
0 commit comments