gpt4 book ai didi

c - 如何在执行chaincode的docker中添加额外的C语言库编程环境?

转载 作者:行者123 更新时间:2023-11-30 16:31:51 26 4
gpt4 key购买 nike

我想使用基于配对的加密库,但我的链代码中没有 Go 语言版本。

我已经运行了官方示例“e2e_cli”。使用命令“docker ps”,我们可以看到九个docker。

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”的 docker 是在节点“peer0.org1”中执行链代码的地方。

所以我需要向 Docker 添加 pbc 库编程环境,例如“dev-peer0.org1.example.com-mycc-1.0”。

但是“dev-peer0.org1.example.com-mycc-1.0”是在安装和实例化链代码时自动创建的,我找不到添加库的方法。我没有找到像“这样的卷路径”卷:'文件'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*/

最佳答案

我重新编译了镜像--hyperledger/fabric-ccenv:x86_64-1.0.0,添加了我需要的库。因为链码是在基于fabric-ccenv镜像运行的容器中编译的。

关于c - 如何在执行chaincode的docker中添加额外的C语言库编程环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50424171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com