How to use fabric-network - 10 common examples

To help you get started, we’ve selected a few fabric-network examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / invoke.ts View on Github external
test('\n\n***** Network End-to-end flow: invoke transaction to move money using in memory wallet and NETWORK_SCOPE_ALLFORTX event strategy *****\n\n', async (t: tape.Test) => {
	const gateway = new Gateway();
	let org1EventHub: ChannelEventHub | undefined;
	let org2EventHub: ChannelEventHub | undefined;

	try {
		const wallet = await getWallet();
		const contract = await createContract(t, gateway, {
			clientTlsIdentity: tlsIdentityName,
			discovery: {
				enabled: false,
			},
			eventHandlerOptions: {
				strategy: DefaultEventHandlerStrategies.NETWORK_SCOPE_ALLFORTX,
			},
			identity: identityName,
			wallet,
		});

		const transaction = contract.createTransaction('move');
		const transactionId = transaction.getTransactionID().getTransactionID();

		// Obtain an event hub that that will be used by the underlying implementation
		org1EventHub = await getInternalEventHubForOrg(gateway, 'Org1MSP');
		org2EventHub = await getInternalEventHubForOrg(gateway, 'Org2MSP');

		let org1EventFired = 0;
		let org2EventFired = 0;
		org1EventHub.registerTxEvent('all', (txId, code) => {
			if (code === 'VALID' && txId === transactionId) {
github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / invoke.ts View on Github external
test('\n\n***** Network End-to-end flow: invoke transaction to move money using in memory wallet and NETWORK_SCOPE_ALLFORTX event strategy with discovery *****\n\n', async (t: tape.Test) => {
	const gateway = new Gateway();
	let org1EventHub: ChannelEventHub | undefined;
	let org2EventHub: ChannelEventHub | undefined;

	try {
		const wallet = await getWallet();
		const contract = await createContract(t, gateway, {
			clientTlsIdentity: tlsIdentityName,
			discovery: {
				asLocalhost: true,
				enabled: true,
			},
			eventHandlerOptions: {
				strategy: DefaultEventHandlerStrategies.NETWORK_SCOPE_ALLFORTX,
			},
			identity: identityName,
			wallet,
		});

		const transaction = contract.createTransaction('move');
		const transactionId = transaction.getTransactionID().getTransactionID();

		// Obtain an event hub that that will be used by the underlying implementation
		org1EventHub = await getInternalEventHubForOrg(gateway, 'Org1MSP');
		org2EventHub = await getInternalEventHubForOrg(gateway, 'Org2MSP');

		let org1EventFired = 0;
		let org2EventFired = 0;
		org1EventHub.registerTxEvent('all', (txId, code) => {
			if (code === 'VALID' && txId === transactionId) {
github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / invoke.ts View on Github external
test('\n\n***** Network End-to-end flow: invoke transaction to move money using in memory wallet and MSPID_SCOPE_ALLFORTX event strategy *****\n\n', async (t: tape.Test) => {
	const gateway = new Gateway();
	let org1EventHub: ChannelEventHub | undefined;

	try {
		const wallet = await getWallet();
		const contract = await createContract(t, gateway, {
			clientTlsIdentity: tlsIdentityName,
			discovery: {
				enabled: false,
			},
			eventHandlerOptions: {
				strategy: DefaultEventHandlerStrategies.MSPID_SCOPE_ALLFORTX,
			},
			identity: identityName,
			wallet,
		});

		const transaction = contract.createTransaction('move');
		const transactionId = transaction.getTransactionID().getTransactionID();

		// Obtain an event hub that that will be used by the underlying implementation
		org1EventHub = await getInternalEventHubForOrg(gateway, 'Org1MSP');
		const org2EventHub = await getInternalEventHubForOrg(gateway, 'Org2MSP');

		let eventFired = 0;

		org1EventHub.registerTxEvent('all', (txId, code) => {
			if (code === 'VALID' && txId === transactionId) {
github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / invoke.ts View on Github external
test('\n\n***** Network End-to-end flow: invoke transaction to move money using in memory wallet and MSPID_SCOPE_ANYFORTX event strategy *****\n\n', async (t: tape.Test) => {
	const gateway = new Gateway();
	let org1EventHub: ChannelEventHub | undefined;

	try {
		const wallet = await getWallet();
		const contract = await createContract(t, gateway, {
			clientTlsIdentity: tlsIdentityName,
			discovery: {
				enabled: false,
			},
			eventHandlerOptions: {
				strategy: DefaultEventHandlerStrategies.MSPID_SCOPE_ANYFORTX,
			},
			identity: identityName,
			wallet,
		});

		const transaction = contract.createTransaction('move');
		const transactionId = transaction.getTransactionID().getTransactionID();

		// Obtain an event hub that that will be used by the underlying implementation
		org1EventHub = await getInternalEventHubForOrg(gateway, 'Org1MSP');
		const org2EventHub = await getInternalEventHubForOrg(gateway, 'Org2MSP');

		let eventFired = 0;

		org1EventHub.registerTxEvent('all', (txId, code) => {
			if (code === 'VALID' && txId === transactionId) {
github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / invoke.ts View on Github external
test('\n\n***** Network End-to-end flow: invoke transaction to move money using in memory wallet and NETWORK_SCOPE_ANYFORTX event strategy *****\n\n', async (t: tape.Test) => {
	const gateway = new Gateway();
	let org1EventHub: ChannelEventHub | undefined;
	let org2EventHub: ChannelEventHub | undefined;

	try {
		const wallet = await getWallet();
		const contract = await createContract(t, gateway, {
			clientTlsIdentity: tlsIdentityName,
			discovery: {
				enabled: false,
			},
			eventHandlerOptions: {
				strategy: DefaultEventHandlerStrategies.NETWORK_SCOPE_ANYFORTX,
			},
			identity: identityName,
			wallet,
		});

		const transaction = contract.createTransaction('move');
		const transactionId = transaction.getTransactionID().getTransactionID();

		// Obtain an event hub that that will be used by the underlying implementation
		org1EventHub = await getInternalEventHubForOrg(gateway, 'Org1MSP');
		org2EventHub = await getInternalEventHubForOrg(gateway, 'Org2MSP');

		let org1EventFired = 0;
		let org2EventFired = 0;
		org1EventHub.registerTxEvent('all', (txId, code) => {
			if (code === 'VALID' && txId === transactionId) {
github hyperledger / fabric-sdk-node / test / ts-scenario / steps / lib / gateway.ts View on Github external
const myWalletReference: string = `${Constants.WALLET}_walletType`;
	let wallet: Wallet = stateStore.get(myWalletReference);
	if (!wallet) {
		BaseUtils.logMsg(`Creating wallet of type ${walletType}`);
		switch (walletType) {
			case Constants.MEMORY_WALLET:
				wallet = await Wallets.newInMemoryWallet();
				break;
			case Constants.FILE_WALLET:
				const tempDir: string = path.join(__dirname, Constants.LIB_TO_TEMP, Constants.FILE_WALLET);
				if (fs.existsSync(tempDir)) {
					BaseUtils.recursiveDirDelete(tempDir);
				}
				await fs.mkdirSync(tempDir);
				wallet = await Wallets.newFileSystemWallet(tempDir);
				break;
			case Constants.COUCH_WALLET:
				wallet = await Wallets.newCouchDBWallet({url: Constants.COUCH_WALLET_URL as string});
				break;
			default:
				BaseUtils.logAndThrow(`Unmatched wallet backing store`);
		}
	}

	// Might already have a user@org in that wallet
	const userId: string = `${userName}@${orgName}`;
	const userIdentity: Identity | undefined = await wallet.get(userId);

	// Will always be adding a gateway
	const gateway: Gateway = new Gateway();
github hyperledger-labs / weaver-dlt-interoperability / tests / network-setups / fabric / dev / scripts / fabric-cli / src / helpers / fabric-functions.ts View on Github external
userPwd: string = '',
  register: boolean = false,
  logger: any = console
) => {
  // Create a new CA client for interacting with the CA.
  // Create a new CA client for interacting with the CA.
  const org = ccp.client['organization']
  const caName = ccp.organizations[org]['certificateAuthorities'][0]
  const caURL = ccp.certificateAuthorities[caName].url
  const ca = new FabricCAServices(caURL)
  const ident = ca.newIdentityService()

  const walletPath = process.env.WALLET_PATH
    ? process.env.WALLET_PATH
    : path.join(__dirname, '../', `wallet-${networkName}`)
  const wallet = await Wallets.newFileSystemWallet(walletPath)

  logger.info(`Wallet Setup: wallet path: ${walletPath}`)

  // build a user object for authenticating with the CA        // Check to see if we've already enrolled the admin user.
  let adminIdentity = await wallet.get('admin')

  if (adminIdentity) {
    logger.debug(
      'An identity for the admin user "admin" already exists in the wallet.'
    )
  } else {
    // Enroll the admin user, and import the new identity into the wallet.
    const enrollment = await ca.enroll({
      enrollmentID: 'admin',
      enrollmentSecret: 'adminpw'
    })
github hyperledger / fabric-sdk-node / test / ts-scenario / steps / lib / gateway.ts View on Github external
export async function createGateway(ccp: CommonConnectionProfileHelper, tls: boolean, userName: string, orgName: string, gatewayName: string, useDiscovery: boolean, walletType: string): Promise {

	// Might already have a wallet to use, but sanitize the passed walletType
	if (!walletType || !supportedWallets.includes(walletType)) {
		BaseUtils.logAndThrow(`Passed wallet type [${walletType}] is not supported, must be one of: ${supportedWallets}`);
	}

	const myWalletReference: string = `${Constants.WALLET}_walletType`;
	let wallet: Wallet = stateStore.get(myWalletReference);
	if (!wallet) {
		BaseUtils.logMsg(`Creating wallet of type ${walletType}`);
		switch (walletType) {
			case Constants.MEMORY_WALLET:
				wallet = await Wallets.newInMemoryWallet();
				break;
			case Constants.FILE_WALLET:
				const tempDir: string = path.join(__dirname, Constants.LIB_TO_TEMP, Constants.FILE_WALLET);
				if (fs.existsSync(tempDir)) {
					BaseUtils.recursiveDirDelete(tempDir);
				}
				await fs.mkdirSync(tempDir);
				wallet = await Wallets.newFileSystemWallet(tempDir);
				break;
			case Constants.COUCH_WALLET:
				wallet = await Wallets.newCouchDBWallet({url: Constants.COUCH_WALLET_URL as string});
				break;
			default:
				BaseUtils.logAndThrow(`Unmatched wallet backing store`);
		}
	}
github hyperledger / fabric-sdk-node / test / typescript / integration / network-e2e / query.ts View on Github external
async function createWallet(t: tape.Test): Promise {
	// define the identity to use
	const credPath = fixtures + '/crypto-material/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp';
	const cert = fs.readFileSync(credPath + '/signcerts/User1@org1.example.com-cert.pem').toString();
	const key = fs.readFileSync(credPath + '/keystore/key.pem').toString();

	const wallet = await Wallets.newInMemoryWallet();

	// prep wallet and test it at the same time
	const identity: X509Identity = {
		credentials: {
			certificate: cert,
			privateKey: key,
		},
		mspId: 'Org1MSP',
		type: 'X.509',
	};
	await wallet.put(identityLabel, identity);
	const savedIdentity = await wallet.get(identityLabel);
	t.ok(savedIdentity, 'Successfully imported User1@org1.example.com into wallet');

	const tlsInfo = await e2eUtils.tlsEnroll('org1');
	const tlsIdentity: X509Identity = {
github hyperledger / fabric-sdk-node / test / scenario / features / lib / network.js View on Github external
async function connectGateway(ccp, tls, userName, orgName, gatewayName, useDiscovery) {

	const gateway = new Gateway();
	const wallet = await Wallets.newInMemoryWallet();

	// import specified user to wallet
	const userIdentity = await identitySetup(wallet, ccp, orgName, userName);

	if (tls) {
		const caName = ccp.getCertificatAuthoritiesForOrg(orgName)[0];
		const fabricCAEndpoint = ccp.getCertificateAuthority(caName).url;
		const tlsInfo = await testUtil.tlsEnroll(fabricCAEndpoint, caName);
		const caOrg = ccp.getOrganization(orgName);

		const tlsIdentity = {
			credentials: {
				certificate: tlsInfo.certificate,
				privateKey: tlsInfo.key
			},
			mspId: caOrg.mspid,