Я использую модифицированную версию учебника byfn
, с 5 заказчиками, 1 организацией, 2 пирами и 1 сервисом ca с docker -compose. Локально я запускаю приложение узла, используя node v10.18.1
на macOs Catalina
. hyperledger fabric version 1.4
также используется.
Я попытался заменить путь в файле connection.json
, относящийся к grpcUrl's, с localhost
на IP для контейнеров, предоставленных командой docker inspect
, а также на 0.0.0.0
безуспешно, также использовали te lnet для grep открытых портов и запустили docker ps
, чтобы проверить, что все контейнеры работают с правильными портами.
В моем коде я могу успешно зарегистрироваться администратор и другие пользователи, но не удается подключиться к шлюзу для вызова кода цепи.
В журналах API постоянно появляется ошибка:
2020-01-15T15:42:37.920Z - error: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:7051
2020-01-15T15:42:37.922Z - error: [Channel.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:7051
2020-01-15T15:42:40.929Z - error: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:8051
2020-01-15T15:42:40.929Z - error: [Channel.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:8051
2020-01-15T15:42:40.930Z - error: [Network]: _initializeInternalChannel: Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpcs://localhost:8051
level:warn time:2020-01-15T15:42:40.932Z message: "x-request-id_ac5294fd-9587-4432-87d9-ada4e73a1142 creating user product Unable to initialize channel. Attempted to contact 2 Peers. Last error was Error: Failed to connect before the deadline URL:grpcs://localhost:8051"
Почему Я получаю эту ошибку?
Мой connection.json
файл:
{
"name": "first-network-org1",
"version": "1.0.0",
"client": {
"organization": "Org1",
"connection": {
"timeout": {
"peer": {
"endorser": "300"
}
}
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"peers": [
"peer0.org1.example.com",
"peer1.org1.example.com"
],
"certificateAuthorities": [
"ca.org1.example.com"
]
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpcs://localhost:7051",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com",
"hostnameOverride": "peer0.org1.example.com"
}
},
"peer1.org1.example.com": {
"url": "grpcs://localhost:8051",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com",
"hostnameOverride": "peer1.org1.example.com"
}
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "https://localhost:7054",
"caName": "ca-org1",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----...\n-----END CERTIFICATE-----\n"
},
"httpOptions": {
"verify": false
}
}
}
}
Это зависимости в моем пакете. json файл (на первый взгляд, я пытался вручную установить последнюю версию модуль grp c безуспешно):
"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"express": "^4.16.4",
"fabric-ca-client": "^1.4.4",
"fabric-client": "^1.4.4",
"fabric-network": "^1.4.4",
"helmet": "^3.15.1",
"http-status": "^1.3.1",
"joi": "^14.3.1",
"lodash": "^4.17.11",
"nconf": "^0.10.0",
"request-promise": "^4.2.4",
"swagger-stats": "^0.95.7",
"uuid": "^3.3.2",
"winston": "^3.2.1",
"xss": "^1.0.3"
}
Вот мой ошибочный код:
const initGateway = async (params) => {
try {
const {
wallet,
identity,
discovery, // object with { enabled: true, asLocalhost: true }
channelName,
contractName
} = params;
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity, discovery });
// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork(channelName);
logger.info({ message: `NETWORK ${network}` });
// Get the contract from the network.
const contract = network.getContract(contractName);
return { gateway, contract };
} catch (err) {
throw err;
}
};
const createProduct = async (dataObj) => {
try {
const {
userIdentity,
seller,
value,
description,
issueDateTime,
productId
} = dataObj;
// Create a new file system based wallet for managing identities
const wallet = new FileSystemWallet(walletFilePath);
const params = {
wallet,
identity: userIdentity,
discovery: { enabled: true, asLocalhost: true },
channelName: 'mychannel',
contractName: 'mychaincode'
};
// Get the contract from the network.
const { gateway, contract } = await initGateway(params);
await contract.submitTransaction('setForSale', seller, productId, issueDateTime, value, description);
// Disconnect from the gateway.
await gateway.disconnect();
} catch (err) {
throw err;
}
};