Esempio n. 1
0
def createInvokeProposalForBDD(context, ccSpec, chainID, signersCert, Mspid, type):
    import binascii

    "Returns a deployment proposal of chaincode type"
    lc_chaincode_invocation_spec = chaincode_pb2.ChaincodeInvocationSpec(chaincode_spec = ccSpec)

    # Create
    ccHdrExt = proposal_pb2.ChaincodeHeaderExtension(chaincode_id=ccSpec.chaincode_id)

    ccProposalPayload = proposal_pb2.ChaincodeProposalPayload(input=lc_chaincode_invocation_spec.SerializeToString())

    bootstrapHelper = ContextHelper.GetHelper(context=context).getBootrapHelper(chainId=chainID)

    serializedIdentity = identities_pb2.SerializedIdentity(mspid=Mspid, id_bytes=crypto.dump_certificate(crypto.FILETYPE_PEM, signersCert))

    nonce = bootstrap_util.BootstrapHelper.getNonce()

    sigHdr = bootstrapHelper.makeSignatureHeader(serializedIdentity.SerializeToString(), nonce)

    # Calculate the transaction ID
    tx_id = binascii.hexlify(bootstrap_util.computeCryptoHash(nonce + serializedIdentity.SerializeToString()))

    chainHdr = bootstrapHelper.makeChainHeader(type=common_dot_common_pb2.HeaderType.Value(type),
                                               txID=tx_id, extension=ccHdrExt.SerializeToString())

    header = common_dot_common_pb2.Header(channel_header=chainHdr.SerializeToString(), signature_header=sigHdr.SerializeToString())

    # make proposal
    proposal = proposal_pb2.Proposal(header=header.SerializeToString(), payload=ccProposalPayload.SerializeToString())


    return proposal
Esempio n. 2
0
 def __init__(self,
              context,
              composeFilesYaml,
              projectName=None,
              force_recreate=True,
              components=[],
              register_and_up=True):
     self.contextHelper = ContextHelper.GetHelper(context=context,
                                                  guuid=projectName)
     if not projectName:
         projectName = self.contextHelper.getGuuid()
     self.projectName = projectName
     self.context = context
     self.containerDataList = []
     self.composeFilesYaml = composeFilesYaml
     self.serviceNames = []
     self.serviceNames = self._collectServiceNames()
     self.env_extensions = defaultdict(dict)
     if register_and_up:
         # Register with contextHelper (Supports docgen)
         self.contextHelper.registerComposition(self)
         [
             callback.composing(self, context) for callback in
             Composition.GetCompositionCallbacksFromContext(context)
         ]
         self.up(context, force_recreate, components)
def step_impl(context, orderer_snapshot_alias):
    contextHelper = ContextHelper.GetHelper(context=context)
    bootstrap_helper = contextHelper.get_bootstrap_helper()
    assert "composition" in context, "No composition found in context"
    composition = context.composition
    orderers_to_snapshot = [row['Orderer'] for row in context.table.rows]
    bootstrap_helper.snapshot_orderers(orderers_to_snapshot=orderers_to_snapshot, context=context, composition=composition,
                                       snapshot_name=orderer_snapshot_alias)
def step_impl(context, peer_snapshot_alias):
    contextHelper = ContextHelper.GetHelper(context=context)
    bootstrap_helper = contextHelper.get_bootstrap_helper()
    directory = bootstrap_util.getDirectory(context)
    assert "composition" in context, "No composition found in context"
    composition = context.composition
    peers_to_snapshot = [row['Peer'] for row in context.table.rows]
    bootstrap_helper.snapshot_peers(peers_to_snapshot=peers_to_snapshot, context=context, composition=composition,
                                    snapshot_name=peer_snapshot_alias)
def step_impl(context, orderer_snapshot_alias):
    contextHelper = ContextHelper.GetHelper(context=context)
    bootstrap_helper = contextHelper.get_bootstrap_helper()
    directory = bootstrap_util.getDirectory(context)
    ordererBootstrapAdmin = bootstrap_util.getOrdererBootstrapAdmin(context)
    assert "composition" in context, "No composition found in context"
    composition = context.composition
    bootstrap_helper.snapshot_orderer_system(context=context, composition=composition,
                                             snapshot_name=orderer_snapshot_alias)
Esempio n. 6
0
    def __init__(self, context, composeFilesYaml, projectName = None,
                 force_recreate = True, components = []):
        self.contextHelper = ContextHelper.GetHelper(context=context)
        if not projectName:
            projectName = self.contextHelper.getGuuid()
        self.projectName = projectName
        self.context = context
        self.containerDataList = []
        self.composeFilesYaml = composeFilesYaml

        [callback.composing(self, context) for callback in Composition.GetCompositionCallbacksFromContext(context)]
        self.up(context, force_recreate, components)
def step_impl(context, userName, createChannelSignedConfigEnvelopeName):
    assert 'table' in context, "Expected table of peer organizations"
    directory = bootstrap_util.getDirectory(context)
    contextHelper = ContextHelper.GetHelper(context=context)
    bootstrap_helper = contextHelper.get_bootstrap_helper()
    user = directory.getUser(userName=userName)
    config_update_envelope = user.tags[createChannelSignedConfigEnvelopeName]
    for row in context.table.rows:
        user = directory.getUser(row['Developer'])
        namedAdminTuple = user.tags[row['Cert Alias']]
        cert = directory.findCertForNodeAdminTuple(namedAdminTuple)
        bootstrap_helper.add_signature_to_config_update_envelope(
            config_update_envelope, (user, namedAdminTuple.organization, cert))
