mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
Update FabCar to use BYFN. As a result, the sample client applications need to change so that they use the correct connection profile paths, and so that they use service discovery. Change-Id: If02b7fb4ad308c6a7d1e1aa9f953e1bc4e942719 Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
/*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { FileSystemWallet, Gateway } = require('fabric-network');
|
|
const path = require('path');
|
|
|
|
const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
|
|
|
|
async function main() {
|
|
try {
|
|
|
|
// Create a new file system based wallet for managing identities.
|
|
const walletPath = path.join(process.cwd(), 'wallet');
|
|
const wallet = new FileSystemWallet(walletPath);
|
|
console.log(`Wallet path: ${walletPath}`);
|
|
|
|
// Check to see if we've already enrolled the user.
|
|
const userExists = await wallet.exists('user1');
|
|
if (!userExists) {
|
|
console.log('An identity for the user "user1" does not exist in the wallet');
|
|
console.log('Run the registerUser.js application before retrying');
|
|
return;
|
|
}
|
|
|
|
// Create a new gateway for connecting to our peer node.
|
|
const gateway = new Gateway();
|
|
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
|
|
|
|
// Get the network (channel) our contract is deployed to.
|
|
const network = await gateway.getNetwork('mychannel');
|
|
|
|
// Get the contract from the network.
|
|
const contract = network.getContract('fabcar');
|
|
|
|
// Submit the specified transaction.
|
|
// createCar transaction - requires 5 argument, ex: ('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom')
|
|
// changeCarOwner transaction - requires 2 args , ex: ('changeCarOwner', 'CAR10', 'Dave')
|
|
await contract.submitTransaction('createCar', 'CAR12', 'Honda', 'Accord', 'Black', 'Tom');
|
|
console.log('Transaction has been submitted');
|
|
|
|
// Disconnect from the gateway.
|
|
await gateway.disconnect();
|
|
|
|
} catch (error) {
|
|
console.error(`Failed to submit transaction: ${error}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main();
|