Skip to content

Commit 4cacbaf

Browse files
LordKubayaRafaelAPB
authored andcommitted
chore: upgrade satp to the new fabric-connector
Signed-off-by: Carlos Amaro <[email protected]>
1 parent a172fd6 commit 4cacbaf

File tree

41 files changed

+2468
-6104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2468
-6104
lines changed

examples/cactus-example-cbdc-bridging-backend/src/main/typescript/infrastructure/cbdc-bridging-app-dummy-infrastructure.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
DEFAULT_PORT_GATEWAY_SERVER,
4444
DEFAULT_PORT_GATEWAY_OAPI,
4545
} from "@hyperledger/cactus-plugin-satp-hermes";
46-
import { setupGatewayDockerFiles } from "./utils";
46+
import { getTestConfigFilesDirectory, setupGatewayDockerFiles } from "./utils";
4747
import {
4848
ISATPGatewayRunnerConstructorOptions,
4949
SATPGatewayRunner,
@@ -59,9 +59,9 @@ export class CbdcBridgingAppDummyInfrastructure {
5959

6060
private static readonly networkName = "CDBC_Network";
6161

62-
private static readonly DOCKER_IMAGE_VERSION = "42f2d28b7-2025-05-28";
62+
private static readonly DOCKER_IMAGE_VERSION = "5f190f37f-2025-08-19";
6363
private static readonly DOCKER_IMAGE_NAME =
64-
"aaugusto11/cacti-satp-hermes-gateway";
64+
"kubaya/cacti-satp-hermes-gateway";
6565

6666
private readonly log: Logger;
6767
private readonly logLevel: LogLevelDesc;
@@ -236,7 +236,7 @@ export class CbdcBridgingAppDummyInfrastructure {
236236
const besuGatewayKeyPair = Secp256k1Keys.generateKeyPairsBuffer();
237237

238238
const fabricGatewayIdentity = {
239-
id: "mockID-1",
239+
id: "FabricGateway",
240240
name: "CustomGateway",
241241
version: [
242242
{
@@ -260,7 +260,7 @@ export class CbdcBridgingAppDummyInfrastructure {
260260
} as GatewayIdentity;
261261

262262
const besuGatewayIdentity = {
263-
id: "mockID-2",
263+
id: "BesuGateway",
264264
name: "CustomGateway",
265265
version: [
266266
{
@@ -283,8 +283,9 @@ export class CbdcBridgingAppDummyInfrastructure {
283283
pubKey: Buffer.from(besuGatewayKeyPair.publicKey).toString("hex"),
284284
} as GatewayIdentity;
285285

286-
const fabricConfig =
287-
await this.fabricEnvironment.createFabricDockerConfig();
286+
const fabricConfig = await this.fabricEnvironment.createFabricDockerConfig(
287+
getTestConfigFilesDirectory(`gateway-info-${fabricGatewayIdentity.id}`),
288+
);
288289

289290
const besuConfig = await this.besuEnvironment.createBesuDockerConfig();
290291

@@ -346,14 +347,9 @@ export class CbdcBridgingAppDummyInfrastructure {
346347
ontologyPath: "/opt/cacti/satp-hermes/ontologies",
347348
};
348349

349-
const besuGatewayDockerFiles = setupGatewayDockerFiles(
350-
besuGatewayOptions,
351-
"besu-gateway",
352-
);
353-
const fabricGatewayDockerFiles = setupGatewayDockerFiles(
354-
fabricGatewayOptions,
355-
"fabric-gateway",
356-
);
350+
const besuGatewayDockerFiles = setupGatewayDockerFiles(besuGatewayOptions);
351+
const fabricGatewayDockerFiles =
352+
setupGatewayDockerFiles(fabricGatewayOptions);
357353

358354
const besuGatewayRunnerOptions: ISATPGatewayRunnerConstructorOptions = {
359355
containerImageVersion:
@@ -364,7 +360,7 @@ export class CbdcBridgingAppDummyInfrastructure {
364360
oapiPort: DEFAULT_PORT_GATEWAY_OAPI,
365361
logLevel: this.logLevel,
366362
emitContainerLogs: true,
367-
configFilePath: besuGatewayDockerFiles.configFilePath,
363+
configPath: besuGatewayDockerFiles.configPath,
368364
logsPath: besuGatewayDockerFiles.logsPath,
369365
ontologiesPath: besuGatewayDockerFiles.ontologiesPath,
370366
networkName: CbdcBridgingAppDummyInfrastructure.networkName,
@@ -380,7 +376,7 @@ export class CbdcBridgingAppDummyInfrastructure {
380376
oapiPort: DEFAULT_PORT_GATEWAY_OAPI + 100,
381377
logLevel: this.logLevel,
382378
emitContainerLogs: true,
383-
configFilePath: fabricGatewayDockerFiles.configFilePath,
379+
configPath: fabricGatewayDockerFiles.configPath,
384380
logsPath: fabricGatewayDockerFiles.logsPath,
385381
ontologiesPath: fabricGatewayDockerFiles.ontologiesPath,
386382
networkName: CbdcBridgingAppDummyInfrastructure.networkName,

examples/cactus-example-cbdc-bridging-backend/src/main/typescript/infrastructure/cbdc-fabric-environment.ts

Lines changed: 172 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
FabricContractInvocationType,
1515
FabricSigningCredential,
1616
FileBase64,
17+
IPluginLedgerConnectorFabricOptions,
1718
PluginLedgerConnectorFabric,
1819
} from "@hyperledger/cactus-plugin-ledger-connector-fabric";
1920
import {
@@ -39,6 +40,11 @@ import fs from "fs-extra";
3940
import { getUserFromPseudonim } from "./utils";
4041
import CryptoMaterial from "../../../crypto-material/crypto-material.json";
4142
import ExampleOntology from "../../json/ontologies/ontology-satp-erc20-interact-fabric.json";
43+
import { PeerCerts } from "@hyperledger/cactus-test-tooling/dist/lib/main/typescript/fabric/fabric-test-ledger-v1";
44+
import {
45+
TargetOrganization,
46+
FabricConfigJSON,
47+
} from "@hyperledger/cactus-plugin-satp-hermes";
4248

4349
export class FabricEnvironment {
4450
public static readonly FABRIC_NETWORK_ID: string = "FabricLedgerNetwork";
@@ -72,6 +78,10 @@ export class FabricEnvironment {
7278
private fabricKeychainPlugin?: PluginKeychainMemory;
7379
private approveAddress?: string;
7480

81+
private peer0Org1Certs: PeerCerts | undefined;
82+
private peer0Org2Certs: PeerCerts | undefined;
83+
private coreFile: FileBase64 | undefined;
84+
7585
private readonly logLevel: LogLevelDesc;
7686

7787
public constructor(logLevel: LogLevelDesc, network?: string) {
@@ -178,21 +188,17 @@ export class FabricEnvironment {
178188
asLocalhost: true,
179189
};
180190

181-
const connectorOptions = {
191+
const connectorOptions: IPluginLedgerConnectorFabricOptions = {
182192
instanceId: uuidv4(),
183-
dockerBinary: "/usr/local/bin/docker",
184-
peerBinary: "/fabric-samples/bin/peer",
185-
goBinary: "/usr/local/go/bin/go",
186193
pluginRegistry,
187-
cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
188-
sshConfig: this.sshConfig,
189194
logLevel: this.logLevel,
190195
connectionProfile: this.connectionProfileOrg1,
191196
discoveryOptions: this.discoveryOptions,
192197
eventHandlerOptions: {
193198
strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx,
194199
commitTimeout: 300,
195200
},
201+
dockerNetworkName: this.dockerNetwork,
196202
};
197203

198204
this.connector = new PluginLedgerConnectorFabric(connectorOptions);
@@ -201,6 +207,22 @@ export class FabricEnvironment {
201207
keychainId: keychainId,
202208
keychainRef: keychainEntryKey4,
203209
};
210+
211+
this.peer0Org1Certs = await this.ledger.getPeerOrgCertsAndConfig(
212+
"org1",
213+
"peer0",
214+
);
215+
this.peer0Org2Certs = await this.ledger.getPeerOrgCertsAndConfig(
216+
"org2",
217+
"peer0",
218+
);
219+
220+
const filePath = path.join(__dirname, "../../yml/resources/core.yml");
221+
const buffer = await fs.readFile(filePath);
222+
this.coreFile = {
223+
body: buffer.toString("base64"),
224+
filename: "core.yaml",
225+
};
204226
}
205227

206228
// Deploys smart contracts and sets up configurations for testing
@@ -298,23 +320,43 @@ export class FabricEnvironment {
298320
});
299321
}
300322

323+
if (!this.peer0Org1Certs || !this.peer0Org2Certs || !this.coreFile) {
324+
throw new Error("Peer certificates are not defined");
325+
}
326+
301327
const res = await this.connector?.deployContract({
302328
channelId: this.fabricChannelName,
303329
ccVersion: "1.0.0",
304330
sourceFiles: satpSourceFiles,
305331
ccName: FabricEnvironment.SATP_CONTRACT_NAME,
306332
targetOrganizations: [
307-
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
308-
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
333+
{
334+
CORE_PEER_LOCALMSPID:
335+
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.CORE_PEER_LOCALMSPID,
336+
CORE_PEER_ADDRESS:
337+
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.CORE_PEER_ADDRESS,
338+
CORE_PEER_MSPCONFIG: this.peer0Org1Certs.mspConfig,
339+
CORE_PEER_TLS_ROOTCERT: this.peer0Org1Certs.peerTlsCert,
340+
ORDERER_TLS_ROOTCERT: this.peer0Org1Certs.ordererTlsRootCert,
341+
},
342+
{
343+
CORE_PEER_LOCALMSPID:
344+
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2.CORE_PEER_LOCALMSPID,
345+
CORE_PEER_ADDRESS:
346+
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2.CORE_PEER_ADDRESS,
347+
CORE_PEER_MSPCONFIG: this.peer0Org2Certs.mspConfig,
348+
CORE_PEER_TLS_ROOTCERT: this.peer0Org2Certs.peerTlsCert,
349+
ORDERER_TLS_ROOTCERT: this.peer0Org2Certs.ordererTlsRootCert,
350+
},
309351
],
310-
caFile:
311-
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE,
352+
caFile: this.peer0Org1Certs.ordererTlsRootCert,
312353
ccLabel: "satp-contract",
313354
ccLang: ChainCodeProgrammingLanguage.Typescript,
314355
ccSequence: 1,
315356
orderer: "orderer.example.com:7050",
316357
ordererTLSHostnameOverride: "orderer.example.com",
317358
connTimeout: 60,
359+
coreYamlFile: this.coreFile,
318360
});
319361

320362
if (!res) {
@@ -556,28 +598,133 @@ export class FabricEnvironment {
556598

557599
return parseInt(response.functionOutput);
558600
}
559-
public async createFabricDockerConfig(): Promise<INetworkOptions> {
601+
602+
public async createFabricDockerConfig(
603+
testFilesDirectory: string,
604+
): Promise<FabricConfigJSON & INetworkOptions> {
605+
if (!this.peer0Org1Certs || !this.peer0Org2Certs || !this.coreFile) {
606+
throw new Error("Peer certificates are not defined");
607+
}
608+
609+
const testFileCerts = path.join(testFilesDirectory, "certs");
610+
611+
if (!fs.existsSync(testFileCerts)) {
612+
fs.mkdirSync(testFileCerts, { recursive: true });
613+
}
614+
615+
for (const org of ["org1", "org2"]) {
616+
if (!fs.existsSync(path.join(testFileCerts, "certs", org))) {
617+
fs.mkdirSync(path.join(testFileCerts, org), {
618+
recursive: true,
619+
});
620+
} else {
621+
// Clear the directory if it already exists
622+
fs.emptyDirSync(path.join(testFileCerts, org));
623+
}
624+
}
625+
626+
// Write peer certs and core.yaml to files in the testFilesDirectory
627+
const org1Dir = path.join(testFileCerts, "org1");
628+
const org2Dir = path.join(testFileCerts, "org2");
629+
const coreYamlPath = path.join(testFileCerts, "core.yaml");
630+
631+
// Org1 certs
632+
const org1MspConfigPath = path.join(org1Dir, "msp");
633+
const org1PeerTlsCertPath = path.join(org1Dir, "peerTlsCert.pem");
634+
const org1OrdererTlsRootCertPath = path.join(
635+
org1Dir,
636+
"ordererTlsRootCert.pem",
637+
);
638+
639+
// Org2 certs
640+
const org2MspConfigPath = path.join(org2Dir, "msp");
641+
const org2PeerTlsCertPath = path.join(org2Dir, "peerTlsCert.pem");
642+
const org2OrdererTlsRootCertPath = path.join(
643+
org2Dir,
644+
"ordererTlsRootCert.pem",
645+
);
646+
647+
// mspConfig is a folder of files with relative paths, so we need to write each file
648+
for (const peerCerts of [
649+
{ certs: this.peer0Org1Certs, mspPath: org1MspConfigPath },
650+
{ certs: this.peer0Org2Certs, mspPath: org2MspConfigPath },
651+
]) {
652+
for (const file of peerCerts.certs.mspConfig) {
653+
const destPath = path.join(
654+
peerCerts.mspPath,
655+
file.filepath || "",
656+
file.filename,
657+
);
658+
const destDir = path.dirname(destPath);
659+
if (!fs.existsSync(destDir)) {
660+
fs.mkdirSync(destDir, { recursive: true });
661+
}
662+
// Ensure fileContent is a string or Buffer
663+
await fs.writeFile(destPath, Buffer.from(file.body, "base64"));
664+
}
665+
}
666+
667+
await fs.writeFile(org1PeerTlsCertPath, this.peer0Org1Certs.peerTlsCert);
668+
await fs.writeFile(
669+
org1OrdererTlsRootCertPath,
670+
this.peer0Org1Certs.ordererTlsRootCert,
671+
);
672+
673+
await fs.writeFile(org2PeerTlsCertPath, this.peer0Org2Certs.peerTlsCert);
674+
await fs.writeFile(
675+
org2OrdererTlsRootCertPath,
676+
this.peer0Org2Certs.ordererTlsRootCert,
677+
);
678+
679+
// core.yaml
680+
await fs.writeFile(coreYamlPath, Buffer.from(this.coreFile.body, "base64"));
681+
682+
// targetOrganizations array
683+
const basePath = path.join("/opt/cacti/satp-hermes/config", "certs");
684+
const targetOrganizations: TargetOrganization[] = [
685+
{
686+
CORE_PEER_LOCALMSPID:
687+
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.CORE_PEER_LOCALMSPID,
688+
CORE_PEER_ADDRESS:
689+
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.CORE_PEER_ADDRESS,
690+
CORE_PEER_MSPCONFIG_PATH: path.join(basePath, "org1/msp"),
691+
CORE_PEER_TLS_ROOTCERT_PATH: path.join(
692+
basePath,
693+
"/org1/peerTlsCert.pem",
694+
),
695+
ORDERER_TLS_ROOTCERT_PATH: path.join(
696+
basePath,
697+
"/org1/ordererTlsRootCert.pem",
698+
),
699+
},
700+
{
701+
CORE_PEER_LOCALMSPID:
702+
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2.CORE_PEER_LOCALMSPID,
703+
CORE_PEER_ADDRESS:
704+
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2.CORE_PEER_ADDRESS,
705+
CORE_PEER_MSPCONFIG_PATH: path.join(basePath, "org2/msp"),
706+
CORE_PEER_TLS_ROOTCERT_PATH: path.join(
707+
basePath,
708+
"/org2/peerTlsCert.pem",
709+
),
710+
ORDERER_TLS_ROOTCERT_PATH: path.join(
711+
basePath,
712+
"/org2/ordererTlsRootCert.pem",
713+
),
714+
},
715+
];
716+
this.peer0Org2Certs;
560717
return {
561718
networkIdentification: this.network,
562719
userIdentity: this.bridgeIdentity,
563720
channelName: this.fabricChannelName,
564-
targetOrganizations: [
565-
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
566-
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
567-
],
568-
caFile:
569-
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2.ORDERER_TLS_ROOTCERT_FILE,
570-
ccSequence: 1,
721+
targetOrganizations: targetOrganizations,
722+
caFilePath: path.join(basePath, "/org2/ordererTlsRootCert.pem"),
571723
orderer: "orderer.example.com:7050",
572724
ordererTLSHostnameOverride: "orderer.example.com",
573725
connTimeout: 60,
574726
mspId: this.bridgeMSPID,
575727
connectorOptions: {
576-
dockerBinary: "/usr/local/bin/docker",
577-
peerBinary: "/fabric-samples/bin/peer",
578-
goBinary: "/usr/local/go/bin/go",
579-
cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
580-
sshConfig: await this.ledger.getSshConfig(false),
581728
connectionProfile: await this.ledger.getConnectionProfileOrgX(
582729
"org2",
583730
false,
@@ -592,7 +739,8 @@ export class FabricEnvironment {
592739
},
593740
},
594741
claimFormats: [ClaimFormat.DEFAULT],
595-
} as INetworkOptions;
742+
coreYamlFilePath: path.join(basePath, "core.yaml"),
743+
};
596744
}
597745

598746
public async giveRoleToBridge(mspID: string): Promise<void> {

0 commit comments

Comments
 (0)