IBM Blockchain VSCode:无法调用链代码演示合同

IBM Blockchain VSCode: Failed to invoke chaincode demo-contract

我遵循了 IBM 区块链教程“A4:从 VS Code 调用智能合约”。我使用 IBM Blockchain 扩展创建了一个演示合同项目,如教程中所述,合同语言为“TypeScript”。但是在步骤 A4.4 中,我无法展开 Fabric Gateways 视图中的通道树来显示可用事务。

我正在使用 Mac 最新的 VS Code 和 IBM Blockchain Extension,以及最新的 Docker 桌面版 3.3.3。

我注意到在将合约部署到“1 Org Local Fabric”环境时出现问题(完整日志请见下文):

chaincode registration failed: failed to wait on container exit: builder 'node' run failed: exit status 1

在 VSCode 控制台中,我还收到了这些日志,其中指出链代码调用存在问题:

15.5.2021 16:18:13] [INFO] affectionate_diffie|[        org1peer] 2021-05-15 14:18:13.867 UTC [endorser] callChaincode -> INFO 119 finished chaincode: demo-contract duration: 974ms channel=mychannel txID=c962db53
[15.5.2021 16:18:13] [INFO] affectionate_diffie|[        org1peer] 2021-05-15 14:18:13.867 UTC [endorser] SimulateProposal -> ERRO 11a failed to invoke chaincode demo-contract, error: exit status 1
[15.5.2021 16:18:13] [INFO] affectionate_diffie|[        org1peer] builder 'node' run failed
[15.5.2021 16:18:13] [INFO] affectionate_diffie|[        org1peer] 2021-05-15 14:18:13.867 UTC [endorser] callChaincode -> INFO 119 finished chaincode: demo-contract duration: 974ms channel=mychannel txID=c962db53
[15.5.2021 16:18:13] [INFO] affectionate_diffie|[        org1peer] 2021-05-15 14:18:13.867 UTC [endorser] SimulateProposal -> ERRO 11a failed to invoke chaincode demo-contract, error: exit status 1
[15.5.2021 16:18:13] [INFO] affectionate_diffie|[        org1peer] builder 'node' run failed

在 docker 容器内引用的 /tmp/npm-cache/_logs/2021-05-15T14_28_30_384Z-debug.log 文件中,我看到了这个错误:

6 info lifecycle demo-contract@0.0.1~start: demo-contract@0.0.1
7 verbose lifecycle demo-contract@0.0.1~start: unsafe-perm in lifecycle true
8 verbose lifecycle demo-contract@0.0.1~start: PATH: /opt/node/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/.bin:/opt/microfab/bin:/opt/fabric/bin:/opt/gradle/bin:/opt/maven/bin:/opt/go/bin:/opt/node/bin:/opt/java/bin:/opt/couchdb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle demo-contract@0.0.1~start: CWD: /opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld
10 silly lifecycle demo-contract@0.0.1~start: Args: [
10 silly lifecycle   '-c',
10 silly lifecycle   'fabric-chaincode-node start "--peer.address=172.17.0.2:2005"'
10 silly lifecycle ]
11 silly lifecycle demo-contract@0.0.1~start: Returned: code: 1  signal: null
12 info lifecycle demo-contract@0.0.1~start: Failed to exec start script
13 verbose stack Error: demo-contract@0.0.1 start: `fabric-chaincode-node start "--peer.address=172.17.0.2:2005"`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/opt/node/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/opt/node/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid demo-contract@0.0.1
15 verbose cwd /opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld
16 verbose Linux 4.19.121-linuxkit
17 verbose argv "/opt/node/bin/node" "/opt/node/bin/npm" "start" "--" "--peer.address=172.17.0.2:2005"
18 verbose node v12.17.0
19 verbose npm  v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error demo-contract@0.0.1 start: `fabric-chaincode-node start "--peer.address=172.17.0.2:2005"`
22 error Exit status 1
23 error Failed at the demo-contract@0.0.1 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

我删除了“1 Org Local Fabric”环境并删除了Docker容器和图像“ibmcom/ibp-microfab:0.0.11”并重新启动了整个过程多次,但总是出现错误再次.

请帮我解决这个问题。

这里是从合约部署到“1 Org Local Fabric”环境的完整日志:

