无法实例化此java链代码
我试图在“first network”示例中部署一个基于Java的链码。 该代码由IBM区块链平台VSCode插件生成。 它在本地环境中工作(使用VSCode插件安装、调用……),但当我尝试在“first network”示例中测试链码时,它崩溃了 当地环境:无法实例化此java链代码,java,hyperledger-fabric,hyperledger,hyperledger-chaincode,chaincode,Java,Hyperledger Fabric,Hyperledger,Hyperledger Chaincode,Chaincode,我试图在“first network”示例中部署一个基于Java的链码。 该代码由IBM区块链平台VSCode插件生成。 它在本地环境中工作(使用VSCode插件安装、调用……),但当我尝试在“first network”示例中测试链码时,它崩溃了 当地环境: peer0.org1.example.com ca.org1.example.com order.example.com 第一个网络环境: cli peer0.org2.example.com peer1.org2.example.
- peer0.org1.example.com
- ca.org1.example.com
- order.example.com
- cli
- peer0.org2.example.com
- peer1.org2.example.com
- peer0.org1.example.com
- peer1.org1.example.com
- order.example.com
- couchdb2
- couchdb1
- couchdb3
- couchdb0
- ca.example.com
/*
* SPDX-License-Identifier: Apache-2.0
*/
package org.example;
import org.hyperledger.fabric.contract.annotation.DataType;
import org.hyperledger.fabric.contract.annotation.Property;
import org.json.JSONObject;
@DataType()
public class SimpleAsset {
@Property()
private String value;
public SimpleAsset(){
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String toJSONString() {
return new JSONObject(this).toString();
}
public static SimpleAsset fromJSONString(String json) {
String value = new JSONObject(json).getString("value");
SimpleAsset asset = new SimpleAsset();
asset.setValue(value);
return asset;
}
}
SimpleAssetContract.java
/*
* SPDX-License-Identifier: Apache-2.0
*/
package org.example;
import org.hyperledger.fabric.contract.Context;
import org.hyperledger.fabric.contract.ContractInterface;
import org.hyperledger.fabric.contract.annotation.Contract;
import org.hyperledger.fabric.contract.annotation.Default;
import org.hyperledger.fabric.contract.annotation.Transaction;
import org.hyperledger.fabric.contract.annotation.Contact;
import org.hyperledger.fabric.contract.annotation.Info;
import org.hyperledger.fabric.contract.annotation.License;
import static java.nio.charset.StandardCharsets.UTF_8;
@Contract(name = "SimpleAssetContract",
info = @Info(title = "SimpleAsset contract",
description = "My Smart Contract",
version = "0.0.1",
license =
@License(name = "Apache-2.0",
url = ""),
contact = @Contact(email = "SimpleAsset@example.com",
name = "SimpleAsset",
url = "http://SimpleAsset.me")))
@Default
public class SimpleAssetContract implements ContractInterface {
public SimpleAssetContract() {
}
@Transaction()
public boolean simpleAssetExists(Context ctx, String simpleAssetId) {
byte[] buffer = ctx.getStub().getState(simpleAssetId);
return (buffer != null && buffer.length > 0);
}
@Transaction()
public void createSimpleAsset(Context ctx, String simpleAssetId, String value) {
boolean exists = simpleAssetExists(ctx,simpleAssetId);
if (exists) {
throw new RuntimeException("The asset "+simpleAssetId+" already exists");
}
SimpleAsset asset = new SimpleAsset();
asset.setValue(value);
ctx.getStub().putState(simpleAssetId, asset.toJSONString().getBytes(UTF_8));
}
@Transaction()
public SimpleAsset readSimpleAsset(Context ctx, String simpleAssetId) {
boolean exists = simpleAssetExists(ctx,simpleAssetId);
if (!exists) {
throw new RuntimeException("The asset "+simpleAssetId+" does not exist");
}
SimpleAsset newAsset = SimpleAsset.fromJSONString(new String(ctx.getStub().getState(simpleAssetId),UTF_8));
return newAsset;
}
@Transaction()
public void updateSimpleAsset(Context ctx, String simpleAssetId, String newValue) {
boolean exists = simpleAssetExists(ctx,simpleAssetId);
if (!exists) {
throw new RuntimeException("The asset "+simpleAssetId+" does not exist");
}
SimpleAsset asset = new SimpleAsset();
asset.setValue(newValue);
ctx.getStub().putState(simpleAssetId, asset.toJSONString().getBytes(UTF_8));
}
@Transaction()
public void deleteSimpleAsset(Context ctx, String simpleAssetId) {
boolean exists = simpleAssetExists(ctx,simpleAssetId);
if (!exists) {
throw new RuntimeException("The asset "+simpleAssetId+" does not exist");
}
ctx.getStub().delState(simpleAssetId);
}
}
我不知道我做得对不对。我将遵循以下步骤:
$ ./byfn.sh up -s couchdb -l java # Deploy the network with Couchdb and Java
$ cp -r SimpleAsset fabric-samples/chaincode/ # This is the chaincodes path in the docker
$ docker exec -it cli bash # Go to the Cli # We go inside the docker
$ /opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode install -n sa01 -v 1.0 -l java -p /opt/gopath/src/github.com/chaincode/SimpleAsset/ # Install the SimpleAsset chaincode -> OK!
$ /opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n sa01 -l java -v 1.0 -c '{"Args":[]}' -P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'')'
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg chaincode registration failed: container exited with 1
我做错了什么?如何解决这个问题?java fabric shim版本1.4.2存在一个问题,这意味着如果您声明对该版本的依赖,它将无法实例化。检查pom.xml或build.gradle文件,查看正在使用哪个版本,并使用1.4.4或更高版本(目前只有1.4.4可用,但有进一步发布的计划)在所有对等机上安装链码。如果不工作,请检查订购者日志和对等日志。经常检查你的日志。StackOverflow用户不是透视者,但您也可以随时检查日志。谢谢这就是问题所在!我不明白为什么它接受Go、TypeScript和NodeJS而不接受Java。build.gradle中的版本(1.4.2)是问题所在。将行更改为->编译组:“org.hyperledger.fabric chaincode java”,名称:“fabric chaincode shim”,版本:“1.4.4”