@@ -21,14 +21,23 @@ pub struct TransactionBuilderConfiguration {
2121}
2222
2323impl TransactionBuilderConfiguration {
24+ #[ cfg( not( target_arch = "wasm32" ) ) ]
2425 pub fn new ( ) -> Result < Self , TxBuilderError > {
2526 Self :: new_with_network ( NetworkInfo :: mainnet ( ) )
2627 }
27-
28+ # [ cfg ( not ( target_arch = "wasm32" ) ) ]
2829 pub fn new_testnet ( ) -> Result < Self , TxBuilderError > {
2930 Self :: new_with_network ( NetworkInfo :: testnet ( ) )
3031 }
3132
33+ pub async fn new_async ( ) -> Result < Self , TxBuilderError > {
34+ Self :: new_with_network_async ( NetworkInfo :: mainnet ( ) ) . await
35+ }
36+
37+ pub async fn new_testnet_async ( ) -> Result < Self , TxBuilderError > {
38+ Self :: new_with_network_async ( NetworkInfo :: testnet ( ) ) . await
39+ }
40+
3241 pub fn new_devnet ( ) -> Result < Self , TxBuilderError > {
3342 Ok ( Self {
3443 network : NetworkInfo :: devnet ( ) ,
@@ -38,6 +47,7 @@ impl TransactionBuilderConfiguration {
3847 } )
3948 }
4049
50+ #[ cfg( not( target_arch = "wasm32" ) ) ]
4151 pub fn new_with_network ( network : NetworkInfo ) -> Result < Self , TxBuilderError > {
4252 let script_handlers = Self :: generate_system_handlers ( & network) ?;
4353 Ok ( Self {
@@ -47,7 +57,17 @@ impl TransactionBuilderConfiguration {
4757 estimate_tx_size : 128000 ,
4858 } )
4959 }
60+ pub async fn new_with_network_async ( network : NetworkInfo ) -> Result < Self , TxBuilderError > {
61+ let script_handlers = Self :: generate_system_handlers_async ( & network) . await ?;
62+ Ok ( Self {
63+ network,
64+ script_handlers,
65+ fee_rate : 1000 ,
66+ estimate_tx_size : 128000 ,
67+ } )
68+ }
5069
70+ #[ cfg( not( target_arch = "wasm32" ) ) ]
5171 fn generate_system_handlers (
5272 network : & NetworkInfo ,
5373 ) -> Result < Vec < Box < dyn ScriptHandler > > , TxBuilderError > {
@@ -74,6 +94,33 @@ impl TransactionBuilderConfiguration {
7494 ] ;
7595 Ok ( ret)
7696 }
97+ async fn generate_system_handlers_async (
98+ network : & NetworkInfo ,
99+ ) -> Result < Vec < Box < dyn ScriptHandler > > , TxBuilderError > {
100+ let ret =
101+ vec ! [
102+ Box :: new(
103+ handler:: sighash:: Secp256k1Blake160SighashAllScriptHandler :: new_with_network_async(
104+ network,
105+ ) . await ?,
106+ ) as Box <_>,
107+ Box :: new(
108+ handler:: multisig:: Secp256k1Blake160MultisigAllScriptHandler :: new_async(
109+ network,
110+ MultisigScript :: Legacy ,
111+ ) . await ?,
112+ ) as Box <_>,
113+ Box :: new(
114+ handler:: multisig:: Secp256k1Blake160MultisigAllScriptHandler :: new_async(
115+ network,
116+ MultisigScript :: V2 ,
117+ ) . await ?,
118+ ) as Box <_>,
119+ Box :: new( handler:: sudt:: SudtHandler :: new_with_network( network) ?) as Box <_>,
120+ Box :: new( handler:: typeid:: TypeIdHandler ) as Box <_>,
121+ ] ;
122+ Ok ( ret)
123+ }
77124
78125 pub fn network_info ( & self ) -> & NetworkInfo {
79126 & self . network
0 commit comments