@@ -63,15 +63,8 @@ impl Cheatcode for stopBroadcastCall {
6363
6464impl Cheatcode for getWalletsCall {
6565 fn apply_stateful ( & self , ccx : & mut CheatsCtxt ) -> Result {
66- let script_wallets =
67- ccx. state . script_wallets ( ) . cloned ( ) . map ( |sw| sw. signers ( ) . unwrap_or_default ( ) ) ;
68-
69- if let Some ( script_wallets) = script_wallets {
70- let script_wallets: Vec < Address > = script_wallets. into_iter ( ) . collect ( ) ;
71- Ok ( script_wallets. abi_encode ( ) )
72- } else {
73- Ok ( Default :: default ( ) )
74- }
66+ let wallets = ccx. state . wallets ( ) . signers ( ) . unwrap_or_default ( ) ;
67+ Ok ( wallets. abi_encode ( ) )
7568 }
7669}
7770
@@ -135,6 +128,21 @@ impl Wallets {
135128 pub fn signers ( & self ) -> Result < Vec < Address > > {
136129 Ok ( self . inner . lock ( ) . multi_wallet . signers ( ) ?. keys ( ) . cloned ( ) . collect ( ) )
137130 }
131+
132+ /// Number of signers in the [MultiWallet].
133+ pub fn len ( & self ) -> usize {
134+ let mut inner = self . inner . lock ( ) ;
135+ let signers = inner. multi_wallet . signers ( ) ;
136+ if signers. is_err ( ) {
137+ return 0 ;
138+ }
139+ signers. unwrap ( ) . len ( )
140+ }
141+
142+ /// Whether the [MultiWallet] is empty.
143+ pub fn is_empty ( & self ) -> bool {
144+ self . len ( ) == 0
145+ }
138146}
139147
140148/// Sets up broadcasting from a script using `new_origin` as the sender.
@@ -148,16 +156,14 @@ fn broadcast(ccx: &mut CheatsCtxt, new_origin: Option<&Address>, single_call: bo
148156 let mut new_origin = new_origin. cloned ( ) ;
149157
150158 if new_origin. is_none ( ) {
151- if let Some ( script_wallets) = ccx. state . script_wallets ( ) {
152- let mut script_wallets = script_wallets. inner . lock ( ) ;
153- if let Some ( provided_sender) = script_wallets. provided_sender {
154- new_origin = Some ( provided_sender) ;
155- } else {
156- let signers = script_wallets. multi_wallet . signers ( ) ?;
157- if signers. len ( ) == 1 {
158- let address = signers. keys ( ) . next ( ) . unwrap ( ) ;
159- new_origin = Some ( * address) ;
160- }
159+ let mut wallets = ccx. state . wallets ( ) . inner . lock ( ) ;
160+ if let Some ( provided_sender) = wallets. provided_sender {
161+ new_origin = Some ( provided_sender) ;
162+ } else {
163+ let signers = wallets. multi_wallet . signers ( ) ?;
164+ if signers. len ( ) == 1 {
165+ let address = signers. keys ( ) . next ( ) . unwrap ( ) ;
166+ new_origin = Some ( * address) ;
161167 }
162168 }
163169 }
@@ -175,17 +181,16 @@ fn broadcast(ccx: &mut CheatsCtxt, new_origin: Option<&Address>, single_call: bo
175181}
176182
177183/// Sets up broadcasting from a script with the sender derived from `private_key`.
178- /// Adds this private key to `state`'s `script_wallets ` vector to later be used for signing
184+ /// Adds this private key to `state`'s `wallets ` vector to later be used for signing
179185/// if broadcast is successful.
180186fn broadcast_key ( ccx : & mut CheatsCtxt , private_key : & U256 , single_call : bool ) -> Result {
181187 let wallet = super :: crypto:: parse_wallet ( private_key) ?;
182188 let new_origin = wallet. address ( ) ;
183189
184190 let result = broadcast ( ccx, Some ( & new_origin) , single_call) ;
185191 if result. is_ok ( ) {
186- if let Some ( script_wallets) = ccx. state . script_wallets ( ) {
187- script_wallets. add_local_signer ( wallet) ;
188- }
192+ let wallets = ccx. state . wallets ( ) ;
193+ wallets. add_local_signer ( wallet) ;
189194 }
190195 result
191196}
0 commit comments