mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-21 09:05:10 +00:00
added getNetwork functionality
Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
This commit is contained in:
parent
19e28d817b
commit
804f4a6468
2 changed files with 11 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ import {
|
||||||
TxEventHandler,
|
TxEventHandler,
|
||||||
TxEventHandlerFactory,
|
TxEventHandlerFactory,
|
||||||
Wallets,
|
Wallets,
|
||||||
|
Network
|
||||||
} from 'fabric-network';
|
} from 'fabric-network';
|
||||||
import { Redis } from 'ioredis';
|
import { Redis } from 'ioredis';
|
||||||
import * as config from './config';
|
import * as config from './config';
|
||||||
|
|
@ -24,6 +25,12 @@ import {
|
||||||
TransactionNotFoundError,
|
TransactionNotFoundError,
|
||||||
} from './errors';
|
} 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> => {
|
export const getGateway = async (): Promise<Gateway> => {
|
||||||
const wallet = await Wallets.newInMemoryWallet();
|
const wallet = await Wallets.newInMemoryWallet();
|
||||||
|
|
||||||
|
|
@ -346,3 +353,4 @@ const isDuplicateTransaction = (error: {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import pinoMiddleware from 'pino-http';
|
||||||
import { logger } from './logger';
|
import { logger } from './logger';
|
||||||
import { assetsRouter } from './assets.router';
|
import { assetsRouter } from './assets.router';
|
||||||
import { transactionsRouter } from './transactions.router';
|
import { transactionsRouter } from './transactions.router';
|
||||||
import { getContracts, getGateway } from './fabric';
|
import { getContracts, getGateway, getNetwork } from './fabric';
|
||||||
import { redis } from './redis';
|
import { redis } from './redis';
|
||||||
|
|
||||||
const { BAD_REQUEST, INTERNAL_SERVER_ERROR, NOT_FOUND, OK } = StatusCodes;
|
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 gateway = await getGateway();
|
||||||
const contracts = await getContracts(gateway);
|
const contracts = await getContracts(gateway);
|
||||||
|
const network = await getNetwork(gateway)
|
||||||
app.set('contracts', contracts);
|
app.set('contracts', contracts);
|
||||||
app.set('redis', redis);
|
app.set('redis', redis);
|
||||||
|
app.set('network',network)
|
||||||
|
|
||||||
// Health routes
|
// Health routes
|
||||||
app.get('/ready', (_req, res) =>
|
app.get('/ready', (_req, res) =>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue