Skip to content

Commit

Permalink
review changes for ago api
Browse files Browse the repository at this point in the history
Signed-off-by: manishdas12 <[email protected]>
  • Loading branch information
manishdas12 committed Sep 25, 2023
1 parent 413e7f5 commit 9b43711
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
5 changes: 2 additions & 3 deletions app/persistence/fabric/CRUDService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ export class CRUDService {
* @returns
* @memberof CRUDService
*/
async getChannelsInfo(network_name, channel_genesis_hash) {
const currentTime = queryDatevalidator(network_name, channel_genesis_hash);
async getChannelsInfo(network_name) {
const channels = await this.sql.getRowsBySQlNoCondition(
` SELECT c.id as id, c.name as channelName, c.blocks as blocks, c.channel_genesis_hash as channel_genesis_hash,
c.trans as transactions, c.createdt as createdat, c.channel_hash as channel_hash, MAX(blocks.createdt)
Expand All @@ -549,7 +548,7 @@ export class CRUDService {
ORDER BY c.name `,
[network_name]
);
return { channels, currentTime };
return channels;
}

// Orderer BE-303
Expand Down
33 changes: 19 additions & 14 deletions app/platform/fabric/Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,23 @@ export class Proxy {
return channel_genesis_hash;
}

getLatestBlockTime(channel, currentTime) {
let curBlockTime: any;
/**
*
*
* @param {*} channel
* @returns
* @memberof Proxy
*/

getLatestBlockTime(channel) {
let latestBlockEntry: Date;
let agoTime = '';
if (!channel?.latestdate) return agoTime;
curBlockTime = channel.latestdate;
const dateCurBlock = new Date(curBlockTime);
const dateCur = new Date(currentTime.to);
const timeCurBlock = dateCurBlock.getTime();
const timeCur = dateCur.getTime();
const curBlockTimeDiff = timeCur - timeCurBlock;
const seconds = Math.floor(curBlockTimeDiff / 1000);
latestBlockEntry = channel.latestdate;
const latestBlockEntryTime = latestBlockEntry.getTime();
const currentBlockDate = Date.now();
const agoBlockTimeDiff = currentBlockDate - latestBlockEntryTime;
const seconds = Math.floor(agoBlockTimeDiff / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
Expand All @@ -227,14 +233,13 @@ export class Proxy {
*/
async getChannelsInfo(network_id) {
const client = this.platform.getClient(network_id);
const {
channels,
currentTime
} = await this.persistence.getCrudService().getChannelsInfo(network_id);
const channels = await this.persistence
.getCrudService()
.getChannelsInfo(network_id);
const currentchannels = [];
for (const channel of channels) {
const channel_genesis_hash = client.getChannelGenHash(channel.channelname);
let agoBlockTime = this.getLatestBlockTime(channel, currentTime);
let agoBlockTime = this.getLatestBlockTime(channel);
if (
channel_genesis_hash &&
channel_genesis_hash === channel.channel_genesis_hash
Expand Down

0 comments on commit 9b43711

Please sign in to comment.