diff --git a/packages/backend/src/entity/Deployer.ts b/packages/backend/src/entity/Deployer.ts index 056ed64c..40d91a77 100644 --- a/packages/backend/src/entity/Deployer.ts +++ b/packages/backend/src/entity/Deployer.ts @@ -1,5 +1,4 @@ import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm'; -import { Deployment } from './Deployment'; @Entity() export class Deployer { diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index 5368d36f..79d0cc64 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -14,7 +14,7 @@ import { ApplicationDeploymentRequest, ApplicationDeploymentRemovalRequest } from './entity/Deployment'; -import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams } from './types'; +import { AppDeploymentRecord, AppDeploymentRemovalRecord, AuctionParams, DeployerRecord } from './types'; import { getConfig, getRepoDetails, sleep } from './utils'; const log = debug('snowball:registry'); @@ -25,6 +25,7 @@ const APP_DEPLOYMENT_REQUEST_TYPE = 'ApplicationDeploymentRequest'; const APP_DEPLOYMENT_REMOVAL_REQUEST_TYPE = 'ApplicationDeploymentRemovalRequest'; const APP_DEPLOYMENT_RECORD_TYPE = 'ApplicationDeploymentRecord'; const APP_DEPLOYMENT_REMOVAL_RECORD_TYPE = 'ApplicationDeploymentRemovalRecord'; +const WEBAPP_DEPLOYER_RECORD_TYPE = 'WebappDeployer' const SLEEP_DURATION = 1000; // TODO: Move registry code to registry-sdk/watcher-ts @@ -116,7 +117,7 @@ export class Registry { this.registryConfig.privateKey, fee ); - + log("Result: ", result); log(`Published application record ${result.id}`); log('Application record data:', applicationRecord); @@ -291,32 +292,33 @@ export class Registry { }; } - async getAuctionWinningDeployers( + async getAuctionWinningDeployerRecords( auctionId: string - ): Promise { + ): Promise { const records = await this.registry.getAuctionsByIds([auctionId]); const auctionResult = records[0]; - let deployerLrns = []; + let deployerRecords = []; const { winnerAddresses } = auctionResult; for (const auctionWinner of winnerAddresses) { - const deployerRecords = await this.registry.queryRecords( + const records = await this.registry.queryRecords( { paymentAddress: auctionWinner, + type: WEBAPP_DEPLOYER_RECORD_TYPE, }, true ); - for (const record of deployerRecords) { - if (record.names && record.names.length > 0) { - deployerLrns.push(record.names[0]); + for (const record of records) { + if (record.id) { + deployerRecords.push(record); break; } } } - return deployerLrns; + return deployerRecords; } async releaseDeployerFunds( diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index 897de44c..a559868c 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -140,7 +140,6 @@ type Deployer { updatedAt: String! } - type AuthResult { token: String! } diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index baa86b87..70b6b530 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -308,20 +308,21 @@ export class Service { completedAuctionIds.includes(project.auctionId!) ); - for (const project of projectsToBedeployed) { - const deployerLrns = await this.laconicRegistry.getAuctionWinningDeployers(project.auctionId!); - if (!deployerLrns) { + for (const project of projectsToBedeployed) { + const deployers = await this.laconicRegistry.getAuctionWinningDeployerRecords(project!.auctionId!); + + if (!deployers) { log(`No winning deployer for auction ${project!.auctionId}`); } else { - // Update project with deployer LRNs - await this.db.updateProjectById(project.id!, { - deployerLrns - }); + // TODO:Update project with deployer LRNs + // await this.db.updateProjectById(project.id!, { + // deployers + // }); - for (const deployer of deployerLrns) { + for (const deployer of deployers) { log(`Creating deployment for deployer LRN ${deployer}`); - await this.createDeploymentFromAuction(project, deployer); + await this.createDeploymentFromAuction(project, deployer.names[0]); } } } @@ -588,7 +589,7 @@ export class Service { domain: prodBranchDomains[0], commitHash: oldDeployment.commitHash, commitMessage: oldDeployment.commitMessage, - deployer: oldDeployment.deployer + deployer: oldDeployment.deployer }); return newDeployment; diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 0b6a3a1b..4ea4123c 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -82,3 +82,20 @@ export interface EnvironmentVariables { key: string, value: string, } + +export interface DeployerRecord { + id: string; + names: string[]; + owners: string[]; + bondId: string; + createTime: string; + expiryTime: string; + attributes: { + apiUrl: string; + name: string; + paymentAddress: string; + publicKey: string; + type: string; + version: string; + }; +}