Skip to content

Commit f392eda

Browse files
committed
handle smart account tx in the case of a contractCreated being emiited
1 parent 2dad2f0 commit f392eda

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import { EventManager } from '../eventManager'
33
import type { Transaction as InternalTransaction } from './txRunner'
44
import { Web3 } from 'web3'
5-
import { toBigInt, toHex } from 'web3-utils'
5+
import { toBigInt, toHex, toChecksumAddress } from 'web3-utils'
66
import { ethers } from 'ethers'
7+
import { normalizeHexAddress } from '../helpers/uiHelper'
78

89
export class TxRunnerWeb3 {
910
event
@@ -38,7 +39,7 @@ export class TxRunnerWeb3 {
3839
}
3940

4041
let currentDateTime = new Date();
41-
const cb = (err, resp) => {
42+
const cb = (err, resp, isCreation: boolean) => {
4243
if (err) {
4344
return callback(err, resp)
4445
}
@@ -48,6 +49,18 @@ export class TxRunnerWeb3 {
4849
return new Promise(async (resolve, reject) => {
4950
const receipt = await tryTillReceiptAvailable(resp, this.getWeb3())
5051
tx = await tryTillTxAvailable(resp, this.getWeb3())
52+
if (isCreation && !receipt.contractAddress) {
53+
// if it is a isCreation, contractAddress should be defined.
54+
// if it's not the case look for the event ContractCreated(uint256,address,uint256,bytes32) and extract the address
55+
// topic id: 0xa1fb700aaee2ae4a2ff6f91ce7eba292f89c2f5488b8ec4c5c5c8150692595c3
56+
if (receipt.logs && receipt.logs.length) {
57+
receipt.logs.map((log) => {
58+
if (log.topics[0] === '0xa1fb700aaee2ae4a2ff6f91ce7eba292f89c2f5488b8ec4c5c5c8150692595c3') {
59+
(receipt as any).contractAddress = toChecksumAddress(normalizeHexAddress(toHex(log.topics[2])))
60+
}
61+
})
62+
}
63+
}
5164
currentDateTime = new Date();
5265
resolve({
5366
receipt,
@@ -59,18 +72,19 @@ export class TxRunnerWeb3 {
5972
listenOnResponse().then((txData) => { callback(null, txData) }).catch((error) => { callback(error) })
6073
}
6174

75+
const isCreation = !tx.to
6276
if (api.personalMode()) {
6377
promptCb(
6478
async (value) => {
6579
try {
6680
const res = await (this.getWeb3() as any).eth.personal.sendTransaction({ ...tx, value }, { checkRevertBeforeSending: false, ignoreGasPricing: true })
67-
cb(null, res.transactionHash)
81+
cb(null, res.transactionHash, isCreation)
6882
} catch (e) {
6983
console.log(`Send transaction failed: ${e.message || e.error} . if you use an injected provider, please check it is properly unlocked. `)
7084
// in case the receipt is available, we consider that only the execution failed but the transaction went through.
7185
// So we don't consider this to be an error.
72-
if (e.receipt) cb(null, e.receipt.transactionHash)
73-
else cb(e, null)
86+
if (e.receipt) cb(null, e.receipt.transactionHash, isCreation)
87+
else cb(e, null, isCreation)
7488
}
7589
},
7690
() => {
@@ -80,7 +94,7 @@ export class TxRunnerWeb3 {
8094
} else {
8195
try {
8296
const res = await this.getWeb3().eth.sendTransaction(tx, null, { checkRevertBeforeSending: false, ignoreGasPricing: true })
83-
cb(null, res.transactionHash)
97+
cb(null, res.transactionHash, isCreation)
8498
} catch (e) {
8599
if (!e.message) e.message = ''
86100
if (e.error) {
@@ -89,8 +103,8 @@ export class TxRunnerWeb3 {
89103
console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `)
90104
// in case the receipt is available, we consider that only the execution failed but the transaction went through.
91105
// So we don't consider this to be an error.
92-
if (e.receipt) cb(null, e.receipt.transactionHash)
93-
else cb(e, null)
106+
if (e.receipt) cb(null, e.receipt.transactionHash, isCreation)
107+
else cb(e, null, isCreation)
94108
}
95109
}
96110
}

0 commit comments

Comments
 (0)