@sentio/truffle-fetch-and-compile
Version:
Used to obtain external verified sources and compile them
63 lines • 2.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SingleRecognizer = void 0;
const debug_1 = __importDefault(require("debug"));
const debug = (0, debug_1.default)("fetch-and-compile:recognizer");
class SingleRecognizer {
constructor(address) {
this.recognized = false;
this.address = address;
}
getResult() {
return {
compileResult: this.compileResult,
sourceInfo: this.sourceInfo,
fetchedVia: this.fetchedVia
};
}
/*
* Interface methods follow
*/
isAddressUnrecognized(address) {
return !this.recognized || address !== this.address; //I guess?
}
getAnUnrecognizedAddress() {
return this.recognized ? undefined : this.address;
}
markUnrecognizable(address, reason, error) {
//just throw...
if (error) {
throw error;
}
else if (reason) {
switch (reason) {
case "fetch":
throw new Error(`Error in fetching sources for ${address}`);
case "compile":
throw new Error(`Error in compiling sources for ${address}`);
case "language":
throw new Error(`Sources for ${address} were not in a supported language`);
}
}
else {
throw new Error(`No verified sources found for ${address}`);
}
}
markBadFetcher(_fetcherName) {
//do nothing
}
addCompiledInfo(info, address) {
this.compileResult = info.compileResult;
this.sourceInfo = info.sourceInfo;
if (address === this.address) {
//I guess? this should never be false
this.recognized = true;
this.fetchedVia = info.fetchedVia;
}
}
}
exports.SingleRecognizer = SingleRecognizer;
//# sourceMappingURL=recognizer.js.map