Comments (13)
Electronが良さそう、、、一番開発が活発。
from estate-sample.
Electronでアプリケーションを作ってみよう
install
$ npm -g install electron
初期設定
$ mkdir electron-estate
$ cd electron-estate
$ npm init -y
参考ページの index.html, index.js を用意して
electron .
from estate-sample.
ElectronのメニューからJavaScript呼び出し
以下でsourceをdl
git clone https://github.com/atom/electron-quick-start
そのあと、js の renderer.js に alert書き込んだら動いた。ここにfabric lib を読み込ませる。
ただ、
const fs = require('fs')
とやっただけで、alertが発生しなくなる、、、
const fs = require('fs')
alert('aaa');
debugをしなければ
from estate-sample.
Electronの環境構築とVisual Studio Codeでデバッグする方法
以下に lunch.json を置き換える
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
// "program": "${workspaceRoot}/main.js",
// "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"runtimeExecutable": "/Users/shohu33/.nodebrew/current/bin/electron",
"runtimeArgs": [
"--enable-logging"
],
"args": [
"."
],
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"console":"integratedTerminal",
}
]
}
すると vscodeのconsoleに以下エラー
"Uncaught ReferenceError: require is not defined", source: file:///Users/shohu33/sc/electron-quick-start/renderer.js (4)
require が使えないと。
そうか、browserで呼び出すjsではそりゃ無理だ
from estate-sample.
試しに以下のような const で fabric の lib 読み込むjs作って、main.jsから呼び出してみる
const fs = require('fs')
const path = require('path')
const FabricCAService = require('fabric-ca-client')
const Client = require('fabric-client')
const hash = require('fabric-client/lib/hash')
const jsrsa = require('jsrsasign')
const { KEYUTIL } = jsrsa
const elliptic = require('elliptic')
const EC = elliptic.ec
function demo() {
alert('demo!!!');
}
exports.default = demo;
すると、以下エラー
Error: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: electron-v5.0-darwin-x64-unknown
Found: [node-v57-darwin-x64-unknown]
This problem can often be fixed by running "npm rebuild" on the current system
Original error: Cannot find module '/Users/shohu33/sc/electron-quick-start/node_modules/grpc/src/node/extension_binary/electron-v5.0-darwin-x64-unknown/grpc_node.node'
npm rebuild 試してみたが、変わらず。
以下に解決策?
https://stackoverflow.com/questions/52156883/error-with-firebase-on-electron-app-failed-to-load-grpc
どうも node の version あわせて rebuild する必要があると
$ npm rebuild --runtime=electron --target=8.16.0
をやったが、以下エラー
/Users/shohu33/.node-gyp/8.16.0/include/node/openssl/e_os2.h:276:11: error: 'OPENSSL_EXPORT' macro redefined
[-Werror,-Wmacro-redefined]
# define OPENSSL_EXPORT extern
^
from estate-sample.
electron / electron-vueでgRPCを使う
これを試してみたが
$ yarn add grpc electron-rebuild
$ ./node_modules/.bin/electron-rebuild
同じエラー
../deps/grpc/third_party/boringssl/include/openssl/base.h:143:9: error: 'OPENSSL_THREADS' macro redefined [-Werror,-Wmacro-redefined]
#define OPENSSL_THREADS
さらに下みると grpc の 1.17.0 がよばれている。これが 1.21.1 じゃないと最新じゃない。
これ、どうも node 8系つかってたからっぽい、、、、が、fabric 8系じゃないとだめなんじゃなかったっけか。
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build --library=static_library`
npm ERR! Exit status 1
以下のようにelectrumを4系にしたら通ったので一旦これで進める。
$ node -v
v8.16.0
$ yarn add [email protected]
$ npm rebuild --target=4.1.0 --runtime=electron --dist-url=https://atom.io/download/electron
from estate-sample.
offline署名のtestを試す
CAをBYFNで立ち上げる。 -a というオプションつけるとCAも立ち上がる
./byfn.sh up -a -l node
CAのportは以下
ports:
- "7054:7054"
:
ports:
- "8054:8054"
実行すると以下部分で
const sendSignedProposalReq = {signedProposal, targets}
const proposalResponses = await channel.sendSignedProposal(sendSignedProposalReq)
https://fabric-sdk-node.github.io/release-1.3/Channel.html#.sendSignedProposal__anchor
以下エラー
E0617 10:26:29.098517000 4304881088 ssl_transport_security.cc:1229] Handshake failed with fatal error SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED.
以下で同じようにはまってる人が
Generic ("*") wildcard certificates aren't accepted
証明書が違う??
そうか、そもそもtestがbyfn用のnetworkに作られていないので証明書など指定しなおす必要があるな
carfabのsmartcontractをインストール
以下を使ってインストールしておく
https://github.com/shohu/estate-sample/blob/release-1.4/fabcar/startFabric.sh
./startFabric.sh javascript
Admin と User の wallet作成して秘密鍵などを手に入れておく
$ node enrollAdmin.js
Wallet path: /Users/shohu33/sc/estate-sample/fabcar/javascript/wallet
Successfully enrolled admin user "admin" and imported it into the wallet
$ node registerUser.js
Wallet path: /Users/shohu33/sc/estate-sample/fabcar/javascript/wallet
Successfully registered and enrolled admin user "user1" and imported it into the wallet
certは、user1というファイルができるのでその箇所の"BEGIN CERTIFICATE"から"END CERTIFICATE"を抜き出して取得
from estate-sample.
byfn.sh の環境でテストが動かないので、sdk環境でテストをまず動かして、その環境にelectrumもってくることを試してみる
秘密鍵など作成
コンテナ起動
$ cd fabric-sdk-node/test/fixtures/docker-compose
$ docker-compose up -d
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a9fcfd970fca hyperledger/fabric-peer "peer node start" 5 seconds ago Up 3 seconds 0.0.0.0:8051->8051/tcp peer0.org2.example.com
e01292affe52 hyperledger/fabric-peer "peer node start" 5 seconds ago Up 3 seconds 0.0.0.0:7051->7051/tcp peer0.org1.example.com
397b52e9b888 hyperledger/fabric-couchdb "tini -- /docker-ent…" 7 seconds ago Up 5 seconds 4369/tcp, 9100/tcp, 0.0.0.0:6984->5984/tcp couchdb.org2.example.com
e3cd7d6de665 hyperledger/fabric-ca "sh -c 'fabric-ca-se…" 7 seconds ago Up 5 seconds 0.0.0.0:8054->7054/tcp ca1.example.com
c5d1a21b2943 hyperledger/fabric-ca "sh -c 'fabric-ca-se…" 7 seconds ago Up 5 seconds 0.0.0.0:7054->7054/tcp ca0.example.com
95765caced97 hyperledger/fabric-couchdb "tini -- /docker-ent…" 7 seconds ago Up 5 seconds 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb.org1.example.com
test
test実行して以下エラー
$ node signTransactionOffline.js
TAP version 13
:
2019-06-17T05:46:44.855Z - error: [FabricCAClientService.js]: Failed to enroll admin, error:%o message=Calling enrollment endpoint failed with error [Error: write EPROTO 4484330944:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827:
これはcaのdocker-composeに以下パラメータ入れた。byfnを参照した
- FABRIC_CA_SERVER_TLS_ENABLED=true
エラー対応 : routines:SSL3_GET_RECORD:wrong
次は以下エラー
Handshake failed with fatal error SSL_ERROR_SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number.
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
結局以下に変更。
- grpcs -> grpc
// 'grpcs://localhost:7051',
'grpc://localhost:7051',
- https -> http
// const caService = new FabricCAService('https://localhost:7054', tlsOptions, 'ca-org1');
const caService = new FabricCAService('http://localhost:7054', tlsOptions, 'ca-org1');
- FABRIC_CA_SERVER_TLS_ENABLEDをfalse. docker-compose.yaml
- FABRIC_CA_SERVER_TLS_ENABLED=false
エラー対応 : access denied: channel [mychannel] creator org [Org1MSP]
以下のような対応が必要だと想われる。
____ _____ _ ____ _____
/ ___| |_ _| / \ | _ \ |_ _|
\___ \ | | / _ \ | |_) | | |
___) | | | / ___ \ | _ < | |
|____/ |_| /_/ \_\ |_| \_\ |_|
Build your first network (BYFN) end-to-end test
Channel name : mychannel
Creating channel...
+ peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
これは、fabcarの中のstartFabric.shにchannel作成があった。
これをそのまま使うことにした。
Error: 2 UNKNOWN
2019-06-17T07:10:33.623Z - info: [Peer.js]: sendProposal - Received proposal response from: grpc://localhost:7051 status: Error: 2 UNKNOWN: Stream removed
fabric call --- 2.5 [ { Error: 2 UNKNOWN: Stream removed
https://github.com/hyperledger/composer/issues/4305
fabcarのディレクトリをもってきたやってもいっしょだ。うまくいかない。
from estate-sample.
以下の方法で offline署名のscriptが動いた 👍
- sampleソースから以下持ち込む
- chaincode
- first-network
- fabcar - ネットワーク構築
cd ./fabcar
./startFabric.sh javascript - ソースを以下に修正
- ユーザーの privateKeyPathなどは、first-network/crypto-configの下のファイルにあわせる
- peer, ordererも同じく first-network/crypto-configの下のファイルにあわせる
- chaincode呼び出しを以下のようにfabcarのchaincodeに変更
const transactionProposalReq = {
fcn: 'createCar',
args: ['CAR12', 'Honda', 'Accord', 'Black', 'Tom'],
chaincodeId: 'fabcar',
channelId: 'mychannel'
}
- 起動
$ yarn start
yarn run v1.15.2
$ electron .
:
Successfully build commit transaction proposal
2019-06-17T08:33:25.876Z - info: [Remote.js]: Successfully connected to remote gRPC server
Successfully commit should response success { status: 'SUCCESS', info: '' }
Successfully registered event for e48ff071bf55e36bb82c9e5b2e655fc5de694075b4bb39ced15b13472689ad68
Successfully called connect on localhost:7051
Event has been seen with transaction code:ENDORSEMENT_POLICY_FAILURE for transaction id:e48ff071bf55e36bb82c9e5b2e655fc5de694075b4bb39ced15b13472689ad68 for blockNum:7
Successfully transactionMonitor
from estate-sample.
estateのchaincodeをインストール
- chaincodeのestateフォルダを、PJのchaincode配下にもってくる
- estateフォルダ内で npm install
- fabcarのstartFabric.shを改造して estate用にする。
- node estate.js で estateのchaincodeを呼び出せるように改造
offlineからestateのchaincodeの呼び出し
できた 👍
$ node estate.js
Successfully build endorse transaction proposal
Successfully build commit transaction proposal
Successfully commit should response success { status: 'SUCCESS', info: '' }
Successfully registered event for da5a3afb03e5dc25e276af3ac5f619dc5f8f764c5619ec9d26c69f01550e40b9
Successfully called connect on localhost:7051
Event has been seen with transaction code:ENDORSEMENT_POLICY_FAILURE for transaction id:da5a3afb03e5dc25e276af3ac5f619dc5f8f764c5619ec9d26c69f01550e40b9 for blockNum:4
Successfully transactionMonitor
Estate program complete.
from estate-sample.
Event has been seen with transaction code:ENDORSEMENT_POLICY_FAILURE for transaction id:edbc1615124a8aed88c0c666b1876e9d0d05223e01f3d9ad0a2667cab0c6948c for blockNum:6
こちらがエラーであるため、データ登録できていなかった 😢
https://stackoverflow.com/questions/52773566/hyperledger-fabric-client-endorsement-policy-failure
ここによると
This likely occurred because when you need multiple peers from different orgs to have the transaction be sent to, the endorsement policy is AND.
であるとのこと。2つのpeerをあげてないからだめ?initiate は org1だけだから AND から OR にすればいいんだか。
該当箇所はおそらく以下
docker exec \
-e CORE_PEER_LOCALMSPID=Org1MSP \
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
cli \
peer chaincode instantiate \
-o orderer.example.com:7050 \
-C mychannel \
-n $CHAINCODE_ID \
-l "$CC_RUNTIME_LANGUAGE" \
-v $VERSION \
-c '{"Args":["org.estatenet.estatecontract:instantiate"]}' \
-P "AND('Org1MSP.member','Org2MSP.member')" \
--tls \
--cafile ${ORDERER_TLS_ROOTCERT_FILE} \
--peerAddresses peer0.org1.example.com:7051 \
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE}
テストなのでこちらの -P の部分を AND から OR にする。
うまくいった 👍
$ node estate.js create
Successfully build endorse transaction proposal
Successfully build commit transaction proposal
Successfully commit should response success { status: 'SUCCESS', info: '' }
Successfully registered event for 158ff78adb2e7ddbcb1306521c12e8a537b309934e9d1a6ed33bf60d6090f1f3
Successfully called connect on localhost:7051
Event has been seen with transaction code:VALID for transaction id:158ff78adb2e7ddbcb1306521c12e8a537b309934e9d1a6ed33bf60d6090f1f3 for blockNum:4
Successfully transactionMonitor
Estate program complete.
from estate-sample.
find などの参照するだけのmethodがうまくいかない
$ node estate.js find
======== find !!!!!
Successfully build endorse transaction proposal
Successfully build commit transaction proposal
Successfully commit should response success { status: 'SUCCESS', info: '' }
Successfully registered event for fc3ada8c75d8196c0168af0241a3d3dec09bfce407002fb222b9b22fce41308d
Successfully called connect on localhost:7051
Event has been seen with transaction code:VALID for transaction id:fc3ada8c75d8196c0168af0241a3d3dec09bfce407002fb222b9b22fce41308d for blockNum:7
Successfully transactionMonitor
Estate program complete.
こんな感じでどうも block が進んでいます。transaction を発行しないようなmethodがありそう。
fabcar は evaluateTransaction で実行している。これにあたるもの
const result = await contract.evaluateTransaction('queryAllCars');
以下は使える?
https://fabric-sdk-node.github.io/release-1.4/Channel.html#queryByChaincode__anchor
var request = {
fcn: 'find',
args: [
'apart',
'000001',
],
chaincodeId: 'estate',
channelId: 'mychannel',
};
let response_payloads = await channel.queryByChaincode(request);
if (response_payloads) {
console.log("========", response_payloads);
}
return;
上記を試してみたが
Error: No identity has been assigned to this client
がでてしまう。channelに何か設定する必要があるんかな、、、
他のsampleだとchannel を以下のように作成していて、clientをまず作ってる。たぶん、これにidentify設定しているんだろうな。
client = await helper.getClientForOrg(org_name, username);
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
channel = client.getChannel(channelName);
from estate-sample.
https://stackoverflow.com/questions/56646247/how-do-i-get-fabcar-object-response-at-offline-process
に答えに書いた
const proposalResponses = await channel.sendSignedProposal(sendSignedProposalReq);
ここでresponse取れる
from estate-sample.
Related Issues (15)
- 要件定義
- データモデル定義 HOT 3
- nodeのフレームワーク選定 HOT 3
- 開発方針の決定 HOT 6
- fabricのロールバック処理対応
- chainnodeを動かす HOT 3
- 起動用script作成
- Estate売買実装 HOT 6
- Client側で秘密鍵&公開鍵を作成してtransaction実行させてみる HOT 5
- ReactNativeでfabricのlib使えるかサンプルアプリ作成 HOT 7
- queryByChaincode が offlineでも使えるか調べる HOT 6
- sendSignProposalを調べる HOT 3
- fabric-ca-client の中身を探る
- Electronで画面を作る HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from estate-sample.