Skip to content

Commit

Permalink
fix: pox4 properties missing in various endpoints (#1977)
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x authored May 14, 2024
1 parent 85ea5af commit 521d771
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/api/routes/v2/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,12 @@ export function parseDbPoxSignerStacker(stacker: DbPoxCycleSignerStacker): PoxSt
stacked_amount: stacker.locked,
pox_address: stacker.pox_addr,
};
// Special handling for pool operator stackers
if (
stacker.name === 'stack-aggregation-commit-indexed' ||
stacker.name === 'stack-aggregation-commit'
) {
result.stacked_amount = stacker.amount_ustx;
}
return result;
}
2 changes: 2 additions & 0 deletions src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,8 @@ export interface DbPoxCycleSignerStacker {
stacker: string;
locked: string;
pox_addr: string;
name: string;
amount_ustx: string;
}

interface ReOrgEntities {
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/pg-store-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ export class PgStoreV2 extends BasePgStoreModule {
);
const results = await sql<(DbPoxCycleSignerStacker & { total: number })[]>`
WITH stackers AS (
SELECT DISTINCT ON (stacker) stacker, locked, pox_addr
SELECT DISTINCT ON (stacker) stacker, locked, pox_addr, amount_ustx, name
FROM pox4_events
WHERE canonical = true
AND microblock_canonical = true
Expand Down
12 changes: 8 additions & 4 deletions src/datastore/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,10 @@ export class PgStore extends BasePgStore {
if (!dbTx.found) {
return { found: false };
}
const cols =
poxTable === 'pox4_events' ? POX4_SYNTHETIC_EVENT_COLUMNS : POX_SYNTHETIC_EVENT_COLUMNS;
const queryResults = await sql<PoxSyntheticEventQueryResult[]>`
SELECT ${sql(POX_SYNTHETIC_EVENT_COLUMNS)}
SELECT ${sql(cols)}
FROM ${sql(poxTable)}
WHERE canonical = true AND microblock_canonical = true AND tx_id = ${txId}
ORDER BY block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC
Expand All @@ -1957,8 +1959,10 @@ export class PgStore extends BasePgStore {
poxTable: PoxSyntheticEventTable;
}): Promise<FoundOrNot<DbPoxSyntheticEvent[]>> {
return await this.sqlTransaction(async sql => {
const cols =
poxTable === 'pox4_events' ? POX4_SYNTHETIC_EVENT_COLUMNS : POX_SYNTHETIC_EVENT_COLUMNS;
const queryResults = await sql<PoxSyntheticEventQueryResult[]>`
SELECT ${sql(POX_SYNTHETIC_EVENT_COLUMNS)}
SELECT ${sql(cols)}
FROM ${sql(poxTable)}
WHERE canonical = true AND microblock_canonical = true AND stacker = ${principal}
ORDER BY block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC
Expand Down Expand Up @@ -2349,7 +2353,7 @@ export class PgStore extends BasePgStore {
// Special case for `handle-unlock` which should be returned if it is the last received event.

const pox4EventQuery = await sql<PoxSyntheticEventQueryResult[]>`
SELECT ${sql(POX_SYNTHETIC_EVENT_COLUMNS)}
SELECT ${sql(POX4_SYNTHETIC_EVENT_COLUMNS)}
FROM pox4_events
WHERE canonical = true AND microblock_canonical = true AND stacker = ${stxAddress}
AND block_height <= ${blockHeight}
Expand Down Expand Up @@ -4243,7 +4247,7 @@ export class PgStore extends BasePgStore {

let poxV4Unlocks: StxLockEventResult[] = [];
const pox4EventQuery = await sql<PoxSyntheticEventQueryResult[]>`
SELECT DISTINCT ON (stacker) stacker, ${sql(POX_SYNTHETIC_EVENT_COLUMNS)}
SELECT DISTINCT ON (stacker) stacker, ${sql(POX4_SYNTHETIC_EVENT_COLUMNS)}
FROM pox4_events
WHERE canonical = true AND microblock_canonical = true
AND block_height <= ${block.block_height}
Expand Down
20 changes: 20 additions & 0 deletions src/tests-2.5/pox-4-delegate-aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,26 @@ describe('PoX-4 - Delegate aggregation increase operations', () => {
name: 'stack-aggregation-commit-indexed',
pox_addr: delegateeAccount.btcTestnetAddr,
stacker: delegatorAccount.stxAddr,
data: expect.objectContaining({
signer_key: `0x${signerPubKey}`,
end_cycle_id: expect.stringMatching(/\d+/),
start_cycle_id: expect.stringMatching(/\d+/),
}),
})
);

const stackerRes: any = await fetchGet(`/extended/v1/pox4/stacker/${delegatorAccount.stxAddr}`);
expect(stackerRes).toBeDefined();
expect(stackerRes.results[0]).toEqual(
expect.objectContaining({
name: 'stack-aggregation-commit-indexed',
pox_addr: delegateeAccount.btcTestnetAddr,
stacker: delegatorAccount.stxAddr,
data: expect.objectContaining({
signer_key: `0x${signerPubKey}`,
end_cycle_id: expect.stringMatching(/\d+/),
start_cycle_id: expect.stringMatching(/\d+/),
}),
})
);
});
Expand Down

0 comments on commit 521d771

Please sign in to comment.