2024-04-24 06:38:56 +00:00
|
|
|
import debug from 'debug';
|
|
|
|
import { DataSource } from 'typeorm';
|
|
|
|
import path from 'path';
|
|
|
|
|
2024-10-16 08:43:51 +00:00
|
|
|
import { parseGasAndFees, Registry } from '@cerc-io/registry-sdk';
|
2024-04-24 06:38:56 +00:00
|
|
|
|
|
|
|
import { getConfig } from '../src/utils';
|
|
|
|
import { Deployment, DeploymentStatus } from '../src/entity/Deployment';
|
|
|
|
|
|
|
|
const log = debug('snowball:publish-deployment-removal-records');
|
|
|
|
|
|
|
|
async function main () {
|
2024-10-16 08:43:51 +00:00
|
|
|
const { registryConfig, database } = await getConfig();
|
2024-04-24 06:38:56 +00:00
|
|
|
|
|
|
|
const registry = new Registry(
|
|
|
|
registryConfig.gqlEndpoint,
|
|
|
|
registryConfig.restEndpoint,
|
2024-10-16 08:43:51 +00:00
|
|
|
{ chainId: registryConfig.chainId }
|
2024-04-24 06:38:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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-16 08:43:51 +00:00
|
|
|
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
|
|
|
|
|
2024-04-24 06:38:56 +00:00
|
|
|
const result = await registry.setRecord(
|
|
|
|
{
|
|
|
|
privateKey: registryConfig.privateKey,
|
|
|
|
record: applicationDeploymentRemovalRecord,
|
|
|
|
bondId: registryConfig.bondId
|
|
|
|
},
|
|
|
|
'',
|
2024-10-16 08:43:51 +00:00
|
|
|
fee
|
2024-04-24 06:38:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
log('Application deployment removal record data:', applicationDeploymentRemovalRecord);
|
2024-10-16 08:43:51 +00:00
|
|
|
log(`Application deployment removal record published: ${result.id}`);
|
2024-04-24 06:38:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((err) => {
|
|
|
|
log(err);
|
|
|
|
});
|