https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/installation.htmlhtml
安裝[Python-3.7.X][ http://www.javashuo.com/article/p-yvzvbahy-ch.html ]和git軟件node
Visual C++ 14.0庫 https://pan.baidu.com/s/1ZmDUGZjZNgFJ8D14zBu9og 提取碼: zrbypython
solc編譯器下載成功後,解壓,將其中的 solc.exe 文件複製 ${python-sdk}\bin 目錄下。若 python-sdk 路爲 D:\open-source\python-sdk, 則 solc.exe 文件複製路徑爲D:\open-source\python-sdk\bin\solc.exenginx
拉取python-sdk源碼git
git clone https://github.com/FISCO-BCOS/python-sdk
配置solc編譯器的路徑github
# 修改client_config.py.template: # 配置solc編譯器路徑,若solc存放路徑爲D:\\open-source\\python-sdk\\bin\\solc.exe,則solc_path配置以下: solc_path = "D:\\open-source\\python-sdk\\bin\\solc.exe" # 將client_config.py.template拷貝到client_config.py,即新建一個client_config.py文件
安裝Python SDK依賴web
cd python-sdk pip install -r requirements.txt #清華的pip源 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
配置Channel通訊協議算法
SDK鏈接的節點已經在虛擬機如下目錄中json
~/fisco/nodes/127.0.0.1
在nodes文件夾下的config.ini文件中獲取channel_listen_port,這裏是20200windows
[rpc] listen_ip=0.0.0.0 channel_listen_port=20200 jsonrpc_listen_port=8545
切換到python-sdk目錄,修改client_config.py文件的相關配置信息以下:
channel_host = "192.168.14.134" channel_port = 20200
先前鏈已經搭好了,證書已經發到如下虛擬機下的目錄中:
fisco/nodes/127.0.0.1/sdk/*
將虛擬機裏面生成的證書文件所有copy到window下的python-sdk文件下的bin目錄下
國密支持
鏈接國密節點時,有如下相關的配置項須要修改和確認,IP端口也須要確認是指向國密版本節點
crypto_type = "GM" #密碼算法選擇: 大小寫不敏感:"GM" 標識國密, "ECDSA" 或其餘是橢圓曲線默認實現。 gm_account_keyfile = "gm_account.json" #國密帳號的存儲文件,能夠加密存儲,若是留空則不加載 gm_account_password = "123456" #若是不設密碼,置爲None或""則不加密 gm_solc_path = "./bin/solc/v0.4.25/solc-gm" #合約編譯器配置,經過執行bash init_env.sh -i命令下載
使用Channel協議訪問節點
# 獲取FISCO BCOS節點版本號 $ python ./console.py getNodeVersion INFO >> user input : ['getNodeVersion'] INFO : getNodeVersion : { "Build Time": "20200814 08:45:06", "Build Type": "Linux/clang/Release", "Chain Id": "1", "FISCO-BCOS Version": "2.6.0", "Git Branch": "HEAD", "Git Commit Hash": "e4a5ef2ef64d1943fccc4ebc61467a91779fb1c0", "Supported Version": "2.6.0" } #獲取區塊號 $ python ./console.py getBlockNumber INFO >> user input : ['getBlockNumber'] INFO : getBlockNumber : 1
至此,Python-SDK已跑通。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
下載https://gitee.com/medical-alliance/medical-blockchain
主操做文件 medical-blockchain,該文件中已經包括了Python-SDK,步驟同上:
利用SDK部署鏈碼
$ python ./console.py deploy evidence save INFO >> user input : ['deploy', 'evidence', 'save'] backup [contracts/evidence.abi] to [contracts/evidence.abi.20201013165207] backup [contracts/evidence.bin] to [contracts/evidence.bin.20201013165207] INFO >> compile with solc compiler deploy result for [evidence] is: { "blockHash": "0xf74c3bc86adad85e610e4d7a13991155a73042cfe845e25fcf7185eb9f58 a537", "blockNumber": "0x5", "contractAddress": "0x83592a3cf1af302612756b8687c8dc7935c0ad1d", "from": "0x95198b93705e394a916579e048c8a32ddfb900f7", "gasUsed": "0x113fd8", "input": "0x6080604052610bba600055610bb960015534801561001c57600080fd5b50610f......", "logs": [], "logsBloom": "0x000000.......................................................00000", "output": "0x", "root": "0x8d96f0afc9f75fe254314fd8308266a8a34cdface6a05b42690b762ac13a4fbe" , "status": "0x0", "to": "0x0000000000000000000000000000000000000000", "transactionHash": "0x14b633920f7c589e520f5c6c67bb3c2a62f146753da5f653ebd7d5 fbb828e326", "transactionIndex": "0x0" } on block : 5,address: 0x83592a3cf1af302612756b8687c8dc7935c0ad1d address save to file: bin/contract.ini
運行下面的命令
$ python app.py * Serving Flask app "app" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off * Running on http://0.0.0.0:5081/ (Press CTRL+C to quit)
在medical-blockchain文件夾中新建一個post.py文件,文件內容以下:
import requests import json def server(url, data): result = requests.post(url, data=json.dumps(data, ensure_ascii=False).encode( 'utf8').decode('latin-1')) return result.json() # 生成公私鑰 print(json.dumps(server("http://127.0.0.1:5081/api/p/medical/blockchain/crate", {"key": "mx"}), ensure_ascii=False, indent=2)) # 文件hash print(json.dumps(server("http://127.0.0.1:5081/api/p/medical/blockchain/hash", {"text": "病人姓名:甲,年齡:29,有無慢性病史:無,體檢結果:指標正常"}), ensure_ascii=False, indent=2)) # 私鑰簽名 print(json.dumps(server("http://127.0.0.1:5081/api/p/medical/blockchain/sign", {"prvkey":"0xec4c341369061b7e3ce5f69561e8d461a64344a43a19e33acba6f2c801cb2918", "text":"病人姓名:甲,年齡:29,有無慢性病史:無,體檢結果:指標正常" }), ensure_ascii=False,indent=2)) # 驗證簽名 print(json.dumps(server("http://127.0.0.1:5081/api/p/medical/blockchain/verify", { "sign":"0xd1639bdfc81c89e5c4afecaaf471f7409ea9e906dc2f3504cd743817657ce27507c90a60c64ccf4acdea20101e9060bcddea294e6561c3326cc080771163d1691b", "text":"病人姓名:甲,年齡:29,有無慢性病史:無,體檢結果:指標正常", "address":"0x8Cb7a51eF56BE8170d17eA138c2ec58b4Aed5858" }), ensure_ascii=False, indent=2)) # 上鍊 print(json.dumps(server("http://127.0.0.1:5081/api/p/medical/blockchain/upload", {"file_hash": "fdf13b54ec5bc73ff743ce2bdf716be5e23d00d1516a37c800c6a13c5c95f6f4", "file_data": "病人姓名:甲,年齡:29,有無慢性病史:無,體檢結果:指標正常", "file_pubkey": "0x8Cb7a51eF56BE8170d17eA138c2ec58b4Aed5858", "file_sign": "0xd1639bdfc81c89e5c4afecaaf471f7409ea9e906dc2f3504cd743817657ce27507c90a60c64ccf4acdea20101e9060bcddea294e6561c3326cc080771163d1691b", "file_time": "2020.10.9" }), ensure_ascii=False, indent=2)) # 查詢 print(json.dumps(server("http://127.0.0.1:5081/api/p/medical/blockchain/download", {"file_hash": "fdf13b54ec5bc73ff743ce2bdf716be5e23d00d1516a37c800c6a13c5c95f6f4"}), ensure_ascii=False, indent=2))
在medical-blockchain下打開另一個終端
第一次post請求,生成公私鑰,post.py文件中只包含生成公私鑰的post請求代碼,在執行下一個生成文件hash的post請求時,將生成公私鑰的請求代碼註釋掉。按照上述思路,爲每一個功能執行一次post請求。
window下安裝nginx
http://www.javashuo.com/article/p-rreplidj-nu.html
將medical-blockchain項目下的html_web文件所有copy到nginx安裝包下的html目錄下:
每一個請求頁面中post地址都須要按照上面進行修改