Skip to content

Commit

Permalink
fix: fixed an issue happened when listing
Browse files Browse the repository at this point in the history
- Updated the import of 'BaseModule' in 'migration.ts' to be local dir instead the dist one to fix the un-exported issue
- Flated the array of the contracts then looped over them all
- Updated the moduleName after listing the 'Fullvm' to 'vm' again to list the other deployemtns
- Pushed the newly changed contract to the 'newContracts' array to avoid the lag of gql
- Updated the 'moduleName' in 'base.ts' to take 'Fullvm' if the 'moduleNames' is undefined
  • Loading branch information
Mahmoud-Emad committed May 15, 2024
1 parent 96d71a4 commit 014e51f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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
21 changes: 14 additions & 7 deletions packages/playground/src/utils/migration.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import type { BaseModule } from "@threefold/grid_client/dist/es6/modules/base";
import type { Contract, ExtrinsicResult } from "@threefold/tfchain_client";

export async function migrateOldFullVMs(module: BaseModule) {
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 contracts = await module._list();
const wrapedContracts = await Promise.all(contracts.map(contractName => module.getDeploymentContracts(contractName)));
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(
wrapedContracts[0].map(async contract => {
contracts.flat().map(async contract => {
const oldData = JSON.parse(contract.deploymentData || "{}") as unknown as {
type: string;
name: string;
Expand All @@ -21,25 +25,28 @@ export async function migrateOldFullVMs(module: BaseModule) {
}

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 (contracts.length) {
if (deploymentNames.length) {
await loadUpdateExtrinsics();
return await module.tfClient.applyAllExtrinsics<Contract>(extrinsics);
}
}

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

const path = module.getNewDeploymentPath();
Expand Down

0 comments on commit 014e51f

Please sign in to comment.