Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): migrate supply chain app to XDai connector #3380

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/cactus-example-supply-chain-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RUN source ~/.bashrc && \
cat /usr/src/app/package.json | jq --arg NPM_PKG_VERSION ${NPM_PKG_VERSION} '.resolutions += { "@hyperledger/cactus-plugin-keychain-memory": "\($NPM_PKG_VERSION)" } ' | sponge /usr/src/app/package.json && \
cat /usr/src/app/package.json | jq --arg NPM_PKG_VERSION ${NPM_PKG_VERSION} '.resolutions += { "@hyperledger/cactus-plugin-ledger-connector-besu": "\($NPM_PKG_VERSION)" } ' | sponge /usr/src/app/package.json && \
cat /usr/src/app/package.json | jq --arg NPM_PKG_VERSION ${NPM_PKG_VERSION} '.resolutions += { "@hyperledger/cactus-plugin-ledger-connector-fabric": "\($NPM_PKG_VERSION)" } ' | sponge /usr/src/app/package.json && \
cat /usr/src/app/package.json | jq --arg NPM_PKG_VERSION ${NPM_PKG_VERSION} '.resolutions += { "@hyperledger/cactus-plugin-ledger-connector-quorum": "\($NPM_PKG_VERSION)" } ' | sponge /usr/src/app/package.json && \
cat /usr/src/app/package.json | jq --arg NPM_PKG_VERSION ${NPM_PKG_VERSION} '.resolutions += { "@hyperledger/cactus-plugin-ledger-connector-xdai": "\($NPM_PKG_VERSION)" } ' | sponge /usr/src/app/package.json && \
yarn install

