TypeError [ERR_INVALID_ARG_TYPE]: аргумент «путь» должен иметь строковый тип. Полученный тип не определен

Я пытаюсь установить цепной код с помощью fabricsdk в nodejs. Функция installchaincode выдает следующую ошибку:

TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received type undefined 

Ниже приведен код:

exports.installChaincode =
    async function() {
  let errorMessage = null;
  try {
    // first setup the client for this org
    var client = new Client();
    let serverCertPeer = await storageUtil.getFileContent(
        '/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem',
        'fabriccerts');
    let peer = client.newPeer('grpcs://IPADDRESS:7051', {
      'pem': Buffer.from(serverCertPeer).toString(),
      'ssl-target-name-override': 'peer0.org1.example.com'
    });
    var request = {
      targets: [peer],
      chaincodePath: 'github.com/chaincode/fabcar/go',
      chaincodeId: 'fabcar',
      chaincodeVersion: '5.0',
      chaincodeType: 'golang'
    };
    let results = await client.installChaincode(request);
    // the returned object has both the endorsement results
    // and the actual proposal, the proposal will be needed
    // later when we send a transaction to the orederer
    var proposalResponses = results[0];
    var proposal = results[1];

    // lets have a look at the responses to see if they are
    // all good, if good they will also include signatures
    // required to be committed
    for (const i in proposalResponses) {
      if (proposalResponses[i] instanceof Error) {
        errorMessage = util.format(
            'install proposal resulted in an error :: %s',
            proposalResponses[i].toString());
        console.log(errorMessage);
      } else if (
          proposalResponses[i].response &&
          proposalResponses[i].response.status === 200) {
        console.log('install proposal was good');
      } else {
        all_good = false;
        errorMessage = util.format(
            'install proposal was bad for an unknown reason %j',
            proposalResponses[i]);
        console.log(errorMessage);
      }
    }
  } catch (error) {
    console.log(
        'Failed to install due to error: ' + error.stack ? error.stack : error);
    errorMessage = error.toString();
  }

  if (!errorMessage) {
    let message = util.format('Successfully installed chaincode');
    console.log(message);
    // build a response to send back to the REST caller
    const response = {success: true, message: message};
    return response;
  } else {
    let message = util.format('Failed to install due to:%s', errorMessage);
    console.log(message);
    const response = {success: false, message: message};
    return response;
  }
}

Похоже, многие люди сталкивались с этой проблемой в сообществе, но нигде не было решения. Какой путь мы должны указать в параметре chaincodepath? Путь к контейнеру или локальный путь?

Дополнительная информация: я взял блок кода из примера приложения для переноса баланса, но внес несколько изменений, например, прочитал сведения об организации из входных данных вместо использования файла профиля подключения. Я могу создать канал, присоединиться к каналу, обновить канал, создать экземпляр цепного кода, используя вышеуказанный метод, который отлично работает, но когда дело доходит до установки цепного кода, он выдает ошибку.


person Ronald    schedule 02.06.2020    source источник


Ответы (1)


Вышеупомянутая проблема возникает, когда мы не устанавливаем gopath. Мы можем установить, используя ниже process.env.GOPATH = 'YOUR_GOPATH_HERE' перед отправкой запроса.

Если мы используем java chaincode, то путь указывать не нужно :)

person Ronald    schedule 03.06.2020