Skip to content

Commit aad6cca

Browse files
committed
feat: handle pox-3 force unlocks, pox-4 events, and revoke-delegate-stx event
1 parent 0359fe7 commit aad6cca

File tree

15 files changed

+624
-549
lines changed

15 files changed

+624
-549
lines changed

src/api/controllers/db-controller.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ import {
5959
BaseTx,
6060
DbMinerReward,
6161
StxUnlockEvent,
62-
DbPox2Event,
63-
DbPox3Event,
62+
DbPoxSyntheticEvent,
6463
} from '../../datastore/common';
6564
import { unwrapOptional, FoundOrNot, unixEpochToIso, EMPTY_HASH_256, ChainID } from '../../helpers';
6665
import { serializePostCondition, serializePostConditionMode } from '../serializers/post-conditions';
6766
import { getOperations, parseTransactionMemo } from '../../rosetta/rosetta-helpers';
6867
import { PgStore } from '../../datastore/pg-store';
69-
import { Pox2EventName } from '../../pox-helpers';
68+
import { SyntheticPoxEventName } from '../../pox-helpers';
7069
import { logger } from '../../logger';
7170

7271
export function parseTxTypeStrings(values: string[]): TransactionType[] {
@@ -193,7 +192,7 @@ export function getAssetEventTypeString(
193192
}
194193
}
195194