SHELL ["/bin/bash", "--login", "-c"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0-rc.2",
"@hyperledger/cactus-plugin-ledger-connector-besu": "2.0.0-rc.2",
"@hyperledger/cactus-plugin-ledger-connector-fabric": "2.0.0-rc.2",
"@hyperledger/cactus-plugin-ledger-connector-quorum": "2.0.0-rc.2",
"@hyperledger/cactus-plugin-ledger-connector-xdai": "2.0.0-rc.2",
"@hyperledger/cactus-test-tooling": "2.0.0-rc.2",
"async-exit-hook": "2.0.1",
"axios": "1.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { PluginRegistry } from "@hyperledger/cactus-core";
import { PluginLedgerConnectorBesu } from "@hyperledger/cactus-plugin-ledger-connector-besu";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
import {
PluginLedgerConnectorQuorum,
PluginLedgerConnectorXdai,
Web3SigningCredentialType,
} from "@hyperledger/cactus-plugin-ledger-connector-quorum";
} from "@hyperledger/cactus-plugin-ledger-connector-xdai";
import { IPluginKeychain } from "@hyperledger/cactus-core-api";
import { FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1 } from "@hyperledger/cactus-test-tooling";
import { FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2 } from "@hyperledger/cactus-test-tooling";
Expand All @@ -23,7 +23,6 @@ import {
FABRIC_25_LTS_AIO_FABRIC_VERSION,
FABRIC_25_LTS_AIO_IMAGE_VERSION,
FabricTestLedgerV1,
QuorumTestLedger,
} from "@hyperledger/cactus-test-tooling";
import {
IEthContractDeployment,
Expand Down Expand Up @@ -69,18 +68,18 @@ export class SupplyChainAppDummyInfrastructure {
public static readonly CLASS_NAME = "SupplyChainAppDummyInfrastructure";

public readonly besu: BesuTestLedger;
public readonly quorum: QuorumTestLedger;
public readonly xdaiBesu: BesuTestLedger;
public readonly fabric: FabricTestLedgerV1;
public readonly keychain: IPluginKeychain;
private readonly log: Logger;
private _quorumAccount?: Account;
private _xdaiAccount?: Account;
private _besuAccount?: Account;

public get quorumAccount(): Account {
if (!this._quorumAccount) {
public get xdaiAccount(): Account {
if (!this._xdaiAccount) {
throw new Error(`Must call deployContracts() first.`);
} else {
return this._quorumAccount;
return this._xdaiAccount;
}
}

Expand Down Expand Up @@ -110,7 +109,7 @@ export class SupplyChainAppDummyInfrastructure {
logLevel: level,
emitContainerLogs: true,
});
this.quorum = new QuorumTestLedger({
this.xdaiBesu = new BesuTestLedger({
logLevel: level,
emitContainerLogs: true,
});
Expand Down Expand Up @@ -145,10 +144,10 @@ export class SupplyChainAppDummyInfrastructure {
.stop()
.then(() => this.besu.destroy())
.catch((ex) => this.log.warn(ledgerStopFailErrorMsg("Besu"), ex)),
this.quorum
this.xdaiBesu
.stop()
.then(() => this.quorum.destroy())
.catch((ex) => this.log.warn(ledgerStopFailErrorMsg("Quorum"), ex)),
.then(() => this.xdaiBesu.destroy())
.catch((ex) => this.log.warn(ledgerStopFailErrorMsg("BesuXdai"), ex)),
this.fabric
.stop()
.then(() => this.fabric.destroy())
Expand All @@ -166,7 +165,7 @@ export class SupplyChainAppDummyInfrastructure {
this.log.info(`Starting dummy infrastructure...`);
await this.fabric.start({ omitPull: false });
await this.besu.start();
await this.quorum.start();
await this.xdaiBesu.start();
this.log.info(`Started dummy infrastructure OK`);
} catch (ex) {
this.log.error(`Starting of dummy infrastructure crashed: `, ex);
Expand All @@ -187,8 +186,8 @@ export class SupplyChainAppDummyInfrastructure {
JSON.stringify(BambooHarvestRepositoryJSON),
);

const bambooHarvestRepository = await this.deployQuorumContract();
const bookshelfRepository = await this.deployBesuContract();
const bambooHarvestRepository = await this.deployXdaiContract();
const shipmentRepository = await this.deployFabricContract();

const out: ISupplyChainContractDeploymentInfo = {
Expand All @@ -200,32 +199,38 @@ export class SupplyChainAppDummyInfrastructure {
this.log.info(`Deployed example supply chain app smart contracts OK`);

return out;
} catch (ex) {
await new Promise((res) => setTimeout(res, 6000000));
} catch (ex: unknown) {
this.log.error(`Deployment of smart contracts crashed: `, ex);
throw ex;
}
}

public async deployQuorumContract(): Promise<IEthContractDeployment> {
this._quorumAccount = await this.quorum.createEthTestAccount(2000000);
const rpcApiHttpHost = await this.quorum.getRpcApiHttpHost();
public async deployXdaiContract(): Promise<IEthContractDeployment> {
this.log.debug("ENTER deployXdaiContract()");

this._xdaiAccount = await this.xdaiBesu.createEthTestAccount(2000000);
this.log.debug("Created test ledger account with initial balance OK");

const rpcApiHttpHost = await this.xdaiBesu.getRpcApiHttpHost();
this.log.debug("Xdai test ledger rpcApiHttpHost=%s", rpcApiHttpHost);

const pluginRegistry = new PluginRegistry();
pluginRegistry.add(this.keychain);
const connector = new PluginLedgerConnectorQuorum({
instanceId: "PluginLedgerConnectorQuorum_Contract_Deployment",
const connector = new PluginLedgerConnectorXdai({
instanceId: "PluginLedgerConnectorXdai_Contract_Deployment",
rpcApiHttpHost,
logLevel: this.options.logLevel,
pluginRegistry,
});

this.log.debug("Instantiated Xdai connector plugin OK");

const res = await connector.deployContract({
contractName: BambooHarvestRepositoryJSON.contractName,
gas: 1000000,
web3SigningCredential: {
ethAccount: this.quorumAccount.address,
secret: this.quorumAccount.privateKey,
ethAccount: this.xdaiAccount.address,
secret: this.xdaiAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
keychainId: this.keychain.getKeychainId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ import { PluginConsortiumManual } from "@hyperledger/cactus-plugin-consortium-ma
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";

import {
PluginLedgerConnectorQuorum,
PluginLedgerConnectorXdai,
Web3SigningCredentialType,
DefaultApi as QuorumApi,
} from "@hyperledger/cactus-plugin-ledger-connector-quorum";
DefaultApi as XdaiApi,
} from "@hyperledger/cactus-plugin-ledger-connector-xdai";

import {
PluginLedgerConnectorBesu,
Expand Down Expand Up @@ -84,7 +84,7 @@ export class SupplyChainApp {
private readonly ledgers: SupplyChainAppDummyInfrastructure;
public readonly keychain: IPluginKeychain;
private _besuApiClient?: BesuApi;
private _quorumApiClient?: QuorumApi;
private _xdaiApiClient?: XdaiApi;
private _fabricApiClient?: FabricApi;
private authorizationConfig?: IAuthorizationConfig;
private token?: string;
Expand All @@ -97,9 +97,9 @@ export class SupplyChainApp {
}
}

public get quorumApiClientOrThrow(): QuorumApi {
if (this._quorumApiClient) {
return this._quorumApiClient;
public get xdaiApiClientOrThrow(): XdaiApi {
if (this._xdaiApiClient) {
return this._xdaiApiClient;
} else {
throw new Error("Invalid state: ledgers were not started yet.");
}
Expand Down Expand Up @@ -218,7 +218,7 @@ export class SupplyChainApp {

const besuAccount = await this.ledgers.besu.createEthTestAccount();
await this.keychain.set(besuAccount.address, besuAccount.privateKey);
const quorumAccount = await this.ledgers.quorum.createEthTestAccount();
const quorumAccount = await this.ledgers.xdaiBesu.createEthTestAccount();
await this.keychain.set(quorumAccount.address, quorumAccount.privateKey);

const enrollAdminOut = await this.ledgers.fabric.enrollAdmin();
Expand Down Expand Up @@ -262,7 +262,7 @@ export class SupplyChainApp {
});

const besuApiClient = new BesuApi(besuConfig);
const quorumApiClient = new QuorumApi(quorumConfig);
const xdaiApiClient = new XdaiApi(quorumConfig);
const fabricApiClient = new FabricApi(fabricConfig);

const keyPairA = await generateKeyPair("ES256K");
Expand All @@ -288,7 +288,7 @@ export class SupplyChainApp {
this.log.info(`Configuring Cactus Node for Ledger A...`);
const rpcApiHostA = await this.ledgers.besu.getRpcApiHttpHost();
const rpcApiWsHostA = await this.ledgers.besu.getRpcApiWsHost();
const rpcApiHostB = await this.ledgers.quorum.getRpcApiHttpHost();
const rpcApiHostB = await this.ledgers.xdaiBesu.getRpcApiHttpHost();

const connectionProfile =
await this.ledgers.fabric.getConnectionProfileOrg1();
Expand All @@ -312,7 +312,7 @@ export class SupplyChainApp {
contracts: contractsInfo,
instanceId: uuidv4(),
besuApiClient,
quorumApiClient,
xdaiApiClient,
fabricApiClient,
web3SigningCredential: {
keychainEntryKey: besuAccount.address,
Expand Down Expand Up @@ -356,7 +356,7 @@ export class SupplyChainApp {
contracts: contractsInfo,
instanceId: uuidv4(),
besuApiClient,
quorumApiClient,
xdaiApiClient,
fabricApiClient,
web3SigningCredential: {
keychainEntryKey: quorumAccount.address,
Expand All @@ -368,8 +368,8 @@ export class SupplyChainApp {
],
});

const quorumConnector = new PluginLedgerConnectorQuorum({
instanceId: "PluginLedgerConnectorQuorum_B",
const quorumConnector = new PluginLedgerConnectorXdai({
instanceId: "PluginLedgerConnectorXdai_B",
rpcApiHttpHost: rpcApiHostB,
logLevel: this.options.logLevel,
pluginRegistry: registryB,
Expand Down Expand Up @@ -399,7 +399,7 @@ export class SupplyChainApp {
contracts: contractsInfo,
instanceId: uuidv4(),
besuApiClient,
quorumApiClient,
xdaiApiClient,
fabricApiClient,
fabricEnvironment: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
}),
Expand Down Expand Up @@ -440,7 +440,7 @@ export class SupplyChainApp {
apiServerC,
besuApiClient,
fabricApiClient,
quorumApiClient,
xdaiApiClient,
supplyChainApiClientA: new SupplyChainApi(
new Configuration({ basePath: nodeApiHostA, baseOptions }),
),
Expand Down Expand Up @@ -644,7 +644,7 @@ export interface IStartInfo {
readonly apiServerB: ApiServer;
readonly apiServerC: ApiServer;
readonly besuApiClient: BesuApi;
readonly quorumApiClient: QuorumApi;
readonly xdaiApiClient: XdaiApi;
readonly fabricApiClient: FabricApi;
readonly supplyChainApiClientA: SupplyChainApi;
readonly supplyChainApiClientB: SupplyChainApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test("Supply chain backend API calls can be executed", async (t: Test) => {
t.true(httpSrvApiB.listening, "httpSrvApiB.listening true OK");
t.true(httpSrvApiC.listening, "httpSrvApiC.listening true OK");

const { besuApiClient, fabricApiClient, quorumApiClient } = startResult;
const { besuApiClient, fabricApiClient, xdaiApiClient } = startResult;

const metricsResB = await besuApiClient.getPrometheusMetricsV1();
t.ok(metricsResB, "besu metrics res truthy OK");
Expand All @@ -101,7 +101,7 @@ test("Supply chain backend API calls can be executed", async (t: Test) => {
t.true(metricsResF.status > 199, "metricsResF.status > 199 true OK");
t.true(metricsResF.status < 300, "metricsResF.status < 300 true OK");

const metricsResQ = await quorumApiClient.getPrometheusMetricsV1();
const metricsResQ = await xdaiApiClient.getPrometheusMetricsV1();
t.ok(metricsResQ, "quorum metrics res truthy OK");
t.true(metricsResQ.status > 199, "metricsResQ.status > 199 true OK");
t.true(metricsResQ.status < 300, "metricsResQ.status < 300 true OK");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"path": "../../packages/cactus-plugin-ledger-connector-fabric/tsconfig.json"
},
{
"path": "../../packages/cactus-plugin-ledger-connector-quorum/tsconfig.json"
"path": "../../packages/cactus-plugin-ledger-connector-xdai/tsconfig.json"
},
{
"path": "../../packages/cactus-test-tooling/tsconfig.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0-rc.2",
"@hyperledger/cactus-plugin-ledger-connector-besu": "2.0.0-rc.2",
"@hyperledger/cactus-plugin-ledger-connector-fabric": "2.0.0-rc.2",
"@hyperledger/cactus-plugin-ledger-connector-quorum": "2.0.0-rc.2",
"@hyperledger/cactus-plugin-ledger-connector-xdai": "2.0.0-rc.2",
"async-exit-hook": "2.0.1",
"axios": "1.6.0",
"express": "4.19.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
import {
DefaultApi as QuorumApi,
DefaultApi as XdaiApi,
Web3SigningCredential,
} from "@hyperledger/cactus-plugin-ledger-connector-quorum";
} from "@hyperledger/cactus-plugin-ledger-connector-xdai";
import { DefaultApi as BesuApi } from "@hyperledger/cactus-plugin-ledger-connector-besu";
import { InsertBambooHarvestEndpoint } from "./web-services/insert-bamboo-harvest-endpoint";
import { DefaultApi as FabricApi } from "@hyperledger/cactus-plugin-ledger-connector-fabric";
Expand All @@ -37,7 +37,7 @@ export interface OrgEnv {
export interface ISupplyChainCactusPluginOptions {
logLevel?: LogLevelDesc;
instanceId: string;
quorumApiClient: QuorumApi;
xdaiApiClient: XdaiApi;
besuApiClient: BesuApi;
fabricApiClient: FabricApi;
web3SigningCredential?: Web3SigningCredential;
Expand Down Expand Up @@ -66,10 +66,7 @@ export class SupplyChainCactusPlugin
Checks.truthy(options.instanceId, `${fnTag} arg options.instanceId`);
Checks.nonBlankString(options.instanceId, `${fnTag} options.instanceId`);
Checks.truthy(options.contracts, `${fnTag} arg options.contracts`);
Checks.truthy(
options.quorumApiClient,
`${fnTag} arg options.quorumApiClient`,
);
Checks.truthy(options.xdaiApiClient, `${fnTag} arg options.xdaiApiClient`);

const level = this.options.logLevel || "INFO";
const label = this.className;
Expand All @@ -95,7 +92,7 @@ export class SupplyChainCactusPlugin
// contractAddress: this.options.contracts.bambooHarvestRepository.address,
// contractAbi: this.options.contracts.bambooHarvestRepository.abi,
contractName: this.options.contracts.bambooHarvestRepository.contractName,
apiClient: this.options.quorumApiClient,
apiClient: this.options.xdaiApiClient,
web3SigningCredential: this.options
.web3SigningCredential as Web3SigningCredential,
logLevel: this.options.logLevel,
Expand All @@ -106,7 +103,7 @@ export class SupplyChainCactusPlugin
// contractAddress: this.options.contracts.bambooHarvestRepository.address,
// contractAbi: this.options.contracts.bambooHarvestRepository.abi,
contractName: this.options.contracts.bambooHarvestRepository.contractName,
apiClient: this.options.quorumApiClient,
apiClient: this.options.xdaiApiClient,
logLevel: this.options.logLevel,
keychainId: this.options.contracts.bambooHarvestRepository.keychainId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import {
} from "@hyperledger/cactus-core";

import {
DefaultApi as QuorumApi,
DefaultApi as XdaiApi,
EthContractInvocationType,
Web3SigningCredential,
} from "@hyperledger/cactus-plugin-ledger-connector-quorum";
} from "@hyperledger/cactus-plugin-ledger-connector-xdai";

import OAS from "../../../json/openapi.json";
import { InsertBambooHarvestRequest } from "../../generated/openapi/typescript-axios";
Expand All @@ -32,7 +32,7 @@ export interface IInsertBambooHarvestEndpointOptions {
logLevel?: LogLevelDesc;
contractName: string;
// contractAbi: any;
apiClient: QuorumApi;
apiClient: XdaiApi;
web3SigningCredential: Web3SigningCredential;
keychainId: string;
authorizationOptionsProvider?: AuthorizationOptionsProvider;
Expand Down
Loading
Loading