@@ -47,9 +47,6 @@ public class SmartWallet
47
47
public bool IsDeployed => _deployed ;
48
48
public bool IsDeploying => _deploying ;
49
49
50
- private readonly SemaphoreSlim _semaphore = new SemaphoreSlim ( 1 , 1 ) ;
51
- private readonly ConcurrentQueue < TaskCompletionSource < RpcResponseMessage > > _responseQueue = new ConcurrentQueue < TaskCompletionSource < RpcResponseMessage > > ( ) ;
52
-
53
50
public SmartWallet ( Web3 personalWeb3 , ThirdwebSDK . SmartWalletConfig config )
54
51
{
55
52
PersonalWeb3 = personalWeb3 ;
@@ -140,29 +137,7 @@ internal async Task<RpcResponseMessage> Request(RpcRequestMessage requestMessage
140
137
141
138
if ( requestMessage . Method == "eth_sendTransaction" )
142
139
{
143
- var tcs = new TaskCompletionSource < RpcResponseMessage > ( ) ;
144
- _responseQueue . Enqueue ( tcs ) ;
145
-
146
- await _semaphore . WaitAsync ( ) ;
147
-
148
- if ( _responseQueue . TryDequeue ( out var dequeuedTcs ) && dequeuedTcs == tcs )
149
- {
150
- try
151
- {
152
- var response = await CreateUserOpAndSend ( requestMessage ) ;
153
- tcs . SetResult ( response ) ;
154
- }
155
- catch ( Exception ex )
156
- {
157
- tcs . SetException ( ex ) ;
158
- }
159
- finally
160
- {
161
- _semaphore . Release ( ) ;
162
- }
163
- }
164
-
165
- return await tcs . Task ;
140
+ return await CreateUserOpAndSend ( requestMessage ) ;
166
141
}
167
142
else if ( requestMessage . Method == "eth_chainId" )
168
143
{
@@ -177,6 +152,14 @@ internal async Task<RpcResponseMessage> Request(RpcRequestMessage requestMessage
177
152
178
153
private async Task < RpcResponseMessage > CreateUserOpAndSend ( RpcRequestMessage requestMessage )
179
154
{
155
+ await new WaitUntil ( ( ) => ! _deploying ) ;
156
+
157
+ await UpdateDeploymentStatus ( ) ;
158
+ if ( ! _deployed )
159
+ {
160
+ _deploying = true ;
161
+ }
162
+
180
163
string apiKey = ThirdwebManager . Instance . SDK . session . Options . clientId ;
181
164
182
165
// Deserialize the transaction input from the request message
@@ -188,7 +171,6 @@ private async Task<RpcResponseMessage> CreateUserOpAndSend(RpcRequestMessage req
188
171
for ( int i = 0 ; i < Constants . DUMMY_SIG_LENGTH ; i ++ )
189
172
dummySig [ i ] = 0x01 ;
190
173
191
- await UpdateDeploymentStatus ( ) ;
192
174
var ( initCode , gas ) = await GetInitCode ( ) ;
193
175
194
176
var executeFn = new AccountContract . ExecuteFunction
@@ -248,24 +230,33 @@ private async Task<RpcResponseMessage> CreateUserOpAndSend(RpcRequestMessage req
248
230
249
231
// Check if successful
250
232
251
- var receipt = await Transaction . WaitForTransactionResultRaw ( txHash ) ;
252
- var decodedEvents = receipt . DecodeAllEvents < EntryPointContract . UserOperationEventEventDTO > ( ) ;
253
- if ( decodedEvents [ 0 ] . Event . Success == false )
233
+ if ( ! _deployed )
254
234
{
255
- throw new Exception ( $ "Transaction { txHash } execution reverted") ;
256
- }
257
- else
258
- {
259
- ThirdwebDebug . Log ( "Transaction successful" ) ;
260
- _deployed = true ;
235
+ var receipt = await Transaction . WaitForTransactionResultRaw ( txHash ) ;
236
+ var decodedEvents = receipt . DecodeAllEvents < EntryPointContract . UserOperationEventEventDTO > ( ) ;
237
+ if ( decodedEvents [ 0 ] . Event . Success == false )
238
+ {
239
+ throw new Exception ( $ "Transaction { txHash } execution reverted") ;
240
+ }
241
+ else
242
+ {
243
+ ThirdwebDebug . Log ( "Transaction successful" ) ;
244
+ _deployed = true ;
245
+ }
261
246
}
247
+
248
+ _deploying = false ;
249
+
262
250
return new RpcResponseMessage ( requestMessage . Id , txHash ) ;
263
251
}
264
252
265
253
private async Task < BigInteger > GetNonce ( )
266
254
{
267
- var nonce = await TransactionManager . ThirdwebRead < AccountContract . GetNonceFunction , AccountContract . GetNonceOutputDTO > ( Accounts [ 0 ] , new AccountContract . GetNonceFunction ( ) { } ) ;
268
- return nonce . ReturnValue1 ;
255
+ var nonce = await TransactionManager . ThirdwebRead < EntryPointContract . GetNonceFunction , EntryPointContract . GetNonceOutputDTO > (
256
+ Config . entryPointAddress ,
257
+ new EntryPointContract . GetNonceFunction ( ) { Sender = Accounts [ 0 ] , Key = UserOpUtils . GetRandomInt192 ( ) }
258
+ ) ;
259
+ return nonce . Nonce ;
269
260
}
270
261
271
262
private async Task < byte [ ] > GetPaymasterAndData ( object requestId , UserOperationHexified userOp , string apiKey )
0 commit comments