Upgrade from laconic-sdk to registry-sdk (#1)

Part of [Service provider auctions for web deployments](https://www.notion.so/Service-provider-auctions-for-web-deployments-104a6b22d47280dbad51d28aa3a91d75)

Co-authored-by: IshaVenikar <ishavenikar7@gmail.com>
Co-authored-by: Adw8 <adwaitgharpure@gmail.com>
Reviewed-on: cerc-io/snowballtools-base#1
This commit is contained in:
2024-10-16 08:43:51 +00:00
co-authored by IshaVenikar Adw8
parent e5a00016c1
commit 42bdd21089
19 changed files with 415 additions and 128 deletions
+2 -2
View File
@@ -22,10 +22,10 @@ yarn build --ignore frontend
#### Local
Copy the `envionments/local.toml.example` file to `envionments/local.toml`:
Copy the `environments/local.toml.example` file to `environments/local.toml`:
```zsh
cp envionments/local.toml.example envionments/local.toml
cp environments/local.toml.example environments/local.toml
```
#### Staging environment variables
@@ -36,9 +36,9 @@
bondId = ""
authority = ""
[registryConfig.fee]
amount = "200000"
denom = "aphoton"
gas = "750000"
gas = "200000"
fees = "200000alnt"
gasPrice = ""
[misc]
projectDomain = "apps.snowballtools.com"
+1 -1
View File
@@ -4,10 +4,10 @@
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"@cerc-io/registry-sdk": "^0.2.11",
"@graphql-tools/schema": "^10.0.2",
"@graphql-tools/utils": "^10.0.12",
"@octokit/oauth-app": "^6.1.0",
"@snowballtools/laconic-sdk": "^0.1.17",
"@turnkey/sdk-server": "^0.1.0",
"@types/debug": "^4.1.5",
"@types/express": "^4.17.21",
+2 -2
View File
@@ -36,9 +36,9 @@ export interface RegistryConfig {
fetchDeploymentRecordDelay: number;
authority: string;
fee: {
amount: string;
denom: string;
gas: string;
fees: string;
gasPrice: string;
};
}
+39 -32
View File
@@ -3,7 +3,7 @@ import assert from 'assert';
import { inc as semverInc } from 'semver';
import { DateTime } from 'luxon';
import { Registry as LaconicRegistry } from '@snowballtools/laconic-sdk';
import { Registry as LaconicRegistry, parseGasAndFees } from '@cerc-io/registry-sdk';
import { RegistryConfig } from './config';
import {
@@ -24,7 +24,7 @@ const APP_DEPLOYMENT_RECORD_TYPE = 'ApplicationDeploymentRecord';
const APP_DEPLOYMENT_REMOVAL_RECORD_TYPE = 'ApplicationDeploymentRemovalRecord';
const SLEEP_DURATION = 1000;
// TODO: Move registry code to laconic-sdk/watcher-ts
// TODO: Move registry code to registry-sdk/watcher-ts
export class Registry {
private registry: LaconicRegistry;
private registryConfig: RegistryConfig;
@@ -34,7 +34,7 @@ export class Registry {
this.registry = new LaconicRegistry(
registryConfig.gqlEndpoint,
registryConfig.restEndpoint,
registryConfig.chainId
{ chainId: registryConfig.chainId }
);
}
@@ -54,7 +54,7 @@ export class Registry {
applicationRecordId: string;
applicationRecordData: ApplicationRecord;
}> {
// Use laconic-sdk to publish record
// Use registry-sdk to publish record
// Reference: https://git.vdb.to/cerc-io/test-progressive-web-app/src/branch/main/scripts/publish-app-record.sh
// Fetch previous records
const records = await this.registry.queryRecords(
@@ -100,48 +100,50 @@ export class Registry {
...(packageJSON.version && { app_version: packageJSON.version })
};
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const result = await this.registry.setRecord(
{
privateKey: this.registryConfig.privateKey,
record: applicationRecord,
bondId: this.registryConfig.bondId
},
'',
this.registryConfig.fee
this.registryConfig.privateKey,
fee
);
log('Application record data:', applicationRecord);
// TODO: Discuss computation of CRN
const crn = this.getCrn(appName);
log(`Setting name: ${crn} for record ID: ${result.data.id}`);
// TODO: Discuss computation of LRN
const lrn = this.getLrn(appName);
log(`Setting name: ${lrn} for record ID: ${result.id}`);
await sleep(SLEEP_DURATION);
await this.registry.setName(
{ cid: result.data.id, crn },
{ cid: result.id, lrn },
this.registryConfig.privateKey,
this.registryConfig.fee
fee
);
await sleep(SLEEP_DURATION);
await this.registry.setName(
{ cid: result.data.id, crn: `${crn}@${applicationRecord.app_version}` },
{ cid: result.id, lrn: `${lrn}@${applicationRecord.app_version}` },
this.registryConfig.privateKey,
this.registryConfig.fee
fee
);
await sleep(SLEEP_DURATION);
await this.registry.setName(
{
cid: result.data.id,
crn: `${crn}@${applicationRecord.repository_ref}`
cid: result.id,
lrn: `${lrn}@${applicationRecord.repository_ref}`
},
this.registryConfig.privateKey,
this.registryConfig.fee
fee
);
return {
applicationRecordId: result.data.id,
applicationRecordId: result.id,
applicationRecordData: applicationRecord
};
}
@@ -156,12 +158,12 @@ export class Registry {
applicationDeploymentRequestId: string;
applicationDeploymentRequestData: ApplicationDeploymentRequest;
}> {
const crn = this.getCrn(data.appName);
const records = await this.registry.resolveNames([crn]);
const lrn = this.getLrn(data.appName);
const records = await this.registry.resolveNames([lrn]);
const applicationRecord = records[0];
if (!applicationRecord) {
throw new Error(`No record found for ${crn}`);
throw new Error(`No record found for ${lrn}`);
}
// Create record of type ApplicationDeploymentRequest and publish
@@ -169,11 +171,11 @@ export class Registry {
type: APP_DEPLOYMENT_REQUEST_TYPE,
version: '1.0.0',
name: `${applicationRecord.attributes.name}@${applicationRecord.attributes.app_version}`,
application: `${crn}@${applicationRecord.attributes.app_version}`,
application: `${lrn}@${applicationRecord.attributes.app_version}`,
dns: data.dns,
// TODO: Not set in test-progressive-web-app CI
// deployment: '$CERC_REGISTRY_DEPLOYMENT_CRN',
// deployment: '$CERC_REGISTRY_DEPLOYMENT_LRN',
// https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b
config: JSON.stringify({
@@ -189,20 +191,23 @@ export class Registry {
};
await sleep(SLEEP_DURATION);
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const result = await this.registry.setRecord(
{
privateKey: this.registryConfig.privateKey,
record: applicationDeploymentRequest,
bondId: this.registryConfig.bondId
},
'',
this.registryConfig.fee
this.registryConfig.privateKey,
fee
);
log(`Application deployment request record published: ${result.data.id}`);
log(`Application deployment request record published: ${result.id}`);
log('Application deployment request data:', applicationDeploymentRequest);
return {
applicationDeploymentRequestId: result.data.id,
applicationDeploymentRequestId: result.id,
applicationDeploymentRequestData: applicationDeploymentRequest
};
}
@@ -281,27 +286,29 @@ export class Registry {
deployment: data.deploymentId
};
const fee = parseGasAndFees(this.registryConfig.fee.gas, this.registryConfig.fee.fees);
const result = await this.registry.setRecord(
{
privateKey: this.registryConfig.privateKey,
record: applicationDeploymentRemovalRequest,
bondId: this.registryConfig.bondId
},
'',
this.registryConfig.fee
this.registryConfig.privateKey,
fee
);
log(`Application deployment removal request record published: ${result.data.id}`);
log(`Application deployment removal request record published: ${result.id}`);
log('Application deployment removal request data:', applicationDeploymentRemovalRequest);
return {
applicationDeploymentRemovalRequestId: result.data.id,
applicationDeploymentRemovalRequestId: result.id,
applicationDeploymentRemovalRequestData: applicationDeploymentRemovalRequest
};
}
getCrn (appName: string): string {
getLrn(appName: string): string {
assert(this.registryConfig.authority, "Authority doesn't exist");
return `crn://${this.registryConfig.authority}/applications/${appName}`;
return `lrn://${this.registryConfig.authority}/applications/${appName}`;
}
}
+2
View File
@@ -1,8 +1,10 @@
import assert from 'assert';
import fs from 'fs-extra';
import path from 'path';
import toml from 'toml';
import debug from 'debug';
import { DataSource, DeepPartial, EntityTarget, ObjectLiteral } from 'typeorm';
import { Config } from './config';
import { DEFAULT_CONFIG_FILE_PATH } from './constants';
+1 -3
View File
@@ -2,8 +2,6 @@ import * as fs from 'fs/promises';
import debug from 'debug';
import { getConfig } from '../src/utils';
import { Config } from '../src/config';
import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants';
const log = debug('snowball:delete-database');
@@ -13,7 +11,7 @@ const deleteFile = async (filePath: string) => {
};
const main = async () => {
const config = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
const config = await getConfig();
deleteFile(config.database.dbPath);
};
+1 -3
View File
@@ -16,8 +16,6 @@ import {
getEntities,
loadAndSaveData
} from '../src/utils';
import { Config } from '../src/config';
import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants';
const log = debug('snowball:initialize-database');
@@ -156,7 +154,7 @@ const generateTestData = async (dataSource: DataSource) => {
};
const main = async () => {
const config = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
const config = await getConfig();
const isDbPresent = await checkFileExists(config.database.dbPath);
if (!isDbPresent) {
+10 -9
View File
@@ -1,39 +1,40 @@
import debug from 'debug';
import { Registry } from '@snowballtools/laconic-sdk';
import { parseGasAndFees, Registry } from '@cerc-io/registry-sdk';
import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants';
import { Config } from '../src/config';
import { getConfig } from '../src/utils';
const log = debug('snowball:initialize-registry');
const DENOM = 'aphoton';
const DENOM = 'alnt';
const BOND_AMOUNT = '1000000000';
async function main () {
const { registryConfig } = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
const { registryConfig } = await getConfig();
// TODO: Get authority names from args
const authorityNames = ['snowballtools', registryConfig.authority];
const registry = new Registry(registryConfig.gqlEndpoint, registryConfig.restEndpoint, registryConfig.chainId);
const registry = new Registry(registryConfig.gqlEndpoint, registryConfig.restEndpoint, {chainId: registryConfig.chainId});
const bondId = await registry.getNextBondId(registryConfig.privateKey);
log('bondId:', bondId);
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
await registry.createBond(
{ denom: DENOM, amount: BOND_AMOUNT },
registryConfig.privateKey,
registryConfig.fee
fee
);
for await (const name of authorityNames) {
await registry.reserveAuthority({ name }, registryConfig.privateKey, registryConfig.fee);
await registry.reserveAuthority({ name }, registryConfig.privateKey, fee);
log('Reserved authority name:', name);
await registry.setAuthorityBond(
{ name, bondId },
registryConfig.privateKey,
registryConfig.fee
fee
);
log(`Bond ${bondId} set for authority ${name}`);
}
@@ -2,22 +2,20 @@ import debug from 'debug';
import { DataSource } from 'typeorm';
import path from 'path';
import { Registry } from '@snowballtools/laconic-sdk';
import { parseGasAndFees, Registry } from '@cerc-io/registry-sdk';
import { Config } from '../src/config';
import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants';
import { getConfig } from '../src/utils';
import { Deployment, DeploymentStatus, Environment } from '../src/entity/Deployment';
const log = debug('snowball:publish-deploy-records');
async function main () {
const { registryConfig, database, misc } = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
async function main() {
const { registryConfig, database, misc } = await getConfig();
const registry = new Registry(
registryConfig.gqlEndpoint,
registryConfig.restEndpoint,
registryConfig.chainId
{ chainId: registryConfig.chainId }
);
const dataSource = new DataSource({
@@ -61,6 +59,8 @@ async function main () {
url
};
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
const result = await registry.setRecord(
{
privateKey: registryConfig.privateKey,
@@ -68,7 +68,7 @@ async function main () {
bondId: registryConfig.bondId
},
'',
registryConfig.fee
fee
);
// Remove deployment for project subdomain if deployment is for production environment
@@ -82,12 +82,12 @@ async function main () {
bondId: registryConfig.bondId
},
'',
registryConfig.fee
fee
);
}
log('Application deployment record data:', applicationDeploymentRecord);
log(`Application deployment record published: ${result.data.id}`);
log(`Application deployment record published: ${result.id}`);
}
}
@@ -2,22 +2,20 @@ import debug from 'debug';
import { DataSource } from 'typeorm';
import path from 'path';
import { Registry } from '@cerc-io/laconic-sdk';
import { parseGasAndFees, Registry } from '@cerc-io/registry-sdk';
import { Config } from '../src/config';
import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants';
import { getConfig } from '../src/utils';
import { Deployment, DeploymentStatus } from '../src/entity/Deployment';
const log = debug('snowball:publish-deployment-removal-records');
async function main () {
const { registryConfig, database, misc } = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
const { registryConfig, database } = await getConfig();
const registry = new Registry(
registryConfig.gqlEndpoint,
registryConfig.restEndpoint,
registryConfig.chainId
{ chainId: registryConfig.chainId }
);
const dataSource = new DataSource({
@@ -47,6 +45,8 @@ async function main () {
request: deployment.applicationDeploymentRemovalRequestId,
}
const fee = parseGasAndFees(registryConfig.fee.gas, registryConfig.fee.fees);
const result = await registry.setRecord(
{
privateKey: registryConfig.privateKey,
@@ -54,11 +54,11 @@ async function main () {
bondId: registryConfig.bondId
},
'',
registryConfig.fee
fee
);
log('Application deployment removal record data:', applicationDeploymentRemovalRecord);
log(`Application deployment removal record published: ${result.data.id}`);
log(`Application deployment removal record published: ${result.id}`);
}
}