added getNetwork functionality

Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
This commit is contained in:
sapthasurendran 2021-07-26 11:59:41 +05:30 committed by James Taylor
parent 19e28d817b
commit 804f4a6468
2 changed files with 11 additions and 1 deletions

View file

@ -12,6 +12,7 @@ import {
TxEventHandler,
TxEventHandlerFactory,
Wallets,
Network
} from 'fabric-network';
import { Redis } from 'ioredis';
import * as config from './config';
@ -24,6 +25,12 @@ import {
TransactionNotFoundError,
} from './errors';
export const getNetwork = async (gateway: Gateway): Promise<Network> => {
const network = await gateway.getNetwork(config.channelName);
return network;
};
export const getGateway = async (): Promise<Gateway> => {
const wallet = await Wallets.newInMemoryWallet();
@ -346,3 +353,4 @@ const isDuplicateTransaction = (error: {
return false;
};

View file

@ -10,7 +10,7 @@ import pinoMiddleware from 'pino-http';
import { logger } from './logger';
import { assetsRouter } from './assets.router';
import { transactionsRouter } from './transactions.router';
import { getContracts, getGateway } from './fabric';
import { getContracts, getGateway, getNetwork } from './fabric';
import { redis } from './redis';
const { BAD_REQUEST, INTERNAL_SERVER_ERROR, NOT_FOUND, OK } = StatusCodes;
@ -51,8 +51,10 @@ export const createServer = async (): Promise<Application> => {
const gateway = await getGateway();
const contracts = await getContracts(gateway);
const network = await getNetwork(gateway)
app.set('contracts', contracts);
app.set('redis', redis);
app.set('network',network)
// Health routes
app.get('/ready', (_req, res) =>