Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Can't list deployments #2701

Merged
merged 9 commits into from
May 21, 2024
4 changes: 3 additions & 1 deletion packages/grid_client/src/modules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ class BaseModule {

private async getMyContracts(fetch = false) {
if (fetch || !this.contracts) {
console.log("modulesNames:", modulesNames[this.moduleName]);
console.log("moduleName: ", this.moduleName);
let contracts = await this.tfClient.contracts.listMyNodeContracts({
graphqlURL: this.config.graphqlURL,
type: modulesNames[this.moduleName],
type: modulesNames[this.moduleName] ?? this.moduleName,
projectName: this.projectName,
});
const alreadyFetchedContracts: GqlNodeContract[] = [];
Expand Down
49 changes: 47 additions & 2 deletions packages/playground/src/utils/migration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
import type { BaseModule } from "@threefold/grid_client/dist/es6/modules/base";
import type { Contract } from "@threefold/tfchain_client";
import type { Contract, ExtrinsicResult } from "@threefold/tfchain_client";

import { BaseModule } from "../../../grid_client/dist/es6/modules/base";

async function _migrateOldFullVMs(module: BaseModule) {
module.moduleName = "Fullvm"; // Load old deployments that deployed with `Fullvm` type.
const deploymentNames = await module._list();
const contracts = await Promise.all(
deploymentNames.map(deploymentName => module.getDeploymentContracts(deploymentName)),
);

const extrinsics: ExtrinsicResult<Contract>[] = [];

const loadUpdateExtrinsics = async () => {
return await Promise.all(
contracts.flat().map(async contract => {
const oldData = JSON.parse(contract.deploymentData || "{}") as unknown as {
type: string;
name: string;
projectName: string;
};

if (oldData.type === "vm") {
return;
}

oldData.type = "vm";

const extrinsic = await module.tfClient.contracts.updateNode({
id: +contract.contractID,
data: JSON.stringify(oldData),
hash: contract.deploymentHash,
});

extrinsics.push(extrinsic);
BaseModule.newContracts.push(contract);
}),
);
};

if (deploymentNames.length) {
await loadUpdateExtrinsics();
return await module.tfClient.applyAllExtrinsics<Contract>(extrinsics);
}
}

export async function migrateModule(module: BaseModule) {
await _migrateOldFullVMs(module);
module.moduleName = "vm";
await module._list(); // force grid_client migration

const path = module.getNewDeploymentPath();
Expand Down
Loading