@@ -85,61 +85,66 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {
8585 UserOperation buildUserOperation ({
8686 required Uint8List callData,
8787 BigInt ? customNonce,
88- }) =>
89- UserOperation .partial (
90- callData: callData,
91- initCode: _initCode,
92- sender: _walletAddress,
93- nonce: customNonce);
88+ }) {
89+ return UserOperation .partial (
90+ callData: callData,
91+ initCode: _initCode,
92+ sender: _walletAddress,
93+ nonce: customNonce);
94+ }
9495
9596 @override
9697 Future <UserOperationResponse > send (
97- EthereumAddress recipient, EtherAmount amount) =>
98- sendUserOperation (buildUserOperation (
99- callData: Contract .execute (_walletAddress,
100- to: recipient, amount: amount, isSafe: isSafe)));
98+ EthereumAddress recipient, EtherAmount amount) {
99+ final cd = Contract .execute (_walletAddress,
100+ to: recipient, amount: amount, isSafe: isSafe);
101+ return sendUserOperation (buildUserOperation (callData: cd));
102+ }
101103
102104 @override
103105 Future <UserOperationResponse > sendTransaction (
104- EthereumAddress to, Uint8List encodedFunctionData,
105- {EtherAmount ? amount}) =>
106- sendUserOperation (buildUserOperation (
107- callData: Contract .execute (_walletAddress,
108- to: to,
109- amount: amount,
110- innerCallData: encodedFunctionData,
111- isSafe: isSafe)));
106+ EthereumAddress to, Uint8List encodedFunctionData,
107+ {EtherAmount ? amount}) {
108+ final cd = Contract .execute (_walletAddress,
109+ to: to,
110+ amount: amount,
111+ innerCallData: encodedFunctionData,
112+ isSafe: isSafe);
113+ return sendUserOperation (buildUserOperation (callData: cd));
114+ }
112115
113116 @override
114117 Future <UserOperationResponse > sendBatchedTransaction (
115118 List <EthereumAddress > recipients, List <Uint8List > calls,
116119 {List <EtherAmount >? amounts}) {
120+ Uint8List cd;
117121 if (isSafe) {
118122 final innerCall = plugin <_SafePlugin >('safe' )
119123 .getSafeMultisendCallData (recipients, amounts, calls);
120- return sendUserOperation ( buildUserOperation (
121- callData : Contract . executeBatch (
122- walletAddress : _walletAddress ,
123- recipients : [Constants .safeMultiSendaddress ],
124- amounts : [],
125- innerCalls : [innerCall],
126- isSafe : true ) ));
124+ cd = Contract . executeBatch (
125+ walletAddress : _walletAddress,
126+ recipients : [ Constants .safeMultiSendaddress] ,
127+ amounts : [],
128+ innerCalls : [innerCall ],
129+ isSafe : true );
130+ return sendUserOperation ( buildUserOperation (callData : cd ));
127131 } else {
128- return sendUserOperation ( buildUserOperation (
129- callData : Contract . executeBatch (
130- walletAddress : _walletAddress ,
131- recipients : recipients ,
132- amounts : amounts,
133- innerCalls : calls) ));
132+ cd = Contract . executeBatch (
133+ walletAddress : _walletAddress,
134+ recipients : recipients ,
135+ amounts : amounts ,
136+ innerCalls : calls);
137+ return sendUserOperation ( buildUserOperation (callData : cd ));
134138 }
135139 }
136140
137141 @override
138- Future <UserOperationResponse > sendSignedUserOperation (UserOperation op) =>
139- plugin <BundlerProviderBase >('bundler' )
140- .sendUserOperation (
141- op.toMap (_chain.entrypoint.version), _chain.entrypoint)
142- .catchError ((e) => throw SendError (e.toString (), op));
142+ Future <UserOperationResponse > sendSignedUserOperation (UserOperation op) {
143+ return plugin <BundlerProviderBase >('bundler' )
144+ .sendUserOperation (
145+ op.toMap (_chain.entrypoint.version), _chain.entrypoint)
146+ .catchError ((e) => throw SendError (e.toString (), op));
147+ }
143148
144149 @override
145150 Future <UserOperationResponse > sendUserOperation (UserOperation op) =>
@@ -198,39 +203,41 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {
198203 /// Otherwise, retrieves the nonce by calling the 'getNonce' function on the entrypoint.
199204 ///
200205 /// If an error occurs during the nonce retrieval process, a [NonceError] exception is thrown.
201- Future <Uint256 > _getNonce () => isDeployed.then ((deployed) => ! deployed
202- ? Future .value (Uint256 .zero)
203- : plugin <Contract >("contract" )
204- .read (_chain.entrypoint.address, ContractAbis .get ('getNonce' ),
205- "getNonce" ,
206- params: [_walletAddress, BigInt .zero])
207- .then ((value) => Uint256 (value[0 ]))
208- .catchError ((e) => throw NonceError (e.toString (), _walletAddress)));
206+ Future <Uint256 > _getNonce () {
207+ return isDeployed.then ((deployed) => ! deployed
208+ ? Future .value (Uint256 .zero)
209+ : plugin <Contract >("contract" )
210+ .read (_chain.entrypoint.address, ContractAbis .get ('getNonce' ),
211+ "getNonce" ,
212+ params: [_walletAddress, BigInt .zero])
213+ .then ((value) => Uint256 (value[0 ]))
214+ .catchError ((e) => throw NonceError (e.toString (), _walletAddress)));
215+ }
209216
210217 /// Returns the balance for the Smart Wallet address.
211218 ///
212219 /// If an error occurs during the balance retrieval process, a [FetchBalanceError] exception is thrown.
213- Future <EtherAmount > _getBalance () => plugin <Contract >("contract" )
214- .getBalance (_walletAddress)
215- .catchError ((e) => throw FetchBalanceError (e.toString (), _walletAddress));
220+ Future <EtherAmount > _getBalance () {
221+ return plugin <Contract >("contract" ).getBalance (_walletAddress).catchError (
222+ (e) => throw FetchBalanceError (e.toString (), _walletAddress));
223+ }
216224
217225 /// Updates the user operation with the latest nonce and gas prices.
218226 ///
219227 /// [op] is the user operation to update.
220228 ///
221229 /// Returns a [Future] that resolves to the updated [UserOperation] object.
222- Future <UserOperation > _updateUserOperation (UserOperation op) =>
223- Future .wait <dynamic >([
224- _getNonce (),
225- plugin <JsonRPCProviderBase >('jsonRpc' ).getGasPrice ()
226- ]).then ((responses) {
227- op = op.copyWith (
228- nonce: op.nonce > BigInt .zero ? op.nonce : responses[0 ].value,
229- initCode: responses[0 ] > Uint256 .zero ? Uint8List (0 ) : null ,
230- signature: dummySignature);
231-
232- return _updateUserOperationGas (op, responses[1 ]);
233- });
230+ Future <UserOperation > _updateUserOperation (UserOperation op) async {
231+ final responses = await Future .wait <dynamic >(
232+ [_getNonce (), plugin <JsonRPCProviderBase >('jsonRpc' ).getGasPrice ()]);
233+
234+ op = op.copyWith (
235+ nonce: op.nonce > BigInt .zero ? op.nonce : responses[0 ].value,
236+ initCode: responses[0 ] > Uint256 .zero ? Uint8List (0 ) : null ,
237+ signature: dummySignature);
238+
239+ return _updateUserOperationGas (op, responses[1 ]);
240+ }
234241
235242 /// Updates the gas information for the user operation.
236243 ///
@@ -240,10 +247,11 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase {
240247 /// Returns a [Future] that resolves to the updated [UserOperation] object.
241248 ///
242249 /// If an error occurs during the gas estimation process, a [GasEstimationError] exception is thrown.
243- Future <UserOperation > _updateUserOperationGas (UserOperation op, Fee fee) =>
244- plugin <BundlerProviderBase >('bundler' )
245- .estimateUserOperationGas (
246- op.toMap (_chain.entrypoint.version), _chain.entrypoint)
247- .then ((opGas) => op.updateOpGas (opGas, fee))
248- .catchError ((e) => throw GasEstimationError (e.toString (), op));
250+ Future <UserOperation > _updateUserOperationGas (UserOperation op, Fee fee) {
251+ return plugin <BundlerProviderBase >('bundler' )
252+ .estimateUserOperationGas (
253+ op.toMap (_chain.entrypoint.version), _chain.entrypoint)
254+ .then ((opGas) => op.updateOpGas (opGas, fee))
255+ .catchError ((e) => throw GasEstimationError (e.toString (), op));
256+ }
249257}
0 commit comments