[        org1peer] 2021-05-15 15:43:10.424 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0b4 Error: Cannot find module '/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/dist/index.js' command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0b5 Require stack: command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0b6 - /opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/contract-spi/bootstrap.js command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0b7 - /opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/cmds/metadata/lib/generate.js command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0b8 - /opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/cmds/metadata.js command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0b9 - /opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/yargs/index.js command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0ba - /opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/cli.js command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0bb     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0bc     at Function.Module._load (internal/modules/cjs/loader.js:842:27) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0bd     at Module.require (internal/modules/cjs/loader.js:1026:19) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0be     at require (internal/modules/cjs/helpers.js:72:18) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0bf     at Function.getInfoFromContract (/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/contract-spi/bootstrap.js:77:23) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c0     at Function.bootstrap (/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/contract-spi/bootstrap.js:54:63) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c1     at Object.exports.handler (/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/cmds/startCommand.js:46:40) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c2     at Object.runCommand (/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/yargs/build/lib/command.js:196:48) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c3     at Object.parseArgs [as _parseArgs] (/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/yargs/build/lib/yargs.js:1043:55) command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c4     at Object.get [as argv] (/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/yargs/build/lib/yargs.js:986:25) { command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c5   code: 'MODULE_NOT_FOUND', command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c6   requireStack: [ command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c7     '/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/contract-spi/bootstrap.js', command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c8     '/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/cmds/metadata/lib/generate.js', command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0c9     '/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/lib/cmds/metadata.js', command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0ca     '/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/yargs/index.js', command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0cb     '/opt/microfab/data/peer-org1/data/externalbuilder/builds/demo-contract_0.0.1-d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9/bld/node_modules/fabric-shim/cli.js' command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0cc   ] command=run
[        org1peer] 2021-05-15 15:43:10.425 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0cd } command=run
[        org1peer] 2021-05-15 15:43:10.436 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0ce npm ERR! code ELIFECYCLE command=run
[        org1peer] 2021-05-15 15:43:10.436 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0cf npm ERR! errno 1 command=run
[        org1peer] 2021-05-15 15:43:10.437 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0d0 npm ERR! demo-contract@0.0.1 start: `fabric-chaincode-node start "--peer.address=172.17.0.2:2005"` command=run
[        org1peer] 2021-05-15 15:43:10.437 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0d1 npm ERR! Exit status 1 command=run
[        org1peer] 2021-05-15 15:43:10.437 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0d2 npm ERR!  command=run
[        org1peer] 2021-05-15 15:43:10.438 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0d3 npm ERR! Failed at the demo-contract@0.0.1 start script. command=run
[        org1peer] 2021-05-15 15:43:10.438 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0d4 npm ERR! This is probably not a problem with npm. There is likely additional logging output above. command=run
[        org1peer] 2021-05-15 15:43:10.443 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0d5  command=run
[        org1peer] 2021-05-15 15:43:10.443 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0d6 npm ERR! A complete log of this run can be found in: command=run
[        org1peer] 2021-05-15 15:43:10.443 UTC [chaincode.externalbuilder.node] waitForExit -> INFO 0d7 npm ERR!     /tmp/npm-cache/_logs/2021-05-15T15_43_10_439Z-debug.log command=run
[        org1peer] 2021-05-15 15:43:10.448 UTC [lifecycle] Work -> WARN 0d8 could not launch chaincode 'demo-contract_0.0.1:d66596dd67ab1c8de75d7ad3c0ce89d18584a27a4d804b1cb97cda493a13d8d9': chaincode registration failed: failed to wait on container exit: builder 'node' run failed: exit status 1

我猜你选择了 typescript 作为你 chaincode/contract 的语言,它看起来没有将 typescript 代码转换为 javascript。我怀疑 package.json 中有一个构建选项,因此请尝试 运行ning npm run build 在智能合约存储目录中的 vscode 终端中(应该有一个package.json 该目录中的文件)。如果因为找不到 tsc 而失败,那么您需要先 运行 npm install 安装所有先决条件,然后您应该能够 运行 npm run build.

一旦你的智能合约成功转译(应该在 dist 目录的 index.js 文件中,这就是你发布的错误消息所抱怨的)你应该能够打包 chaincode/contract 再次安装它(您可能需要在尝试再次安装之前更改新软件包的版本号,这是 package.json 文件中的 version 字段。