Skip to content

Commit 145ffa2

Browse files
committed
fix: provision
1 parent c97717b commit 145ffa2

File tree

9 files changed

+95
-22
lines changed

9 files changed

+95
-22
lines changed

infrastructure/web3-adapter/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function spinUpEVault(
3737
registryEntropy,
3838
namespace,
3939
verificationId: finalVerificationCode,
40+
publicKey: "0x0000000000000000000000000000000000000000"
4041
},
4142
);
4243

platforms/cerberus/src/services/GroupService.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,10 @@ export class GroupService {
4040
}
4141

4242
async getUserGroups(userId: string): Promise<Group[]> {
43-
console.log("Getting groups for user:", userId);
44-
45-
// First, let's get all groups and filter manually to debug
4643
const allGroups = await this.groupRepository.find({
4744
relations: ['participants']
4845
});
49-
50-
console.log("All groups found:", allGroups.length);
51-
allGroups.forEach(group => {
52-
console.log(`Group ${group.id} (${group.name}):`, {
53-
participants: group.participants?.map(p => p.id) || [],
54-
hasUser: group.participants?.some(p => p.id === userId) || false
55-
});
56-
});
5746

58-
// Filter groups where user is a participant
5947
const userGroups = allGroups.filter(group =>
6048
group.participants?.some(participant => participant.id === userId)
6149
);

platforms/evoting-api/src/controllers/WebhookController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export class WebhookController {
150150
group.owner = local.data.owner as string;
151151
group.admins = adminIds.map(id => ({ id } as User));
152152
group.participants = participants;
153+
group.charter = local.data.charter as string;
153154

154155
this.adapter.addToLockedIds(localId);
155156
await this.groupService.groupRepository.save(group);

platforms/group-charter-manager-api/src/database/entities/Group.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export class Group {
3131
@Column({ type: "text", nullable: true })
3232
charter!: string; // Markdown content for the group charter
3333

34+
@Column({ nullable: true })
35+
ename!: string
36+
3437
@ManyToMany("User")
3538
@JoinTable({
3639
name: "group_participants",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class Migration1756064053488 implements MigrationInterface {
4+
name = 'Migration1756064053488'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`ALTER TABLE "group" ADD "ename" character varying`);
8+
}
9+
10+
public async down(queryRunner: QueryRunner): Promise<void> {
11+
await queryRunner.query(`ALTER TABLE "group" DROP COLUMN "ename"`);
12+
}
13+
14+
}

platforms/group-charter-manager-api/src/services/GroupService.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,11 @@ export class GroupService {
6060
}
6161

6262
async getUserGroups(userId: string): Promise<any[]> {
63-
console.log("Getting groups for user:", userId);
64-
6563
// First, let's get all groups and filter manually to debug
6664
const allGroups = await this.groupRepository.find({
6765
relations: ['participants']
6866
});
6967

70-
console.log("All groups found:", allGroups.length);
71-
allGroups.forEach(group => {
72-
console.log(`Group ${group.id} (${group.name}):`, {
73-
participants: group.participants?.map(p => p.id) || [],
74-
hasUser: group.participants?.some(p => p.id === userId) || false
75-
});
76-
});
77-
7868
// Filter groups where user is a participant AND group has at least 3 participants
7969
const userGroups = allGroups.filter(group => {
8070
const isUserParticipant = group.participants?.some(participant => participant.id === userId);

platforms/group-charter-manager-api/src/web3adapter/watchers/subscriber.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ObjectLiteral,
88
} from "typeorm";
99
import { Web3Adapter } from "../../../../../infrastructure/web3-adapter/src/index";
10+
import { createGroupEVault } from "../../../../../infrastructure/web3-adapter/src/index";
1011
import path from "path";
1112
import dotenv from "dotenv";
1213
import { AppDataSource } from "../../database/data-source";
@@ -177,6 +178,20 @@ export class PostgresSubscriber implements EntitySubscriberInterface {
177178

178179
if (fullEntity) {
179180
console.log("✅ Full entity loaded:", { id: fullEntity.id, tableName: event.metadata.tableName });
181+
182+
// Check if this is a Group entity and if charter was just added (not updated)
183+
if (entityName === "Group" && fullEntity.charter && fullEntity.charter.trim() !== "") {
184+
// Check if this group doesn't have an ename yet (meaning eVault wasn't created)
185+
if (!fullEntity.ename) {
186+
console.log("Group just got chartered, spinning up eVault for group:", fullEntity.id);
187+
188+
// Fire and forget eVault creation
189+
this.spinUpGroupEVault(fullEntity).catch(error => {
190+
console.error("Failed to create eVault for group:", fullEntity.id, error);
191+
});
192+
}
193+
}
194+
180195
entity = (await this.enrichEntity(
181196
fullEntity,
182197
event.metadata.tableName,
@@ -354,6 +369,55 @@ console.log("hmm?")
354369
}
355370
}
356371

372+
/**
373+
* Spin up eVault for a newly chartered group
374+
*/
375+
private async spinUpGroupEVault(group: any): Promise<void> {
376+
try {
377+
console.log("Starting eVault creation for group:", group.id);
378+
379+
// Get environment variables for eVault creation
380+
const registryUrl = process.env.PUBLIC_REGISTRY_URL;
381+
const provisionerUrl = process.env.PUBLIC_PROVISIONER_URL;
382+
383+
if (!registryUrl || !provisionerUrl) {
384+
throw new Error("Missing required environment variables for eVault creation");
385+
}
386+
387+
// Prepare group data for eVault creation
388+
const groupData = {
389+
name: group.name || "Unnamed Group",
390+
avatar: group.avatarUrl,
391+
description: group.description,
392+
members: group.participants?.map((p: any) => p.id) || [],
393+
admins: group.admins || [],
394+
owner: group.owner,
395+
charter: group.charter
396+
};
397+
398+
console.log("Creating eVault with data:", groupData);
399+
400+
// Create the eVault (this is the long-running operation)
401+
const evaultResult = await createGroupEVault(
402+
registryUrl,
403+
provisionerUrl,
404+
groupData
405+
);
406+
407+
console.log("eVault created successfully:", evaultResult);
408+
409+
// Update the group with the ename (w3id)
410+
const groupRepository = AppDataSource.getRepository("Group");
411+
await groupRepository.update(group.id, { ename: evaultResult.w3id });
412+
413+
console.log("Group updated with ename:", evaultResult.w3id);
414+
415+
} catch (error: any) {
416+
console.error("Error creating eVault for group:", group.id, error);
417+
throw error; // Re-throw to be caught by the caller
418+
}
419+
}
420+
357421
/**
358422
* Convert TypeORM entity to plain object
359423
*/

platforms/group-charter-manager/src/app/charter/[id]/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface Group {
3232
admins: string[];
3333
participants: any[];
3434
charter?: string;
35+
ename?: string; // eVault identifier (w3id)
3536
createdAt: string;
3637
updatedAt: string;
3738
}
@@ -212,6 +213,11 @@ export default function CharterDetail({
212213
<h2 className="text-3xl font-bold text-gray-800 mb-2">
213214
{group.name || 'Unnamed Group'}
214215
</h2>
216+
{group.ename && (
217+
<div className="text-xs text-gray-500 font-mono mb-2">
218+
{group.ename}
219+
</div>
220+
)}
215221
<div className="text-gray-600 mb-2">
216222
Group Charter
217223
</div>

platforms/group-charter-manager/src/app/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface Group {
4545
admins: string[];
4646
participants: any[];
4747
charter?: string;
48+
ename?: string; // eVault identifier (w3id)
4849
hasSigned?: boolean; // Add signing status field
4950
createdAt: string;
5051
updatedAt: string;
@@ -229,6 +230,11 @@ export default function Dashboard() {
229230
<h3 className="font-semibold text-gray-900 mb-1">
230231
{group.name || 'Unnamed Group'}
231232
</h3>
233+
{group.ename && (
234+
<p className="text-xs text-gray-500 font-mono mb-1">
235+
{group.ename}
236+
</p>
237+
)}
232238
<div className="text-sm text-gray-600 space-y-1">
233239
{hasCharter ? (
234240
hasSigned ? (

0 commit comments

Comments
 (0)