Skip to content

Commit 747af28

Browse files
authored
Update ggf.js
1 parent 386ee33 commit 747af28

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/space/ggf.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ggf.js - Galactic Governance Framework
1+
// src/space/ggf.js - Galactic Governance Framework
22

33
const crypto = require('crypto');
44
const { v4: uuidv4 } = require('uuid');
@@ -10,7 +10,7 @@ class GalacticGovernanceFramework extends EventEmitter {
1010
constructor() {
1111
super();
1212
this.proposals = []; // Store proposals
13-
this.votes = []; // Store votes
13+
this.votes = new Map(); // Store votes as a map for quick access
1414
this.entities = new Set(); // Unique set of authorized entities
1515
this.logger = this.createLogger(); // Create a logger
1616
this.tachyonicCommunicationProtocol = null; // Placeholder for tachyonic communication protocol
@@ -24,6 +24,10 @@ class GalacticGovernanceFramework extends EventEmitter {
2424
log: (message) => {
2525
const timestamp = new Date().toISOString();
2626
console.log(`[${timestamp}] ${message}`);
27+
},
28+
error: (message) => {
29+
const timestamp = new Date().toISOString();
30+
console.error(`[${timestamp}] ERROR: ${message}`);
2731
}
2832
};
2933
}
@@ -33,7 +37,7 @@ class GalacticGovernanceFramework extends EventEmitter {
3337
this.tachyonicCommunicationProtocol = tachyonicProtocol;
3438
this.tbpg.initializeTBPG(tachyonicProtocol); // Initialize TBPG with the protocol
3539
this.asgm.initializeASGM(); // Initialize ASGM
36-
console.log("Galactic Governance Framework initialized with tachyonic protocol and ASGM.");
40+
this.logger.log("Galactic Governance Framework initialized with tachyonic protocol and ASGM.");
3741
}
3842

3943
// Register a new entity
@@ -81,12 +85,15 @@ class GalacticGovernanceFramework extends EventEmitter {
8185
}
8286

8387
// Check if the entity has already voted
84-
if (this.votes.find(v => v.proposalId === proposalId && v.entityId === entityId)) {
88+
if (this.votes.has(proposalId) && this.votes.get(proposalId).has(entityId)) {
8589
throw new Error('Entity has already voted on this proposal');
8690
}
8791

8892
proposal.votes += 1;
89-
this.votes.push({ proposalId, entityId });
93+
if (!this.votes.has(proposalId)) {
94+
this.votes.set(proposalId, new Set());
95+
}
96+
this.votes.get(proposalId).add(entityId);
9097
this.logger.log(`Vote cast by ${entityId} on proposal ${proposalId}`);
9198
this.emit('voteCast', { proposalId, entityId });
9299

@@ -113,7 +120,7 @@ class GalacticGovernanceFramework extends EventEmitter {
113120
getVotingResults(proposalId) {
114121
const proposal = this.getProposalById(proposalId);
115122
if (!proposal) {
116-
throw new Error('Proposal not found');
123+
throw new Error ('Proposal not found');
117124
}
118125
return {
119126
proposalId,
@@ -126,7 +133,6 @@ class GalacticGovernanceFramework extends EventEmitter {
126133
executeProposal(proposalId) {
127134
const proposal = this.getProposalById(proposalId);
128135
if (!proposal) throw new Error('Proposal not found');
129-
}
130136
if (proposal.status !== 'approved') {
131137
throw new Error('Proposal must be approved before execution');
132138
}
@@ -148,7 +154,7 @@ class GalacticGovernanceFramework extends EventEmitter {
148154
type: 'proposal',
149155
proposals,
150156
});
151-
console.log(`Proposal sent to ${node}:`, proposals);
157+
this.logger.log(`Proposal sent to ${node}: ${JSON.stringify(proposals)}`);
152158
});
153159
}
154160

0 commit comments

Comments
 (0)