Skip to content

Commit

Permalink
fix: fix mempool transaction issue response issue
Browse files Browse the repository at this point in the history
 make changes to mempool response as per rosetta
  • Loading branch information
asimm241 authored and zone117x committed Oct 6, 2020
1 parent 256d442 commit 4bb146d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 31 deletions.
22 changes: 10 additions & 12 deletions src/api/routes/rosetta/mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { parseLimitQuery, parsePagingQueryInput } from '../../pagination';
import { rosettaValidateRequest, ValidSchema, makeRosettaError } from '../../rosetta-validate';
import {
RosettaMempoolResponse,
RosettaMempoolTransactionResponse,
RosettaTransaction,
} from '@blockstack/stacks-blockchain-api-types';
import { getOperations } from '../../../rosetta-helpers';
Expand All @@ -28,23 +29,17 @@ export function createRosettaMempoolRouter(db: DataStore): RouterWithAsync {
return;
}

const limit = req.body.metadata
? parseMempoolTxQueryLimit(req.body.metadata.limit ?? 100)
: 100;
const offset = req.body.metadata ? parsePagingQueryInput(req.body.metadata.offset ?? 0) : 0;
const { results: txResults, total } = await db.getMempoolTxIdList({ offset, limit });
// const limit = req.body.metadata
// ? parseMempoolTxQueryLimit(req.body.metadata.limit ?? 100)
// : 100;
// const offset = req.body.metadata ? parsePagingQueryInput(req.body.metadata.offset ?? 0) : 0;
const { results: txResults, total } = await db.getMempoolTxIdList();

const transaction_identifiers = txResults.map(tx => {
return { hash: tx.tx_id };
});
const metadata = {
limit: limit,
total: total,
offset: offset,
};
const response: RosettaMempoolResponse = {
transaction_identifiers,
metadata,
};
res.json(response);
});
Expand All @@ -68,10 +63,13 @@ export function createRosettaMempoolRouter(db: DataStore): RouterWithAsync {
}

const operations = getOperations(mempoolTxQuery.result);
const result: RosettaTransaction = {
const transaction: RosettaTransaction = {
transaction_identifier: { hash: tx_id },
operations: operations,
};
const result: RosettaMempoolTransactionResponse = {
transaction: transaction,
};
res.json(result);
});

Expand Down
5 changes: 1 addition & 4 deletions src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ export interface DataStore extends DataStoreEventEmitter {
limit: number;
offset: number;
}): Promise<{ results: DbMempoolTx[]; total: number }>;
getMempoolTxIdList(args: {
limit: number;
offset: number;
}): Promise<{ results: DbMempoolTxId[]; total: number }>;
getMempoolTxIdList(): Promise<{ results: DbMempoolTxId[]; total: number }>;
getTx(txId: string): Promise<FoundOrNot<DbTx>>;
getTxList(args: {
limit: number;
Expand Down
5 changes: 1 addition & 4 deletions src/datastore/memory-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ export class MemoryDataStore extends (EventEmitter as { new (): DataStoreEventEm
throw new Error('not yet implemented');
}

getMempoolTxIdList(args: {
limit: number;
offset: number;
}): Promise<{ results: DbMempoolTx[]; total: number }> {
getMempoolTxIdList(): Promise<{ results: DbMempoolTx[]; total: number }> {
throw new Error('not yet implemented');
}

Expand Down
13 changes: 2 additions & 11 deletions src/datastore/postgres-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1152,13 +1152,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
return { results: parsed, total: totalQuery.rows[0].count };
}

async getMempoolTxIdList({
limit,
offset,
}: {
limit: number;
offset: number;
}): Promise<{ results: DbMempoolTxId[]; total: number }> {
async getMempoolTxIdList(): Promise<{ results: DbMempoolTxId[]; total: number }> {
const totalQuery = await this.pool.query<{ count: number }>(
`
SELECT COUNT(*)::integer
Expand All @@ -1170,10 +1164,7 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
SELECT ${MEMPOOL_TX_ID_COLUMNS}
FROM mempool_txs
ORDER BY receipt_time DESC
LIMIT $1
OFFSET $2
`,
[limit, offset]
`
);
const parsed = resultQuery.rows.map(r => {
const tx: DbMempoolTxId = {
Expand Down

0 comments on commit 4bb146d

Please sign in to comment.