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
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class BaseModule {
if (fetch || !this.contracts) {
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
54 changes: 52 additions & 2 deletions packages/playground/src/utils/migration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
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";

Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
/**
* `_migrateOldFullVMs` is a function is implemented to list all old `FullVM` that listed in the old `Playground` with type `Fullvm`
* @param `module` takes the `module` which is an instance of the `BaseModule`.
* @returns Applying the extrinsic in the chain with the batch request.
*/
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);
}),
);
};

Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
if (deploymentNames.length) {
await loadUpdateExtrinsics();
return await module.tfClient.applyAllExtrinsics<Contract>(extrinsics);
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
}
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
}

export async function migrateModule(module: BaseModule) {
await _migrateOldFullVMs(module);
module.moduleName = "vm";
await module._list(); // force grid_client migration
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved

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