Skip to content

Commit 29994ce

Browse files
committed
Debug transaction for constructor
1 parent 524c94c commit 29994ce

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

src/api/service/bean/CFGContract.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { Operation } from '../../bytecode/Operation'
44
export interface CFGContract {
55
contractConstructor?: {
66
bytecode: Operation[]
7-
blocks: CFGBlocks
7+
blocks: CFGBlocks,
8+
rawBytecode
89
}
910
contractRuntime: {
1011
bytecode: Operation[]

src/api/service/controller/DebuggerController.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ export class DebuggerController extends Controller {
4343
blockchainBasicAuthPassword
4444
} as Web3Configuration
4545
const contractBlocks: CFGContract = await this.cfgService.buildCFGFromSource(name, source.request, path)
46-
const runtimeRawBytecode = contractBlocks.contractRuntime.rawBytecode.startsWith('0x')? contractBlocks.contractRuntime.rawBytecode: `0x${contractBlocks.contractRuntime.rawBytecode}`
47-
const trace: DebugTrace = await this.transactionService.findTransactionTrace(tx, runtimeRawBytecode, config)
48-
const cfg = this.createCFG(contractBlocks, false, trace)
49-
return this.buildResponse(contractBlocks, false, cfg, trace)
46+
const transaction = await this.transactionService.findTransaction(tx, config)
47+
const isConstructor = transaction.to? false: true
48+
let rawBytecode = contractBlocks.contractRuntime.rawBytecode.startsWith('0x')? contractBlocks.contractRuntime.rawBytecode: `0x${contractBlocks.contractRuntime.rawBytecode}`
49+
if (isConstructor) {
50+
rawBytecode = contractBlocks.contractConstructor.rawBytecode.startsWith('0x')? contractBlocks.contractConstructor.rawBytecode: `0x${ contractBlocks.contractConstructor.rawBytecode}`
51+
}
52+
const trace: DebugTrace = await this.transactionService.findTransactionTrace(tx, rawBytecode, config)
53+
const cfg = this.createCFG(contractBlocks, isConstructor, trace)
54+
return this.buildResponse(contractBlocks, isConstructor, cfg, trace)
5055
} catch (err) {
5156
logger.error(err)
5257
throw new Error(err.message)

src/api/service/service/CFGService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export class CFGService {
114114
const constructorBlocks = this.calculateCfgBlocks(contract.constructor)
115115
cfgContract.contractConstructor = {
116116
blocks: constructorBlocks,
117-
bytecode: contract.constructor
117+
bytecode: contract.constructor,
118+
rawBytecode: contract.bytecode
118119
}
119120
}
120121
return cfgContract

src/api/service/service/TransactionServiceImpl.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ export class TransactionServiceImpl implements TransactionService {
6969
throw new Error(`Transaction ${transactionHash} not found in node`)
7070
}
7171
const toAddress = transaction.to
72-
const deployedBytecode = await web3.eth.getCode(toAddress)
72+
let deployedBytecode = bytecode
73+
if (toAddress) {
74+
deployedBytecode = await web3.eth.getCode(toAddress)
75+
}
7376
const trace: DebugTrace = await this.getTrace(transactionHash, config)
7477
return await this.findContractTraceDepth(bytecode, deployedBytecode, trace, web3)
7578
}

src/client/components/Tab/TabPanel/TabPanel.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
&__side-bar {
2929
position: absolute;
3030
top: 30px;
31-
left: -262px;
31+
left: -400px;
3232
transition: left 0.2s;
3333
pointer-events: none;
3434
}

0 commit comments

Comments
 (0)