Hyperledger Fabric SDKを使用したアプリケーションの開発
アプリケーションでは、ソフトウェア開発キット(SDK)を使用して、レジャーへの問合せおよび更新を可能にするAPIにアクセスします。Hyperledger Fabric SDKをインストールして使用し、Oracle Blockchain Platform用のアプリケーションを開発できます。
Oracle Blockchain Platformに用意されているREST APIは、柔軟性を念頭に置いて作成されており、トランザクションの呼出し、問合せの呼出し、トランザクションのステータスの表示が可能です。『Oracle Blockchain Platform REST API』を参照してください。
ただし、この柔軟性により、オブジェクトレベルの制御を実現するために、既存のAPIエンドポイントをアプリケーション内にラップする可能性が高くなります。アプリケーションに、さらに詳細な操作を含めることができます。
SDKのバージョン
複数のバージョンのHyperledger Fabric SDKを使用できます。インスタンスのベースとなっているHyperledger Fabricのバージョンに一致するSDKのバージョンを使用します。
Hyperledger Fabric SDK for Node.jsのインストール
Fabric SDK for Node.jsの使用方法に関する情報は、次の場所にあります: Hyperledger Fabric SDK for Node.jsのドキュメント
開発者ツールタブで、アプリケーション開発ペインを開きます。このタブのリンクを使用して、Hyperledger Fabric Node.js SDKをインストールできます。
Hyperledger Fabric SDK for Javaのインストール
Fabric SDK for Javaの使用方法に関する情報は、次の場所にあります: Hyperledger Fabric SDK for Javaのドキュメント
- このタブのリンクを使用して、Hyperledger Fabric Java SDKをインストールできます。
- (Hyperledger Fabric v2.x)以前にSDKをインストールした場合は、Hyperledger Fabric v2.x SDKを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コンソールでレジャーをチェックして変更を確認できます:
- コンソールでチャネル・タブに移動し、チェーンコードを実行しているチャネルの名前を探してクリックします。
- チャネルのレジャー・ペインで、チェーンコードのレジャーのサマリーを確認します。
Hyperledger Fabric v2.x SDKをOracle Blockchain Platformと連携するように更新します
OCIインフラストラクチャ・コンポーネントと、Hyperledger Fabric v2.xで提供されているJava SDKには互換性がありません。このトピックのステップに従ってこの問題を解決します。
Hyperledger Fabric SDKの更新方法
SDKを更新する方法は2つあります:
- 変更したパッケージをコンソールからダウンロードします。Java SDKが参照するモジュールで、変更が必要な
grpc-netty-shaded-1.38.0.jar
ファイルが作成されています。 - この項の説明に従って、パッケージを手動でビルドします。
grpc-netty-shaded-1.38.0.jar
ファイルをダウンロードするには、コンソールの「開発者ツール」タブをクリックし、「アプリケーション開発」ペインを選択します。
パッケージの手動構築
fabric-sdk-java
プロジェクトの場合は、次のステップを実行してgrpc-netty-shaded
パッケージを再ビルドし、ピアおよびオーダラを(TLS経由で) grpcs
クライアントに接続します。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
-
ターゲットのパッチ適用済パッケージを生成するプロジェクトを構築します。
grpc-java-shaded
プロジェクトを構築するにはgradleを使用します。cd netty/shaded gradle build -PskipAndroid=true -PskipCodegen=true
ビルドの完了後、ターゲットのパッチ適用済
.jar
パッケージはgrpc-java/netty/build/libs/grpc-netty-shaded-1.38.0.jar
にあります。 -
パッチ適用済パッケージをMavenローカル・リポジトリに追加します。
次の2つの方法のいずれかで、元の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リポジトリに移動し、ターゲット・パッケージがあるディレクトリを探し、パッケージをパッチ適用済パッケージに置き換えます。
-
-
プロジェクトを実行します。