Skip to content

Commit 17e4b07

Browse files
authored
Merge pull request #2010 from hirosystems/develop
Cut beta release
2 parents 3badbf0 + ae78773 commit 17e4b07

File tree

10 files changed

+2679
-63
lines changed

10 files changed

+2679
-63
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ jobs:
413413
parallel: true
414414

415415
test-subnets:
416+
if: false
416417
runs-on: ubuntu-latest
417418
steps:
418419
- uses: actions/checkout@v3

docs/openapi.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@ paths:
219219
items:
220220
type: string
221221
enum: [coinbase, token_transfer, smart_contract, contract_call, poison_microblock, tenure_change]
222+
- name: sort_by
223+
in: query
224+
description: Option to sort results by block height, timestamp, or fee
225+
required: false
226+
schema:
227+
type: string
228+
enum: [block_height, burn_block_time, fee]
229+
example: burn_block_time
230+
default: block_height
231+
- name: order
232+
in: query
233+
description: Option to sort results in ascending or descending order
234+
required: false
235+
schema:
236+
type: string
237+
enum: [asc, desc]
238+
example: desc
239+
default: desc
222240
- name: unanchored
223241
in: query
224242
description: Include transaction data from unanchored (i.e. unconfirmed) microblocks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
2+
exports.up = pgm => {
3+
pgm.createIndex('txs', 'burn_block_time');
4+
pgm.createIndex('txs', 'fee_rate');
5+
};
6+
7+
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
8+
exports.down = pgm => {
9+
pgm.dropIndex('txs', 'burn_block_time');
10+
pgm.dropIndex('txs', 'fee_rate');
11+
};

src/api/routes/tx.ts

+31
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,43 @@ export function createTxRouter(db: PgStore): express.Router {
6565
txTypeFilter = [];
6666
}
6767

68+
let order: 'asc' | 'desc' | undefined;
69+
if (req.query.order) {
70+
if (
71+
typeof req.query.order === 'string' &&
72+
(req.query.order === 'asc' || req.query.order === 'desc')
73+
) {
74+
order = req.query.order;
75+
} else {
76+
throw new InvalidRequestError(
77+
`The "order" query parameter must be a 'desc' or 'asc'`,
78+
InvalidRequestErrorType.invalid_param
79+
);
80+
}
81+
}
82+
83+
let sortBy: 'block_height' | 'burn_block_time' | 'fee' | undefined;
84+
if (req.query.sort_by) {
85+
if (
86+
typeof req.query.sort_by === 'string' &&
87+
['block_height', 'burn_block_time', 'fee'].includes(req.query.sort_by)
88+
) {
89+
sortBy = req.query.sort_by as typeof sortBy;
90+
} else {
91+
throw new InvalidRequestError(
92+
`The "sort_by" query parameter must be 'block_height', 'burn_block_time', or 'fee'`,
93+
InvalidRequestErrorType.invalid_param
94+
);
95+
}
96+
}
6897
const includeUnanchored = isUnanchoredRequest(req, res, next);
6998
const { results: txResults, total } = await db.getTxList({
7099
offset,
71100
limit,
72101
txTypeFilter,
73102
includeUnanchored,
103+
order,
104+
sortBy,
74105
});
75106
const results = txResults.map(tx => parseDbTx(tx));
76107
const response: TransactionResults = { limit, offset, total, results };

src/datastore/helpers.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -273,29 +273,18 @@ export function prefixedCols(columns: string[], prefix: string): string[] {
273273
return columns.map(c => `${prefix}.${c}`);
274274
}
275275

276-
/**
277-
* Concatenates column names to use on a query. Necessary when one or more of those columns is complex enough
278-
* so that postgres.js can't figure out how to list it (e.g. abi column, aggregates, partitions, etc.).
279-
* @param sql - SQL client
280-
* @param columns - list of columns
281-
* @returns raw SQL column list string
282-
*/
283-
export function unsafeCols(sql: PgSqlClient, columns: string[]): postgres.PendingQuery<any> {
284-
return sql.unsafe(columns.join(', '));
285-
}
286-
287276
/**
288277
* Shorthand function that returns a column query to retrieve the smart contract abi when querying transactions
289278
* that may be of type `contract_call`. Usually used alongside `TX_COLUMNS` or `MEMPOOL_TX_COLUMNS`.
290279
* @param tableName - Name of the table that will determine the transaction type. Defaults to `txs`.
291280
* @returns `string` - abi column select statement portion
292281
*/
293-
export function abiColumn(tableName: string = 'txs'): string {
294-
return `
295-
CASE WHEN ${tableName}.type_id = ${DbTxTypeId.ContractCall} THEN (
282+
export function abiColumn(sql: PgSqlClient, tableName: string = 'txs'): postgres.Fragment {
283+
return sql`
284+
CASE WHEN ${sql(tableName)}.type_id = ${DbTxTypeId.ContractCall} THEN (
296285
SELECT abi
297286
FROM smart_contracts
298-
WHERE smart_contracts.contract_id = ${tableName}.contract_call_contract_id
287+
WHERE smart_contracts.contract_id = ${sql(tableName)}.contract_call_contract_id
299288
ORDER BY abi != 'null' DESC, canonical DESC, microblock_canonical DESC, block_height DESC
300289
LIMIT 1
301290
) END as abi

0 commit comments

Comments
 (0)