Esempio n. 8
0
def createDeploymentSpec(context, ccSpec):
    contextHelper = ContextHelper.GetHelper(context=context)
    cacheDeploymentSpec = contextHelper.isConfigEnabled("cache-deployment-spec")
    fileName = "deploymentspec-{0}-{1}-{2}-{3}".format(chaincode_pb2.ChaincodeSpec.Type.Name(ccSpec.type), ccSpec.chaincode_id.path, ccSpec.chaincode_id.name, ccSpec.chaincode_id.version)
    outputPath, fileExists = contextHelper.getTmpPathForName(name=fileName,
                                                             copyFromCache=cacheDeploymentSpec)
    if not fileExists:
        _createDeploymentSpecAsFile(ccSpec=ccSpec, outputPath=outputPath)
        if cacheDeploymentSpec:
            contextHelper.copyToCache(fileName)
    ccDeploymentSpec = chaincode_pb2.ChaincodeDeploymentSpec()
    with open(outputPath, 'rb') as f:
        ccDeploymentSpec.ParseFromString(f.read())
    return ccDeploymentSpec
def step_impl(context, user_name, config_update_alias, config_update_source_alias, channel_id_or_ref, mod_policy):
    contextHelper = ContextHelper.GetHelper(context=context)
    bootstrap_helper = contextHelper.get_bootstrap_helper()
    directory = bootstrap_util.getDirectory(context)
    config_admin = directory.getUser(user_name)
    (channel_id,) = bootstrap_util.get_args_for_user([channel_id_or_ref], config_admin)
    source_channel_group = config_admin.getTagValue(config_update_source_alias)
    group_to_capabilities_to_add = defaultdict(set)
    [group_to_capabilities_to_add[row['Group']].add(row['Capabilities']) for row in context.table.rows]
    # new_config_group = bootstrap_helper.add_capabilities(config_group=source_channel_group.groups[group_name], capabilities_to_add=capabilities_to_add)
    new_config_update = bootstrap_helper.create_capabilities_config_update(channel_id=channel_id,
                                                                           config_group=source_channel_group,
                                                                           group_to_capabilities_to_add=group_to_capabilities_to_add)
    config_admin.setTagValue(config_update_alias, new_config_update)
Esempio n. 10
0
 def __init__(self, context, composeFilesYaml, projectName=None):
     self.contextHelper = ContextHelper.GetHelper(context=context)
     if not projectName:
         projectName = self.contextHelper.getGuuid()
     self.projectName = projectName
     self.context = context
     self.containerDataList = []
     self.composeFilesYaml = composeFilesYaml
     self.serviceNames = []
     self.serviceNames = self._collectServiceNames()
     [
         callback.composing(self, context) for callback in
         Composition.GetCompositionCallbacksFromContext(context)
     ]
     self.issueCommand(["up", "--force-recreate", "-d"])
Esempio n. 11
0
def step_impl(context, certAlias, ordererGenesisBlockName,
              ordererSystemChainIdName, composeFile, consensusType,
              consortiumsModPolicy):
    directory = bootstrap_util.getDirectory(context=context)
    contextHelper = ContextHelper.GetHelper(context=context)
    bootstrap_helper = contextHelper.get_bootstrap_helper()

    ordererBootstrapAdmin = bootstrap_util.getOrdererBootstrapAdmin(context)
    ordererSystemChainIdGUUID = ordererBootstrapAdmin.tags[
        ordererSystemChainIdName]
    # Now collect the named signed config items
    configGroups = [
        bootstrap_util.getDefaultConsortiumGroup(consortiumsModPolicy)
    ]
    for row in context.table.rows:
        configGroupName = row['Consortium']
        configGroups += ordererBootstrapAdmin.tags[configGroupName]
    # Concatenate signedConfigItems

    service_names = compose.Composition(
        context, composeFilesYaml=composeFile,
        register_and_up=False).getServiceNames()

    # Construct block
    nodeAdminTuple = ordererBootstrapAdmin.tags[certAlias]
    bootstrapCert = directory.findCertForNodeAdminTuple(
        nodeAdminTuple=nodeAdminTuple)
    (genesisBlock, envelope,
     genesis_block_channel_config) = bootstrap_helper.create_genesis_block(
         context=context,
         service_names=service_names,
         chainId=ordererSystemChainIdGUUID,
         consensusType=consensusType,
         nodeAdminTuple=nodeAdminTuple,
         signedConfigItems=configGroups)
    ordererBootstrapAdmin.setTagValue(
        ordererGenesisBlockName + "_genesis_channel_config",
        genesis_block_channel_config)
    ordererBootstrapAdmin.setTagValue(ordererGenesisBlockName, genesisBlock)
    ordererBootstrapAdmin.setTagValue("ConsensusType", consensusType)
    ordererCallback = bootstrap_util.OrdererGensisBlockCompositionCallback(
        context, genesisBlock)
    peerCallback = bootstrap_util.PeerCompositionCallback(context)
    composer.ComposerCompositionCallback(context, peerCallback)