"use strict";
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateRegistry = exports.migrateIssuer = exports.migratePrivateIssuer = void 0;
const ethers_1 = require("ethers");
const const_1 = require("./const");
const contracts_1 = require("./contracts");
function migratePrivateIssuer(provider, deployKey, issuerAddress) {
    return __awaiter(this, void 0, void 0, function* () {
        const privateKeyDeployment = deployKey.startsWith('0x') ? deployKey : `0x${deployKey}`;
        const wallet = new ethers_1.ethers.Wallet(privateKeyDeployment, provider);
        const privateIssuerContract = yield new contracts_1.factories.PrivateIssuerFactory(wallet).deploy();
        yield privateIssuerContract.deployed();
        const tx = yield privateIssuerContract.initialize(issuerAddress);
        yield tx.wait();
        const version = yield privateIssuerContract.version();
        console.log(`PrivateIssuer ${version} created at ${privateIssuerContract.address}`);
        return privateIssuerContract;
    });
}
exports.migratePrivateIssuer = migratePrivateIssuer;
function migrateIssuer(provider, deployKey, registryAddress) {
    return __awaiter(this, void 0, void 0, function* () {
        const privateKeyDeployment = deployKey.startsWith('0x') ? deployKey : `0x${deployKey}`;
        const wallet = new ethers_1.ethers.Wallet(privateKeyDeployment, provider);
        const issuerContract = yield new contracts_1.factories.IssuerFactory(wallet).deploy();
        yield issuerContract.deployed();
        const tx = yield issuerContract.initialize(const_1.CertificateTopic.IREC, registryAddress);
        yield tx.wait();
        const version = yield issuerContract.version();
        console.log(`Issuer ${version} created at ${issuerContract.address}`);
        return issuerContract;
    });
}
exports.migrateIssuer = migrateIssuer;
function migrateRegistry(provider, deployKey, uri = '') {
    return __awaiter(this, void 0, void 0, function* () {
        const privateKeyDeployment = deployKey.startsWith('0x') ? deployKey : `0x${deployKey}`;
        const wallet = new ethers_1.ethers.Wallet(privateKeyDeployment, provider);
        const registryContract = yield new contracts_1.factories.RegistryExtendedFactory(wallet).deploy(uri);
        yield registryContract.deployed();
        console.log(`RegistryExtended.sol deployed at ${registryContract.address}`);
        return registryContract;
    });
}
exports.migrateRegistry = migrateRegistry;
//# sourceMappingURL=migrate.js.map