forked from cardano-foundation/cardano-rosetta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/search transactions (cardano-foundation#426)
* feat: add queries when searching by operation type * feat: add search transactions with type filter * feat: add filters to search transactions query * test: adapt network options test * refactor: move order by sentence to type queries * Add coin filter to search transactions (cardano-foundation#428) * feat: add coin filter to search transactions * feat: add operator enum * refactor: change coin query to not get hash and index by query param * feat: add currency filter and refact old createCompose method * feat: add coin filter to type query * feat: address filter to search API * feat: handle or operator when searching txs * refactor: improve total count query for requests with or operator * test: add test set up for search transactions endpoint * test: add tests for currency, coin and tx hash filters * test: add address and account identifier filter tests * test: add test cases for search txs with type filter * test: add tests for requests with composed filters at search api * doc: add doc for search api * fix: remove duplicated test * test: resolve test conflicts * doc: add how it works documentation for search api * refactor: add disable search api default value
- Loading branch information
Showing
26 changed files
with
12,998 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
cardano-rosetta-server/src/server/controllers/search-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { FastifyRequest } from 'fastify'; | ||
import { withNetworkValidation } from '../controllers/controllers-helper'; | ||
import { BlockService } from '../services/block-service'; | ||
import { CardanoService } from '../services/cardano-services'; | ||
import { NetworkService } from '../services/network-service'; | ||
import { mapToSearchTransactionsResponse } from '../utils/index-mapper'; | ||
|
||
export interface SearchController { | ||
searchTransactions( | ||
request: FastifyRequest<unknown, unknown, unknown, unknown, Components.Schemas.SearchTransactionsRequest> | ||
): Promise<Components.Schemas.SearchTransactionsResponse | Components.Schemas.Error>; | ||
} | ||
|
||
const configure = ( | ||
blockService: BlockService, | ||
cardanoService: CardanoService, | ||
PAGE_SIZE: number, | ||
networkService: NetworkService | ||
): SearchController => ({ | ||
searchTransactions: async request => | ||
withNetworkValidation( | ||
request.body.network_identifier, | ||
request, | ||
async () => { | ||
const logger = request.log; | ||
const searchTransactionsRequest = request.body; | ||
logger.debug({ searchTransactionsRequest }, '[searchTransactions] Request received'); | ||
let limit = searchTransactionsRequest.limit; | ||
if (limit === undefined || limit > PAGE_SIZE) { | ||
logger.info('[searchTransactions] Setting limit value ', PAGE_SIZE); | ||
limit = PAGE_SIZE; | ||
} | ||
let offset = searchTransactionsRequest.offset; | ||
if (offset === undefined || offset === null) { | ||
offset = 0; | ||
} | ||
const filters = { ...searchTransactionsRequest, limit, offset }; | ||
const transactionsFound = await blockService.findTransactionsByFilters(logger, filters, limit, offset); | ||
logger.info('[searchTransactions] Looking for transactions full data'); | ||
const transactions = await blockService.fillTransactions(logger, transactionsFound.transactions); | ||
const { poolDeposit } = await cardanoService.getDepositParameters(logger); | ||
const parameters = { | ||
transactions, | ||
poolDeposit, | ||
offset, | ||
limit, | ||
totalCount: transactionsFound.totalCount | ||
}; | ||
const toReturn = mapToSearchTransactionsResponse(parameters); | ||
logger.debug(toReturn, '[searchTransactions] About to return '); | ||
return toReturn; | ||
}, | ||
request.log, | ||
networkService | ||
) | ||
}); | ||
|
||
export default configure; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.