1- use std:: { io :: stdout , str:: FromStr } ;
1+ use std:: str:: FromStr ;
22
33use bdk:: {
44 bitcoin:: {
5- psbt :: serialize :: Serialize , Address as BitcoinAddress ,
6- Network as BitcoinNetwork , PrivateKey ,
5+ Address as BitcoinAddress , Network as BitcoinNetwork , PrivateKey ,
6+ Transaction ,
77 } ,
88 blockchain:: {
99 ConfigurableBlockchain , ElectrumBlockchain , ElectrumBlockchainConfig ,
@@ -17,36 +17,34 @@ use sbtc_core::operations::op_return::deposit::build_deposit_transaction;
1717use stacks_core:: address:: StacksAddress ;
1818use url:: Url ;
1919
20- use crate :: commands:: utils;
21-
2220#[ derive( Parser , Debug , Clone ) ]
2321pub struct DepositArgs {
2422 /// Where to broadcast the transaction
2523 #[ clap( short( 'u' ) , long) ]
26- node_url : Url ,
24+ pub node_url : Url ,
2725
2826 /// Bitcoin WIF of the P2wPKH address
2927 #[ clap( short, long) ]
30- wif : String ,
28+ pub wif : String ,
3129
3230 /// Bitcoin network where the deposit will be broadcasted to
3331 #[ clap( short, long) ]
34- network : BitcoinNetwork ,
32+ pub network : BitcoinNetwork ,
3533
3634 /// Stacks address that will receive sBTC
3735 #[ clap( short, long) ]
38- recipient : String ,
36+ pub recipient : String ,
3937
4038 /// The amount of sats to send
4139 #[ clap( short, long) ]
42- amount : u64 ,
40+ pub amount : u64 ,
4341
4442 /// Dkg wallet address
4543 #[ clap( short, long) ]
46- dkg_wallet : String ,
44+ pub dkg_wallet : String ,
4745}
4846
49- pub fn build_deposit_tx ( deposit : & DepositArgs ) -> anyhow:: Result < ( ) > {
47+ pub fn build_deposit_tx ( deposit : & DepositArgs ) -> anyhow:: Result < Transaction > {
5048 let private_key = PrivateKey :: from_wif ( & deposit. wif ) ?;
5149
5250 let blockchain =
@@ -72,21 +70,12 @@ pub fn build_deposit_tx(deposit: &DepositArgs) -> anyhow::Result<()> {
7270 StacksAddress :: try_from ( deposit. recipient . as_str ( ) ) ?;
7371 let dkg_address = BitcoinAddress :: from_str ( & deposit. dkg_wallet ) ?;
7472
75- let tx = build_deposit_transaction (
73+ build_deposit_transaction (
7674 wallet,
7775 recipient_address. into ( ) ,
7876 dkg_address,
7977 deposit. amount ,
8078 deposit. network ,
81- ) ?;
82-
83- serde_json:: to_writer_pretty (
84- stdout ( ) ,
85- & utils:: TransactionData {
86- id : tx. txid ( ) . to_string ( ) ,
87- hex : hex:: encode ( tx. serialize ( ) ) ,
88- } ,
89- ) ?;
90-
91- Ok ( ( ) )
79+ )
80+ . map_err ( |e| e. into ( ) )
9281}
0 commit comments