Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add addressFilter parameter to the router of the tx-APIs #236

Merged
merged 1 commit into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/models/logic/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions src/routers/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
});
Expand Down
11 changes: 11 additions & 0 deletions src/routers/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("|")}))*$`)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make addressFilter invalidate if an address is not given.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Expand Down Expand Up @@ -69,6 +79,7 @@ export const paginationSchema = {

export const txSchema = {
address,
addressFilter,
assetType: assetTypeSchema,
tracker,
type,
Expand Down