我想使用基于配对的加密库,它在我的链码中没有go语言版本。
我已经运行了官方示例' e2e_cli'。 使用Command' docker ps',我们可以看到九个码头工人。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
846a361282bb dev-peer1.org2.example.com-mycc-1.0 "chaincode -peer.add…" 19 minutes ago Up 19 minutes dev-peer1.org2.example.com-mycc-1.0
1cae2900a68a dev-peer0.org1.example.com-mycc-1.0 "chaincode -peer.add…" 20 minutes ago Up 20 minutes dev-peer0.org1.example.com-mycc-1.0
7b6de20b250b dev-peer0.org2.example.com-mycc-1.0 "chaincode -peer.add…" 21 minutes ago Up 21 minutes dev-peer0.org2.example.com-mycc-1.0
d9ab459a1f85 hyperledger/fabric-tools "/bin/bash -c './scr…" 22 minutes ago Up 22 minutes cli
91ec21c0632f hyperledger/fabric-peer "peer node start" 23 minutes ago Up 23 minutes 0.0.0.0:8051->7051/tcp, 0.0.0.0:8052->7052/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
e028c96b2d6c hyperledger/fabric-peer "peer node start" 23 minutes ago Up 22 minutes 0.0.0.0:7051-7053->7051-7053/tcp peer0.org1.example.com
08d057bc084f hyperledger/fabric-peer "peer node start" 23 minutes ago Up 23 minutes 0.0.0.0:10051->7051/tcp, 0.0.0.0:10052->7052/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com
2be6cf82c41e hyperledger/fabric-orderer "orderer" 23 minutes ago Up 22 minutes 0.0.0.0:7050->7050/tcp orderer.example.com
6e084f144bb1 hyperledger/fabric-peer "peer node start" 23 minutes ago Up 22 minutes 0.0.0.0:9051->7051/tcp, 0.0.0.0:9052->7052/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com
我认为这个名为' dev-peer0.org1.example.com-mycc-1.0'是链接代码在节点< peer0.org1'。
中执行的地方所以我需要将pbc库编程环境添加到docker中,例如' dev-peer0.org1.example.com-mycc-1.0'。
但是' dev-peer0.org1.example.com-mycc-1.0'在安装和实例化链码时自动创建,我无法找到添加libray的方法。我没有找到像卷一样的卷路径:'文件中的设置' docker-compose-cli.yaml'。
cli:
container_name: cli
image: hyperledger/fabric-tools
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'
volumes:
- /var/run/:/host/var/run/
- ./../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
depends_on:
- orderer.example.com
- peer0.org1.example.com
- peer1.org1.example.com
- peer0.org2.example.com
- peer1.org2.example.com
以下是我在链码中使用PBC库的部分。
package main
/*
#cgo LDFLAGS: -L. -lpbc -lgmp -lcrypto
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pbc/pbc.h"
int myfunc(char * keyword)
{
/*C language codes using PBC library*/
char *str_pairing= "type a\nq 878071079966331252243778198475404981580688\
31994142082110286533992664756308802229570786251794226622214231558587695823174\
59277713367317481324925129998224791\nh 12016012264891146079388821366740534204\
802954401251311822919615131047207289359704531102844802183906537786776\nr
7307\ 50818665451621361119245571504901405976559617\nexp2 159\nexp1 107\nsign1 1\nsi\gn0 1";
pairing_t pairing;
element_t a,b,c,d,e,g,h,r;
pairing_init_set_str(pairing, str_pairing);
element_init_Zr(e, pairing);
element_random(e);
element_init_G1(g, pairing);
element_random(g);
element_init_G1(h, pairing);
element_pow_zn(h, g, e);
element_init_G1(a, pairing);
element_init_G1(b, pairing);
element_init_G1(c, pairing);
element_init_GT(d, pairing);
element_init_Zr(r, pairing);
element_random(r);
element_pow_zn(a, g, r);
element_pow_zn(b, h, r);
element_from_hash(c, keyword, strlen(keyword));
element_pairing(d, c, b);
........
}
*/
import "C"
import "unsafe"
import (
"fmt"
"strconv"
"os/exec"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
……/*go language codes*/
答案 0 :(得分:0)
我重新编译图像 - hyperledger / fabric-ccenv:x86_64-1.0.0,添加了我需要的库。因为链代码是在一个基于fabric-ccenv映像运行的容器中编译的。