Skip to content

Commit

Permalink
refactor: rename activities events
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Sep 8, 2023
1 parent 6b3ce97 commit 6968cea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/pg/brc20/brc20-pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class Brc20PgStore extends BasePgStoreModule {
WHERE id = (SELECT brc20_deploy_id FROM validated_transfer)
)
INSERT INTO brc20_events (operation, inscription_id, genesis_location_id, brc20_deploy_id, transfer_id) (
SELECT 'transfer_send', inscription_id, ${location.id}, brc20_deploy_id, id
SELECT 'transfer_send', ${location.inscription_id}, ${location.id}, brc20_deploy_id, id
FROM validated_transfer
)
`;
Expand Down Expand Up @@ -341,24 +341,24 @@ export class Brc20PgStore extends BasePgStoreModule {
}

async rollBackInscription(args: { inscription: DbInscription }): Promise<void> {
const activities = await this.sql<DbBrc20Event[]>`
const events = await this.sql<DbBrc20Event[]>`
SELECT * FROM brc20_events WHERE inscription_id = ${args.inscription.id}
`;
if (activities.count === 0) return;
if (events.count === 0) return;
// Traverse all activities generated by this inscription and roll back actions that are NOT
// otherwise handled by the ON DELETE CASCADE postgres constraint.
for (const activity of activities) {
switch (activity.operation) {
for (const event of events) {
switch (event.operation) {
case 'deploy':
// Deploy events are handled by the ON DELETE CASCADE postgres constraint.
// - tx_count is lost successfully, since the deploy will be deleted.
break;
case 'mint':
await this.rollBackMint(activity);
await this.rollBackMint(event);
break;
case 'transfer':
case 'transfer_send':
await this.rollBackTransfer(activity);
await this.rollBackTransfer(event);
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/brc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,10 @@ describe('BRC-20', () => {
ticker: 'ABCD',
tx_count: '2', // only the deploy and mint remain
} as Brc20TokenResponse),
expect.objectContaining({
ticker: 'PEPE',
tx_count: '1',
} as Brc20TokenResponse),
]);
});
});
Expand Down

0 comments on commit 6968cea

Please sign in to comment.