Skip to content

Commit d6f1649

Browse files
committed
intermediate commit
1 parent 6cd21cd commit d6f1649

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

apps/remix-ide/src/blockchain/blockchain.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ const profile = {
2323
name: 'blockchain',
2424
displayName: 'Blockchain',
2525
description: 'Blockchain - Logic',
26-
methods: ['getCode', 'getTransactionReceipt', 'addProvider', 'removeProvider', 'getCurrentFork', 'getAccounts', 'web3VM', 'web3', 'getProvider', 'getCurrentProvider', 'getCurrentNetworkStatus', 'getAllProviders', 'getPinnedProviders'],
26+
methods: ['getCode', 'getTransactionReceipt', 'addProvider', 'removeProvider', 'getCurrentFork', 'isSmartAccount', 'getAccounts', 'web3VM', 'web3', 'getProvider', 'getCurrentProvider', 'getCurrentNetworkStatus', 'getAllProviders', 'getPinnedProviders'],
2727
version: packageJson.version
2828
}
2929

3030
export type TransactionContextAPI = {
3131
getAddress: (cb: (error: Error, result: string) => void) => void
3232
getValue: (cb: (error: Error, result: string) => void) => void
3333
getGasLimit: (cb: (error: Error, result: string) => void) => void
34+
isSmartAccount: (address: string) => boolean
3435
}
3536

3637
// see TxRunner.ts in remix-lib
@@ -217,6 +218,10 @@ export class Blockchain extends Plugin {
217218
return this.networkStatus
218219
}
219220

221+
isSmartAccount(address) {
222+
return this.transactionContextAPI.isSmartAccount(address)
223+
}
224+
220225
setupProviders() {
221226
this.providers = {}
222227
this.providers['vm'] = new VMProvider(this.executionContext)
@@ -747,20 +752,30 @@ export class Blockchain extends Plugin {
747752
(_) => this.executionContext.currentblockGasLimit()
748753
)
749754

750-
web3Runner.event.register('transactionBroadcasted', (txhash) => {
755+
web3Runner.event.register('transactionBroadcasted', (txhash, isUserOp) => {
751756
this.executionContext.detectNetwork((error, network) => {
752757
if (error || !network) return
753758
if (network.name === 'VM') return
754-
const viewEtherScanLink = etherScanLink(network.name, txhash)
755-
756-
if (viewEtherScanLink) {
759+
if (isUserOp) {
760+
const userOpLink = `https://jiffyscan.xyz/userOpHash/${txhash}?network=${network.name}`
757761
this.call(
758762
'terminal',
759763
'logHtml',
760-
<a href={etherScanLink(network.name, txhash)} target="_blank">
761-
view on etherscan
764+
<a href={userOpLink} target="_blank">
765+
view on Jiffyscan
762766
</a>
763767
)
768+
} else {
769+
const viewEtherScanLink = etherScanLink(network.name, txhash)
770+
if (viewEtherScanLink) {
771+
this.call(
772+
'terminal',
773+
'logHtml',
774+
<a href={etherScanLink(network.name, txhash)} target="_blank">
775+
view on Etherscan
776+
</a>
777+
)
778+
}
764779
}
765780
})
766781
})
@@ -903,10 +918,12 @@ export class Blockchain extends Plugin {
903918
// eslint-disable-next-line no-async-promise-executor
904919
return new Promise(async (resolve, reject) => {
905920
let fromAddress
921+
let fromSmartAccount
906922
let value
907923
let gasLimit
908924
try {
909925
fromAddress = await getAccount()
926+
fromSmartAccount = this.isSmartAccount(fromAddress)
910927
value = await queryValue()
911928
gasLimit = await getGasLimit()
912929
} catch (e) {
@@ -919,6 +936,7 @@ export class Blockchain extends Plugin {
919936
data: args.data.dataHex,
920937
useCall: args.useCall,
921938
from: fromAddress,
939+
fromSmartAccount,
922940
value: value,
923941
gasLimit: gasLimit,
924942
timestamp: args.data.timestamp

libs/remix-lib/src/execution/txRunner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EventManager } from '../eventManager'
33

44
export type Transaction = {
55
from: string,
6+
fromSmartAccount: boolean,
67
to?: string,
78
value: string,
89
data: string,

libs/remix-lib/src/execution/txRunnerWeb3.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EventManager } from '../eventManager'
33
import type { Transaction as InternalTransaction } from './txRunner'
44
import { Web3 } from 'web3'
55
import { toBigInt, toHex } from 'web3-utils'
6+
import "viem/window"
67

78
export class TxRunnerWeb3 {
89
event
@@ -38,11 +39,11 @@ export class TxRunnerWeb3 {
3839

3940
let currentDateTime = new Date();
4041
const start = currentDateTime.getTime() / 1000
41-
const cb = (err, resp) => {
42+
const cb = (err, resp, isUserOp) => {
4243
if (err) {
4344
return callback(err, resp)
4445
}
45-
this.event.trigger('transactionBroadcasted', [resp])
46+
this.event.trigger('transactionBroadcasted', [resp, isUserOp])
4647
const listenOnResponse = () => {
4748
// eslint-disable-next-line no-async-promise-executor
4849
return new Promise(async (resolve, reject) => {
@@ -64,13 +65,13 @@ export class TxRunnerWeb3 {
6465
async (value) => {
6566
try {
6667
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)
6869
} catch (e) {
6970
console.log(`Send transaction failed: ${e.message || e.error} . if you use an injected provider, please check it is properly unlocked. `)
7071
// in case the receipt is available, we consider that only the execution failed but the transaction went through.
7172
// 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)
7475
}
7576
},
7677
() => {
@@ -79,8 +80,13 @@ export class TxRunnerWeb3 {
7980
)
8081
} else {
8182
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+
}
8490
} catch (e) {
8591
if (!e.message) e.message = ''
8692
if (e.error) {
@@ -89,23 +95,24 @@ export class TxRunnerWeb3 {
8995
console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `)
9096
// in case the receipt is available, we consider that only the execution failed but the transaction went through.
9197
// 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)
94100
}
95101
}
96102
}
97103

98104
execute (args: InternalTransaction, confirmationCb, gasEstimationForceSend, promptCb, callback) {
105+
console.log('execute txRunnerWeb3--->', args)
99106
let data = args.data
100107
if (data.slice(0, 2) !== '0x') {
101108
data = '0x' + data
102109
}
103110

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)
105112
}
106113

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 }
109116
if (!from) return callback('the value of "from" is not defined. Please make sure an account is selected.')
110117
if (useCall) {
111118
if (this._api && this._api.isVM()) {
@@ -189,6 +196,10 @@ export class TxRunnerWeb3 {
189196
}
190197
}
191198

199+
const sendUserOp = async (tx) => {
200+
console.log('sendUserOp--tx-->', tx)
201+
}
202+
192203
async function tryTillReceiptAvailable (txhash: string, web3: Web3) {
193204
try {
194205
const receipt = await web3.eth.getTransactionReceipt(txhash)

libs/remix-ui/run-tab/src/lib/actions/events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ export const resetAndInit = (plugin: RunTab) => {
281281
} catch (e) {
282282
cb(e.message)
283283
}
284+
},
285+
isSmartAccount: (address) => {
286+
if (plugin.REACT_API.smartAccounts && plugin.REACT_API.smartAccounts.addresses.includes(address)) return true
287+
else return false
284288
}
285289
})
286290
}

0 commit comments

Comments
 (0)