Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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();
if (userIdentity) {
// We have an identity to use
BaseUtils.logMsg(`Identity ${userId} already exists in wallet and will be used`);
test('\n\n***** Network End-to-end flow: invoke transaction to move money using CouchDB wallet *****\n\n', async (t: tape.Test) => {
const gateway = new Gateway();
try {
const couchDBWallet = await Wallets.newCouchDBWallet({url: 'http://localhost:5984'});
await identitySetup(couchDBWallet);
await gateway.connect(JSON.parse(ccp.toString()), {
clientTlsIdentity: tlsIdentityName,
discovery: {
enabled: false,
},
identity: identityName,
wallet: couchDBWallet,
});
t.pass('Connected to the gateway');
const network = await gateway.getNetwork(channelName);
t.pass('Initialized the channel, ' + channelName);
const contract = await network.getContract(chaincodeId);