hardhat 2.13.0-dev.0 → 2.13.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builtin-tasks/compile.js +1 -10
- package/builtin-tasks/compile.js.map +1 -1
- package/builtin-tasks/task-names.d.ts +0 -1
- package/builtin-tasks/task-names.d.ts.map +1 -1
- package/builtin-tasks/task-names.js +2 -3
- package/builtin-tasks/task-names.js.map +1 -1
- package/internal/artifacts/caching.d.ts +27 -0
- package/internal/artifacts/caching.d.ts.map +1 -0
- package/internal/artifacts/caching.js +167 -0
- package/internal/artifacts/caching.js.map +1 -0
- package/internal/artifacts/index.d.ts +44 -0
- package/internal/artifacts/index.d.ts.map +1 -0
- package/internal/artifacts/index.js +187 -0
- package/internal/artifacts/index.js.map +1 -0
- package/internal/artifacts/mutable.d.ts +29 -0
- package/internal/artifacts/mutable.d.ts.map +1 -0
- package/internal/artifacts/mutable.js +226 -0
- package/internal/artifacts/mutable.js.map +1 -0
- package/internal/artifacts/readonly.d.ts +88 -0
- package/internal/artifacts/readonly.d.ts.map +1 -0
- package/internal/artifacts/readonly.js +324 -0
- package/internal/artifacts/readonly.js.map +1 -0
- package/internal/cli/cli.js +5 -2
- package/internal/cli/cli.js.map +1 -1
- package/internal/core/config/config-env.d.ts +7 -1
- package/internal/core/config/config-env.d.ts.map +1 -1
- package/internal/core/config/config-env.js +13 -2
- package/internal/core/config/config-env.js.map +1 -1
- package/internal/core/config/extenders.d.ts +7 -4
- package/internal/core/config/extenders.d.ts.map +1 -1
- package/internal/core/config/extenders.js +12 -5
- package/internal/core/config/extenders.js.map +1 -1
- package/internal/core/errors-list.d.ts +7 -0
- package/internal/core/errors-list.d.ts.map +1 -1
- package/internal/core/errors-list.js +9 -0
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/runtime-environment.d.ts +2 -2
- package/internal/core/runtime-environment.d.ts.map +1 -1
- package/internal/core/runtime-environment.js +2 -2
- package/internal/core/runtime-environment.js.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js +9 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts +32 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts.map +1 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js +87 -0
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js.map +1 -0
- package/internal/hardhat-network/provider/utils/bloom.d.ts +28 -0
- package/internal/hardhat-network/provider/utils/bloom.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/bloom.js +73 -0
- package/internal/hardhat-network/provider/utils/bloom.js.map +1 -0
- package/internal/hardhat-network/provider/utils/convertToRethnet.d.ts +26 -1
- package/internal/hardhat-network/provider/utils/convertToRethnet.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/convertToRethnet.js +189 -6
- package/internal/hardhat-network/provider/utils/convertToRethnet.js.map +1 -1
- package/internal/hardhat-network/provider/vm/block-builder.d.ts +30 -0
- package/internal/hardhat-network/provider/vm/block-builder.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/block-builder.js +147 -0
- package/internal/hardhat-network/provider/vm/block-builder.js.map +1 -0
- package/internal/hardhat-network/provider/vm/dual.d.ts +43 -0
- package/internal/hardhat-network/provider/vm/dual.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/dual.js +120 -0
- package/internal/hardhat-network/provider/vm/dual.js.map +1 -0
- package/internal/hardhat-network/provider/vm/ethereumjs.d.ts +55 -0
- package/internal/hardhat-network/provider/vm/ethereumjs.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/ethereumjs.js +272 -0
- package/internal/hardhat-network/provider/vm/ethereumjs.js.map +1 -0
- package/internal/hardhat-network/provider/vm/rethnet.d.ts +111 -0
- package/internal/hardhat-network/provider/vm/rethnet.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/rethnet.js +171 -0
- package/internal/hardhat-network/provider/vm/rethnet.js.map +1 -0
- package/internal/hardhat-network/provider/vm/vm-adapter.d.ts +36 -0
- package/internal/hardhat-network/provider/vm/vm-adapter.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/vm-adapter.js +3 -0
- package/internal/hardhat-network/provider/vm/vm-adapter.js.map +1 -0
- package/internal/lib/hardhat-lib.d.ts.map +1 -1
- package/internal/lib/hardhat-lib.js +4 -1
- package/internal/lib/hardhat-lib.js.map +1 -1
- package/internal/solidity/compiler/compiler-input.d.ts.map +1 -1
- package/internal/solidity/compiler/compiler-input.js +5 -1
- package/internal/solidity/compiler/compiler-input.js.map +1 -1
- package/internal/solidity/compiler/downloader.d.ts.map +1 -1
- package/internal/solidity/compiler/downloader.js +10 -12
- package/internal/solidity/compiler/downloader.js.map +1 -1
- package/internal/solidity/resolver.d.ts +3 -4
- package/internal/solidity/resolver.d.ts.map +1 -1
- package/internal/solidity/resolver.js +3 -5
- package/internal/solidity/resolver.js.map +1 -1
- package/package.json +1 -1
- package/register.js +4 -1
- package/register.js.map +1 -1
- package/src/builtin-tasks/compile.ts +1 -16
- package/src/builtin-tasks/task-names.ts +0 -2
- package/src/internal/artifacts/caching.ts +239 -0
- package/src/internal/artifacts/index.ts +296 -0
- package/src/internal/artifacts/mutable.ts +330 -0
- package/src/internal/artifacts/readonly.ts +438 -0
- package/src/internal/cli/cli.ts +6 -1
- package/src/internal/core/config/config-env.ts +13 -1
- package/src/internal/core/config/extenders.ts +15 -6
- package/src/internal/core/errors-list.ts +9 -0
- package/src/internal/core/runtime-environment.ts +3 -1
- package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +15 -3
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.ts +162 -0
- package/src/internal/lib/hardhat-lib.ts +6 -1
- package/src/internal/solidity/compiler/compiler-input.ts +7 -1
- package/src/internal/solidity/compiler/downloader.ts +11 -11
- package/src/internal/solidity/resolver.ts +3 -8
- package/src/register.ts +6 -1
- package/src/types/artifacts.ts +104 -4
- package/src/types/runtime.ts +7 -1
- package/types/artifacts.d.ts +90 -4
- package/types/artifacts.d.ts.map +1 -1
- package/types/runtime.d.ts +6 -1
- package/types/runtime.d.ts.map +1 -1
- package/src/internal/artifacts.ts +0 -918
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import * as os from "os";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
|
|
4
|
+
import fsExtra from "fs-extra";
|
|
5
|
+
|
|
6
|
+
import { Artifact, BuildInfo } from "../../types";
|
|
7
|
+
import {
|
|
8
|
+
getFullyQualifiedName,
|
|
9
|
+
isFullyQualifiedName,
|
|
10
|
+
parseFullyQualifiedName,
|
|
11
|
+
findDistance,
|
|
12
|
+
} from "../../utils/contract-names";
|
|
13
|
+
import { replaceBackslashes } from "../../utils/source-names";
|
|
14
|
+
|
|
15
|
+
import { BUILD_INFO_DIR_NAME, EDIT_DISTANCE_THRESHOLD } from "../constants";
|
|
16
|
+
import { HardhatError } from "../core/errors";
|
|
17
|
+
import { ERRORS } from "../core/errors-list";
|
|
18
|
+
import {
|
|
19
|
+
FileNotFoundError,
|
|
20
|
+
getAllFilesMatching,
|
|
21
|
+
getAllFilesMatchingSync,
|
|
22
|
+
getFileTrueCase,
|
|
23
|
+
getFileTrueCaseSync,
|
|
24
|
+
} from "../util/fs-utils";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The purpose of this class is to encapsulate JSON file I/O. It assumes that
|
|
28
|
+
* all input strings are simply paths, not contract names nor fully-qualified
|
|
29
|
+
* contract names like other interfaces around here accept.
|
|
30
|
+
*/
|
|
31
|
+
class ReadOnlyByPath {
|
|
32
|
+
protected async _readArtifactByPath(artifactPath: string): Promise<Artifact> {
|
|
33
|
+
return fsExtra.readJson(artifactPath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected _readArtifactByPathSync(artifactPath: string): Artifact {
|
|
37
|
+
return fsExtra.readJsonSync(artifactPath);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected async _artifactPathExists(artifactPath: string): Promise<boolean> {
|
|
41
|
+
return fsExtra.pathExists(artifactPath);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected async _getBuildInfoByPath(
|
|
45
|
+
buildInfoPath: string
|
|
46
|
+
): Promise<BuildInfo | undefined> {
|
|
47
|
+
return fsExtra.readJSON(buildInfoPath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Given the path to a debug file, returns the absolute path to its
|
|
52
|
+
* corresponding build info file if it exists, or undefined otherwise.
|
|
53
|
+
*/
|
|
54
|
+
protected static async _getBuildInfoFromDebugFile(
|
|
55
|
+
debugFilePath: string
|
|
56
|
+
): Promise<string | undefined> {
|
|
57
|
+
if (await fsExtra.pathExists(debugFilePath)) {
|
|
58
|
+
const { buildInfo } = await fsExtra.readJson(debugFilePath);
|
|
59
|
+
return path.resolve(path.dirname(debugFilePath), buildInfo);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected _getDebugFilePath(artifactPath: string): string {
|
|
66
|
+
return artifactPath.replace(/\.json$/, ".dbg.json");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* This class takes responsibility for the mappings between contract names,
|
|
72
|
+
* fully-qualified contract names, and file paths.
|
|
73
|
+
*/
|
|
74
|
+
export class ReadOnlySource extends ReadOnlyByPath {
|
|
75
|
+
constructor(protected _artifactsPath: string) {
|
|
76
|
+
super();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public async artifactExists(name: string): Promise<boolean> {
|
|
80
|
+
const artifactPath = await this._getArtifactPath(name);
|
|
81
|
+
|
|
82
|
+
if (artifactPath === undefined) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return super._artifactPathExists(artifactPath);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public async getArtifactPaths(): Promise<string[]> {
|
|
90
|
+
const buildInfosDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);
|
|
91
|
+
|
|
92
|
+
const paths = await getAllFilesMatching(
|
|
93
|
+
this._artifactsPath,
|
|
94
|
+
(f) =>
|
|
95
|
+
f.endsWith(".json") &&
|
|
96
|
+
!f.startsWith(buildInfosDir) &&
|
|
97
|
+
!f.endsWith(".dbg.json")
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return paths.sort();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Returns the absolute path to the given artifact
|
|
105
|
+
*/
|
|
106
|
+
public formArtifactPathFromFullyQualifiedName(
|
|
107
|
+
fullyQualifiedName: string
|
|
108
|
+
): string {
|
|
109
|
+
const { sourceName, contractName } =
|
|
110
|
+
parseFullyQualifiedName(fullyQualifiedName);
|
|
111
|
+
|
|
112
|
+
return path.join(this._artifactsPath, sourceName, `${contractName}.json`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public async getAllFullyQualifiedNames(): Promise<string[]> {
|
|
116
|
+
const paths = await this.getArtifactPaths();
|
|
117
|
+
return paths.map((p) => this._getFullyQualifiedNameFromPath(p)).sort();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public async getBuildInfo(
|
|
121
|
+
fullyQualifiedName: string
|
|
122
|
+
): Promise<BuildInfo | undefined> {
|
|
123
|
+
const buildInfoPath = await this._getBuildInfoPath(fullyQualifiedName);
|
|
124
|
+
|
|
125
|
+
if (buildInfoPath === undefined) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return super._getBuildInfoByPath(buildInfoPath);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public async getBuildInfoPaths(): Promise<string[]> {
|
|
133
|
+
const paths = await getAllFilesMatching(
|
|
134
|
+
path.join(this._artifactsPath, BUILD_INFO_DIR_NAME),
|
|
135
|
+
(f) => f.endsWith(".json")
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
return paths.sort();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public async getDebugFilePaths(): Promise<string[]> {
|
|
142
|
+
const paths = await getAllFilesMatching(
|
|
143
|
+
path.join(this._artifactsPath),
|
|
144
|
+
(f) => f.endsWith(".dbg.json")
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return paths.sort();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public async readArtifact(name: string): Promise<Artifact | undefined> {
|
|
151
|
+
const artifactPath = await this._getArtifactPath(name);
|
|
152
|
+
if (artifactPath === undefined) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return super._readArtifactByPath(artifactPath);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public readArtifactSync(name: string): Artifact | undefined {
|
|
160
|
+
const artifactPath = this._getArtifactPathSync(name);
|
|
161
|
+
if (artifactPath === undefined) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return super._readArtifactByPathSync(artifactPath);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public getSuggestions(name: string): string[] {
|
|
169
|
+
if (isFullyQualifiedName(name)) {
|
|
170
|
+
const fqns = this._getAllFullyQualifiedNamesSync();
|
|
171
|
+
|
|
172
|
+
return ReadOnlySource._getSimilarContractNames(name, fqns);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const files = this._getArtifactPathsSync();
|
|
176
|
+
const names = this._getAllContractNamesFromFiles(files);
|
|
177
|
+
|
|
178
|
+
let similarNames = ReadOnlySource._getSimilarContractNames(name, names);
|
|
179
|
+
|
|
180
|
+
if (similarNames.length > 1) {
|
|
181
|
+
similarNames = this._filterDuplicatesAsFullyQualifiedNames(
|
|
182
|
+
files,
|
|
183
|
+
similarNames
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return similarNames;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* If the project has these contracts:
|
|
192
|
+
* - 'contracts/Greeter.sol:Greeter'
|
|
193
|
+
* - 'contracts/Meeter.sol:Greeter'
|
|
194
|
+
* - 'contracts/Greater.sol:Greater'
|
|
195
|
+
* And the user tries to get an artifact with the name 'Greter', then
|
|
196
|
+
* the suggestions will be 'Greeter', 'Greeter', and 'Greater'.
|
|
197
|
+
*
|
|
198
|
+
* We don't want to show duplicates here, so we use FQNs for those. The
|
|
199
|
+
* suggestions will then be:
|
|
200
|
+
* - 'contracts/Greeter.sol:Greeter'
|
|
201
|
+
* - 'contracts/Meeter.sol:Greeter'
|
|
202
|
+
* - 'Greater'
|
|
203
|
+
*/
|
|
204
|
+
private _filterDuplicatesAsFullyQualifiedNames(
|
|
205
|
+
files: string[],
|
|
206
|
+
similarNames: string[]
|
|
207
|
+
): string[] {
|
|
208
|
+
const outputNames = [];
|
|
209
|
+
const groups = similarNames.reduce((obj, cur) => {
|
|
210
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
211
|
+
obj[cur] = obj[cur] ? obj[cur] + 1 : 1;
|
|
212
|
+
return obj;
|
|
213
|
+
}, {} as { [k: string]: number });
|
|
214
|
+
|
|
215
|
+
for (const [name, occurrences] of Object.entries(groups)) {
|
|
216
|
+
if (occurrences > 1) {
|
|
217
|
+
for (const file of files) {
|
|
218
|
+
if (path.basename(file) === `${name}.json`) {
|
|
219
|
+
outputNames.push(this._getFullyQualifiedNameFromPath(file));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
outputNames.push(name);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return outputNames;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private _getAllContractNamesFromFiles(files: string[]): string[] {
|
|
232
|
+
return files.map((file) => {
|
|
233
|
+
const fqn = this._getFullyQualifiedNameFromPath(file);
|
|
234
|
+
return parseFullyQualifiedName(fqn).contractName;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private _getAllFullyQualifiedNamesSync(): string[] {
|
|
239
|
+
const paths = this._getArtifactPathsSync();
|
|
240
|
+
return paths.map((p) => this._getFullyQualifiedNameFromPath(p)).sort();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Returns the absolute path to the artifact that corresponds to the given
|
|
245
|
+
* name.
|
|
246
|
+
*
|
|
247
|
+
* If the name is fully qualified, the path is computed from it. If not, an
|
|
248
|
+
* artifact that matches the given name is searched in the existing artifacts.
|
|
249
|
+
* If there is an ambiguity, an error is thrown.
|
|
250
|
+
*/
|
|
251
|
+
protected async _getArtifactPath(name: string): Promise<string | undefined> {
|
|
252
|
+
let result: string | undefined;
|
|
253
|
+
if (isFullyQualifiedName(name)) {
|
|
254
|
+
result = await this._getValidArtifactPathFromFullyQualifiedName(name);
|
|
255
|
+
} else {
|
|
256
|
+
const files = await this.getArtifactPaths();
|
|
257
|
+
result = this._getArtifactPathFromFiles(name, files);
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
protected _getArtifactPathSync(name: string): string | undefined {
|
|
263
|
+
let result: string | undefined;
|
|
264
|
+
if (isFullyQualifiedName(name)) {
|
|
265
|
+
result = this._getValidArtifactPathFromFullyQualifiedNameSync(name);
|
|
266
|
+
} else {
|
|
267
|
+
const files = this._getArtifactPathsSync();
|
|
268
|
+
result = this._getArtifactPathFromFiles(name, files);
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private _getArtifactPathFromFiles(
|
|
274
|
+
contractName: string,
|
|
275
|
+
files: string[]
|
|
276
|
+
): string | undefined {
|
|
277
|
+
const matchingFiles = files.filter((file) => {
|
|
278
|
+
return path.basename(file) === `${contractName}.json`;
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
if (matchingFiles.length === 0) {
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (matchingFiles.length > 1) {
|
|
286
|
+
const candidates = matchingFiles.map((file) =>
|
|
287
|
+
this._getFullyQualifiedNameFromPath(file)
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
throw new HardhatError(ERRORS.ARTIFACTS.MULTIPLE_FOUND, {
|
|
291
|
+
contractName,
|
|
292
|
+
candidates: candidates.join(os.EOL),
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return matchingFiles[0];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
protected _getArtifactPathsSync(): string[] {
|
|
300
|
+
const buildInfosDir = path.join(this._artifactsPath, BUILD_INFO_DIR_NAME);
|
|
301
|
+
|
|
302
|
+
const paths = getAllFilesMatchingSync(
|
|
303
|
+
this._artifactsPath,
|
|
304
|
+
(f) =>
|
|
305
|
+
f.endsWith(".json") &&
|
|
306
|
+
!f.startsWith(buildInfosDir) &&
|
|
307
|
+
!f.endsWith(".dbg.json")
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
return paths.sort();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
protected async _getBuildInfoPath(
|
|
314
|
+
fullyQualifiedName: string
|
|
315
|
+
): Promise<string | undefined> {
|
|
316
|
+
const artifactPath =
|
|
317
|
+
this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
|
|
318
|
+
|
|
319
|
+
const debugFilePath = this._getDebugFilePath(artifactPath);
|
|
320
|
+
const buildInfoPath = await ReadOnlySource._getBuildInfoFromDebugFile(
|
|
321
|
+
debugFilePath
|
|
322
|
+
);
|
|
323
|
+
return buildInfoPath;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Returns the FQN of a contract giving the absolute path to its artifact.
|
|
328
|
+
*
|
|
329
|
+
* For example, given a path like
|
|
330
|
+
* `/path/to/project/artifacts/contracts/Foo.sol/Bar.json`, it'll return the
|
|
331
|
+
* FQN `contracts/Foo.sol:Bar`
|
|
332
|
+
*/
|
|
333
|
+
private _getFullyQualifiedNameFromPath(absolutePath: string): string {
|
|
334
|
+
const sourceName = replaceBackslashes(
|
|
335
|
+
path.relative(this._artifactsPath, path.dirname(absolutePath))
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const contractName = path.basename(absolutePath).replace(".json", "");
|
|
339
|
+
|
|
340
|
+
return getFullyQualifiedName(sourceName, contractName);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
*
|
|
345
|
+
* @param givenName can be FQN or contract name
|
|
346
|
+
* @param names MUST match type of givenName (i.e. array of FQN's if givenName is FQN)
|
|
347
|
+
* @returns
|
|
348
|
+
*/
|
|
349
|
+
private static _getSimilarContractNames(
|
|
350
|
+
givenName: string,
|
|
351
|
+
names: string[]
|
|
352
|
+
): string[] {
|
|
353
|
+
let shortestDistance = EDIT_DISTANCE_THRESHOLD;
|
|
354
|
+
let mostSimilarNames: string[] = [];
|
|
355
|
+
for (const name of names) {
|
|
356
|
+
const distance = findDistance(givenName, name);
|
|
357
|
+
|
|
358
|
+
if (distance < shortestDistance) {
|
|
359
|
+
shortestDistance = distance;
|
|
360
|
+
mostSimilarNames = [name];
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (distance === shortestDistance) {
|
|
365
|
+
mostSimilarNames.push(name);
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return mostSimilarNames;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private async _getValidArtifactPathFromFullyQualifiedName(
|
|
374
|
+
fullyQualifiedName: string
|
|
375
|
+
): Promise<string | undefined> {
|
|
376
|
+
const artifactPath =
|
|
377
|
+
this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
|
|
378
|
+
|
|
379
|
+
try {
|
|
380
|
+
const trueCasePath = path.join(
|
|
381
|
+
this._artifactsPath,
|
|
382
|
+
await getFileTrueCase(
|
|
383
|
+
this._artifactsPath,
|
|
384
|
+
path.relative(this._artifactsPath, artifactPath)
|
|
385
|
+
)
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
if (artifactPath !== trueCasePath) {
|
|
389
|
+
throw new HardhatError(ERRORS.ARTIFACTS.WRONG_CASING, {
|
|
390
|
+
correct: this._getFullyQualifiedNameFromPath(trueCasePath),
|
|
391
|
+
incorrect: fullyQualifiedName,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return trueCasePath;
|
|
396
|
+
} catch (e) {
|
|
397
|
+
if (e instanceof FileNotFoundError) {
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
|
|
402
|
+
throw e;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
private _getValidArtifactPathFromFullyQualifiedNameSync(
|
|
407
|
+
fullyQualifiedName: string
|
|
408
|
+
): string | undefined {
|
|
409
|
+
const artifactPath =
|
|
410
|
+
this.formArtifactPathFromFullyQualifiedName(fullyQualifiedName);
|
|
411
|
+
|
|
412
|
+
try {
|
|
413
|
+
const trueCasePath = path.join(
|
|
414
|
+
this._artifactsPath,
|
|
415
|
+
getFileTrueCaseSync(
|
|
416
|
+
this._artifactsPath,
|
|
417
|
+
path.relative(this._artifactsPath, artifactPath)
|
|
418
|
+
)
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
if (artifactPath !== trueCasePath) {
|
|
422
|
+
throw new HardhatError(ERRORS.ARTIFACTS.WRONG_CASING, {
|
|
423
|
+
correct: this._getFullyQualifiedNameFromPath(trueCasePath),
|
|
424
|
+
incorrect: fullyQualifiedName,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return trueCasePath;
|
|
429
|
+
} catch (e) {
|
|
430
|
+
if (e instanceof FileNotFoundError) {
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
|
|
435
|
+
throw e;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
package/src/internal/cli/cli.ts
CHANGED
|
@@ -223,7 +223,7 @@ async function main() {
|
|
|
223
223
|
Reporter.setEnabled(true);
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
const envExtenders = ctx.extendersManager.
|
|
226
|
+
const envExtenders = ctx.extendersManager.getEnvironmentExtenders();
|
|
227
227
|
const taskDefinitions = ctx.tasksDSL.getTaskDefinitions();
|
|
228
228
|
|
|
229
229
|
const [abortAnalytics, hitPromise] = await analytics.sendTaskHit(taskName);
|
|
@@ -255,11 +255,16 @@ async function main() {
|
|
|
255
255
|
);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
const artifactsExtensions = ctx.extendersManager
|
|
259
|
+
.getArtifactsExtenders()
|
|
260
|
+
.map((artifactsExtender) => artifactsExtender(resolvedConfig));
|
|
261
|
+
|
|
258
262
|
const env = new Environment(
|
|
259
263
|
resolvedConfig,
|
|
260
264
|
hardhatArguments,
|
|
261
265
|
taskDefinitions,
|
|
262
266
|
envExtenders,
|
|
267
|
+
artifactsExtensions,
|
|
263
268
|
ctx.experimentalHardhatNetworkMessageTraceHooks,
|
|
264
269
|
userConfig
|
|
265
270
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ActionType,
|
|
3
|
+
ArtifactsExtender,
|
|
3
4
|
ConfigExtender,
|
|
4
5
|
ConfigurableTaskDefinition,
|
|
5
6
|
EnvironmentExtender,
|
|
@@ -127,7 +128,7 @@ export const types = argumentTypes;
|
|
|
127
128
|
export function extendEnvironment(extender: EnvironmentExtender) {
|
|
128
129
|
const ctx = HardhatContext.getHardhatContext();
|
|
129
130
|
const extenderManager = ctx.extendersManager;
|
|
130
|
-
extenderManager.
|
|
131
|
+
extenderManager.addEnvironmentExtender(extender);
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
export function extendConfig(extender: ConfigExtender) {
|
|
@@ -135,6 +136,17 @@ export function extendConfig(extender: ConfigExtender) {
|
|
|
135
136
|
ctx.configExtenders.push(extender);
|
|
136
137
|
}
|
|
137
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Accepts a function that receives the resolved configuration and returns an
|
|
141
|
+
* extra source of artifacts. This source has to implement the ArtifactsSource
|
|
142
|
+
* interface.
|
|
143
|
+
*/
|
|
144
|
+
export function extendArtifacts(artifactsExtender: ArtifactsExtender) {
|
|
145
|
+
const ctx = HardhatContext.getHardhatContext();
|
|
146
|
+
const extenderManager = ctx.extendersManager;
|
|
147
|
+
extenderManager.addArtifactsExtender(artifactsExtender);
|
|
148
|
+
}
|
|
149
|
+
|
|
138
150
|
// NOTE: This is experimental and will be removed. Please contact our team
|
|
139
151
|
// if you are planning to use it.
|
|
140
152
|
export function experimentalAddHardhatNetworkMessageTraceHook(
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
import { EnvironmentExtender } from "../../../types";
|
|
1
|
+
import { ArtifactsExtender, EnvironmentExtender } from "../../../types";
|
|
2
2
|
|
|
3
3
|
export class ExtenderManager {
|
|
4
|
-
private readonly
|
|
4
|
+
private readonly _environmentExtenders: EnvironmentExtender[] = [];
|
|
5
|
+
private readonly _artifactsExtenders: ArtifactsExtender[] = [];
|
|
5
6
|
|
|
6
|
-
public
|
|
7
|
-
this.
|
|
7
|
+
public addEnvironmentExtender(environmentExtender: EnvironmentExtender) {
|
|
8
|
+
this._environmentExtenders.push(environmentExtender);
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
public
|
|
11
|
-
|
|
11
|
+
public addArtifactsExtender(artifactsExtender: ArtifactsExtender) {
|
|
12
|
+
this._artifactsExtenders.push(artifactsExtender);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public getEnvironmentExtenders(): EnvironmentExtender[] {
|
|
16
|
+
return this._environmentExtenders;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public getArtifactsExtenders(): ArtifactsExtender[] {
|
|
20
|
+
return this._artifactsExtenders;
|
|
12
21
|
}
|
|
13
22
|
}
|
|
@@ -1058,6 +1058,15 @@ Please [report it](https://github.com/nomiclabs/hardhat/issues/new) to help us i
|
|
|
1058
1058
|
title: "Inferred artifact path doesn't exist",
|
|
1059
1059
|
description: `The inferred artifact path doesn't exist.
|
|
1060
1060
|
|
|
1061
|
+
Please [report it](https://github.com/nomiclabs/hardhat/issues/new) to help us improve Hardhat.`,
|
|
1062
|
+
shouldBeReported: true,
|
|
1063
|
+
},
|
|
1064
|
+
NO_SUPPORTED_ARTIFACT_SOURCE: {
|
|
1065
|
+
number: 904,
|
|
1066
|
+
message: "No configured artifact source can handle method %method%",
|
|
1067
|
+
title: "No configured artifact source can handle the request",
|
|
1068
|
+
description: `No configured artifact source can handle the requested method.
|
|
1069
|
+
|
|
1061
1070
|
Please [report it](https://github.com/nomiclabs/hardhat/issues/new) to help us improve Hardhat.`,
|
|
1062
1071
|
shouldBeReported: true,
|
|
1063
1072
|
},
|
|
@@ -2,6 +2,7 @@ import debug from "debug";
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
Artifacts as IArtifacts,
|
|
5
|
+
ArtifactsSource,
|
|
5
6
|
EnvironmentExtender,
|
|
6
7
|
ExperimentalHardhatNetworkMessageTraceHook,
|
|
7
8
|
HardhatArguments,
|
|
@@ -67,6 +68,7 @@ export class Environment implements HardhatRuntimeEnvironment {
|
|
|
67
68
|
public readonly hardhatArguments: HardhatArguments,
|
|
68
69
|
public readonly tasks: TasksMap,
|
|
69
70
|
extenders: EnvironmentExtender[] = [],
|
|
71
|
+
artifactsExtensions: ArtifactsSource[] = [],
|
|
70
72
|
experimentalHardhatNetworkMessageTraceHooks: ExperimentalHardhatNetworkMessageTraceHook[] = [],
|
|
71
73
|
public readonly userConfig: HardhatUserConfig = {}
|
|
72
74
|
) {
|
|
@@ -85,7 +87,7 @@ export class Environment implements HardhatRuntimeEnvironment {
|
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
this.artifacts = new Artifacts(config.paths.artifacts);
|
|
90
|
+
this.artifacts = new Artifacts(config.paths.artifacts, artifactsExtensions);
|
|
89
91
|
|
|
90
92
|
const provider = lazyObject(() => {
|
|
91
93
|
log(`Creating provider for network ${networkName}`);
|
|
@@ -24,6 +24,7 @@ import { ReadOnlyValidTransaction } from "../transactions/ReadOnlyValidTransacti
|
|
|
24
24
|
import { HardhatBlockchainInterface } from "../types/HardhatBlockchainInterface";
|
|
25
25
|
|
|
26
26
|
import { ReadOnlyValidEIP1559Transaction } from "../transactions/ReadOnlyValidEIP1559Transaction";
|
|
27
|
+
import { ReadOnlyValidUnknownTypeTransaction } from "../transactions/ReadOnlyValidUnknownTypeTransaction";
|
|
27
28
|
import { rpcToBlockData } from "./rpcToBlockData";
|
|
28
29
|
import { rpcToTxData } from "./rpcToTxData";
|
|
29
30
|
|
|
@@ -297,9 +298,20 @@ export class ForkBlockchain
|
|
|
297
298
|
rpcToTxData(transaction) as FeeMarketEIP1559TxData
|
|
298
299
|
);
|
|
299
300
|
} else {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
// we try to interpret unknown txs as legacy transactions, to support
|
|
302
|
+
// networks like Arbitrum that have non-standards tx types
|
|
303
|
+
try {
|
|
304
|
+
tx = new ReadOnlyValidUnknownTypeTransaction(
|
|
305
|
+
new Address(transaction.from),
|
|
306
|
+
Number(transaction.type),
|
|
307
|
+
rpcToTxData(transaction)
|
|
308
|
+
);
|
|
309
|
+
} catch (e: any) {
|
|
310
|
+
throw new InternalError(
|
|
311
|
+
`Could not process transaction with type ${transaction.type.toString()}`,
|
|
312
|
+
e
|
|
313
|
+
);
|
|
314
|
+
}
|
|
303
315
|
}
|
|
304
316
|
|
|
305
317
|
block.transactions.push(tx);
|