使用超级账本架构 SDK 开发应用
应用程序使用软件开发工具包 (SDK) 访问允许查询和更新分类账的 API。您可以安装并使用超级账本架构 SDK 开发适用于 Oracle Blockchain Platform 的应用。
Oracle Blockchain Platform 提供的 REST API 已创建,具有最大的灵活性;您可以调用事务处理、调用查询或查看事务处理的状态。请参阅 REST API for Oracle Blockchain Platform 。
但是,这种灵活性意味着您可能希望将现有 API 端点封装到应用程序中以提供对象级控制。应用程序可以包含更细粒度的操作。
SDK 版本
Hyperledger Fabric SDK 提供多个版本。使用与实例基于的超级账本架构版本匹配的 SDK 版本。
安装适用于 Node.js 的 Hyperledger Fabric SDK
有关如何使用适用于 Node.js 的 Fabric SDK 的信息,请参阅:适用于 Node.js 的 Hyperledger Fabric SDK 文档
在开发人员工具选项卡上,打开应用程序开发窗格。您可以使用此选项卡上的链接安装超级账本架构 Node.js SDK。
安装适用于 Java 的 Hyperledger Fabric SDK
有关如何使用适用于 Java 的 Fabric SDK 的信息,请参阅:适用于 Java 的 Hyperledger Fabric SDK 文档
- 您可以使用此选项卡上的链接安装超级账本架构 Java SDK。
- (Hyperledger Fabric v2.x) 如果您以前安装了 SDK,则必须按照 Update the Hyperledger Fabric v2.x SDK to Work with Oracle Blockchain Platform 中的说明进行修改以使用 Oracle Blockchain Platform 。
安装构建工具,例如 Apache Maven。
构建应用程序
与以下示例相似,构建您的 Java 应用程序:
/Application
/artifacts
/cypto
/orderer
Contains the certificates required for the application to act on the orderer node
In participant instances only contains TLS certificates
/peer
Contains the certificates required for the application to act on the peer node
/src
chaincode.go if installing and deploying chaincode to the blockchain
/java
pom.xml or other build configuration files
/resources
Any resources used by the Java code, including artifacts such as the endorsement policy yaml file and blockchain configuration properties
/src
Java source files
构造 Node.js 应用程序,类似于以下示例:
/Application
/artifacts
/cypto
/orderer
Contains the certificates required for the application to act on the orderer node
In participant instances only contains TLS certificates
/peer
Contains the certificates required for the application to act on the peer node
/src
chaincode.go if installing and deploying chaincode to the blockchain
/node
package.json file
application.js
/app
Any javascript files called by the application
/tools
运行应用程序
现在,您已准备好运行和测试应用程序。除了应用返回的任何状态消息之外,您还可以在 Oracle Blockchain Platform 控制台中检查账本,以查看您的更改:
- 转到控制台中的 Channels(通道)选项卡,然后找到并单击运行链代码的通道的名称。
- 在渠道的分类账窗格中,查看链代码的分类账汇总。
将 Hyperledger Fabric v2.x SDK 更新为与 Oracle Blockchain Platform 配合使用
OCI 基础设施组件与随 Hyperledger Fabric v2.x 提供的 Java SDK 之间存在不兼容性。请按照本主题中的步骤更正此问题。
更新 Hyperledger Fabric SDK 的方法
更新 SDK 有两种方法:
- 从控制台下载修改后的软件包。我们创建了一个更新的
grpc-netty-shaded-1.38.0.jar
文件,该文件是需要修改的 Java SDK 引用的模块。 - 手动构建软件包,如本主题所述。
要下载 grpc-netty-shaded-1.38.0.jar
文件,请单击控制台的 Developer Tools(开发人员工具)选项卡,然后选择 Application Development(应用程序开发)窗格。
手动构建软件包
对于 fabric-sdk-java
项目,完成以下步骤以重建 grpc-netty-shaded
软件包,将对等节点和排序节点与 grpcs
客户机(通过 TLS)连接。grpc-netty-shaded
软件包是 grpc-java
的子项目。
-
安装项目相关性:
mvn install
-
下载
grpc-java
源码:git clone https://github.com/grpc/grpc-java.git
- 找到
fabric-sdk-java
使用的grpc
版本,然后查看代码。在grpc-java
目录中,检查fabric-sdk-java
使用的grpc
版本:cd grpc-java && git checkout v1.38.0
-
更改代码以避免服务器端出现
alpn
错误。创建包含以下内容的grpc-java-patch
修补程序文件:diff --git a/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java b/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java index 19d3e01b7..ebc4786a3 100644 — a/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java +++ b/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java @@ -611,7 +611,8 @@ final class ProtocolNegotiators { SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt; if (handshakeEvent.isSuccess()) { SslHandler handler = ctx.pipeline().get(SslHandler.class); if (sslContext.applicationProtocolNegotiator().protocols() + if (handler.applicationProtocol() == null + || sslContext.applicationProtocolNegotiator().protocols() .contains(handler.applicationProtocol())) { // Successfully negotiated the protocol. logSslEngineDetails(Level.FINER, ctx, "TLS negotiation succeeded.", null);
-
应用补丁程序:
git apply grpc-java.patch
-
构建项目以生成目标打补丁程序包。使用 gradle 构建
grpc-java-shaded
项目:cd netty/shaded gradle build -PskipAndroid=true -PskipCodegen=true
构建完成后,可在
grpc-java/netty/build/libs/grpc-netty-shaded-1.38.0.jar
上获取已打补丁的目标.jar
软件包。 -
将打补丁的软件包添加到 Maven 本地系统信息库中。
通过以下两种方式之一将原始grpc-netty-shaded
.jar
软件包替换为已修补的软件包:-
使用 Maven 按本地文件安装软件包:
必须使目标mvn install:install-file -Dfile=grpc-netty-shaded-build/grpc-netty-shaded-1.38.0.jar -DgroupId=io.grpc -DartifactId=grpc-netty-shaded -Dversion=1.38.0 -Dpackaging=jar
groupid
、artifactid
和version
与要替换的软件包保持相同。 -
手动替换软件包。转到本地 Maven 系统信息库,找到目标软件包所在的目录,然后将该软件包替换为修补的软件包。
-
-
运行项目。