@@ -3,6 +3,7 @@ import { EventManager } from '../eventManager'
3
3
import type { Transaction as InternalTransaction } from './txRunner'
4
4
import { Web3 } from 'web3'
5
5
import { toBigInt , toHex } from 'web3-utils'
6
+ import "viem/window"
6
7
7
8
export class TxRunnerWeb3 {
8
9
event
@@ -38,11 +39,11 @@ export class TxRunnerWeb3 {
38
39
39
40
let currentDateTime = new Date ( ) ;
40
41
const start = currentDateTime . getTime ( ) / 1000
41
- const cb = ( err , resp ) => {
42
+ const cb = ( err , resp , isUserOp ) => {
42
43
if ( err ) {
43
44
return callback ( err , resp )
44
45
}
45
- this . event . trigger ( 'transactionBroadcasted' , [ resp ] )
46
+ this . event . trigger ( 'transactionBroadcasted' , [ resp , isUserOp ] )
46
47
const listenOnResponse = ( ) => {
47
48
// eslint-disable-next-line no-async-promise-executor
48
49
return new Promise ( async ( resolve , reject ) => {
@@ -64,13 +65,13 @@ export class TxRunnerWeb3 {
64
65
async ( value ) => {
65
66
try {
66
67
const res = await ( this . getWeb3 ( ) as any ) . eth . personal . sendTransaction ( { ...tx , value } , { checkRevertBeforeSending : false , ignoreGasPricing : true } )
67
- cb ( null , res . transactionHash )
68
+ cb ( null , res . transactionHash , false )
68
69
} catch ( e ) {
69
70
console . log ( `Send transaction failed: ${ e . message || e . error } . if you use an injected provider, please check it is properly unlocked. ` )
70
71
// in case the receipt is available, we consider that only the execution failed but the transaction went through.
71
72
// So we don't consider this to be an error.
72
- if ( e . receipt ) cb ( null , e . receipt . transactionHash )
73
- else cb ( e , null )
73
+ if ( e . receipt ) cb ( null , e . receipt . transactionHash , false )
74
+ else cb ( e , null , false )
74
75
}
75
76
} ,
76
77
( ) => {
@@ -79,8 +80,13 @@ export class TxRunnerWeb3 {
79
80
)
80
81
} else {
81
82
try {
82
- const res = await this . getWeb3 ( ) . eth . sendTransaction ( tx , null , { checkRevertBeforeSending : false , ignoreGasPricing : true } )
83
- cb ( null , res . transactionHash )
83
+ if ( tx . fromSmartAccount ) {
84
+ // const userOp = await sendUserOp(tx)
85
+ // cb(null, userOp.userOpHash, true)
86
+ } else {
87
+ const res = await this . getWeb3 ( ) . eth . sendTransaction ( tx , null , { checkRevertBeforeSending : false , ignoreGasPricing : true } )
88
+ cb ( null , res . transactionHash , false )
89
+ }
84
90
} catch ( e ) {
85
91
if ( ! e . message ) e . message = ''
86
92
if ( e . error ) {
@@ -89,23 +95,24 @@ export class TxRunnerWeb3 {
89
95
console . log ( `Send transaction failed: ${ e . message } . if you use an injected provider, please check it is properly unlocked. ` )
90
96
// in case the receipt is available, we consider that only the execution failed but the transaction went through.
91
97
// So we don't consider this to be an error.
92
- if ( e . receipt ) cb ( null , e . receipt . transactionHash )
93
- else cb ( e , null )
98
+ if ( e . receipt ) cb ( null , e . receipt . transactionHash , false )
99
+ else cb ( e , null , false )
94
100
}
95
101
}
96
102
}
97
103
98
104
execute ( args : InternalTransaction , confirmationCb , gasEstimationForceSend , promptCb , callback ) {
105
+ console . log ( 'execute txRunnerWeb3--->' , args )
99
106
let data = args . data
100
107
if ( data . slice ( 0 , 2 ) !== '0x' ) {
101
108
data = '0x' + data
102
109
}
103
110
104
- return this . runInNode ( args . from , args . to , data , args . value , args . gasLimit , args . useCall , args . timestamp , confirmationCb , gasEstimationForceSend , promptCb , callback )
111
+ return this . runInNode ( args . from , args . fromSmartAccount , args . to , data , args . value , args . gasLimit , args . useCall , args . timestamp , confirmationCb , gasEstimationForceSend , promptCb , callback )
105
112
}
106
113
107
- runInNode ( from , to , data , value , gasLimit , useCall , timestamp , confirmCb , gasEstimationForceSend , promptCb , callback ) {
108
- const tx = { from : from , to : to , data : data , value : value }
114
+ runInNode ( from , fromSmartAccount , to , data , value , gasLimit , useCall , timestamp , confirmCb , gasEstimationForceSend , promptCb , callback ) {
115
+ const tx = { from : from , fromSmartAccount , to : to , data : data , value : value }
109
116
if ( ! from ) return callback ( 'the value of "from" is not defined. Please make sure an account is selected.' )
110
117
if ( useCall ) {
111
118
if ( this . _api && this . _api . isVM ( ) ) {
@@ -189,6 +196,10 @@ export class TxRunnerWeb3 {
189
196
}
190
197
}
191
198
199
+ const sendUserOp = async ( tx ) => {
200
+ console . log ( 'sendUserOp--tx-->' , tx )
201
+ }
202
+
192
203
async function tryTillReceiptAvailable ( txhash : string , web3 : Web3 ) {
193
204
try {
194
205
const receipt = await web3 . eth . getTransactionReceipt ( txhash )
0 commit comments