【发布时间】:2021-01-21 12:59:14
【问题描述】:
主要问题是从客户端的角度来看会出现有效负载错误。
基本设置:
Fabric 链码 -> 在 Java 中使用 fabric-chaincode-shim 实现:v2.3.0
应用程序客户端 -> 在 Typescript 中使用 fabric-network: 2.2.5 实现。
已实现的每个事务都可以正常工作,但我想知道如何实现客户端可读的 error_codes。
当我使用如下负载抛出 ChaincodeException 时,从客户端应用程序的角度来看,我得到了空缓冲区属性。
链码角度的示例代码:
public void createAsset(final Context ctx, String createAssetDto) {
throw new ChaincodeException("Sample message", "SamplePayloadWithSpecifiedCode");
}
应用客户端角度的示例代码:
try {
await contract.submitTransaction('createAsset', JSON.stringify(createAssetDto));
success = true;
} catch (err) {
logException(err);
success = false;
}
我注意到在对等实现中有一个函数将 ChaincodeMessage 解析为错误
case pb.ChaincodeMessage_ERROR:
return nil, resp.ChaincodeEvent, errors.Errorf("transaction returned with failure: %s", resp.Payload)
从同行的角度看日志:
failed to invoke chaincode ecmr, error: transaction returned with failure: Sample Message
github.com/hyperledger/fabric/core/chaincode.processChaincodeExecutionResult
/go/src/github.com/hyperledger/fabric/core/chaincode/chaincode_support.go:182
从这个角度来看,这意味着 ChaincodeException 消息是有效负载。
从客户端的角度来看,错误已经得到:
{
status: 500,
message: "error in simulation: transaction returned with failure: Sample Message",
payload: {
},
}
我认为我应该在 response.payload 属性中获得“SamplePayloadWithSpecifiedCode”。
我已经在源代码中找到了可能在 java 链码实现中将消息设置为来自 ChaincodeException 的有效负载的位置:
欢迎任何建议。谢谢
【问题讨论】:
-
我认为这个问题之前已经出现过,在 Hyperledger fabric-sdk-java 火箭聊天频道 - chat.hyperledger.org/channel/… 可能值得在 jira 上打开一个问题 - hyperledger-fabric.readthedocs.io/en/release-2.2/…
-
简单的结论 - 结构 java 链码实现返回不正确的有效负载(仅来自 ChaincodeException 的消息)。来自 ChaincodeException 的有效负载被省略。我说的对吗?
标签: hyperledger-fabric hyperledger hyperledger-chaincode