@sentio/truffle-fetch-and-compile
Version:
Used to obtain external verified sources and compile them
81 lines • 4.39 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSupportedNetworks = exports.fetchAndCompileForDebugger = exports.fetchAndCompileMultiple = exports.fetchAndCompile = exports.fetchAndCompileForRecognizer = void 0;
const debug_1 = __importDefault(require("debug"));
const debug = (0, debug_1.default)("fetch-and-compile");
const recognizer_1 = require("./recognizer");
const multiple_1 = require("./multiple");
const debug_2 = require("./debug");
const fetch_1 = require("./fetch");
Object.defineProperty(exports, "fetchAndCompileForRecognizer", { enumerable: true, get: function () { return fetch_1.fetchAndCompileForRecognizer; } });
const utils_1 = require("./utils");
function fetchAndCompile(address, options, optimizerOverride) {
return __awaiter(this, void 0, void 0, function* () {
const normalizedOptions = (0, utils_1.normalizeFetchAndCompileOptions)(options);
const recognizer = new recognizer_1.SingleRecognizer(address);
yield (0, fetch_1.fetchAndCompileForRecognizer)(recognizer, normalizedOptions, optimizerOverride);
return recognizer.getResult();
});
}
exports.fetchAndCompile = fetchAndCompile;
/**
* warning: while this function deduplicates inputs,
* it does *not* make any further effort to avoid redundant
* fetches (e.g. if multiple addresses share the same source),
* unlike fetchAndCompileForDebugger
*/
function fetchAndCompileMultiple(addresses, options, optimizerOverride) {
return __awaiter(this, void 0, void 0, function* () {
const normalizedOptions = (0, utils_1.normalizeFetchAndCompileOptions)(options);
const recognizer = new multiple_1.MultipleRecognizer(addresses);
yield (0, fetch_1.fetchAndCompileForRecognizer)(recognizer, normalizedOptions, optimizerOverride);
return recognizer.getResults();
});
}
exports.fetchAndCompileMultiple = fetchAndCompileMultiple;
//note: this function is called primarily for its side-effects
//(i.e. adding compilations to the debugger), NOT its return value!
function fetchAndCompileForDebugger(bugger, //sorry; this should be a debugger object
options) {
return __awaiter(this, void 0, void 0, function* () {
const normalizedOptions = (0, utils_1.normalizeFetchAndCompileOptions)(options);
const recognizer = new debug_2.DebugRecognizer(bugger);
yield (0, fetch_1.fetchAndCompileForRecognizer)(recognizer, normalizedOptions);
return recognizer.getErrors();
});
}
exports.fetchAndCompileForDebugger = fetchAndCompileForDebugger;
function getSupportedNetworks(optionsOrFetcherNames) {
const fetcherNames = (0, utils_1.normalizeFetcherNames)(optionsOrFetcherNames);
const fetchers = (0, fetch_1.getSortedFetcherConstructors)(fetcherNames);
//strictly speaking these are fetcher constructors, but since we
//won't be using fetcher instances in this function, I'm not going
//to worry about the difference
let supportedNetworks = {};
for (const fetcher of fetchers) {
const fetcherNetworks = fetcher.getSupportedNetworks();
for (const name in fetcherNetworks) {
if (name in supportedNetworks) {
supportedNetworks[name].fetchers.push(fetcher.fetcherName);
}
else {
supportedNetworks[name] = Object.assign(Object.assign({}, fetcherNetworks[name]), { fetchers: [fetcher.fetcherName] });
}
}
}
return supportedNetworks;
}
exports.getSupportedNetworks = getSupportedNetworks;
//# sourceMappingURL=index.js.map