使用超级账本架构 SDK 开发应用
Hyperledger Fabric SDK 现已过时。但是,您可以安装和使用超级账本架构 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) You must modify the SDK to work with Oracle Blockchain Platform by following the instructions in Update the Hyperledger Fabric Java SDK to Work with 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(通道)选项卡,然后找到并单击运行链代码的通道的名称。
- 在渠道的分类账窗格中,查看链代码的分类账汇总。
更新超级账本架构 Go SDK,与 Oracle Blockchain Platform 协同工作
您必须更新超级账本架构 Go SDK 中的 NormalizeURL 函数,才能将其与基于 Kubernetes 的 Oracle Blockchain Platform 版本结合使用。
- 在超级账本架构 Go SDK 中打开
client.go文件进行编辑:vendor/github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/client.go - 按以下代码中所示更新
NormalizeURL函数。编辑前使用NormalizeURL函数:// NormalizeURL normalizes a URL (from cfssl) func NormalizeURL(addr string) (*url.URL, error) { addr = strings.TrimSpace(addr) u, err := url.Parse(addr) if err != nil { return nil, err } if u.Opaque != "" { u.Host = net.JoinHostPort(u.Scheme, u.Opaque) u.Opaque = "" } else if u.Path != "" && !strings.Contains(u.Path, ":") { u.Host = net.JoinHostPort(u.Path, "") u.Path = "" } else if u.Scheme == "" { u.Host = u.Path u.Path = "" } if u.Scheme != "https" { u.Scheme = "http" } . . .编辑后的NormalizeURL函数:// NormalizeURL normalizes a URL (from cfssl) func NormalizeURL(addr string) (*url.URL, error) { addr = strings.TrimSpace(addr) u, err := url.Parse(addr) if err != nil { return nil, err } if u.Opaque != "" { u.Host = net.JoinHostPort(u.Scheme, u.Opaque) u.Opaque = "" } else if u.Host != "" && !strings.Contains(u.Host, ":") { u.Host = net.JoinHostPort(u.Host, "") u.Path = "" } else if u.Scheme == "" { u.Host = u.Path u.Path = "" } . . . - 保存
client.go文件。
将超级账本架构 Java SDK 更新为与 Oracle Blockchain Platform 协同工作
OCI 基础设施组件与随 Hyperledger Fabric v2.x 提供的 Java SDK 之间存在不兼容性。您必须更新 SDK 才能将其与 Oracle Blockchain Platform 一起使用。
更新 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=jargroupid、artifactid和version与要替换的软件包保持相同。 -
手动替换软件包。转到本地 Maven 系统信息库,找到目标软件包所在的目录,然后将该软件包替换为修补的软件包。
-
-
运行项目。