@@ -256,19 +256,14 @@ decl_module! {
256
256
let sender = ensure_signed( origin) ?;
257
257
let source = T :: ConvertAccountId :: convert_account_id( & sender) ;
258
258
259
- Self :: execute_evm (
259
+ Self :: execute_call (
260
260
source,
261
+ target,
262
+ input,
261
263
value,
262
264
gas_limit,
263
265
gas_price,
264
266
nonce,
265
- |executor| ( ( ) , executor. transact_call(
266
- source,
267
- target,
268
- value,
269
- input,
270
- gas_limit as usize ,
271
- ) ) ,
272
267
) . map_err( Into :: into)
273
268
}
274
269
@@ -291,22 +286,13 @@ decl_module! {
291
286
let sender = ensure_signed( origin) ?;
292
287
let source = T :: ConvertAccountId :: convert_account_id( & sender) ;
293
288
294
- let create_address = Self :: execute_evm (
289
+ let create_address = Self :: execute_create (
295
290
source,
291
+ init,
296
292
value,
297
293
gas_limit,
298
294
gas_price,
299
- nonce,
300
- |executor| {
301
- ( executor. create_address(
302
- evm:: CreateScheme :: Legacy { caller: source } ,
303
- ) , executor. transact_create(
304
- source,
305
- value,
306
- init,
307
- gas_limit as usize ,
308
- ) )
309
- } ,
295
+ nonce
310
296
) ?;
311
297
312
298
Module :: <T >:: deposit_event( Event :: <T >:: Created ( create_address) ) ;
@@ -332,24 +318,14 @@ decl_module! {
332
318
let sender = ensure_signed( origin) ?;
333
319
let source = T :: ConvertAccountId :: convert_account_id( & sender) ;
334
320
335
- let code_hash = H256 :: from_slice( Keccak256 :: digest( & init) . as_slice( ) ) ;
336
- let create_address = Self :: execute_evm(
321
+ let create_address = Self :: execute_create2(
337
322
source,
323
+ init,
324
+ salt,
338
325
value,
339
326
gas_limit,
340
327
gas_price,
341
- nonce,
342
- |executor| {
343
- ( executor. create_address(
344
- evm:: CreateScheme :: Create2 { caller: source, code_hash, salt } ,
345
- ) , executor. transact_create2(
346
- source,
347
- value,
348
- init,
349
- salt,
350
- gas_limit as usize ,
351
- ) )
352
- } ,
328
+ nonce
353
329
) ?;
354
330
355
331
Module :: <T >:: deposit_event( Event :: <T >:: Created ( create_address) ) ;
@@ -391,6 +367,91 @@ impl<T: Trait> Module<T> {
391
367
AccountStorages :: remove_prefix ( address) ;
392
368
}
393
369
370
+ /// Execute a create transaction on behalf of given sender.
371
+ pub fn execute_create (
372
+ source : H160 ,
373
+ init : Vec < u8 > ,
374
+ value : U256 ,
375
+ gas_limit : u32 ,
376
+ gas_price : U256 ,
377
+ nonce : Option < U256 >
378
+ ) -> Result < H160 , Error < T > > {
379
+ Self :: execute_evm (
380
+ source,
381
+ value,
382
+ gas_limit,
383
+ gas_price,
384
+ nonce,
385
+ |executor| {
386
+ ( executor. create_address (
387
+ evm:: CreateScheme :: Legacy { caller : source } ,
388
+ ) , executor. transact_create (
389
+ source,
390
+ value,
391
+ init,
392
+ gas_limit as usize ,
393
+ ) )
394
+ } ,
395
+ )
396
+ }
397
+
398
+ /// Execute a create2 transaction on behalf of a given sender.
399
+ pub fn execute_create2 (
400
+ source : H160 ,
401
+ init : Vec < u8 > ,
402
+ salt : H256 ,
403
+ value : U256 ,
404
+ gas_limit : u32 ,
405
+ gas_price : U256 ,
406
+ nonce : Option < U256 >
407
+ ) -> Result < H160 , Error < T > > {
408
+ let code_hash = H256 :: from_slice ( Keccak256 :: digest ( & init) . as_slice ( ) ) ;
409
+ Self :: execute_evm (
410
+ source,
411
+ value,
412
+ gas_limit,
413
+ gas_price,
414
+ nonce,
415
+ |executor| {
416
+ ( executor. create_address (
417
+ evm:: CreateScheme :: Create2 { caller : source, code_hash, salt } ,
418
+ ) , executor. transact_create2 (
419
+ source,
420
+ value,
421
+ init,
422
+ salt,
423
+ gas_limit as usize ,
424
+ ) )
425
+ } ,
426
+ )
427
+ }
428
+
429
+ /// Execute a call transaction on behalf of a given sender.
430
+ pub fn execute_call (
431
+ source : H160 ,
432
+ target : H160 ,
433
+ input : Vec < u8 > ,
434
+ value : U256 ,
435
+ gas_limit : u32 ,
436
+ gas_price : U256 ,
437
+ nonce : Option < U256 > ,
438
+ ) -> Result < ( ) , Error < T > > {
439
+ Self :: execute_evm (
440
+ source,
441
+ value,
442
+ gas_limit,
443
+ gas_price,
444
+ nonce,
445
+ |executor| ( ( ) , executor. transact_call (
446
+ source,
447
+ target,
448
+ value,
449
+ input,
450
+ gas_limit as usize ,
451
+ ) ) ,
452
+ )
453
+ }
454
+
394
455
/// Execute an EVM operation.
395
456
fn execute_evm < F , R > (
396
457
source : H160 ,
0 commit comments