0

我创建了 Java Chaincode 并将其部署在 Fabric 2.2 网络上。一切似乎都正常,但是当我从分类帐中进行任何查询时,我得到空白的 JSON 响应。我在日志中没有看到任何问题,所以似乎一切正常,但不知何故响应是空白的。

@Transaction()
        public Car queryCarById(final Context ctx, final String id) {
            ChaincodeStub stub = ctx.getStub();
            String CarState = stub.getStringState(id);
            if (CarState.isEmpty()) {
                String errorMessage = String.format("Car %s does not exist", id);
                System.out.println(errorMessage);
                throw new ChaincodeException(errorMessage, CarTransferErrors.Car_NOT_FOUND.toString());
            }
            Car Car = genson.deserialize(CarState, Car.class);
            System.out.println(Car);
            return Car;
        }



package Cartransfer;

import com.owlike.genson.annotation.JsonProperty;
import org.hyperledger.fabric.contract.annotation.DataType;
import org.hyperledger.fabric.contract.annotation.Property;

    @DataType()
    public final class Car {
    @Property()
    private final String id;

    @Property()
    private final String name;

    @Property()
    private final String area;

    @Property()
    private final String ownerName;
    
    @Property()
    private final String value;
    
    public String getid() {
        return id;
    }

    public String getname() {
        return name;
    }

    public String getarea() {
        return area;
    }

    public String getownerName() {
        return ownerName;
    }
    public String getvalue() {
        return value;
    }
    
    public Car(@JsonProperty("id") final String id, @JsonProperty("name") final String name,
            @JsonProperty("area") final String area, @JsonProperty("ownerName") final String ownerName,
            @JsonProperty("value") final String value) {
        this.id = id;
        this.name = name;
        this.area = area;
        this.ownerName = ownerName;this.value= value;}}
4

1 回答 1

0

可能是您对网络进行测试交易(在部署您的链码成功之后)?以下脚本可能有助于单独验证

https://github.com/hyperledger/fabric-samples/blob/75e3be113726d83a2de6d427608a0fec8e9b9711/test-network/scripts/deployCC.sh#L274

并使用此方法查询链码(验证账本上的 txn

https://github.com/hyperledger/fabric-samples/blob/75e3be113726d83a2de6d427608a0fec8e9b9711/test-network/scripts/deployCC.sh#L293

于 2020-10-03T07:07:55.177 回答