Skip to content

Commit 05f6b36

Browse files
feat(plugin-satp-hermes): replace IPFS dependency in SATP package
*implement the repository design pattern to make storage technology-agnostic * due to the deprecation of the ipfs package, this allows one to choose another storage * refactoring of the tests and the CBDC example that is based on the SATP * implement the remote log storage as a SQLite database * add post-build instruction to copy knex files to dist/ closes hyperledger-cacti#2984 depends on hyperledger-cacti#3006 Signed-off-by: André Augusto <andre.augusto@tecnico.ulisboa.pt>
1 parent c71568c commit 05f6b36

File tree

62 files changed

+1252
-2281
lines changed

Some content is hidden

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

62 files changed

+1252
-2281
lines changed

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

+14-23
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ import {
1717
} from "@hyperledger/cactus-cmd-api-server";
1818
import {
1919
Configuration,
20-
DefaultApi as OdapApi,
2120
IKeyPair,
22-
} from "@hyperledger/cactus-plugin-satp-hermes";
21+
DefaultApi as SatpApi,
22+
} from "@hyperledger/cactus-plugin-satp-hermes/";
2323
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
2424
import { CbdcBridgingAppDummyInfrastructure } from "./infrastructure/cbdc-bridging-app-dummy-infrastructure";
2525
import { DefaultApi as FabricApi } from "@hyperledger/cactus-plugin-ledger-connector-fabric";
2626
import { DefaultApi as BesuApi } from "@hyperledger/cactus-plugin-ledger-connector-besu";
27-
import { DefaultApi as IpfsApi } from "@hyperledger/cactus-plugin-object-store-ipfs";
2827
import { FabricSatpGateway } from "./satp-extension/fabric-satp-gateway";
2928
import { BesuSatpGateway } from "./satp-extension/besu-satp-gateway";
3029
import CryptoMaterial from "../../crypto-material/crypto-material.json";
@@ -81,8 +80,6 @@ export class CbdcBridgingApp {
8180
const fabricPlugin =
8281
await this.infrastructure.createFabricLedgerConnector();
8382
const besuPlugin = await this.infrastructure.createBesuLedgerConnector();
84-
const clientIpfsPlugin = await this.infrastructure.createIPFSConnector();
85-
const serverIpfsPlugin = await this.infrastructure.createIPFSConnector();
8683

8784
// Reserve the ports where the API Servers will run
8885
const httpApiA = await Servers.startOnPort(
@@ -100,16 +97,14 @@ export class CbdcBridgingApp {
10097
const addressInfoB = httpApiB.address() as AddressInfo;
10198
const nodeApiHostB = `http://${this.options.apiHost}:${addressInfoB.port}`;
10299

103-
const fabricOdapGateway = await this.infrastructure.createClientGateway(
100+
const fabricSatpGateway = await this.infrastructure.createClientGateway(
104101
nodeApiHostA,
105102
this.options.clientGatewayKeyPair,
106-
`http://${this.options.apiHost}:${addressInfoA.port}`,
107103
);
108104

109-
const besuOdapGateway = await this.infrastructure.createServerGateway(
105+
const besuSatpGateway = await this.infrastructure.createServerGateway(
110106
nodeApiHostB,
111107
this.options.serverGatewayKeyPair,
112-
`http://${this.options.apiHost}:${addressInfoB.port}`,
113108
);
114109

115110
const clientPluginRegistry = new PluginRegistry({
@@ -132,12 +127,10 @@ export class CbdcBridgingApp {
132127
});
133128

134129
clientPluginRegistry.add(fabricPlugin);
135-
clientPluginRegistry.add(fabricOdapGateway);
136-
clientPluginRegistry.add(clientIpfsPlugin);
130+
clientPluginRegistry.add(fabricSatpGateway);
137131

138132
serverPluginRegistry.add(besuPlugin);
139-
serverPluginRegistry.add(serverIpfsPlugin);
140-
serverPluginRegistry.add(besuOdapGateway);
133+
serverPluginRegistry.add(besuSatpGateway);
141134

142135
const apiServer1 = await this.startNode(httpApiA, clientPluginRegistry);
143136
const apiServer2 = await this.startNode(httpApiB, serverPluginRegistry);
@@ -165,17 +158,16 @@ export class CbdcBridgingApp {
165158
return {
166159
apiServer1,
167160
apiServer2,
168-
fabricGatewayApi: new OdapApi(
161+
fabricGatewayApi: new SatpApi(
169162
new Configuration({ basePath: nodeApiHostA }),
170163
),
171-
besuGatewayApi: new OdapApi(
164+
besuGatewayApi: new SatpApi(
172165
new Configuration({ basePath: nodeApiHostB }),
173166
),
174-
ipfsApiClient: new IpfsApi(new Configuration({ basePath: nodeApiHostA })),
175167
fabricApiClient,
176168
besuApiClient,
177-
fabricOdapGateway,
178-
besuOdapGateway,
169+
fabricSatpGateway,
170+
besuSatpGateway,
179171
};
180172
}
181173

@@ -231,11 +223,10 @@ export class CbdcBridgingApp {
231223
export interface IStartInfo {
232224
readonly apiServer1: ApiServer;
233225
readonly apiServer2: ApiServer;
234-
readonly fabricGatewayApi: OdapApi;
235-
readonly besuGatewayApi: OdapApi;
236-
readonly ipfsApiClient: IpfsApi;
226+
readonly fabricGatewayApi: SatpApi;
227+
readonly besuGatewayApi: SatpApi;
237228
readonly besuApiClient: BesuApi;
238229
readonly fabricApiClient: FabricApi;
239-
readonly fabricOdapGateway: FabricSatpGateway;
240-
readonly besuOdapGateway: BesuSatpGateway;
230+
readonly fabricSatpGateway: FabricSatpGateway;
231+
readonly besuSatpGateway: BesuSatpGateway;
241232
}

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

+33-54
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
1414
DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
1515
FabricTestLedgerV1,
16-
GoIpfsTestContainer,
1716
} from "@hyperledger/cactus-test-tooling";
1817
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
1918
import {
@@ -35,14 +34,15 @@ import {
3534
InvokeContractV1Request as BesuInvokeContractV1Request,
3635
} from "@hyperledger/cactus-plugin-ledger-connector-besu";
3736
import { PluginRegistry } from "@hyperledger/cactus-core";
38-
import { PluginObjectStoreIpfs } from "@hyperledger/cactus-plugin-object-store-ipfs";
3937
import AssetReferenceContractJson from "../../../solidity/asset-reference-contract/AssetReferenceContract.json";
4038
import CBDCcontractJson from "../../../solidity/cbdc-erc-20/CBDCcontract.json";
4139
import { IKeyPair } from "@hyperledger/cactus-plugin-satp-hermes";
4240
import { FabricSatpGateway } from "../satp-extension/fabric-satp-gateway";
4341
import { BesuSatpGateway } from "../satp-extension/besu-satp-gateway";
4442
import { PluginImportType } from "@hyperledger/cactus-core-api";
4543
import CryptoMaterial from "../../../crypto-material/crypto-material.json";
44+
import { ClientHelper } from "../satp-extension/client-helper";
45+
import { ServerHelper } from "../satp-extension/server-helper";
4646

4747
export interface ICbdcBridgingAppDummyInfrastructureOptions {
4848
logLevel?: LogLevelDesc;
@@ -56,9 +56,6 @@ export class CbdcBridgingAppDummyInfrastructure {
5656

5757
private readonly besu: BesuTestLedger;
5858
private readonly fabric: FabricTestLedgerV1;
59-
private readonly ipfs: GoIpfsTestContainer;
60-
private readonly ipfsParentPath: string;
61-
6259
private readonly log: Logger;
6360

6461
public get className(): string {
@@ -78,8 +75,6 @@ export class CbdcBridgingAppDummyInfrastructure {
7875
const level = this.options.logLevel || "INFO";
7976
const label = this.className;
8077

81-
this.ipfsParentPath = `/${uuidv4()}/${uuidv4()}/`;
82-
8378
this.log = LoggerProvider.getOrCreate({ level, label });
8479

8580
this.besu = new BesuTestLedger({
@@ -97,10 +92,6 @@ export class CbdcBridgingAppDummyInfrastructure {
9792
]),
9893
logLevel: level || "DEBUG",
9994
});
100-
101-
this.ipfs = new GoIpfsTestContainer({
102-
logLevel: level || "DEBUG",
103-
});
10495
}
10596

10697
public get org1Env(): NodeJS.ProcessEnv & DeploymentTargetOrgFabric2x {
@@ -140,11 +131,7 @@ export class CbdcBridgingAppDummyInfrastructure {
140131
public async start(): Promise<void> {
141132
try {
142133
this.log.info(`Starting dummy infrastructure...`);
143-
await Promise.all([
144-
this.besu.start(),
145-
this.fabric.start(),
146-
this.ipfs.start(),
147-
]);
134+
await Promise.all([this.besu.start(), this.fabric.start()]);
148135
this.log.info(`Started dummy infrastructure OK`);
149136
} catch (ex) {
150137
this.log.error(`Starting of dummy infrastructure crashed: `, ex);
@@ -158,7 +145,6 @@ export class CbdcBridgingAppDummyInfrastructure {
158145
await Promise.all([
159146
this.besu.stop().then(() => this.besu.destroy()),
160147
this.fabric.stop().then(() => this.fabric.destroy()),
161-
this.ipfs.stop().then(() => this.ipfs.destroy()),
162148
]);
163149
this.log.info(`Stopped OK`);
164150
} catch (ex) {
@@ -285,61 +271,43 @@ export class CbdcBridgingAppDummyInfrastructure {
285271
return besuConnector;
286272
}
287273

288-
public async createIPFSConnector(): Promise<PluginObjectStoreIpfs> {
289-
this.log.info(`Creating Besu Connector...`);
290-
291-
const kuboRpcClientModule = await import("kubo-rpc-client");
292-
const ipfsClientOrOptions = kuboRpcClientModule.create({
293-
url: await this.ipfs.getApiUrl(),
294-
});
295-
296-
return new PluginObjectStoreIpfs({
297-
parentDir: this.ipfsParentPath,
298-
logLevel: this.options.logLevel,
299-
instanceId: uuidv4(),
300-
ipfsClientOrOptions,
301-
});
302-
}
303-
304274
public async createClientGateway(
305275
nodeApiHost: string,
306276
keyPair: IKeyPair,
307-
ipfsPath: string,
308277
): Promise<FabricSatpGateway> {
309278
this.log.info(`Creating Source Gateway...`);
310279
const pluginSourceGateway = new FabricSatpGateway({
311280
name: "cactus-plugin-source#satpGateway",
312281
dltIDs: ["DLT2"],
313282
instanceId: uuidv4(),
314283
keyPair: keyPair,
315-
ipfsPath: ipfsPath,
316284
fabricPath: nodeApiHost,
317285
fabricSigningCredential: {
318286
keychainId: CryptoMaterial.keychains.keychain1.id,
319287
keychainRef: "bridge",
320288
},
321289
fabricChannelName: "mychannel",
322290
fabricContractName: "asset-reference-contract",
291+
clientHelper: new ClientHelper(),
292+
serverHelper: new ServerHelper({}),
323293
});
324294

325-
await pluginSourceGateway.database?.migrate.rollback();
326-
await pluginSourceGateway.database?.migrate.latest();
295+
await pluginSourceGateway.localRepository?.reset();
296+
await pluginSourceGateway.remoteRepository?.reset();
327297

328298
return pluginSourceGateway;
329299
}
330300

331301
public async createServerGateway(
332302
nodeApiHost: string,
333303
keyPair: IKeyPair,
334-
ipfsPath: string,
335304
): Promise<BesuSatpGateway> {
336305
this.log.info(`Creating Recipient Gateway...`);
337306
const pluginRecipientGateway = new BesuSatpGateway({
338307
name: "cactus-plugin-recipient#satpGateway",
339308
dltIDs: ["DLT1"],
340309
instanceId: uuidv4(),
341310
keyPair: keyPair,
342-
ipfsPath: ipfsPath,
343311
besuPath: nodeApiHost,
344312
besuWeb3SigningCredential: {
345313
ethAccount: CryptoMaterial.accounts["bridge"].ethAddress,
@@ -348,10 +316,12 @@ export class CbdcBridgingAppDummyInfrastructure {
348316
},
349317
besuContractName: AssetReferenceContractJson.contractName,
350318
besuKeychainId: CryptoMaterial.keychains.keychain2.id,
319+
clientHelper: new ClientHelper(),
320+
serverHelper: new ServerHelper({}),
351321
});
352322

353-
await pluginRecipientGateway.database?.migrate.rollback();
354-
await pluginRecipientGateway.database?.migrate.latest();
323+
await pluginRecipientGateway.localRepository?.reset();
324+
await pluginRecipientGateway.remoteRepository?.reset();
355325

356326
return pluginRecipientGateway;
357327
}
@@ -624,19 +594,28 @@ export class CbdcBridgingAppDummyInfrastructure {
624594
// does the same thing, it just waits 10 seconds for good measure so there
625595
// might not be a way for us to avoid doing this, but if there is a way we
626596
// absolutely should not have timeouts like this, anywhere...
627-
await new Promise((resolve) => setTimeout(resolve, 10000));
628-
629-
await fabricApiClient.runTransactionV1({
630-
contractName,
631-
channelName,
632-
params: ["name1", "symbol1", "8"],
633-
methodName: "Initialize",
634-
invocationType: FabricContractInvocationType.Send,
635-
signingCredential: {
636-
keychainId: CryptoMaterial.keychains.keychain1.id,
637-
keychainRef: "userA",
638-
},
639-
});
597+
let retries_2 = 0;
598+
while (retries_2 <= 5) {
599+
await new Promise((resolve) => setTimeout(resolve, 10000));
600+
601+
await fabricApiClient
602+
.runTransactionV1({
603+
contractName,
604+
channelName,
605+
params: ["name1", "symbol1", "8"],
606+
methodName: "Initialize",
607+
invocationType: FabricContractInvocationType.Send,
608+
signingCredential: {
609+
keychainId: CryptoMaterial.keychains.keychain1.id,
610+
keychainRef: "userA",
611+
},
612+
})
613+
.then(() => (retries_2 = 6))
614+
.catch(() =>
615+
console.log("trying to Initialize fabric contract again"),
616+
);
617+
retries_2++;
618+
}
640619
})
641620
.catch(() => console.log("trying to deploy fabric contract again"));
642621
retries++;

examples/cactus-example-cbdc-bridging-backend/src/main/typescript/satp-extension/besu-satp-gateway.ts

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2-
import { Knex } from "knex";
32
import { Configuration } from "@hyperledger/cactus-core-api";
43
import {
54
DefaultApi as BesuApi,
@@ -8,32 +7,18 @@ import {
87
InvokeContractV1Request as BesuInvokeContractV1Request,
98
} from "@hyperledger/cactus-plugin-ledger-connector-besu";
109
import {
11-
IKeyPair,
10+
IPluginSatpGatewayConstructorOptions,
1211
PluginSatpGateway,
1312
} from "@hyperledger/cactus-plugin-satp-hermes";
1413
import { SessionDataRollbackActionsPerformedEnum } from "@hyperledger/cactus-plugin-satp-hermes";
15-
import { ClientHelper } from "./client-helper";
16-
import { ServerHelper } from "./server-helper";
17-
18-
export interface IBesuSatpGatewayConstructorOptions {
19-
name: string;
20-
dltIDs: string[];
21-
instanceId: string;
22-
keyPair?: IKeyPair;
23-
backupGatewaysAllowed?: string[];
24-
25-
ipfsPath?: string;
26-
27-
besuPath?: string;
2814

15+
export interface IBesuSatpGatewayConstructorOptions
16+
extends IPluginSatpGatewayConstructorOptions {
2917
besuContractName?: string;
3018
besuWeb3SigningCredential?: Web3SigningCredential;
3119
besuKeychainId?: string;
32-
fabricAssetID?: string;
33-
fabricAssetSize?: string;
3420
besuAssetID?: string;
35-
36-
knexConfig?: Knex.Config;
21+
besuPath?: string;
3722
}
3823

3924
export class BesuSatpGateway extends PluginSatpGateway {
@@ -50,8 +35,10 @@ export class BesuSatpGateway extends PluginSatpGateway {
5035
keyPair: options.keyPair,
5136
backupGatewaysAllowed: options.backupGatewaysAllowed,
5237
ipfsPath: options.ipfsPath,
53-
clientHelper: new ClientHelper(),
54-
serverHelper: new ServerHelper({}),
38+
clientHelper: options.clientHelper,
39+
serverHelper: options.serverHelper,
40+
knexLocalConfig: options.knexLocalConfig,
41+
knexRemoteConfig: options.knexRemoteConfig,
5542
});
5643

5744
if (options.besuPath != undefined) this.defineBesuConnection(options);

examples/cactus-example-cbdc-bridging-backend/src/main/typescript/satp-extension/client-helper.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
TransferInitializationV1Request,
55
ClientGatewayHelper,
66
} from "@hyperledger/cactus-plugin-satp-hermes";
7-
import { OdapMessageType } from "@hyperledger/cactus-plugin-satp-hermes";
7+
import { SatpMessageType } from "@hyperledger/cactus-plugin-satp-hermes";
88
import { FabricSatpGateway } from "./fabric-satp-gateway";
99
import { BesuSatpGateway } from "./besu-satp-gateway";
1010

@@ -44,14 +44,16 @@ export class ClientHelper extends ClientGatewayHelper {
4444
throw new Error(`${fnTag}, session data is not correctly initialized`);
4545
}
4646

47-
if (!gateway.supportedDltIDs.includes(sessionData.recipientGatewayDltSystem)) {
47+
if (
48+
!gateway.supportedDltIDs.includes(sessionData.recipientGatewayDltSystem)
49+
) {
4850
throw new Error(
4951
`${fnTag}, recipient gateway dlt system is not supported by this gateway`,
5052
);
5153
}
5254

5355
const initializationRequestMessage: TransferInitializationV1Request = {
54-
messageType: OdapMessageType.InitializationRequest,
56+
messageType: SatpMessageType.InitializationRequest,
5557
sessionID: sessionData.id,
5658
version: sessionData.version,
5759
// developer urn
@@ -132,7 +134,7 @@ export class ClientHelper extends ClientGatewayHelper {
132134

133135
await gateway.makeRequest(
134136
sessionID,
135-
PluginSatpGateway.getOdapAPI(
137+
PluginSatpGateway.getSatpAPI(
136138
sessionData.recipientBasePath,
137139
).phase1TransferInitiationRequestV1(initializationRequestMessage),
138140
"TransferInitializationRequest",

0 commit comments

Comments
 (0)