196-
export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
195+
export function parsePoxSyntheticEvent(poxEvent: DbPoxSyntheticEvent) {
197196
const baseInfo = {
198197
block_height: poxEvent.block_height,
199198
tx_id: poxEvent.tx_id,
@@ -208,7 +207,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
208207
name: poxEvent.name,
209208
};
210209
switch (poxEvent.name) {
211-
case Pox2EventName.HandleUnlock: {
210+
case SyntheticPoxEventName.HandleUnlock: {
212211
return {
213212
...baseInfo,
214213
data: {
@@ -217,7 +216,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
217216
},
218217
};
219218
}
220-
case Pox2EventName.StackStx: {
219+
case SyntheticPoxEventName.StackStx: {
221220
return {
222221
...baseInfo,
223222
data: {
@@ -228,7 +227,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
228227
},
229228
};
230229
}
231-
case Pox2EventName.StackIncrease: {
230+
case SyntheticPoxEventName.StackIncrease: {
232231
return {
233232
...baseInfo,
234233
data: {
@@ -237,7 +236,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
237236
},
238237
};
239238
}
240-
case Pox2EventName.StackExtend: {
239+
case SyntheticPoxEventName.StackExtend: {
241240
return {
242241
...baseInfo,
243242
data: {
@@ -246,7 +245,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
246245
},
247246
};
248247
}
249-
case Pox2EventName.DelegateStx: {
248+
case SyntheticPoxEventName.DelegateStx: {
250249
return {
251250
...baseInfo,
252251
data: {
@@ -256,7 +255,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
256255
},
257256
};
258257
}
259-
case Pox2EventName.DelegateStackStx: {
258+
case SyntheticPoxEventName.DelegateStackStx: {
260259
return {
261260
...baseInfo,
262261
data: {
@@ -268,7 +267,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
268267
},
269268
};
270269
}
271-
case Pox2EventName.DelegateStackIncrease: {
270+
case SyntheticPoxEventName.DelegateStackIncrease: {
272271
return {
273272
...baseInfo,
274273
data: {
@@ -278,7 +277,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
278277
},
279278
};
280279
}
281-
case Pox2EventName.DelegateStackExtend: {
280+
case SyntheticPoxEventName.DelegateStackExtend: {
282281
return {
283282
...baseInfo,
284283
data: {
@@ -288,7 +287,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
288287
},
289288
};
290289
}
291-
case Pox2EventName.StackAggregationCommit: {
290+
case SyntheticPoxEventName.StackAggregationCommit: {
292291
return {
293292
...baseInfo,
294293
data: {
@@ -297,7 +296,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
297296
},
298297
};
299298
}
300-
case Pox2EventName.StackAggregationCommitIndexed: {
299+
case SyntheticPoxEventName.StackAggregationCommitIndexed: {
301300
return {
302301
...baseInfo,
303302
data: {
@@ -306,7 +305,7 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
306305
},
307306
};
308307
}
309-
case Pox2EventName.StackAggregationIncrease: {
308+
case SyntheticPoxEventName.StackAggregationIncrease: {
310309
return {
311310
...baseInfo,
312311
data: {
@@ -315,8 +314,17 @@ export function parsePox2Event(poxEvent: DbPox2Event | DbPox3Event) {
315314
},
316315
};
317316
}
317+
case SyntheticPoxEventName.RevokeDelegateStx: {
318+
return {
319+
...baseInfo,
320+
data: {
321+
amount_ustx: poxEvent.data.amount_ustx.toString(),
322+
delegate_to: poxEvent.data.delegate_to,
323+
},
324+
};
325+
}
318326
default:
319-
throw new Error(`Unexpected Pox2 event name ${(poxEvent as DbPox2Event).name}`);
327+
throw new Error(`Unexpected Pox2 event name ${(poxEvent as DbPoxSyntheticEvent).name}`);
320328
}
321329
}
322330

src/api/rosetta-constants.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,3 @@ export const RosettaSchemas: Record<string, SchemaFiles> = {
476476
'@stacks/stacks-blockchain-api-types/api/rosetta/rosetta-construction-combine-response.schema.json',
477477
},
478478
};
479-
480-
export const PoxContractIdentifier = {
481-
pox1: {
482-
mainnet: 'SP000000000000000000002Q6VF78.pox',
483-
testnet: 'ST000000000000000000002AMW42H.pox',
484-
},
485-
pox2: {
486-
mainnet: 'SP000000000000000000002Q6VF78.pox-2',
487-
testnet: 'ST000000000000000000002AMW42H.pox-2',
488-
},
489-
pox3: {
490-
mainnet: 'SP000000000000000000002Q6VF78.pox-3',
491-
testnet: 'ST000000000000000000002AMW42H.pox-3',
492-
},
493-
} as const;

src/api/routes/pox2.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { isValidBitcoinAddress, tryConvertC32ToBtc } from '../../helpers';
1212
import { InvalidRequestError, InvalidRequestErrorType } from '../../errors';
1313
import { getPagingQueryLimit, parsePagingQueryInput, ResourceType } from '../pagination';
1414
import { PgStore } from '../../datastore/pg-store';
15-
import { parsePox2Event } from '../controllers/db-controller';
15+
import { parsePoxSyntheticEvent } from '../controllers/db-controller';
1616
import { validatePrincipal, validateRequestHexInput } from '../query-helpers';
1717

1818
export function createPox2EventsRouter(db: PgStore): express.Router {
@@ -24,8 +24,12 @@ export function createPox2EventsRouter(db: PgStore): express.Router {
2424
const limit = getPagingQueryLimit(ResourceType.Pox2Event, req.query.limit);
2525
const offset = parsePagingQueryInput(req.query.offset ?? 0);
2626

27-
const queryResults = await db.getPox2Events({ offset, limit });
28-
const parsedResult = queryResults.map(r => parsePox2Event(r));
27+
const queryResults = await db.getPoxSyntheticEvents({
28+
offset,
29+
limit,
30+
poxTable: 'pox2_events',
31+
});
32+
const parsedResult = queryResults.map(r => parsePoxSyntheticEvent(r));
2933
const response = {
3034
limit,
3135
offset,
@@ -41,12 +45,15 @@ export function createPox2EventsRouter(db: PgStore): express.Router {
4145
asyncHandler(async (req, res) => {
4246
const { tx_id } = req.params;
4347
validateRequestHexInput(tx_id);
44-
const queryResults = await db.getPox2EventsForTx({ txId: tx_id });
48+
const queryResults = await db.getPoxSyntheticEventsForTx({
49+
txId: tx_id,
50+
poxTable: 'pox2_events',
51+
});
4552
if (!queryResults.found) {
4653
res.status(404).json({ error: `could not find transaction by ID ${tx_id}` });
4754
return;
4855
}
49-
const parsedResult = queryResults.result.map(r => parsePox2Event(r));
56+
const parsedResult = queryResults.result.map(r => parsePoxSyntheticEvent(r));
5057
const response = {
5158
results: parsedResult,
5259
};
@@ -60,12 +67,15 @@ export function createPox2EventsRouter(db: PgStore): express.Router {
6067
asyncHandler(async (req, res) => {
6168
const { principal } = req.params;
6269
validatePrincipal(principal);
63-
const queryResults = await db.getPox2EventsForStacker({ principal });
70+
const queryResults = await db.getPoxSyntheticEventsForStacker({
71+
principal,
72+
poxTable: 'pox2_events',
73+
});
6474
if (!queryResults.found) {
6575
res.status(404).json({ error: `could not find principal ${principal}` });
6676
return;
6777
}
68-
const parsedResult = queryResults.result.map(r => parsePox2Event(r));
78+
const parsedResult = queryResults.result.map(r => parsePoxSyntheticEvent(r));
6979
const response = {
7080
results: parsedResult,
7181
};

src/api/routes/pox3.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as express from 'express';
22
import { asyncHandler } from '../async-handler';
33

44
import { PgStore } from '../../datastore/pg-store';
5-
import { parsePox2Event } from '../controllers/db-controller';
5+
import { parsePoxSyntheticEvent } from '../controllers/db-controller';
66
import { ResourceType, getPagingQueryLimit, parsePagingQueryInput } from '../pagination';
77
import { validatePrincipal, validateRequestHexInput } from '../query-helpers';
88

@@ -15,8 +15,12 @@ export function createPox3EventsRouter(db: PgStore): express.Router {
1515
const limit = getPagingQueryLimit(ResourceType.Pox2Event, req.query.limit);
1616
const offset = parsePagingQueryInput(req.query.offset ?? 0);
1717

18-
const queryResults = await db.getPox3Events({ offset, limit });
19-
const parsedResult = queryResults.map(r => parsePox2Event(r)); // parsePox2Event is pox-3 compatible
18+
const queryResults = await db.getPoxSyntheticEvents({
19+
offset,
20+
limit,
21+
poxTable: 'pox3_events',
22+
});
23+
const parsedResult = queryResults.map(r => parsePoxSyntheticEvent(r));
2024
const response = {
2125
limit,
2226
offset,
@@ -31,12 +35,15 @@ export function createPox3EventsRouter(db: PgStore): express.Router {
3135
asyncHandler(async (req, res) => {
3236
const { tx_id } = req.params;
3337
validateRequestHexInput(tx_id);
34-
const queryResults = await db.getPox3EventsForTx({ txId: tx_id });
38+
const queryResults = await db.getPoxSyntheticEventsForTx({
39+
txId: tx_id,
40+
poxTable: 'pox3_events',
41+
});
3542
if (!queryResults.found) {
3643
res.status(404).json({ error: `could not find transaction by ID ${tx_id}` });
3744
return;
3845
}
39-
const parsedResult = queryResults.result.map(r => parsePox2Event(r));
46+
const parsedResult = queryResults.result.map(r => parsePoxSyntheticEvent(r));
4047
const response = {
4148
results: parsedResult,
4249
};
@@ -49,12 +56,15 @@ export function createPox3EventsRouter(db: PgStore): express.Router {
4956
asyncHandler(async (req, res) => {
5057
const { principal } = req.params;
5158
validatePrincipal(principal);
52-
const queryResults = await db.getPox3EventsForStacker({ principal });
59+
const queryResults = await db.getPoxSyntheticEventsForStacker({
60+
principal,
61+
poxTable: 'pox3_events',
62+
});
5363
if (!queryResults.found) {
5464
res.status(404).json({ error: `could not find principal ${principal}` });
5565
return;
5666
}
57-
const parsedResult = queryResults.result.map(r => parsePox2Event(r));
67+
const parsedResult = queryResults.result.map(r => parsePoxSyntheticEvent(r));
5868
const response = {
5969
results: parsedResult,
6070
};

0 commit comments

Comments
 (0)