Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/listeners/horizonBondEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const server = new Horizon.Server(HORIZON_URL)
* @param {ReplayService} replayService Service to capture failures
* @param {function} onEvent Callback for each bond creation event
*/
export function subscribeBondCreationEvents(onEvent?: (event: { identity: { id: string }; bond: { id: string; amount: string; duration: string | null } }) => void) {
export function subscribeBondCreationEvents(onEvent?: (event: { identity: { id: string }; bond: { id: string; address: string; amount: string; duration: string | null } }) => void) {
// Example: Listen to operations of type 'create_bond' (custom event)
let cursor = 'now';
let stream;
Expand All @@ -42,8 +42,6 @@ export function subscribeBondCreationEvents(onEvent?: (event: { identity: { id:
});
};
startStream();

startStream()
}

/**
Expand All @@ -57,6 +55,7 @@ function parseBondEvent(op: { source_account: string; id: string; amount: string
identity: { id: op.source_account },
bond: {
id: op.id,
address: op.source_account,
amount: op.amount,
duration: op.duration ?? null,
},
Expand Down
24 changes: 8 additions & 16 deletions src/migrations/001_initial_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
type: 'serial',
primaryKey: true,
},
bond_id: {
type: 'integer',
notNull: true,
},
attester_address: {
type: 'varchar(64)',
notNull: true,
Expand All @@ -71,21 +75,12 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
type: 'varchar(64)',
notNull: true,
},
weight: {
score: {
type: 'integer',
notNull: true,
},
timestamp: {
type: 'timestamp',
notNull: true,
},
is_valid: {
type: 'boolean',
notNull: true,
default: true,
},
transaction_hash: {
type: 'varchar(128)',
note: {
type: 'text',
},
created_at: {
type: 'timestamp',
Expand All @@ -97,10 +92,7 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
// Add indexes for attestation queries
pgm.createIndex('attestations', 'attester_address')
pgm.createIndex('attestations', 'subject_address')
pgm.createIndex('attestations', 'is_valid')
pgm.createIndex('attestations', 'timestamp')
// Composite index for common query pattern
pgm.createIndex('attestations', ['subject_address', 'is_valid'])
pgm.createIndex('attestations', 'bond_id')

// Reputation scores table - caches calculated scores
pgm.createTable('reputation_scores', {
Expand Down
6 changes: 4 additions & 2 deletions src/migrations/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ export function validateConfig(config: MigrationConfig): boolean {
}

// Basic URL validation for PostgreSQL
if (!config.databaseUrl.startsWith('postgres://') && !config.databaseUrl.startsWith('postgresql://')) {
throw new Error('DATABASE_URL must be a valid PostgreSQL connection string starting with postgres:// or postgresql://')
if (!config.databaseUrl.startsWith('postgres://') &&
!config.databaseUrl.startsWith('postgresql://') &&
!config.databaseUrl.startsWith('pg-mem://')) {
throw new Error('DATABASE_URL must be a valid PostgreSQL connection string starting with postgres://, postgresql:// or pg-mem://')
}

if (!config.migrationsDir) {
Expand Down
Loading
Loading