diff --git a/src/setup-docker/fabricXDockerWriter.ts b/src/setup-docker/fabricXDockerWriter.ts index dcb7402a..0b8e6f09 100644 --- a/src/setup-docker/fabricXDockerWriter.ts +++ b/src/setup-docker/fabricXDockerWriter.ts @@ -3,13 +3,30 @@ import { renderTemplate, getTemplatePath, getDestinationPath } from "../utils/te import * as fs from "fs-extra"; import * as path from "path"; +export interface FabricXTemplateModel { + channelName: string; + channelProfileName: string; +} + +export const getFabricXTemplateModel = (configExtended: FabloConfigExtended): FabricXTemplateModel => { + const [channel] = configExtended.channels; + if (!channel) { + throw new Error("Fabric-X generation requires exactly one channel."); + } + return { + channelName: channel.name, + channelProfileName: channel.profileName, + }; +}; + export class FabricXDockerWriter { + constructor(private templatesDir: string, private outputDir: string, private log: (msg: string) => void) {} public async write(configExtended: FabloConfigExtended): Promise { this.log("Generating Fabric-X network files..."); - - const data = configExtended as unknown as Record; + const fabricX = getFabricXTemplateModel(configExtended); + const data = { ...configExtended, fabricX } as unknown as Record; await this.renderTemplateFile("fabric-x-docker.sh", data); await this.renderTemplateDirectory("fabric-x", data); diff --git a/src/setup-docker/templates/fabric-x/configtx.yaml b/src/setup-docker/templates/fabric-x/configtx.yaml index 319bc43e..c9a7abcb 100644 --- a/src/setup-docker/templates/fabric-x/configtx.yaml +++ b/src/setup-docker/templates/fabric-x/configtx.yaml @@ -149,7 +149,7 @@ Channel: &ChannelDefaults <<: *ChannelCapabilities Profiles: - OrgsChannel: + <%- fabricX.channelProfileName %>: <<: *ChannelDefaults Orderer: <<: *OrdererDefaults diff --git a/src/setup-docker/templates/fabric-x/fxconfig.yaml b/src/setup-docker/templates/fabric-x/fxconfig.yaml index 86c92024..26f806ec 100644 --- a/src/setup-docker/templates/fabric-x/fxconfig.yaml +++ b/src/setup-docker/templates/fabric-x/fxconfig.yaml @@ -7,7 +7,7 @@ msp: orderer: address: orderer-router:7050 - channel: mychannel + channel: <%- fabricX.channelName %> tls: enabled: true clientCert: /tls/server.crt diff --git a/src/setup-docker/templates/fabric-x/scripts/base-functions.sh b/src/setup-docker/templates/fabric-x/scripts/base-functions.sh index 752a48da..7334d0b2 100644 --- a/src/setup-docker/templates/fabric-x/scripts/base-functions.sh +++ b/src/setup-docker/templates/fabric-x/scripts/base-functions.sh @@ -58,7 +58,7 @@ generateArtifacts() { docker run --rm --user "$(id -u):$(id -g)" \ -v "$FABRIC_X_ROOT:/config" \ "$TOOLS_IMAGE" \ - configtxgen --channelID mychannel --profile OrgsChannel \ + configtxgen --channelID <%- fabricX.channelName %> --profile <%- fabricX.channelProfileName %> \ --outputBlock /config/crypto/config-block.pb.bin \ --configPath /config