diff --git a/examples/cactus-example-supply-chain-frontend/src/app/bamboo-harvest/bamboo-harvest-list/bamboo-harvest-list.page.ts b/examples/cactus-example-supply-chain-frontend/src/app/bamboo-harvest/bamboo-harvest-list/bamboo-harvest-list.page.ts index bf88930ec0..ab163d8715 100644 --- a/examples/cactus-example-supply-chain-frontend/src/app/bamboo-harvest/bamboo-harvest-list/bamboo-harvest-list.page.ts +++ b/examples/cactus-example-supply-chain-frontend/src/app/bamboo-harvest/bamboo-harvest-list/bamboo-harvest-list.page.ts @@ -42,6 +42,7 @@ export class BambooHarvestListPage implements OnInit { this._supplyChainApi = await this.baseClient.ofLedger( this.quorumLedgerId, SupplyChainApi, + {}, ); await this.loadData(); } diff --git a/examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-detail/bookshelf-detail.page.ts b/examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-detail/bookshelf-detail.page.ts index 758afa8681..50220958a6 100644 --- a/examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-detail/bookshelf-detail.page.ts +++ b/examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-detail/bookshelf-detail.page.ts @@ -52,6 +52,7 @@ export class BookshelfDetailPage implements OnInit { this._supplyChainApi = await this.baseClient.ofLedger( this.quorumLedgerId, SupplyChainApi, + {}, ); if (!this.bookshelf) { diff --git a/examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-list/bookshelf-list.page.ts b/examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-list/bookshelf-list.page.ts index 15cf672f5f..2c72ae5821 100644 --- a/examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-list/bookshelf-list.page.ts +++ b/examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-list/bookshelf-list.page.ts @@ -42,6 +42,7 @@ export class BookshelfListPage implements OnInit { this._supplyChainApi = await this.baseClient.ofLedger( this.ledgerId, SupplyChainApi, + {}, ); await this.loadData(); } diff --git a/examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-detail/shipment-detail.page.ts b/examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-detail/shipment-detail.page.ts index 07558f5b49..1411eb459a 100644 --- a/examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-detail/shipment-detail.page.ts +++ b/examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-detail/shipment-detail.page.ts @@ -52,6 +52,7 @@ export class ShipmentDetailPage implements OnInit { this._supplyChainApi = await this.baseClient.ofLedger( this.quorumLedgerId, SupplyChainApi, + {}, ); if (!this.shipment) { diff --git a/examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-list/shipment-list.page.ts b/examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-list/shipment-list.page.ts index e05d9a8c52..2f9a429225 100644 --- a/examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-list/shipment-list.page.ts +++ b/examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-list/shipment-list.page.ts @@ -42,6 +42,7 @@ export class ShipmentListPage implements OnInit { this._supplyChainApi = await this.baseClient.ofLedger( this.ledgerId, SupplyChainApi, + {}, ); await this.loadData(); } diff --git a/packages/cactus-api-client/src/main/typescript/api-client.ts b/packages/cactus-api-client/src/main/typescript/api-client.ts index e9ddb1d240..2ae9679188 100644 --- a/packages/cactus-api-client/src/main/typescript/api-client.ts +++ b/packages/cactus-api-client/src/main/typescript/api-client.ts @@ -82,6 +82,7 @@ export class ApiClient extends BaseAPI { public async ofLedger( ledgerOrId: string | Ledger, ctor: new (configuration?: Configuration) => T, + ctorArgs: Record, ): Promise; /** * Constructs a new `ApiClient` object that is tied to whichever Cactus node @@ -103,6 +104,7 @@ export class ApiClient extends BaseAPI { public async ofLedger( ledgerOrId: string | Ledger, ctor: new (configuration?: Configuration) => T, + ctorArgs: Record, consortiumDbProvider?: IAsyncProvider, ): Promise { const fnTags = "ApiClient#forLedgerId()"; @@ -127,12 +129,13 @@ export class ApiClient extends BaseAPI { // pick a random element from the array of nodes that have a connection to // the target ledger (based on the ledger ID) const randomIdx = Math.floor(Math.random() * nodes.length); - const randomNode = nodes[randomIdx]; - const configuration = new Configuration({ - basePath: randomNode.nodeApiHost, - }); + // overwrite basePath with randomNode api host + ctorArgs.basePath = randomNode.nodeApiHost; + + // create the ApiClient configuration object + const configuration = new Configuration(ctorArgs); return new ApiClient(configuration).extendWith(ctor); } diff --git a/packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts b/packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts index 1136afc6da..aba1826670 100644 --- a/packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts +++ b/packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts @@ -48,6 +48,7 @@ export interface IPluginConsortiumManualOptions extends ICactusPluginOptions { prometheusExporter?: PrometheusExporter; pluginRegistry?: PluginRegistry; logLevel?: LogLevelDesc; + ctorArgs?: Record; } export class PluginConsortiumManual @@ -217,9 +218,16 @@ export class PluginConsortiumManual public async getConsortiumJws(): Promise { const nodes = this.repo.allNodes; + const ctorArgs = this.options.ctorArgs || {}; + const requests = nodes .map((cnm) => cnm.nodeApiHost) - .map((host) => new Configuration({ basePath: host })) + .map(function (host) { + // overwrite basePath with node api host + ctorArgs.basePath = host; + // return the ApiClient configuration object + return new Configuration(ctorArgs); + }) .map((configuration) => new DefaultApi(configuration)) .map((apiClient) => apiClient.getNodeJwsV1()); diff --git a/packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts b/packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts index f378fd1883..ef082e9d60 100644 --- a/packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts +++ b/packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts @@ -254,7 +254,7 @@ test(testCase, async (t: Test) => { }); test("ApiClient #1 Routes based on Ledger ID #1", async (t2: Test) => { - const apiClient1 = await mainApiClient.ofLedger(ledger1.id, QuorumApi); + const apiClient1 = await mainApiClient.ofLedger(ledger1.id, QuorumApi, {}); // send money to the test account on ledger 1 const res = await apiClient1.runTransactionV1({ @@ -278,7 +278,7 @@ test(testCase, async (t: Test) => { }); test("ApiClient #1 Routes based on Ledger ID #2", async (t2: Test) => { - const apiClient2 = await mainApiClient.ofLedger(ledger2.id, QuorumApi); + const apiClient2 = await mainApiClient.ofLedger(ledger2.id, QuorumApi, {}); // send money to the test account on ledger 1 const res = await apiClient2.runTransactionV1({