Skip to content

Commit

Permalink
Add validations to search functionality blockId and blockRange
Browse files Browse the repository at this point in the history
Signed-off-by: ArchanaArige <nigam_archana@yahoo.co.in>
  • Loading branch information
ArchanaArige committed Apr 18, 2023
1 parent cd975ee commit 5fcd2b5
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 92 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ RUN apk add --no-cache --virtual npm-deps python3 make g++ curl bash && \
rm -r /root/.cache

# install node-prune (https://github.com/tj/node-prune)
RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin

RUN curl -sf https://gobinaries.com/tj/node-prune | sh
# install NPM dependencies
RUN npm install && npm run build && npm prune --production

Expand Down
14 changes: 14 additions & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
Maintainers
===========

You can find out who's contributed recently just by looking at GitHub's [contributors list](https://github.com/hyperledger-labs/blockchain-explorer/graphs/contributors). But there are a few more things you ought to know about who maintains this code, and how they do it:

Make sure you read our contributor guidelines so you understand how we work and how to collaborate effectively. This includes instructions about pull request and code review protocols, and it explains what we mean by calling someone a "maintainer" in this file.

Be aware that individual folders in the project may have more specific maintainers; if you see another MAINTAINERS.md in a subfolder, that governs the tree below it.

A lot of interactions with maintainers take place on Discord. You'll need [Linux Foundation credentials](https://identity.linuxfoundation.org/) to comment there; creating them is self-service. The project name you want, once in Discord, is "[blockchain-explorer](https://discord.com/channels/905194001349627914/1039606111654920255)". Most of the team hangs out there during their work day; look for #Blockchain-explorer.

**Who To Contact**
For ordinary questions, we suggest you contact [active contributors](https://github.com/hyperledger-labs/blockchain-explorer/graphs/contributors) generically, on Discord [#blockchain-explorer](https://discord.com/channels/905194001349627914/1039606111654920255). If that doesn't get someone's attention, feel free to contact the contributors individually.

Maintainers are busy and delegate many decisions to other trusted contributors. However, it is appropriate to contact them if you have a complex design decision or a controversial PR.


**Active Maintainers**

| Name | GitHub |
Expand Down
34 changes: 27 additions & 7 deletions app/persistence/fabric/CRUDService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,51 @@ export class CRUDService {
* @param {*} txid
* @param {*} from
* @param {*} to
* @param {*} page
* @param {*} size
* @param {*} orgs
* @returns
* @memberof CRUDService
*/
getTxList(
async getTxList(
network_name: any,
channel_genesis_hash: any,
blockNum: any,
txid: any,
from: any,
to: any,
orgs: string
orgs: string,
page: number,
size: number
) {
var countOfTxns: number;
let sqlTxList = ` select t.creator_msp_id,t.txhash,t.type,t.chaincodename,t.createdt,channel.name as channelName from transactions as t
inner join channel on t.channel_genesis_hash=channel.channel_genesis_hash and t.network_name = channel.network_name where t.blockid >= $1 and t.id >= $2 and
t.channel_genesis_hash = $3 and t.network_name = $4 and t.createdt between $5 and $6 `;
const values = [blockNum, txid, channel_genesis_hash, network_name, from, to];

const values = [blockNum, txid, channel_genesis_hash, network_name, from, to, page, size];
if (page == 1) {
let sqlTxCount: string;
const filterValues = [blockNum, txid, channel_genesis_hash, network_name, from, to];
sqlTxCount = ` select count(*) from transactions as t inner join channel on t.channel_genesis_hash=channel.channel_genesis_hash and t.network_name = channel.network_name
where t.blockid >= $1 and t.id >= $2 and t.channel_genesis_hash = $3 and t.network_name = $4 and t.createdt between $5 and $6 `
if (orgs && orgs.length > 0) {
sqlTxCount += ' and t.creator_msp_id = ANY($7)';
filterValues.push(orgs);
}
countOfTxns = await this.sql.getRowsCountBySQlQuery(sqlTxCount, filterValues)
}
if (orgs && orgs.length > 0) {
sqlTxList += ' and t.creator_msp_id = ANY($7)';
sqlTxList += ' and t.creator_msp_id = ANY($9)';
values.push(orgs);
}
sqlTxList += ' order by t.createdt desc';
sqlTxList += ' order by t.createdt desc LIMIT $8 OFFSET (($7 - 1) * $8)';
let txnsData = await this.sql.getRowsBySQlQuery(sqlTxList, values);
let response = {
txnsData: txnsData,
noOfpages: Math.ceil(countOfTxns / size)
}

return this.sql.getRowsBySQlQuery(sqlTxList, values);
return response;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions app/persistence/postgreSQL/PgService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,28 @@ export class PgService {
});
});
}

/**
*
*
* @param {*} sql
* @param {*} values
* @returns
* @memberof PgService
*/
getRowsCountBySQlQuery(sql, values): Promise<number> {
return new Promise((resolve, reject) => {
this.client.query(sql, values, (err, res) => {
if (err) {
reject(err);
return;
}
logger.debug(`the getRowsCountBySQlQuery ${res}`);
if (res) {
resolve(res.rows[0].count);
}
});
});
}

}
19 changes: 14 additions & 5 deletions app/rest/dbroutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export function dbroutes(router: Router, platform: Platform) {
* GET /txList/
* curl -i 'http://<host>:<port>/txList/<channel_genesis_hash>/<blocknum>/<txid>/<limitrows>/<offset>'
* Response:
* {'rows':[{'id':56,'channelname':'mychannel','blockid':24,
* {'rows':{"txnsData": [{'id':56,'channelname':'mychannel','blockid':24,
* 'txhash':'c42c4346f44259628e70d52c672d6717d36971a383f18f83b118aaff7f4349b8',
* 'createdt':'2018-03-09T19:40:59.000Z','chaincodename':'mycc'}]}
* 'createdt':'2018-03-09T19:40:59.000Z','chaincodename':'mycc'}], "noOfpages": 1}
*/
router.get(
'/txList/:channel_genesis_hash/:blocknum/:txid',
Expand All @@ -139,22 +139,31 @@ export function dbroutes(router: Router, platform: Platform) {
req.query.from as string,
req.query.to as string
);
const { page, size } = req.query;
if (isNaN(txid)) {
txid = 0;
}
if (channel_genesis_hash) {
const extReq = (req as unknown) as ExtRequest;
dbCrudService
let data = await dbCrudService
.getTxList(
extReq.network,
channel_genesis_hash,
blockNum,
txid,
from,
to,
orgs
orgs,
page,
size
)
.then(handleResult(req, res));
if (data) {
return res.send({
status: 200,
rows: data
});
}
return requtil.notFound(req, res);
} else {
return requtil.invalidRequest(req, res);
}
Expand Down
29 changes: 19 additions & 10 deletions app/rest/platformroutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import * as requtil from './requestutils';



/**
*
*
Expand Down Expand Up @@ -190,15 +192,18 @@ export async function platformroutes(
router.get('/fetchDataByBlockNo/:channel_genesis_hash/:blockNo', (req, res) => {
const blockNo = parseInt(req.params.blockNo);
const channel_genesis_hash = req.params.channel_genesis_hash;
if (!isNaN(blockNo) && channel_genesis_hash) {
proxy.fetchDataByBlockNo(req.network, channel_genesis_hash, blockNo).then((data: any) => {
if (data != "response_payloads is null") {
res.send({ status: 200, data: data });
}
else{
} else {
res.send({ status: 404, data: "Block not found" });
}
});
});
} else {
return requtil.invalidRequest(req, res);
}
});

/**
* *
Expand All @@ -210,21 +215,25 @@ export async function platformroutes(
const startBlockNo = parseInt(req.params.startBlockNo);
const endBlockNo = parseInt(req.params.endBlockNo);
const channel_genesis_hash = req.params.channel_genesis_hash;
if (startBlockNo < endBlockNo) {
if (
startBlockNo <= endBlockNo &&
startBlockNo >= 0 &&
endBlockNo >= 0 &&
!isNaN(startBlockNo) &&
!isNaN(endBlockNo) &&
channel_genesis_hash
) {
proxy.fetchDataByBlockRange(req.network, channel_genesis_hash, startBlockNo, endBlockNo).then((data: any) => {
if (data != "response_payloads is null") {
res.send({ status: 200, data: data });
}
else{
} else {
res.send({ status: 404, data: "Block(s) not found" });
}
});
}
else {
} else {
return requtil.invalidRequest(req, res);
}

});
});


/**
Expand Down
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"nock": "^9.3.3",
"pg": "^7.4.1",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react": "^16.14.0",
"react-copy-to-clipboard": "^5.0.1",
"react-d3-graph": "^1.0.1",
"react-datepicker": "^1.6.0",
"react-dom": "^16.2.0",
"react-dom": "^16.14.0",
"react-event-timeline": "^1.5.4",
"react-fontawesome": "^1.6.1",
"react-js-pagination": "^3.0.1",
Expand Down
15 changes: 11 additions & 4 deletions client/src/components/Header/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ const {
chaincodeList,
channels,
peerList,
transactionList
transactionList,
transactionListSearch
} = tableOperations;

const { currentChannelSelector } = chartSelectors;
const { channelsSelector } = tableSelectors;
const { channelsSelector, transactionListSearchPageParamSelector, transactionListSearchQuerySelector } = tableSelectors;
/* istanbul ignore next */
const styles = theme => {
const { type } = theme.palette;
Expand Down Expand Up @@ -458,6 +459,9 @@ export class HeaderView extends Component {
getPeerStatus,
getTransactionByOrg,
getTransactionList,
getTransactionListSearch,
transactionListSearchPageParam,
transactionListSearchQuery,
getTransactionPerHour,
getTransactionPerMin,
getBlockActivity
Expand All @@ -474,7 +478,7 @@ export class HeaderView extends Component {
getPeerList(currentChannel),
getPeerStatus(currentChannel),
getTransactionByOrg(currentChannel),
getTransactionList(currentChannel),
getTransactionListSearch(currentChannel,transactionListSearchQuery,transactionListSearchPageParam),
getTransactionPerHour(currentChannel),
getTransactionPerMin(currentChannel)
]);
Expand Down Expand Up @@ -687,7 +691,9 @@ const mapStateToProps = state => {
return {
currentChannel: currentChannelSelector(state),
channels: channelsSelector(state),
mode: modeSelector(state)
mode: modeSelector(state),
transactionListSearchPageParam: transactionListSearchPageParamSelector(state),
transactionListSearchQuery: transactionListSearchQuerySelector(state),
};
};

Expand All @@ -704,6 +710,7 @@ const mapDispatchToProps = {
getBlockActivity: blockActivity,
getTransactionByOrg: transactionByOrg,
getTransactionList: transactionList,
getTransactionListSearch:transactionListSearch,
getTransactionPerHour: transactionPerHour,
getTransactionPerMin: transactionPerMin,
logout: authOperations.logout
Expand Down
Loading

0 comments on commit 5fcd2b5

Please sign in to comment.