Skip to content

Commit 9b43711

Browse files
committed
review changes for ago api
Signed-off-by: manishdas12 <[email protected]>
1 parent 413e7f5 commit 9b43711

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

app/persistence/fabric/CRUDService.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,7 @@ export class CRUDService {
536536
* @returns
537537
* @memberof CRUDService
538538
*/
539-
async getChannelsInfo(network_name, channel_genesis_hash) {
540-
const currentTime = queryDatevalidator(network_name, channel_genesis_hash);
539+
async getChannelsInfo(network_name) {
541540
const channels = await this.sql.getRowsBySQlNoCondition(
542541
` SELECT c.id as id, c.name as channelName, c.blocks as blocks, c.channel_genesis_hash as channel_genesis_hash,
543542
c.trans as transactions, c.createdt as createdat, c.channel_hash as channel_hash, MAX(blocks.createdt)
@@ -549,7 +548,7 @@ export class CRUDService {
549548
ORDER BY c.name `,
550549
[network_name]
551550
);
552-
return { channels, currentTime };
551+
return channels;
553552
}
554553

555554
// Orderer BE-303

app/platform/fabric/Proxy.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,23 @@ export class Proxy {
194194
return channel_genesis_hash;
195195
}
196196

197-
getLatestBlockTime(channel, currentTime) {
198-
let curBlockTime: any;
197+
/**
198+
*
199+
*
200+
* @param {*} channel
201+
* @returns
202+
* @memberof Proxy
203+
*/
204+
205+
getLatestBlockTime(channel) {
206+
let latestBlockEntry: Date;
199207
let agoTime = '';
200208
if (!channel?.latestdate) return agoTime;
201-
curBlockTime = channel.latestdate;
202-
const dateCurBlock = new Date(curBlockTime);
203-
const dateCur = new Date(currentTime.to);
204-
const timeCurBlock = dateCurBlock.getTime();
205-
const timeCur = dateCur.getTime();
206-
const curBlockTimeDiff = timeCur - timeCurBlock;
207-
const seconds = Math.floor(curBlockTimeDiff / 1000);
209+
latestBlockEntry = channel.latestdate;
210+
const latestBlockEntryTime = latestBlockEntry.getTime();
211+
const currentBlockDate = Date.now();
212+
const agoBlockTimeDiff = currentBlockDate - latestBlockEntryTime;
213+
const seconds = Math.floor(agoBlockTimeDiff / 1000);
208214
const minutes = Math.floor(seconds / 60);
209215
const hours = Math.floor(minutes / 60);
210216
const days = Math.floor(hours / 24);
@@ -227,14 +233,13 @@ export class Proxy {
227233
*/
228234
async getChannelsInfo(network_id) {
229235
const client = this.platform.getClient(network_id);
230-
const {
231-
channels,
232-
currentTime
233-
} = await this.persistence.getCrudService().getChannelsInfo(network_id);
236+
const channels = await this.persistence
237+
.getCrudService()
238+
.getChannelsInfo(network_id);
234239
const currentchannels = [];
235240
for (const channel of channels) {
236241
const channel_genesis_hash = client.getChannelGenHash(channel.channelname);
237-
let agoBlockTime = this.getLatestBlockTime(channel, currentTime);
242+
let agoBlockTime = this.getLatestBlockTime(channel);
238243
if (
239244
channel_genesis_hash &&
240245
channel_genesis_hash === channel.channel_genesis_hash

0 commit comments

Comments
 (0)