1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | var __importStar = (this && this.__importStar) || function (mod) {
|
6 | if (mod && mod.__esModule) return mod;
|
7 | var result = {};
|
8 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
9 | result["default"] = mod;
|
10 | return result;
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const fs_extra_1 = __importDefault(require("fs-extra"));
|
14 | const path = __importStar(require("path"));
|
15 | const errors_1 = require("./core/errors");
|
16 | const errors_list_1 = require("./core/errors-list");
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function getArtifactFromContractOutput(contractName, contractOutput) {
|
24 | const evmBytecode = contractOutput.evm && contractOutput.evm.bytecode;
|
25 | let bytecode = evmBytecode && evmBytecode.object ? evmBytecode.object : "";
|
26 | if (bytecode.slice(0, 2).toLowerCase() !== "0x") {
|
27 | bytecode = `0x${bytecode}`;
|
28 | }
|
29 | const evmDeployedBytecode = contractOutput.evm && contractOutput.evm.deployedBytecode;
|
30 | let deployedBytecode = evmDeployedBytecode && evmDeployedBytecode.object
|
31 | ? evmDeployedBytecode.object
|
32 | : "";
|
33 | if (deployedBytecode.slice(0, 2).toLowerCase() !== "0x") {
|
34 | deployedBytecode = `0x${deployedBytecode}`;
|
35 | }
|
36 | const linkReferences = evmBytecode && evmBytecode.linkReferences ? evmBytecode.linkReferences : {};
|
37 | const deployedLinkReferences = evmDeployedBytecode && evmDeployedBytecode.linkReferences
|
38 | ? evmDeployedBytecode.linkReferences
|
39 | : {};
|
40 | return {
|
41 | contractName,
|
42 | abi: contractOutput.abi,
|
43 | bytecode,
|
44 | deployedBytecode,
|
45 | linkReferences,
|
46 | deployedLinkReferences,
|
47 | };
|
48 | }
|
49 | exports.getArtifactFromContractOutput = getArtifactFromContractOutput;
|
50 | function getArtifactPath(artifactsPath, contractName) {
|
51 | return path.join(artifactsPath, `${contractName}.json`);
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | async function saveArtifact(artifactsPath, artifact) {
|
60 | await fs_extra_1.default.ensureDir(artifactsPath);
|
61 | await fs_extra_1.default.writeJSON(path.join(artifactsPath, `${artifact.contractName}.json`), artifact, {
|
62 | spaces: 2,
|
63 | });
|
64 | }
|
65 | exports.saveArtifact = saveArtifact;
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | async function readArtifact(artifactsPath, contractName) {
|
73 | const artifactPath = getArtifactPath(artifactsPath, contractName);
|
74 | if (!fs_extra_1.default.pathExistsSync(artifactPath)) {
|
75 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.ARTIFACTS.NOT_FOUND, { contractName });
|
76 | }
|
77 | return fs_extra_1.default.readJson(artifactPath);
|
78 | }
|
79 | exports.readArtifact = readArtifact;
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | function readArtifactSync(artifactsPath, contractName) {
|
87 | const artifactPath = getArtifactPath(artifactsPath, contractName);
|
88 | if (!fs_extra_1.default.pathExistsSync(artifactPath)) {
|
89 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.ARTIFACTS.NOT_FOUND, { contractName });
|
90 | }
|
91 | return fs_extra_1.default.readJsonSync(artifactPath);
|
92 | }
|
93 | exports.readArtifactSync = readArtifactSync;
|
94 |
|
\ | No newline at end of file |