Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade configtxgen to v2.5.9 #636

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions src/api-engine/api/lib/configtxgen/configtxgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from subprocess import call
from api.config import CELLO_HOME, FABRIC_TOOL, FABRIC_VERSION

import logging
LOG = logging.getLogger(__name__)


class ConfigTxGen:
"""Class represents cryptotxgen."""
Expand All @@ -22,7 +25,7 @@ def __init__(self, network, filepath=CELLO_HOME, configtxgen=FABRIC_TOOL, versio
self.filepath = filepath
self.version = version

def genesis(self, profile="TwoOrgsOrdererGenesis", channelid="testchainid", outputblock="genesis.block"):
def genesis(self, profile="", channelid="", outputblock="genesis.block"):
"""generate gensis
param:
profile: profile
Expand All @@ -31,27 +34,18 @@ def genesis(self, profile="TwoOrgsOrdererGenesis", channelid="testchainid", outp
return:
"""
try:
call([self.configtxgen, "-configPath", "{}/{}/".format(self.filepath, self.network),
"-profile", "{}".format(profile),
"-outputBlock", "{}/{}/{}".format(self.filepath, self.network, outputblock),
"-channelID", "{}".format(channelid)])
except Exception as e:
err_msg = "configtxgen genesis fail! "
raise Exception(err_msg + str(e))
command = [
self.configtxgen,
"-configPath", "{}/{}/".format(self.filepath, self.network),
"-profile", "{}".format(profile),
"-outputBlock", "{}/{}/{}".format(self.filepath, self.network, outputblock),
"-channelID", "{}".format(channelid)
]

LOG.info("Running command: " + " ".join(command))

call(command)

def channeltx(self, profile, channelid, outputCreateChannelTx="channel.tx"):
"""generate anchorpeer
param:
profile: profile
channelid: channelid
outputblock: outputblock
return:
"""
try:
call([self.configtxgen, "-configPath", "{}/{}/".format(self.filepath, self.network),
"-profile", "{}".format(profile),
"-outputCreateChannelTx", "{}/{}/{}".format(self.filepath, self.network, "channel-artifacts/" + outputCreateChannelTx),
"-channelID", "{}".format(channelid)])
except Exception as e:
err_msg = "configtxgen genesis fail! "
raise Exception(err_msg + str(e))
Expand All @@ -64,8 +58,4 @@ def anchorpeer(self, profile, channelid, outputblock):
outputblock: outputblock
return:
"""
pass


if __name__ == "__main__":
ConfigTxGen("net").channeltx("testchannel", "testchannel")
pass
31 changes: 18 additions & 13 deletions src/api-engine/api/routes/channel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from rest_framework.response import Response
from rest_framework.parsers import MultiPartParser, FormParser, JSONParser
from rest_framework.permissions import IsAuthenticated
#

from drf_yasg.utils import swagger_auto_schema

Expand Down Expand Up @@ -137,28 +136,34 @@ def create(self, request):
if p.status != "running":
raise NoResource

ConfigTX(org.network.name).createChannel(name, [org.name])
ConfigTxGen(org.network.name).channeltx(
profile=name, channelid=name, outputCreateChannelTx="{}.tx".format(name))
tx_path = "{}/{}/channel-artifacts/{}.tx".format(
CELLO_HOME, org.network.name, name)
block_path = "{}/{}/channel-artifacts/{}.block".format(
_orderers = []
_peers = []
_orderers.append({"name": org.name, "hosts": []})
_peers.append({"name": org.name, "hosts": []})
nodes = Node.objects.filter(organization=org)
for node in nodes:
if node.type == "peer":
_peers[0]["hosts"].append({"name": node.name})
elif node.type == "orderer":
_orderers[0]["hosts"].append({"name": node.name})

ConfigTX(org.network.name).create(name, org.network.consensus, _orderers, _peers)
ConfigTxGen(org.network.name).genesis(profile=name, channelid=name, outputblock="{}.block".format(name))

block_path = "{}/{}/{}.block".format(
CELLO_HOME, org.network.name, name)
ordering_node = Node.objects.get(id=orderers[0])
peer_node = Node.objects.get(id=peers[0])
envs = init_env_vars(peer_node, org)
envs = init_env_vars(ordering_node, org)
peer_channel_cli = PeerChannel(**envs)
peer_channel_cli.create(
channel=name,
orderer_url="{}.{}:{}".format(
ordering_node.name, org.name.split(".", 1)[1], str(7050)),
channel_tx=tx_path,
output_block=block_path
ordering_node.name, org.name.split(".", 1)[1], str(7053)),
block_path=block_path
)
for i in range(len(peers)):
peer_node = Node.objects.get(id=peers[i])
envs = init_env_vars(peer_node, org)
# envs["CORE_PEER_LOCALMSPID"] = '{}MSP'.format(peer_node.name.split(".")[0].capitalize()) #Org1MSP
join_peers(envs, block_path)

channel = Channel(
Expand Down
20 changes: 2 additions & 18 deletions src/api-engine/api/routes/network/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def create(self, request):
if serializer.is_valid(raise_exception=True):
name = serializer.validated_data.get("name")
consensus = serializer.validated_data.get("consensus")
# database = serializer.validated_data.get("database")
database = serializer.validated_data.get("database")

try:
if Network.objects.get(name=name):
Expand All @@ -189,24 +189,8 @@ def create(self, request):
raise ResourceExists(
detail="Network exists for the organization")

orderers = []
peers = []
orderers.append({"name": org.name, "hosts": []})
peers.append({"name": org.name, "hosts": []})
nodes = Node.objects.filter(organization=org)
for node in nodes:
if node.type == "peer":
peers[0]["hosts"].append({"name": node.name})
elif node.type == "orderer":
orderers[0]["hosts"].append({"name": node.name})

ConfigTX(name).create(consensus=consensus,
orderers=orderers, peers=peers)
ConfigTxGen(name).genesis()

block = self._genesis2base64(name)
network = Network(
name=name, consensus=consensus, genesisblock=block)
name=name, consensus=consensus, database=database)
network.save()
org.network = network
org.save()
Expand Down
Loading