From 45aba4f1f18c021a83afda7940b79305924347ff Mon Sep 17 00:00:00 2001 From: Seongjae Choi Date: Mon, 15 Apr 2019 18:11:17 +0900 Subject: [PATCH] Add addressFilter parameter to the router of the tx-APIs addressFilter isn't doing anything in this patch yet. src/models/logic/transactions.ts should be changed in the future. --- src/models/logic/transaction.ts | 4 ++++ src/routers/transaction.ts | 40 +++++++++++++++++++++++++++++++++ src/routers/validator.ts | 11 +++++++++ 3 files changed, 55 insertions(+) diff --git a/src/models/logic/transaction.ts b/src/models/logic/transaction.ts index 445fdbf..c4664a3 100644 --- a/src/models/logic/transaction.ts +++ b/src/models/logic/transaction.ts @@ -223,6 +223,7 @@ export async function applyTransaction( export async function getPendingTransactions(params: { address?: string | null; + addressFilter?: string[] | null; assetType?: H160 | null; type?: string[] | null; page: number; @@ -316,6 +317,7 @@ export async function getAllPendingTransactionHashes() { export async function getNumberOfPendingTransactions(params: { address?: string | null; + addressFilter?: string[] | null; assetType?: H160 | null; type?: string[] | null; }) { @@ -459,6 +461,7 @@ export async function removeOutdatedPendings( export async function getTransactions(params: { address?: string | null; + addressFilter?: string[] | null; assetType?: H160 | null; type?: string[] | null; tracker?: H256 | null; @@ -611,6 +614,7 @@ export async function getNumberOfEachTransactionType( export async function getNumberOfTransactions(params: { address?: string | null; + addressFilter?: string[] | null; assetType?: H160 | null; type?: string[] | null; tracker?: H256 | null; diff --git a/src/routers/transaction.ts b/src/routers/transaction.ts index c9194b7..e9b058a 100644 --- a/src/routers/transaction.ts +++ b/src/routers/transaction.ts @@ -43,6 +43,11 @@ export function handle(context: IndexerContext, router: Router) { * in: query * required: false * type: string + * - name: addressFilter + * description: filter by type of address such as TransactionSigner, AssetOwner, Approver, Registrar given by comma saperating + * in: query + * required: false + * type: string * - name: assetType * description: filter by assetType * in: query @@ -112,6 +117,7 @@ export function handle(context: IndexerContext, router: Router) { syncIfNeeded(context), async (req, res, next) => { const address = req.query.address; + const addressFilter = req.query.addressFilter; const assetTypeString = req.query.assetType; const type = req.query.type; const trackerString = req.query.tracker; @@ -137,6 +143,10 @@ export function handle(context: IndexerContext, router: Router) { } const txInsts = await TxModel.getTransactions({ address, + addressFilter: + typeof addressFilter === "string" + ? addressFilter.split(",") + : undefined, assetType, type: typeof type === "string" ? type.split(",") : undefined, @@ -168,6 +178,11 @@ export function handle(context: IndexerContext, router: Router) { * in: query * required: false * type: string + * - name: addressFilter + * description: filter by type of address such as TransactionSigner, AssetOwner, Approver, Registrar given by comma saperating + * in: query + * required: false + * type: string * - name: assetType * description: filter by assetType * in: query @@ -223,6 +238,7 @@ export function handle(context: IndexerContext, router: Router) { syncIfNeeded(context), async (req, res, next) => { const address = req.query.address; + const addressFilter = req.query.addressFilter; const assetTypeString = req.query.assetType; const type = req.query.type; const trackerString = req.query.tracker; @@ -243,6 +259,10 @@ export function handle(context: IndexerContext, router: Router) { } const count = await TxModel.getNumberOfTransactions({ address, + addressFilter: + typeof addressFilter === "string" + ? addressFilter.split(",") + : undefined, assetType, type: typeof type === "string" ? type.split(",") : undefined, @@ -353,6 +373,11 @@ export function handle(context: IndexerContext, router: Router) { * in: query * required: false * type: string + * - name: addressFilter + * description: filter by type of address such as TransactionSigner, AssetOwner, Approver, Registrar given by comma saperating + * in: query + * required: false + * type: string * - name: assetType * description: filter by assetType * in: query @@ -397,6 +422,7 @@ export function handle(context: IndexerContext, router: Router) { syncIfNeeded(context), async (req, res, next) => { const address = req.query.address; + const addressFilter = req.query.addressFilter; const assetTypeString = req.query.assetType; const type = req.query.type; const page = req.query.page || 1; @@ -408,6 +434,10 @@ export function handle(context: IndexerContext, router: Router) { } const pendingTxInsts = await TxModel.getPendingTransactions({ address, + addressFilter: + typeof addressFilter === "string" + ? addressFilter.split(",") + : undefined, assetType, type: typeof type === "string" ? type.split(",") : undefined, @@ -435,6 +465,11 @@ export function handle(context: IndexerContext, router: Router) { * in: query * required: false * type: string + * - name: addressFilter + * description: filter by type of address such as TransactionSigner, AssetOwner, Approver, Registrar given by comma saperating + * in: query + * required: false + * type: string * - name: assetType * description: filter by assetType * in: query @@ -467,6 +502,7 @@ export function handle(context: IndexerContext, router: Router) { syncIfNeeded(context), async (req, res, next) => { const address = req.query.address; + const addressFilter = req.query.addressFilter; const assetTypeString = req.query.assetType; const type = req.query.type; try { @@ -476,6 +512,10 @@ export function handle(context: IndexerContext, router: Router) { } const count = await TxModel.getNumberOfPendingTransactions({ address, + addressFilter: + typeof addressFilter === "string" + ? addressFilter.split(",") + : undefined, assetType, type: typeof type === "string" ? type.split(",") : undefined }); diff --git a/src/routers/validator.ts b/src/routers/validator.ts index 7b393a8..1869e3d 100644 --- a/src/routers/validator.ts +++ b/src/routers/validator.ts @@ -36,12 +36,22 @@ const TYPES = [ "custom" ]; +const ADDRESS_TYPES = [ + "TransactionSigner", + "AssetOwner", + "Approver", + "Registrar" +]; + const LOG_FILTER = ["block", "tx", ...TYPES]; // FIXME: export const platformAddressSchema = Joi.string(); // FIXME: PlatformAddress or AssetAddress const address = Joi.string(); +const addressFilter = Joi.string().regex( + new RegExp(`^(${ADDRESS_TYPES.join("|")})(,(${ADDRESS_TYPES.join("|")}))*$`) +); export const assetTypeSchema = Joi.string().regex(/^(0x)?[0-9a-f]{40}$/); const tracker = Joi.string().regex(/^(0x)?[0-9a-f]{64}$/); const type = Joi.string().regex( @@ -69,6 +79,7 @@ export const paginationSchema = { export const txSchema = { address, + addressFilter, assetType: assetTypeSchema, tracker, type,