hardhat-scilla-plugin
Version:
Hardhat TypeScript plugin for scilla testing
86 lines • 4.02 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.contractFromAddress = contractFromAddress;
const fs_1 = __importDefault(require("fs"));
const plugins_1 = require("hardhat/plugins");
const ScillaContractProxy = __importStar(require("../parser/ScillaContractProxy"));
const ScillaContractsInfoUpdater = __importStar(require("../parser/ScillaContractsInfoUpdater"));
const ScillaParser_1 = require("../parser/ScillaParser");
const ZilliqaUtils = __importStar(require("../ZilliqaUtils"));
const ScillaContractDeployer = __importStar(require("./ScillaContractDeployer"));
async function contractFromAddress(hre, address) {
var _a;
// Fetch the code from the blockchain
if (ScillaContractDeployer.setup === null) {
throw new plugins_1.HardhatPluginError("hardhat-scilla-plugin", "Please call the initZilliqa function.");
}
const setup = ScillaContractDeployer.setup;
const zilliqa = setup.zilliqa;
const codeResult = await zilliqa.blockchain.getSmartContractCode(address);
if (codeResult !== undefined &&
codeResult.result !== undefined &&
codeResult.result.code !== undefined) {
const codeText = codeResult.result.code;
// Now parse it. Sadly, need a file for this. Even more sadly, there's no good way to do it
// generically (tempy causes us to throw module errors :-( )
const tempFile = ZilliqaUtils.createTemporaryFile("contract", "scilla");
fs_1.default.writeFileSync(tempFile, codeText);
const parsed = await (0, ScillaParser_1.parseScilla)(tempFile);
const hash = ScillaContractsInfoUpdater.getFileHash(tempFile);
const contractInfo = {
hash,
path: address,
parsedContract: parsed,
};
ZilliqaUtils.deleteTemporaryFile(tempFile);
// OK. Now I need to create a contract factory ..
// We don't actually need the ABI
const contract = zilliqa.contracts.at(address, undefined);
// Now we can fill the proxies in.
ScillaContractProxy.injectConnectors(setup, contract);
// Set the default deployer
const deployer = (_a = setup.zilliqa.wallet.defaultAccount) !== null && _a !== void 0 ? _a : setup.accounts[0];
contract.connect(deployer);
// Now build a ContractInfo
ScillaContractProxy.injectProxies(setup, contractInfo, contract);
return contract;
}
return undefined;
}
//# sourceMappingURL=ScillaContractInteractor.js.map