diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-10 18:21:05 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-10 18:21:05 +0800 |
commit | 7ae9e79235ed3b7eb110b0a1e88338b3965f44da (patch) | |
tree | 5339e9548142eb6ec3e7a7e4288cb5e5b1a582cc /packages/sol-tracing-utils/src/trace_info_subprovider.ts | |
parent | 15c9479ebeca57e7c275cd2e73ca3daad03a412f (diff) | |
download | dexon-sol-tools-7ae9e79235ed3b7eb110b0a1e88338b3965f44da.tar dexon-sol-tools-7ae9e79235ed3b7eb110b0a1e88338b3965f44da.tar.gz dexon-sol-tools-7ae9e79235ed3b7eb110b0a1e88338b3965f44da.tar.bz2 dexon-sol-tools-7ae9e79235ed3b7eb110b0a1e88338b3965f44da.tar.lz dexon-sol-tools-7ae9e79235ed3b7eb110b0a1e88338b3965f44da.tar.xz dexon-sol-tools-7ae9e79235ed3b7eb110b0a1e88338b3965f44da.tar.zst dexon-sol-tools-7ae9e79235ed3b7eb110b0a1e88338b3965f44da.zip |
Rename sol-trace-based-tools-common to sol-tracing-utils
Diffstat (limited to 'packages/sol-tracing-utils/src/trace_info_subprovider.ts')
-rw-r--r-- | packages/sol-tracing-utils/src/trace_info_subprovider.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/packages/sol-tracing-utils/src/trace_info_subprovider.ts b/packages/sol-tracing-utils/src/trace_info_subprovider.ts new file mode 100644 index 000000000..635a68f58 --- /dev/null +++ b/packages/sol-tracing-utils/src/trace_info_subprovider.ts @@ -0,0 +1,59 @@ +import * as _ from 'lodash'; + +import { constants } from './constants'; +import { getTracesByContractAddress } from './trace'; +import { TraceCollectionSubprovider } from './trace_collection_subprovider'; +import { TraceInfo, TraceInfoExistingContract, TraceInfoNewContract } from './types'; + +// TraceInfoSubprovider is extended by subproviders which need to work with one +// TraceInfo at a time. It has one abstract method: _handleTraceInfoAsync, which +// is called for each TraceInfo. +export abstract class TraceInfoSubprovider extends TraceCollectionSubprovider { + protected abstract _handleTraceInfoAsync(traceInfo: TraceInfo): Promise<void>; + protected async _recordTxTraceAsync(address: string, data: string | undefined, txHash: string): Promise<void> { + await this._web3Wrapper.awaitTransactionMinedAsync(txHash, 0); + const trace = await this._web3Wrapper.getTransactionTraceAsync(txHash, { + disableMemory: true, + disableStack: false, + disableStorage: true, + }); + const tracesByContractAddress = getTracesByContractAddress(trace.structLogs, address); + const subcallAddresses = _.keys(tracesByContractAddress); + if (address === constants.NEW_CONTRACT) { + for (const subcallAddress of subcallAddresses) { + let traceInfo: TraceInfoNewContract | TraceInfoExistingContract; + if (subcallAddress === 'NEW_CONTRACT') { + const traceForThatSubcall = tracesByContractAddress[subcallAddress]; + traceInfo = { + subtrace: traceForThatSubcall, + txHash, + address: subcallAddress, + bytecode: data as string, + }; + } else { + const runtimeBytecode = await this._web3Wrapper.getContractCodeAsync(subcallAddress); + const traceForThatSubcall = tracesByContractAddress[subcallAddress]; + traceInfo = { + subtrace: traceForThatSubcall, + txHash, + address: subcallAddress, + runtimeBytecode, + }; + } + await this._handleTraceInfoAsync(traceInfo); + } + } else { + for (const subcallAddress of subcallAddresses) { + const runtimeBytecode = await this._web3Wrapper.getContractCodeAsync(subcallAddress); + const traceForThatSubcall = tracesByContractAddress[subcallAddress]; + const traceInfo: TraceInfoExistingContract = { + subtrace: traceForThatSubcall, + txHash, + address: subcallAddress, + runtimeBytecode, + }; + await this._handleTraceInfoAsync(traceInfo); + } + } + } +} |