Skip to content

Commit

Permalink
feat(connector-besu, connector-quorum): filesystem replaced by keychain
Browse files Browse the repository at this point in the history
Signed-off-by: jordigiam <jordi.giron.amezcua@accenture.com>
  • Loading branch information
jordigiam authored and jordigiam committed Apr 12, 2021
1 parent 4fc39fc commit 14d1790
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 156 deletions.
@@ -1,7 +1,5 @@
import { Account } from "web3-core";
//import fs from "fs";
//import path from "path";

import { v4 as uuidv4 } from "uuid";
import {
Logger,
Checks,
Expand All @@ -10,6 +8,7 @@ import {
} from "@hyperledger/cactus-common";
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,
Web3SigningCredentialType,
Expand All @@ -20,14 +19,8 @@ import {
QuorumTestLedger,
} from "@hyperledger/cactus-test-tooling";

import {
bytecode as BambooHarvestRepositoryBytecode,
abi as BambooHarvestRepositoryAbi,
} from "../../json/generated/BambooHarvestRepository.json";
import {
bytecode as BookshelfRepositoryBytecode,
abi as BookshelfRepositoryAbi,
} from "../../json/generated/BookshelfRepository.json";
import BambooHarvestRepositoryJSON from "../../json/generated/BambooHarvestRepository.json";
import BookshelfRepositoryJSON from "../../json/generated/BookshelfRepository.json";
import {
IEthContractDeployment,
ISupplyChainContractDeploymentInfo,
Expand Down Expand Up @@ -154,6 +147,19 @@ export class SupplyChainAppDummyInfrastructure {
let bookshelfRepository: IEthContractDeployment;
let shipmentRepository: IFabricContractDeployment;

const keychainPlugin = new PluginKeychainMemory({
instanceId: uuidv4(),
keychainId: uuidv4(),
logLevel: this.options.logLevel || "INFO",
});
keychainPlugin.set(
BookshelfRepositoryJSON.contractName,
BookshelfRepositoryJSON,
);
keychainPlugin.set(
BambooHarvestRepositoryJSON.contractName,
BambooHarvestRepositoryJSON,
);
{
this._quorumAccount = await this.quorum.createEthTestAccount(2000000);
const rpcApiHttpHost = await this.quorum.getRpcApiHttpHost();
Expand All @@ -166,22 +172,23 @@ export class SupplyChainAppDummyInfrastructure {
});

const res = await connector.deployContract({
bytecode: BambooHarvestRepositoryBytecode,
gas: 1000000,
contractName: BambooHarvestRepositoryJSON.contractName,
bytecode: BambooHarvestRepositoryJSON.bytecode,
web3SigningCredential: {
ethAccount: this.quorumAccount.address,
secret: this.quorumAccount.privateKey,
type: Web3SigningCredentialType.PRIVATEKEYHEX,
},
keychainId: keychainPlugin.getKeychainId(),
});
const {
transactionReceipt: { contractAddress },
} = res;

bambooHarvestRepository = {
abi: BambooHarvestRepositoryAbi,
abi: BambooHarvestRepositoryJSON.abi,
address: contractAddress as string,
bytecode: BambooHarvestRepositoryBytecode,
bytecode: BambooHarvestRepositoryJSON.bytecode,
};
}

Expand All @@ -197,22 +204,23 @@ export class SupplyChainAppDummyInfrastructure {
});

const res = await connector.deployContract({
bytecode: BookshelfRepositoryBytecode,
gas: 1000000,
contractName: BookshelfRepositoryJSON.contractName,
bytecode: BookshelfRepositoryJSON.bytecode,
web3SigningCredential: {
ethAccount: this.besuAccount.address,
secret: this.besuAccount.privateKey,
type: Web3SigningCredentialType.PRIVATEKEYHEX,
},
keychainId: keychainPlugin.getKeychainId(),
});
const {
transactionReceipt: { contractAddress },
} = res;

bookshelfRepository = {
abi: BookshelfRepositoryAbi,
abi: BookshelfRepositoryJSON.abi,
address: contractAddress as string,
bytecode: BookshelfRepositoryBytecode,
bytecode: BookshelfRepositoryJSON.bytecode,
};
}

Expand Down
Expand Up @@ -401,10 +401,19 @@
"DeployContractSolidityBytecodeV1Request": {
"type": "object",
"required": [
"contractName",
"bytecode",
"web3SigningCredential"
"web3SigningCredential",
"keychainId"
],
"properties": {
"contractName": {
"type": "string",
"description": "The contract name for retrieve the contracts json on the keychain.",
"minLength": 1,
"maxLength": 100,
"nullable": false
},
"web3SigningCredential": {
"$ref": "#/components/schemas/Web3SigningCredential",
"nullable": false
Expand All @@ -416,6 +425,13 @@
"maxLength": 24576,
"description": "See https://ethereum.stackexchange.com/a/47556 regarding the maximum length of the bytecode"
},
"keychainId": {
"type": "string",
"description": "The keychainId for retrieve the contracts json.",
"minLength": 1,
"maxLength": 100,
"nullable": false
},
"gas": {
"type": "number",
"nullable": false
Expand Down Expand Up @@ -613,6 +629,12 @@
"minimum": 0,
"default": 60000,
"nullable": false
},
"keychainId": {
"type": "string",
"description": "The keychainId for retrieve the contracts json.",
"minLength": 1,
"maxLength": 100
}
}
},
Expand Down
Expand Up @@ -107,6 +107,12 @@ export interface ConsistencyStrategy {
* @interface DeployContractSolidityBytecodeV1Request
*/
export interface DeployContractSolidityBytecodeV1Request {
/**
* The contract name for retrieve the contracts json on the keychain.
* @type {string}
* @memberof DeployContractSolidityBytecodeV1Request
*/
contractName: string;
/**
*
* @type {Web3SigningCredential}
Expand All @@ -119,6 +125,12 @@ export interface DeployContractSolidityBytecodeV1Request {
* @memberof DeployContractSolidityBytecodeV1Request
*/
bytecode: string;
/**
* The keychainId for retrieve the contracts json.
* @type {string}
* @memberof DeployContractSolidityBytecodeV1Request
*/
keychainId: string;
/**
*
* @type {number}
Expand Down Expand Up @@ -319,6 +331,12 @@ export interface InvokeContractV2Request {
* @memberof InvokeContractV2Request
*/
timeoutMs?: number;
/**
* The keychainId for retrieve the contracts json.
* @type {string}
* @memberof InvokeContractV2Request
*/
keychainId?: string;
}
/**
*
Expand Down

0 comments on commit 14d1790

Please sign in to comment.