public FabricClient(UserContext userContext) throws Exception { hfClient=HFClient.createNewInstance(); //设置加密算法 CryptoSuite cryptoSuite=CryptoSuite.Factory.getCryptoSuite(); hfClient.setCryptoSuite(cryptoSuite); //设置环境变量 hfClient.setUserContext(userContext); }
时间: 2023-12-06 13:42:31 浏览: 19
这段代码是用于创建一个Hyperledger Fabric客户端的,其中userContext参数是指用户上下文(UserContext),包含了用户的身份、权限等信息。在创建客户端时,首先使用HFClient.createNewInstance()创建一个新的Hyperledger Fabric客户端实例,然后设置加密算法为CryptoSuite,最后将用户上下文设置到客户端中。通过这个客户端可以进行链码的部署和调用等操作。
相关问题
public String initChainCode() throws Exception { UserContext userContext=new UserContext(); userContext.setName("admin"); userContext.setAffiliation("Org1"); userContext.setMspId("Org1MSP"); userContext.setAccount("zdd"); //使用工具类生成enrollment Enrollment enrollment = UserUtils.getEnrollment(path.keyFolderPath,path.keyFileName,path.certFolderPath,path.certFileName); userContext.setEnrollment(enrollment); FabricClient fabricClient=new FabricClient(userContext); Peer peer = fabricClient.getPeer(path.peer0Name, path.peer0Grpc, path.tlsPeerFilePath); Orderer order = fabricClient.getOrder(path.orderName, path.orderGrpc, path.tlsOrderFilePath); String initArgs[] = {""}; fabricClient.initChainCode(path.channelName, TransactionRequest.Type.GO_LANG, path.chainCodeName,path.chainCodeVersion,order,peer,"init",initArgs); return "init"; }
这段代码是使用 Hyperledger Fabric Java SDK 初始化链码的方法。首先,它创建一个 UserContext 对象,并设置该对象的属性,如名称、隶属关系、MSP ID 和账户。接下来,它使用 UserUtils 工具类生成一个 Enrollment 对象,并将其设置为 UserContext 的属性,以便在后续操作中使用。然后,它创建一个 FabricClient 对象,并使用该对象获取 Peer 和 Orderer 对象。最后,它调用 FabricClient 对象的 initChainCode() 方法,来初始化链码,并传入相应的参数,如通道名称、链码语言、链码名称、链码版本、Orderer、Peer 和初始化参数等。最后,该方法返回 "init" 字符串。
@Override @Transactional public void addLearningRecord(LearningRecordFormDTO dto) { //1.获得当前用户 Long user = UserContext.getUser(); //2.处理学习记录 boolean finished=false; //2.1判断提交的类型 if (dto.getSectionType()==SectionType.EXAM){ //处理考试 finished=handleExam(user,dto); }else { //处理视频 finished=handleVideo(user,dto); } }
这段代码是一个添加学习记录的方法。首先通过`UserContext.getUser()`获取当前用户的ID,并将其赋值给变量`user`。接下来根据传入的学习记录表单`dto`中的`sectionType`属性判断提交的类型。如果`sectionType`等于`SectionType.EXAM`,则表示提交的是考试类型的学习记录,会调用`handleExam(user,dto)`方法进行处理,并将返回结果赋值给变量`finished`。如果`sectionType`不等于`SectionType.EXAM`,则表示提交的是视频类型的学习记录,会调用`handleVideo(user,dto)`方法进行处理,并将返回结果赋值给变量`finished`。最后,方法执行完毕。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)