snowballtools-base/packages/backend/test/publish-deployment-removal-records.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

import debug from 'debug';
import { DataSource } from 'typeorm';
import path from 'path';
2024-10-03 04:50:38 +00:00
import { Registry } from '@cerc-io/registry-sdk';
2024-10-03 04:50:38 +00:00
import { getConfig, parseGasAndFees } from '../src/utils';
import { Deployment, DeploymentStatus } from '../src/entity/Deployment';
const log = debug('snowball:publish-deployment-removal-records');
async function main () {
2024-10-03 04:50:38 +00:00
const { registryConfig, database } = await getConfig();
const registry = new Registry(
registryConfig.gqlEndpoint,
registryConfig.restEndpoint,
2024-10-03 04:50:38 +00:00
{ chainId: registryConfig.chainId }
);
const dataSource = new DataSource({
type: 'better-sqlite3',
database: database.dbPath,
synchronize: true,
entities: [path.join(__dirname, '../src/entity/*')]
});
await dataSource.initialize();
const deploymentRepository = dataSource.getRepository(Deployment);
const deployments = await deploymentRepository.find({
relations: {
project: true
},
where: {
status: DeploymentStatus.Deleting
}
});
for await (const deployment of deployments) {
const applicationDeploymentRemovalRecord = {
type: "ApplicationDeploymentRemovalRecord",
version: "1.0.0",
deployment: deployment.applicationDeploymentRecordId,
request: deployment.applicationDeploymentRemovalRequestId,
}
2024-10-03 04:50:38 +00:00
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
const result = await registry.setRecord(
{
privateKey: registryConfig.privateKey,
record: applicationDeploymentRemovalRecord,
bondId: registryConfig.bondId
},
'',
2024-10-03 04:50:38 +00:00
fee
);
log('Application deployment removal record data:', applicationDeploymentRemovalRecord);
2024-10-03 04:50:38 +00:00
log(`Application deployment removal record published: ${result.id}`);
}
}
main().catch((err) => {
log(err);
});