From ecd62eac5721514dbcfc401d5f28dfdc58ef8873 Mon Sep 17 00:00:00 2001 From: AzaharaC Date: Wed, 24 Mar 2021 13:40:52 +0100 Subject: [PATCH] feat(connector-besu): replace invokeContractV2 Signed-off-by: AzaharaC --- .../generated/BambooHarvestRepository.json | 1 + .../json/generated/BookshelfRepository.json | 1 + .../supply-chain-app-dummy-infrastructure.ts | 4 + .../supply-chain-cactus-plugin.ts | 20 +- .../insert-bamboo-harvest-endpoint.ts | 21 +- .../web-services/insert-bookshelf-endpoint.ts | 18 +- .../list-bamboo-harvest-endpoint.ts | 17 +- .../web-services/list-bookshelf-endpoint.ts | 21 +- .../typescript/i-eth-contract-deployment.ts | 2 + .../src/main/json/openapi.json | 130 +---------- .../generated/openapi/typescript-axios/api.ts | 189 +--------------- .../plugin-ledger-connector-besu.ts | 69 ------ .../invoke-contract-endpoint-v2.ts | 87 -------- .../deploy-contract-from-json.test.ts | 81 +++---- ...act-v2.test.ts => invoke-contract.test.ts} | 26 +-- .../src/main/json/openapi.json | 132 +----------- .../generated/openapi/typescript-axios/api.ts | 203 ++---------------- .../plugin-ledger-connector-quorum.ts | 68 ------ .../invoke-contract-endpoint-v2.ts | 87 -------- .../web-services/invoke-contract-endpoint.ts | 2 +- .../deploy-contract-from-json.test.ts | 92 ++++---- ...act-v2.test.ts => invoke-contract.test.ts} | 26 +-- .../hello-world-contract/HelloWorld.json | 1 + .../deploy-contract-via-web-service.test.ts | 27 +-- 24 files changed, 218 insertions(+), 1107 deletions(-) delete mode 100644 packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/invoke-contract-endpoint-v2.ts rename packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/{invoke-contract-v2.test.ts => invoke-contract.test.ts} (95%) delete mode 100644 packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/invoke-contract-endpoint-v2.ts rename packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/{invoke-contract-v2.test.ts => invoke-contract.test.ts} (95%) diff --git a/examples/cactus-example-supply-chain-backend/src/main/json/generated/BambooHarvestRepository.json b/examples/cactus-example-supply-chain-backend/src/main/json/generated/BambooHarvestRepository.json index 7937fb3bbb..30c8d9dec8 100644 --- a/examples/cactus-example-supply-chain-backend/src/main/json/generated/BambooHarvestRepository.json +++ b/examples/cactus-example-supply-chain-backend/src/main/json/generated/BambooHarvestRepository.json @@ -98,6 +98,7 @@ "name": "solc", "version": "0.7.2+commit.51b20bc0" }, + "networks": {}, "ast": { "absolutePath": "/home/peter/a/blockchain/cactus/packages/cactus-example-supply-chain-backend/src/main/solidity/BambooHarvestRepository.sol", "exportedSymbols": { diff --git a/examples/cactus-example-supply-chain-backend/src/main/json/generated/BookshelfRepository.json b/examples/cactus-example-supply-chain-backend/src/main/json/generated/BookshelfRepository.json index c71e62129f..d2b7bff928 100644 --- a/examples/cactus-example-supply-chain-backend/src/main/json/generated/BookshelfRepository.json +++ b/examples/cactus-example-supply-chain-backend/src/main/json/generated/BookshelfRepository.json @@ -78,6 +78,7 @@ "name": "solc", "version": "0.7.2+commit.51b20bc0" }, + "networks": {}, "ast": { "absolutePath": "/home/peter/a/blockchain/cactus/packages/cactus-example-supply-chain-backend/src/main/solidity/BookshelfRepository .sol", "exportedSymbols": { diff --git a/examples/cactus-example-supply-chain-backend/src/main/typescript/infrastructure/supply-chain-app-dummy-infrastructure.ts b/examples/cactus-example-supply-chain-backend/src/main/typescript/infrastructure/supply-chain-app-dummy-infrastructure.ts index 22897c4fb1..0f92089281 100644 --- a/examples/cactus-example-supply-chain-backend/src/main/typescript/infrastructure/supply-chain-app-dummy-infrastructure.ts +++ b/examples/cactus-example-supply-chain-backend/src/main/typescript/infrastructure/supply-chain-app-dummy-infrastructure.ts @@ -192,6 +192,8 @@ export class SupplyChainAppDummyInfrastructure { abi: BambooHarvestRepositoryJSON.abi, address: contractAddress as string, bytecode: BambooHarvestRepositoryJSON.bytecode, + contractName: BambooHarvestRepositoryJSON.contractName, + keychainId: keychainPlugin.getKeychainId(), }; } @@ -227,6 +229,8 @@ export class SupplyChainAppDummyInfrastructure { abi: BookshelfRepositoryJSON.abi, address: contractAddress as string, bytecode: BookshelfRepositoryJSON.bytecode, + contractName: BookshelfRepositoryJSON.contractName, + keychainId: keychainPlugin.getKeychainId(), }; } diff --git a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/supply-chain-cactus-plugin.ts b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/supply-chain-cactus-plugin.ts index 8bf704a33e..46e092815f 100644 --- a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/supply-chain-cactus-plugin.ts +++ b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/supply-chain-cactus-plugin.ts @@ -89,35 +89,39 @@ export class SupplyChainCactusPlugin return this.endpoints; } const insertBambooHarvest = new InsertBambooHarvestEndpoint({ - contractAddress: this.options.contracts.bambooHarvestRepository.address, - contractAbi: this.options.contracts.bambooHarvestRepository.abi, + // contractAddress: this.options.contracts.bambooHarvestRepository.address, + // contractAbi: this.options.contracts.bambooHarvestRepository.abi, + contractName: this.options.contracts.bambooHarvestRepository.contractName, apiClient: this.options.quorumApiClient, web3SigningCredential: this.options .web3SigningCredential as Web3SigningCredential, logLevel: this.options.logLevel, + keychainId: this.options.contracts.bambooHarvestRepository.keychainId, }); const listBambooHarvest = new ListBambooHarvestEndpoint({ - contractAddress: this.options.contracts.bambooHarvestRepository.address, - contractAbi: this.options.contracts.bambooHarvestRepository.abi, + // contractAddress: this.options.contracts.bambooHarvestRepository.address, + // contractAbi: this.options.contracts.bambooHarvestRepository.abi, + contractName: this.options.contracts.bambooHarvestRepository.contractName, apiClient: this.options.quorumApiClient, logLevel: this.options.logLevel, + keychainId: this.options.contracts.bambooHarvestRepository.keychainId, }); const insertBookshelf = new InsertBookshelfEndpoint({ - contractAddress: this.options.contracts.bookshelfRepository.address, - contractAbi: this.options.contracts.bookshelfRepository.abi, + contractName: this.options.contracts.bookshelfRepository.contractName, besuApi: this.options.besuApiClient, web3SigningCredential: this.options .web3SigningCredential as Web3SigningCredential, logLevel: this.options.logLevel, + keychainId: this.options.contracts.bookshelfRepository.keychainId, }); const listBookshelf = new ListBookshelfEndpoint({ - contractAddress: this.options.contracts.bookshelfRepository.address, - contractAbi: this.options.contracts.bookshelfRepository.abi, + contractName: this.options.contracts.bookshelfRepository.contractName, besuApi: this.options.besuApiClient, logLevel: this.options.logLevel, + keychainId: this.options.contracts.bookshelfRepository.keychainId, }); const insertShipment = new InsertShipmentEndpoint({ diff --git a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/insert-bamboo-harvest-endpoint.ts b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/insert-bamboo-harvest-endpoint.ts index e24b9b4d11..3d997e2f25 100644 --- a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/insert-bamboo-harvest-endpoint.ts +++ b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/insert-bamboo-harvest-endpoint.ts @@ -22,10 +22,11 @@ import { InsertBambooHarvestRequest } from "../../generated/openapi/typescript-a export interface IInsertBambooHarvestEndpointOptions { logLevel?: LogLevelDesc; - contractAddress: string; - contractAbi: any; + contractName: string; + // contractAbi: any; apiClient: QuorumApi; web3SigningCredential: Web3SigningCredential; + keychainId: string; } export class InsertBambooHarvestEndpoint implements IWebServiceEndpoint { @@ -47,10 +48,10 @@ export class InsertBambooHarvestEndpoint implements IWebServiceEndpoint { const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} arg options`); Checks.truthy(opts.apiClient, `${fnTag} options.apiClient`); - Checks.truthy(opts.contractAddress, `${fnTag} options.contractAddress`); - Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`); + // Checks.truthy(opts.contractAddress, `${fnTag} options.contractAddress`); + // Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`); Checks.nonBlankString( - opts.contractAddress, + opts.contractName, `${fnTag} options.contractAddress`, ); @@ -83,18 +84,18 @@ export class InsertBambooHarvestEndpoint implements IWebServiceEndpoint { this.log.debug(`${tag} %o`, bambooHarvest); const { - data: { callOutput, transactionReceipt }, + data: { success, callOutput, transactionReceipt }, } = await this.opts.apiClient.apiV1QuorumInvokeContract({ - contractAbi: this.opts.contractAbi, - contractAddress: this.opts.contractAddress, + contractName: this.opts.contractName, invocationType: EthContractInvocationType.SEND, methodName: "insertRecord", gas: 1000000, params: [bambooHarvest], - web3SigningCredential: this.opts.web3SigningCredential, + signingCredential: this.opts.web3SigningCredential, + keychainId: this.opts.keychainId, }); - const body = { callOutput, transactionReceipt }; + const body = { success, callOutput, transactionReceipt }; res.status(200); res.json(body); } catch (ex) { diff --git a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/insert-bookshelf-endpoint.ts b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/insert-bookshelf-endpoint.ts index b4aa37b723..1e1a42089f 100644 --- a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/insert-bookshelf-endpoint.ts +++ b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/insert-bookshelf-endpoint.ts @@ -22,10 +22,12 @@ import { InsertBookshelfRequest } from "../../generated/openapi/typescript-axios export interface IInsertBookshelfEndpointOptions { logLevel?: LogLevelDesc; - contractAddress: string; - contractAbi: any; + // contractAddress: string; + // contractAbi: any; + contractName: string; besuApi: BesuApi; web3SigningCredential: Web3SigningCredential; + keychainId: string; } export class InsertBookshelfEndpoint implements IWebServiceEndpoint { @@ -47,10 +49,10 @@ export class InsertBookshelfEndpoint implements IWebServiceEndpoint { const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} arg options`); Checks.truthy(opts.besuApi, `${fnTag} options.besuApi`); - Checks.truthy(opts.contractAddress, `${fnTag} options.contractAddress`); - Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`); + // Checks.truthy(opts.contractAddress, `${fnTag} options.contractAddress`); + // Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`); Checks.nonBlankString( - opts.contractAddress, + opts.contractName, `${fnTag} options.contractAddress`, ); @@ -85,13 +87,13 @@ export class InsertBookshelfEndpoint implements IWebServiceEndpoint { const { data: { callOutput, transactionReceipt }, } = await this.opts.besuApi.apiV1BesuInvokeContract({ - contractAbi: this.opts.contractAbi, - contractAddress: this.opts.contractAddress, + contractName: this.opts.contractName, invocationType: EthContractInvocationType.SEND, methodName: "insertRecord", gas: 1000000, params: [bookshelf], - web3SigningCredential: this.opts.web3SigningCredential, + signingCredential: this.opts.web3SigningCredential, + keychainId: this.opts.keychainId, }); const body = { callOutput, transactionReceipt }; diff --git a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/list-bamboo-harvest-endpoint.ts b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/list-bamboo-harvest-endpoint.ts index 84813d69c1..07bee14f82 100644 --- a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/list-bamboo-harvest-endpoint.ts +++ b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/list-bamboo-harvest-endpoint.ts @@ -22,9 +22,10 @@ import { BambooHarvestConverter } from "../../model/converter/bamboo-harvest-con export interface IListBambooHarvestEndpointOptions { logLevel?: LogLevelDesc; - contractAddress: string; - contractAbi: any; + contractName: string; + // contractAbi: any; apiClient: QuorumApi; + keychainId: string; } export class ListBambooHarvestEndpoint implements IWebServiceEndpoint { @@ -46,10 +47,10 @@ export class ListBambooHarvestEndpoint implements IWebServiceEndpoint { const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} arg options`); Checks.truthy(opts.apiClient, `${fnTag} options.apiClient`); - Checks.truthy(opts.contractAddress, `${fnTag} options.contractAddress`); - Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`); + // Checks.truthy(opts.contractAddress, `${fnTag} options.contractAddress`); + // Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`); Checks.nonBlankString( - opts.contractAddress, + opts.contractName, `${fnTag} options.contractAddress`, ); @@ -81,15 +82,15 @@ export class ListBambooHarvestEndpoint implements IWebServiceEndpoint { this.log.debug(`${tag}`); const { data } = await this.opts.apiClient.apiV1QuorumInvokeContract({ - contractAbi: this.opts.contractAbi, - contractAddress: this.opts.contractAddress, + contractName: this.opts.contractName, invocationType: EthContractInvocationType.CALL, methodName: "getAllRecords", gas: 1000000, params: [], - web3SigningCredential: { + signingCredential: { type: Web3SigningCredentialType.NONE, }, + keychainId: this.opts.keychainId, }); const { callOutput } = data; diff --git a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/list-bookshelf-endpoint.ts b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/list-bookshelf-endpoint.ts index e0d304f550..d102464734 100644 --- a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/list-bookshelf-endpoint.ts +++ b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/web-services/list-bookshelf-endpoint.ts @@ -22,9 +22,11 @@ import { BookshelfConverter } from "../../model/converter/bookshelf-converter"; export interface IListBookshelfEndpointOptions { logLevel?: LogLevelDesc; - contractAddress: string; - contractAbi: any; + contractName: string; + // contractAddress: string; + // contractAbi: any; besuApi: BesuApi; + keychainId: string; } export class ListBookshelfEndpoint implements IWebServiceEndpoint { @@ -46,12 +48,9 @@ export class ListBookshelfEndpoint implements IWebServiceEndpoint { const fnTag = `${this.className}#constructor()`; Checks.truthy(opts, `${fnTag} arg options`); Checks.truthy(opts.besuApi, `${fnTag} options.besuApi`); - Checks.truthy(opts.contractAddress, `${fnTag} options.contractAddress`); - Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`); - Checks.nonBlankString( - opts.contractAddress, - `${fnTag} options.contractAddress`, - ); + // Checks.truthy(opts.contractAddress, `${fnTag} options.contractAddress`); + // Checks.truthy(opts.contractAbi, `${fnTag} options.contractAbi`); + Checks.nonBlankString(opts.contractName, `${fnTag} options.contractName`); const level = this.opts.logLevel || "INFO"; const label = this.className; @@ -81,15 +80,15 @@ export class ListBookshelfEndpoint implements IWebServiceEndpoint { this.log.debug(`${tag}`); const { data } = await this.opts.besuApi.apiV1BesuInvokeContract({ - contractAbi: this.opts.contractAbi, - contractAddress: this.opts.contractAddress, + contractName: this.opts.contractName, invocationType: EthContractInvocationType.CALL, methodName: "getAllRecords", gas: 1000000, params: [], - web3SigningCredential: { + signingCredential: { type: Web3SigningCredentialType.NONE, }, + keychainId: this.opts.keychainId, }); const { callOutput } = data; diff --git a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/i-eth-contract-deployment.ts b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/i-eth-contract-deployment.ts index ed5262caf9..8058076c99 100644 --- a/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/i-eth-contract-deployment.ts +++ b/examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/i-eth-contract-deployment.ts @@ -2,4 +2,6 @@ export interface IEthContractDeployment { address: string; abi: any; bytecode: string; + contractName: string; + keychainId: string; } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/json/openapi.json b/packages/cactus-plugin-ledger-connector-besu/src/main/json/openapi.json index dc4ddb7ef2..5c16ee3f8d 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/json/openapi.json +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/json/openapi.json @@ -461,100 +461,6 @@ } }, "InvokeContractV1Request": { - "type": "object", - "required": [ - "contractAbi", - "web3SigningCredential", - "contractAddress", - "invocationType", - "methodName", - "params" - ], - "properties": { - "web3SigningCredential": { - "$ref": "#/components/schemas/Web3SigningCredential", - "nullable": false - }, - "contractAbi": { - "description": "The application binary interface of the solidity contract", - "type": "array", - "items": {}, - "nullable": false - }, - "contractAddress": { - "type": "string", - "nullable": false - }, - "invocationType": { - "$ref": "#/components/schemas/EthContractInvocationType", - "nullable": false, - "description": "Indicates wether it is a CALL or a SEND type of invocation where only SEND ends up creating an actual transaction on the ledger." - }, - "methodName": { - "description": "The name of the contract method to invoke.", - "type": "string", - "nullable": false, - "minLength": 1, - "maxLength": 2048 - }, - "params": { - "description": "The list of arguments to pass in to the contract method being invoked.", - "type": "array", - "default": [], - "items": {} - }, - "value": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "number" - } - ] - }, - "gas": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "number" - } - ] - }, - "gasPrice": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "number" - } - ] - }, - "nonce": { - "type": "number" - }, - "timeoutMs": { - "type": "number", - "description": "The amount of milliseconds to wait for a transaction receipt beforegiving up and crashing. Only has any effect if the invocation type is SEND", - "minimum": 0, - "default": 60000, - "nullable": false - } - } - }, - "InvokeContractV1Response": { - "type": "object", - "properties": { - "transactionReceipt": { - "$ref": "#/components/schemas/Web3TransactionReceipt" - }, - "callOutput": {} - } - }, - "InvokeContractV2Request": { "type": "object", "required": [ "contractName", @@ -638,7 +544,7 @@ } } }, - "InvokeContractV2Response": { + "InvokeContractV1Response": { "type": "object", "required": [ "success" @@ -807,40 +713,6 @@ } } }, - "/api/v2/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract": { - "post": { - "x-hyperledger-cactus": { - "http": { - "verbLowerCase": "post", - "path": "/api/v2/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract" - } - }, - "operationId": "apiV2BesuInvokeContract", - "summary": "Invokeds a contract on a besu ledger", - "parameters": [], - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/InvokeContractV2Request" - } - } - } - }, - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/InvokeContractV2Response" - } - } - } - } - } - } - }, "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/sign-transaction": { "post": { "x-hyperledger-cactus": { diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/generated/openapi/typescript-axios/api.ts index 70c6c60b5a..bfcba154fd 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -181,22 +181,16 @@ export enum EthContractInvocationType { export interface InvokeContractV1Request { /** * - * @type {Web3SigningCredential} - * @memberof InvokeContractV1Request - */ - web3SigningCredential: Web3SigningCredential; - /** - * The application binary interface of the solidity contract - * @type {Array} + * @type {string} * @memberof InvokeContractV1Request */ - contractAbi: Array; + contractName: string; /** * - * @type {string} + * @type {Web3SigningCredential} * @memberof InvokeContractV1Request */ - contractAddress: string; + signingCredential: Web3SigningCredential; /** * * @type {EthContractInvocationType} @@ -245,121 +239,35 @@ export interface InvokeContractV1Request { * @memberof InvokeContractV1Request */ timeoutMs?: number; -} -/** - * - * @export - * @interface InvokeContractV1Response - */ -export interface InvokeContractV1Response { - /** - * - * @type {Web3TransactionReceipt} - * @memberof InvokeContractV1Response - */ - transactionReceipt?: Web3TransactionReceipt; - /** - * - * @type {any} - * @memberof InvokeContractV1Response - */ - callOutput?: any | null; -} -/** - * - * @export - * @interface InvokeContractV2Request - */ -export interface InvokeContractV2Request { - /** - * - * @type {string} - * @memberof InvokeContractV2Request - */ - contractName: string; - /** - * - * @type {Web3SigningCredential} - * @memberof InvokeContractV2Request - */ - signingCredential: Web3SigningCredential; - /** - * - * @type {EthContractInvocationType} - * @memberof InvokeContractV2Request - */ - invocationType: EthContractInvocationType; - /** - * The name of the contract method to invoke. - * @type {string} - * @memberof InvokeContractV2Request - */ - methodName: string; - /** - * The list of arguments to pass in to the contract method being invoked. - * @type {Array} - * @memberof InvokeContractV2Request - */ - params: Array; - /** - * - * @type {string | number} - * @memberof InvokeContractV2Request - */ - value?: string | number; - /** - * - * @type {string | number} - * @memberof InvokeContractV2Request - */ - gas?: string | number; - /** - * - * @type {string | number} - * @memberof InvokeContractV2Request - */ - gasPrice?: string | number; - /** - * - * @type {number} - * @memberof InvokeContractV2Request - */ - nonce?: number; - /** - * The amount of milliseconds to wait for a transaction receipt beforegiving up and crashing. Only has any effect if the invocation type is SEND - * @type {number} - * @memberof InvokeContractV2Request - */ - timeoutMs?: number; /** * The keychainId for retrieve the contracts json. * @type {string} - * @memberof InvokeContractV2Request + * @memberof InvokeContractV1Request */ keychainId?: string; } /** * * @export - * @interface InvokeContractV2Response + * @interface InvokeContractV1Response */ -export interface InvokeContractV2Response { +export interface InvokeContractV1Response { /** * * @type {Web3TransactionReceipt} - * @memberof InvokeContractV2Response + * @memberof InvokeContractV1Response */ transactionReceipt?: Web3TransactionReceipt; /** * * @type {any} - * @memberof InvokeContractV2Response + * @memberof InvokeContractV1Response */ callOutput?: any | null; /** * * @type {boolean} - * @memberof InvokeContractV2Response + * @memberof InvokeContractV1Response */ success: boolean; } @@ -796,47 +704,6 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati options: localVarRequestOptions, }; }, - /** - * - * @summary Invokeds a contract on a besu ledger - * @param {InvokeContractV2Request} [invokeContractV2Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV2BesuInvokeContract: async (invokeContractV2Request?: InvokeContractV2Request, options: any = {}): Promise => { - const localVarPath = `/api/v2/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, 'https://example.com'); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - - - localVarHeaderParameter['Content-Type'] = 'application/json'; - - const query = new URLSearchParams(localVarUrlObj.search); - for (const key in localVarQueryParameter) { - query.set(key, localVarQueryParameter[key]); - } - for (const key in options.query) { - query.set(key, options.query[key]); - } - localVarUrlObj.search = (new URLSearchParams(query)).toString(); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - const needsSerialization = (typeof invokeContractV2Request !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.data = needsSerialization ? JSON.stringify(invokeContractV2Request !== undefined ? invokeContractV2Request : {}) : (invokeContractV2Request || ""); - - return { - url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash, - options: localVarRequestOptions, - }; - }, /** * * @summary Get the Prometheus Metrics @@ -969,20 +836,6 @@ export const DefaultApiFp = function(configuration?: Configuration) { return axios.request(axiosRequestArgs); }; }, - /** - * - * @summary Invokeds a contract on a besu ledger - * @param {InvokeContractV2Request} [invokeContractV2Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async apiV2BesuInvokeContract(invokeContractV2Request?: InvokeContractV2Request, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await DefaultApiAxiosParamCreator(configuration).apiV2BesuInvokeContract(invokeContractV2Request, options); - return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { - const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url}; - return axios.request(axiosRequestArgs); - }; - }, /** * * @summary Get the Prometheus Metrics @@ -1049,16 +902,6 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa apiV1BesuRunTransaction(runTransactionRequest?: RunTransactionRequest, options?: any): AxiosPromise { return DefaultApiFp(configuration).apiV1BesuRunTransaction(runTransactionRequest, options).then((request) => request(axios, basePath)); }, - /** - * - * @summary Invokeds a contract on a besu ledger - * @param {InvokeContractV2Request} [invokeContractV2Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV2BesuInvokeContract(invokeContractV2Request?: InvokeContractV2Request, options?: any): AxiosPromise { - return DefaultApiFp(configuration).apiV2BesuInvokeContract(invokeContractV2Request, options).then((request) => request(axios, basePath)); - }, /** * * @summary Get the Prometheus Metrics @@ -1124,18 +967,6 @@ export class DefaultApi extends BaseAPI { return DefaultApiFp(this.configuration).apiV1BesuRunTransaction(runTransactionRequest, options).then((request) => request(this.axios, this.basePath)); } - /** - * - * @summary Invokeds a contract on a besu ledger - * @param {InvokeContractV2Request} [invokeContractV2Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public apiV2BesuInvokeContract(invokeContractV2Request?: InvokeContractV2Request, options?: any) { - return DefaultApiFp(this.configuration).apiV2BesuInvokeContract(invokeContractV2Request, options).then((request) => request(this.axios, this.basePath)); - } - /** * * @summary Get the Prometheus Metrics diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts index af8337ba4d..13751a6072 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts @@ -42,9 +42,7 @@ import { DeployContractSolidityBytecodeV1Response, EthContractInvocationType, InvokeContractV1Request, - InvokeContractV2Request, InvokeContractV1Response, - InvokeContractV2Response, ReceiptType, RunTransactionRequest, RunTransactionResponse, @@ -57,7 +55,6 @@ import { import { RunTransactionEndpoint } from "./web-services/run-transaction-endpoint"; import { InvokeContractEndpoint } from "./web-services/invoke-contract-endpoint"; -import { InvokeContractEndpointV2 } from "./web-services/invoke-contract-endpoint-v2"; import { isWeb3SigningCredentialNone } from "./model-type-guards"; import { BesuSignTransactionEndpointV1 } from "./web-services/sign-transaction-endpoint-v1"; import { PrometheusExporter } from "./prometheus-exporter/prometheus-exporter"; @@ -198,13 +195,6 @@ export class PluginLedgerConnectorBesu }); endpoints.push(endpoint); } - { - const endpoint = new InvokeContractEndpointV2({ - connector: this, - logLevel: this.options.logLevel, - }); - endpoints.push(endpoint); - } { const opts: IGetPrometheusExporterMetricsEndpointV1Options = { connector: this, @@ -235,65 +225,6 @@ export class PluginLedgerConnectorBesu req: InvokeContractV1Request, ): Promise { const fnTag = `${this.className}#invokeContract()`; - - const { invocationType } = req; - - let abi; - if (typeof req.contractAbi === "string") { - abi = JSON.parse(req.contractAbi); - } else { - abi = req.contractAbi; - } - - const { contractAddress } = req; - const aContract = new this.web3.eth.Contract(abi, contractAddress); - const methodRef = aContract.methods[req.methodName]; - Checks.truthy(methodRef, `${fnTag} YourContract.${req.methodName}`); - - const method: ContractSendMethod = methodRef(...req.params); - - if (req.invocationType === EthContractInvocationType.CALL) { - const callOutput = await (method as any).call(); - return { callOutput }; - } else if (req.invocationType === EthContractInvocationType.SEND) { - if (isWeb3SigningCredentialNone(req.web3SigningCredential)) { - throw new Error(`${fnTag} Cannot deploy contract with pre-signed TX`); - } - const web3SigningCredential = req.web3SigningCredential as Web3SigningCredentialPrivateKeyHex; - - const payload = (method.send as any).request(); - const { params } = payload; - const [transactionConfig] = params; - if (req.gas == undefined) { - req.gas = await this.web3.eth.estimateGas(transactionConfig); - } - transactionConfig.from = web3SigningCredential.ethAccount; - transactionConfig.gas = req.gas; - transactionConfig.gasPrice = req.gasPrice; - transactionConfig.value = req.value; - transactionConfig.nonce = req.nonce; - - const txReq: RunTransactionRequest = { - transactionConfig, - web3SigningCredential, - consistencyStrategy: { - blockConfirmations: 0, - receiptType: ReceiptType.NODETXPOOLACK, - timeoutMs: req.timeoutMs || 60000, - }, - }; - const out = await this.transact(txReq); - - return out; - } else { - throw new Error(`${fnTag} Unsupported invocation type ${invocationType}`); - } - } - - public async invokeContractV2( - req: InvokeContractV2Request, - ): Promise { - const fnTag = `${this.className}#invokeContractV2()`; const contractName = req.contractName; if (req.keychainId != undefined) { diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/invoke-contract-endpoint-v2.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/invoke-contract-endpoint-v2.ts deleted file mode 100644 index 45548a0033..0000000000 --- a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/invoke-contract-endpoint-v2.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { Express, Request, Response } from "express"; - -import { - Logger, - Checks, - LogLevelDesc, - LoggerProvider, -} from "@hyperledger/cactus-common"; -import { - IExpressRequestHandler, - IWebServiceEndpoint, -} from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; - -import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu"; - -import OAS from "../../json/openapi.json"; - -export interface IInvokeContractEndpointV2Options { - logLevel?: LogLevelDesc; - connector: PluginLedgerConnectorBesu; -} - -export class InvokeContractEndpointV2 implements IWebServiceEndpoint { - public static readonly CLASS_NAME = "InvokeContractEndpointV2"; - - private readonly log: Logger; - - public get className(): string { - return InvokeContractEndpointV2.CLASS_NAME; - } - - constructor(public readonly options: IInvokeContractEndpointV2Options) { - const fnTag = `${this.className}#constructor()`; - Checks.truthy(options, `${fnTag} arg options`); - Checks.truthy(options.connector, `${fnTag} arg options.connector`); - - const level = this.options.logLevel || "INFO"; - const label = this.className; - this.log = LoggerProvider.getOrCreate({ level, label }); - } - - public getOasPath() { - return OAS.paths[ - "/api/v2/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract" - ]; - } - - public getPath(): string { - const apiPath = this.getOasPath(); - return apiPath.post["x-hyperledger-cactus"].http.path; - } - - public getVerbLowerCase(): string { - const apiPath = this.getOasPath(); - return apiPath.post["x-hyperledger-cactus"].http.verbLowerCase; - } - - public getOperationId(): string { - return this.getOasPath().post.operationId; - } - - registerExpress(webApp: Express): IWebServiceEndpoint { - registerWebServiceEndpoint(webApp, this); - return this; - } - - public getExpressRequestHandler(): IExpressRequestHandler { - return this.handleRequest.bind(this); - } - - public async handleRequest(req: Request, res: Response): Promise { - const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; - this.log.debug(reqTag); - const reqBody = req.body; - try { - const resBody = await this.options.connector.invokeContractV2(reqBody); - res.json(resBody); - } catch (ex) { - this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: ex?.stack || ex?.message, - }); - } - } -} diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts index 8d6fa05847..4957f2382b 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts @@ -31,6 +31,7 @@ import { K_CACTUS_BESU_TOTAL_TX_COUNT } from "../../../../../main/typescript/pro const testCase = "deploys contract via .json file"; const logLevel: LogLevelDesc = "TRACE"; +const contractName = "HelloWorld"; test("BEFORE " + testCase, async (t: Test) => { const pruning = pruneDockerAllIfGithubAction({ logLevel }); @@ -162,12 +163,12 @@ test(testCase, async (t: Test) => { ); const { callOutput: helloMsg } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "sayHello", params: [], - web3SigningCredential: { + signingCredential: { ethAccount: firstHighNetWorthAccount, secret: besuKeyPair.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -216,12 +217,12 @@ test(testCase, async (t: Test) => { test("invoke Web3SigningCredentialType.PRIVATEKEYHEX", async (t2: Test) => { const newName = `DrCactus${uuidv4()}`; const setNameOut = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -232,13 +233,13 @@ test(testCase, async (t: Test) => { try { const setNameOutInvalid = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -254,13 +255,13 @@ test(testCase, async (t: Test) => { ); } const { callOutput: getNameOut } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -269,13 +270,13 @@ test(testCase, async (t: Test) => { t2.equal(getNameOut, newName, `getName() output reflects the update OK`); const getNameOut2 = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -284,13 +285,13 @@ test(testCase, async (t: Test) => { t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK"); const response = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "deposit", params: [], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -300,13 +301,13 @@ test(testCase, async (t: Test) => { t2.ok(response, "deposit() payable invocation output is truthy OK"); const { callOutput } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "getNameByIndex", params: [0], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -324,7 +325,7 @@ test(testCase, async (t: Test) => { test("invoke Web3SigningCredentialType.CACTUSKEYCHAINREF", async (t2: Test) => { const newName = `DrCactus${uuidv4()}`; - const web3SigningCredential: Web3SigningCredentialCactusKeychainRef = { + const signingCredential: Web3SigningCredentialCactusKeychainRef = { ethAccount: testEthAccount.address, keychainEntryKey, keychainId: keychainPlugin.getKeychainId(), @@ -332,26 +333,26 @@ test(testCase, async (t: Test) => { }; const setNameOut = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential, + signingCredential, nonce: 4, }); t2.ok(setNameOut, "setName() invocation #1 output is truthy OK"); try { const setNameOutInvalid = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential, + signingCredential, nonce: 4, }); t2.ifError(setNameOutInvalid); @@ -364,47 +365,47 @@ test(testCase, async (t: Test) => { } const { callOutput: getNameOut } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential, + signingCredential, }); t2.equal(getNameOut, newName, `getName() output reflects the update OK`); const getNameOut2 = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential, + signingCredential, }); t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK"); const response = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "deposit", params: [], gas: 1000000, - web3SigningCredential, + signingCredential, value: 10, }); t2.ok(response, "deposit() payable invocation output is truthy OK"); const { callOutput } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "getNameByIndex", params: [1], gas: 1000000, - web3SigningCredential, + signingCredential, }); t2.equal( callOutput, diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract-v2.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts similarity index 95% rename from packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract-v2.test.ts rename to packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts index b46ce9d5e3..e0610b24b5 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract-v2.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts @@ -119,7 +119,7 @@ test("deploys contract via .json file", async (t: Test) => { "contractAddress typeof string OK", ); - const { callOutput: helloMsg } = await connector.invokeContractV2({ + const { callOutput: helloMsg } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, @@ -172,7 +172,7 @@ test("deploys contract via .json file", async (t: Test) => { test("invoke Web3SigningCredentialType.PRIVATEKEYHEX", async (t2: Test) => { const newName = `DrCactus${uuidv4()}`; - const setNameOut = await connector.invokeContractV2({ + const setNameOut = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -188,7 +188,7 @@ test("deploys contract via .json file", async (t: Test) => { t2.ok(setNameOut, "setName() invocation #1 output is truthy OK"); try { - const setNameOutInvalid = await connector.invokeContractV2({ + const setNameOutInvalid = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -210,7 +210,7 @@ test("deploys contract via .json file", async (t: Test) => { "setName() invocation with invalid nonce", ); } - const { callOutput: getNameOut } = await connector.invokeContractV2({ + const { callOutput: getNameOut } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, @@ -225,7 +225,7 @@ test("deploys contract via .json file", async (t: Test) => { }); t2.equal(getNameOut, newName, `getName() output reflects the update OK`); - const getNameOut2 = await connector.invokeContractV2({ + const getNameOut2 = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -240,7 +240,7 @@ test("deploys contract via .json file", async (t: Test) => { }); t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK"); - const response = await connector.invokeContractV2({ + const response = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -256,7 +256,7 @@ test("deploys contract via .json file", async (t: Test) => { }); t2.ok(response, "deposit() payable invocation output is truthy OK"); - const { callOutput } = await connector.invokeContractV2({ + const { callOutput } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, @@ -287,7 +287,7 @@ test("deploys contract via .json file", async (t: Test) => { type: Web3SigningCredentialType.CACTUSKEYCHAINREF, }; - const setNameOut = await connector.invokeContractV2({ + const setNameOut = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -300,7 +300,7 @@ test("deploys contract via .json file", async (t: Test) => { t2.ok(setNameOut, "setName() invocation #1 output is truthy OK"); try { - const setNameOutInvalid = await connector.invokeContractV2({ + const setNameOutInvalid = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -319,7 +319,7 @@ test("deploys contract via .json file", async (t: Test) => { ); } - const { callOutput: getNameOut } = await connector.invokeContractV2({ + const { callOutput: getNameOut } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, @@ -330,7 +330,7 @@ test("deploys contract via .json file", async (t: Test) => { }); t2.equal(getNameOut, newName, `getName() output reflects the update OK`); - const getNameOut2 = await connector.invokeContractV2({ + const getNameOut2 = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -341,7 +341,7 @@ test("deploys contract via .json file", async (t: Test) => { }); t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK"); - const response = await connector.invokeContractV2({ + const response = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -353,7 +353,7 @@ test("deploys contract via .json file", async (t: Test) => { }); t2.ok(response, "deposit() payable invocation output is truthy OK"); - const { callOutput: callOut } = await connector.invokeContractV2({ + const { callOutput: callOut } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json b/packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json index 953e5ebbfc..86103aec45 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/json/openapi.json @@ -467,100 +467,6 @@ } }, "InvokeContractV1Request": { - "type": "object", - "required": [ - "contractAbi", - "web3SigningCredential", - "contractAddress", - "invocationType", - "methodName", - "params" - ], - "properties": { - "web3SigningCredential": { - "$ref": "#/components/schemas/Web3SigningCredential", - "nullable": false - }, - "contractAbi": { - "description": "The application binary interface of the solidity contract", - "type": "array", - "items": {}, - "nullable": false - }, - "contractAddress": { - "type": "string", - "nullable": false - }, - "invocationType": { - "$ref": "#/components/schemas/EthContractInvocationType", - "nullable": false, - "description": "Indicates wether it is a CALL or a SEND type of invocation where only SEND ends up creating an actual transaction on the ledger." - }, - "methodName": { - "description": "The name of the contract method to invoke.", - "type": "string", - "nullable": false, - "minLength": 1, - "maxLength": 2048 - }, - "params": { - "description": "The list of arguments to pass in to the contract method being invoked.", - "type": "array", - "default": [], - "items": {} - }, - "gas": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "number" - } - ] - }, - "gasPrice": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "number" - } - ] - }, - "value": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "number" - } - ] - }, - "nonce": { - "type": "number" - }, - "timeoutMs": { - "type": "number", - "description": "The amount of milliseconds to wait for a transaction receipt beforegiving up and crashing. Only has any effect if the invocation type is SEND", - "minimum": 0, - "default": 60000, - "nullable": false - } - } - }, - "InvokeContractV1Response": { - "type": "object", - "properties": { - "transactionReceipt": { - "$ref": "#/components/schemas/Web3TransactionReceipt" - }, - "callOutput": {} - } - }, - "InvokeContractV2Request": { "type": "object", "required": [ "contractName", @@ -644,7 +550,7 @@ } } }, - "InvokeContractV2Response": { + "InvokeContractV1Response": { "type": "object", "required": [ "success" @@ -744,7 +650,7 @@ } }, "operationId": "apiV1QuorumInvokeContract", - "summary": "Invokeds a contract on a quorum ledger", + "summary": "Invokeds a contract on a besu ledger", "parameters": [], "requestBody": { "content": { @@ -769,40 +675,6 @@ } } }, - "/api/v2/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/invoke-contract": { - "post": { - "x-hyperledger-cactus": { - "http": { - "verbLowerCase": "post", - "path": "/api/v2/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/invoke-contract" - } - }, - "operationId": "apiV2QuorumInvokeContract", - "summary": "Invokeds a contract on a besu ledger", - "parameters": [], - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/InvokeContractV2Request" - } - } - } - }, - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/InvokeContractV2Response" - } - } - } - } - } - } - }, "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/get-prometheus-exporter-metrics": { "get": { "x-hyperledger-cactus": { diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts index f75f952751..af3967887f 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -99,22 +99,16 @@ export enum EthContractInvocationType { export interface InvokeContractV1Request { /** * - * @type {Web3SigningCredential} - * @memberof InvokeContractV1Request - */ - web3SigningCredential: Web3SigningCredential; - /** - * The application binary interface of the solidity contract - * @type {Array} + * @type {string} * @memberof InvokeContractV1Request */ - contractAbi: Array; + contractName: string; /** * - * @type {string} + * @type {Web3SigningCredential} * @memberof InvokeContractV1Request */ - contractAddress: string; + signingCredential: Web3SigningCredential; /** * * @type {EthContractInvocationType} @@ -138,19 +132,19 @@ export interface InvokeContractV1Request { * @type {string | number} * @memberof InvokeContractV1Request */ - gas?: string | number; + value?: string | number; /** * * @type {string | number} * @memberof InvokeContractV1Request */ - gasPrice?: string | number; + gas?: string | number; /** * * @type {string | number} * @memberof InvokeContractV1Request */ - value?: string | number; + gasPrice?: string | number; /** * * @type {number} @@ -163,121 +157,35 @@ export interface InvokeContractV1Request { * @memberof InvokeContractV1Request */ timeoutMs?: number; -} -/** - * - * @export - * @interface InvokeContractV1Response - */ -export interface InvokeContractV1Response { - /** - * - * @type {Web3TransactionReceipt} - * @memberof InvokeContractV1Response - */ - transactionReceipt?: Web3TransactionReceipt; - /** - * - * @type {any} - * @memberof InvokeContractV1Response - */ - callOutput?: any | null; -} -/** - * - * @export - * @interface InvokeContractV2Request - */ -export interface InvokeContractV2Request { - /** - * - * @type {string} - * @memberof InvokeContractV2Request - */ - contractName: string; - /** - * - * @type {Web3SigningCredential} - * @memberof InvokeContractV2Request - */ - signingCredential: Web3SigningCredential; - /** - * - * @type {EthContractInvocationType} - * @memberof InvokeContractV2Request - */ - invocationType: EthContractInvocationType; - /** - * The name of the contract method to invoke. - * @type {string} - * @memberof InvokeContractV2Request - */ - methodName: string; - /** - * The list of arguments to pass in to the contract method being invoked. - * @type {Array} - * @memberof InvokeContractV2Request - */ - params: Array; - /** - * - * @type {string | number} - * @memberof InvokeContractV2Request - */ - value?: string | number; - /** - * - * @type {string | number} - * @memberof InvokeContractV2Request - */ - gas?: string | number; - /** - * - * @type {string | number} - * @memberof InvokeContractV2Request - */ - gasPrice?: string | number; - /** - * - * @type {number} - * @memberof InvokeContractV2Request - */ - nonce?: number; - /** - * The amount of milliseconds to wait for a transaction receipt beforegiving up and crashing. Only has any effect if the invocation type is SEND - * @type {number} - * @memberof InvokeContractV2Request - */ - timeoutMs?: number; /** * The keychainId for retrieve the contracts json. * @type {string} - * @memberof InvokeContractV2Request + * @memberof InvokeContractV1Request */ keychainId?: string; } /** * * @export - * @interface InvokeContractV2Response + * @interface InvokeContractV1Response */ -export interface InvokeContractV2Response { +export interface InvokeContractV1Response { /** * * @type {Web3TransactionReceipt} - * @memberof InvokeContractV2Response + * @memberof InvokeContractV1Response */ transactionReceipt?: Web3TransactionReceipt; /** * * @type {any} - * @memberof InvokeContractV2Response + * @memberof InvokeContractV1Response */ callOutput?: any | null; /** * * @type {boolean} - * @memberof InvokeContractV2Response + * @memberof InvokeContractV1Response */ success: boolean; } @@ -668,7 +576,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati }, /** * - * @summary Invokeds a contract on a quorum ledger + * @summary Invokeds a contract on a besu ledger * @param {InvokeContractV1Request} [invokeContractV1Request] * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -748,47 +656,6 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati options: localVarRequestOptions, }; }, - /** - * - * @summary Invokeds a contract on a besu ledger - * @param {InvokeContractV2Request} [invokeContractV2Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV2QuorumInvokeContract: async (invokeContractV2Request?: InvokeContractV2Request, options: any = {}): Promise => { - const localVarPath = `/api/v2/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/invoke-contract`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, 'https://example.com'); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - - - localVarHeaderParameter['Content-Type'] = 'application/json'; - - const query = new URLSearchParams(localVarUrlObj.search); - for (const key in localVarQueryParameter) { - query.set(key, localVarQueryParameter[key]); - } - for (const key in options.query) { - query.set(key, options.query[key]); - } - localVarUrlObj.search = (new URLSearchParams(query)).toString(); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - const needsSerialization = (typeof invokeContractV2Request !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.data = needsSerialization ? JSON.stringify(invokeContractV2Request !== undefined ? invokeContractV2Request : {}) : (invokeContractV2Request || ""); - - return { - url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash, - options: localVarRequestOptions, - }; - }, /** * * @summary Get the Prometheus Metrics @@ -850,7 +717,7 @@ export const DefaultApiFp = function(configuration?: Configuration) { }, /** * - * @summary Invokeds a contract on a quorum ledger + * @summary Invokeds a contract on a besu ledger * @param {InvokeContractV1Request} [invokeContractV1Request] * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -876,20 +743,6 @@ export const DefaultApiFp = function(configuration?: Configuration) { return axios.request(axiosRequestArgs); }; }, - /** - * - * @summary Invokeds a contract on a besu ledger - * @param {InvokeContractV2Request} [invokeContractV2Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async apiV2QuorumInvokeContract(invokeContractV2Request?: InvokeContractV2Request, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await DefaultApiAxiosParamCreator(configuration).apiV2QuorumInvokeContract(invokeContractV2Request, options); - return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { - const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url}; - return axios.request(axiosRequestArgs); - }; - }, /** * * @summary Get the Prometheus Metrics @@ -924,7 +777,7 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa }, /** * - * @summary Invokeds a contract on a quorum ledger + * @summary Invokeds a contract on a besu ledger * @param {InvokeContractV1Request} [invokeContractV1Request] * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -942,16 +795,6 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa apiV1QuorumRunTransaction(runTransactionRequest?: RunTransactionRequest, options?: any): AxiosPromise { return DefaultApiFp(configuration).apiV1QuorumRunTransaction(runTransactionRequest, options).then((request) => request(axios, basePath)); }, - /** - * - * @summary Invokeds a contract on a besu ledger - * @param {InvokeContractV2Request} [invokeContractV2Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV2QuorumInvokeContract(invokeContractV2Request?: InvokeContractV2Request, options?: any): AxiosPromise { - return DefaultApiFp(configuration).apiV2QuorumInvokeContract(invokeContractV2Request, options).then((request) => request(axios, basePath)); - }, /** * * @summary Get the Prometheus Metrics @@ -985,7 +828,7 @@ export class DefaultApi extends BaseAPI { /** * - * @summary Invokeds a contract on a quorum ledger + * @summary Invokeds a contract on a besu ledger * @param {InvokeContractV1Request} [invokeContractV1Request] * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -1007,18 +850,6 @@ export class DefaultApi extends BaseAPI { return DefaultApiFp(this.configuration).apiV1QuorumRunTransaction(runTransactionRequest, options).then((request) => request(this.axios, this.basePath)); } - /** - * - * @summary Invokeds a contract on a besu ledger - * @param {InvokeContractV2Request} [invokeContractV2Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public apiV2QuorumInvokeContract(invokeContractV2Request?: InvokeContractV2Request, options?: any) { - return DefaultApiFp(this.configuration).apiV2QuorumInvokeContract(invokeContractV2Request, options).then((request) => request(this.axios, this.basePath)); - } - /** * * @summary Get the Prometheus Metrics diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts index 6e2e3646e1..1478748ecd 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts @@ -40,8 +40,6 @@ import { EthContractInvocationType, InvokeContractV1Request, InvokeContractV1Response, - InvokeContractV2Request, - InvokeContractV2Response, RunTransactionRequest, RunTransactionResponse, Web3SigningCredentialGethKeychainPassword, @@ -53,7 +51,6 @@ import { import { RunTransactionEndpoint } from "./web-services/run-transaction-endpoint"; import { InvokeContractEndpoint } from "./web-services/invoke-contract-endpoint"; import { isWeb3SigningCredentialNone } from "./model-type-guards"; -import { InvokeContractEndpointV2 } from "./web-services/invoke-contract-endpoint-v2"; import { PrometheusExporter } from "./prometheus-exporter/prometheus-exporter"; import { @@ -183,13 +180,6 @@ export class PluginLedgerConnectorQuorum }); endpoints.push(endpoint); } - { - const endpoint = new InvokeContractEndpointV2({ - connector: this, - logLevel: this.options.logLevel, - }); - endpoints.push(endpoint); - } { const opts: IGetPrometheusExporterMetricsEndpointV1Options = { connector: this, @@ -220,64 +210,6 @@ export class PluginLedgerConnectorQuorum req: InvokeContractV1Request, ): Promise { const fnTag = `${this.className}#invokeContract()`; - - const { invocationType } = req; - - let abi; - if (typeof req.contractAbi === "string") { - abi = JSON.parse(req.contractAbi); - } else { - abi = req.contractAbi; - } - - const { contractAddress } = req; - const aContract = new this.web3.eth.Contract(abi, contractAddress); - const methodRef = aContract.methods[req.methodName]; - - Checks.truthy(methodRef, `${fnTag} YourContract.${req.methodName}`); - - const method: ContractSendMethod = methodRef(...req.params); - - if (req.invocationType === EthContractInvocationType.CALL) { - const callOutput = await (method as any).call(); - return { callOutput }; - } else if (req.invocationType === EthContractInvocationType.SEND) { - if (isWeb3SigningCredentialNone(req.web3SigningCredential)) { - throw new Error(`${fnTag} Cannot deploy contract with pre-signed TX`); - } - const web3SigningCredential = req.web3SigningCredential as - | Web3SigningCredentialGethKeychainPassword - | Web3SigningCredentialPrivateKeyHex; - - const payload = (method.send as any).request(); - const { params } = payload; - const [transactionConfig] = params; - if (req.gas == undefined) { - req.gas = await this.web3.eth.estimateGas(transactionConfig); - } - transactionConfig.from = web3SigningCredential.ethAccount; - transactionConfig.gas = req.gas; - transactionConfig.gasPrice = req.gasPrice; - transactionConfig.value = req.value; - transactionConfig.nonce = req.nonce; - - const txReq: RunTransactionRequest = { - transactionConfig, - web3SigningCredential, - timeoutMs: req.timeoutMs || 60000, - }; - const out = await this.transact(txReq); - - return out; - } else { - throw new Error(`${fnTag} Unsupported invocation type ${invocationType}`); - } - } - - public async invokeContractV2( - req: InvokeContractV2Request, - ): Promise { - const fnTag = `${this.className}#invokeContractV2()`; const contractName = req.contractName; if (req.keychainId != undefined) { diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/invoke-contract-endpoint-v2.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/invoke-contract-endpoint-v2.ts deleted file mode 100644 index 22568cc3db..0000000000 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/invoke-contract-endpoint-v2.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { Express, Request, Response } from "express"; - -import { - Logger, - Checks, - LogLevelDesc, - LoggerProvider, -} from "@hyperledger/cactus-common"; -import { - IExpressRequestHandler, - IWebServiceEndpoint, -} from "@hyperledger/cactus-core-api"; -import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; - -import { PluginLedgerConnectorQuorum } from "../plugin-ledger-connector-quorum"; - -import OAS from "../../json/openapi.json"; - -export interface IInvokeContractEndpointV2Options { - logLevel?: LogLevelDesc; - connector: PluginLedgerConnectorQuorum; -} - -export class InvokeContractEndpointV2 implements IWebServiceEndpoint { - public static readonly CLASS_NAME = "InvokeContractEndpointV2"; - - private readonly log: Logger; - - public get className(): string { - return InvokeContractEndpointV2.CLASS_NAME; - } - - constructor(public readonly options: IInvokeContractEndpointV2Options) { - const fnTag = `${this.className}#constructor()`; - Checks.truthy(options, `${fnTag} arg options`); - Checks.truthy(options.connector, `${fnTag} arg options.connector`); - - const level = this.options.logLevel || "INFO"; - const label = this.className; - this.log = LoggerProvider.getOrCreate({ level, label }); - } - - public getOasPath() { - return OAS.paths[ - "/api/v2/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/invoke-contract" - ]; - } - - public getPath(): string { - const apiPath = this.getOasPath(); - return apiPath.post["x-hyperledger-cactus"].http.path; - } - - public getVerbLowerCase(): string { - const apiPath = this.getOasPath(); - return apiPath.post["x-hyperledger-cactus"].http.verbLowerCase; - } - - public getOperationId(): string { - return this.getOasPath().post.operationId; - } - - registerExpress(webApp: Express): IWebServiceEndpoint { - registerWebServiceEndpoint(webApp, this); - return this; - } - - public getExpressRequestHandler(): IExpressRequestHandler { - return this.handleRequest.bind(this); - } - - public async handleRequest(req: Request, res: Response): Promise { - const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; - this.log.debug(reqTag); - const reqBody = req.body; - try { - const resBody = await this.options.connector.invokeContractV2(reqBody); - res.json(resBody); - } catch (ex) { - this.log.error(`Crash while serving ${reqTag}`, ex); - res.status(500).json({ - message: "Internal Server Error", - error: ex?.stack || ex?.message, - }); - } - } -} diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/invoke-contract-endpoint.ts b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/invoke-contract-endpoint.ts index 7b373df86a..26dbae81ef 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/invoke-contract-endpoint.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/web-services/invoke-contract-endpoint.ts @@ -26,7 +26,7 @@ export class InvokeContractEndpoint implements IWebServiceEndpoint { private readonly log: Logger; - public get className() { + public get className(): string { return InvokeContractEndpoint.CLASS_NAME; } diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts index 13dd48c702..b2231d1aec 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts @@ -37,6 +37,7 @@ import http from "http"; import { AddressInfo } from "net"; const logLevel: LogLevelDesc = "INFO"; +const contractName = "HelloWorld"; test("BEFORE " + testCase, async (t: Test) => { const pruning = pruneDockerAllIfGithubAction({ logLevel }); @@ -164,12 +165,12 @@ test(testCase, async (t: Test) => { ); const { callOutput: helloMsg } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "sayHello", params: [], - web3SigningCredential: { + signingCredential: { ethAccount: firstHighNetWorthAccount, secret: "", type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, @@ -185,12 +186,12 @@ test(testCase, async (t: Test) => { test("invoke Web3SigningCredentialType.GETHKEYCHAINPASSWORD", async (t2: Test) => { const newName = `DrCactus${uuidV4()}`; const setNameOut = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], - web3SigningCredential: { + signingCredential: { ethAccount: firstHighNetWorthAccount, secret: "", type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, @@ -201,20 +202,20 @@ test(testCase, async (t: Test) => { try { const setNameOutInvalid = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: firstHighNetWorthAccount, secret: "", type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, }, nonce: 2, }); - t2.ifError(setNameOutInvalid); + t2.ifError(setNameOutInvalid.transactionReceipt); } catch (error) { t2.notStrictEqual( error, @@ -224,29 +225,26 @@ test(testCase, async (t: Test) => { } const getNameOut = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "getName", params: [], - web3SigningCredential: { + signingCredential: { ethAccount: firstHighNetWorthAccount, secret: "", type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, }, }); - t2.ok( - getNameOut.transactionReceipt, - `getName() SEND invocation produced receipt OK`, - ); + t2.ok(getNameOut.success, `getName() SEND invocation produced receipt OK`); const { callOutput: getNameOut2 } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "getName", params: [], - web3SigningCredential: { + signingCredential: { ethAccount: firstHighNetWorthAccount, secret: "", type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, @@ -292,12 +290,12 @@ test(testCase, async (t: Test) => { test("invoke Web3SigningCredentialType.PRIVATEKEYHEX", async (t2: Test) => { const newName = `DrCactus${uuidV4()}`; const setNameOut = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -308,20 +306,20 @@ test(testCase, async (t: Test) => { try { const setNameOutInvalid = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, }, nonce: 1, }); - t2.ifError(setNameOutInvalid); + t2.ifError(setNameOutInvalid.transactionReceipt); } catch (error) { t2.notStrictEqual( error, @@ -330,13 +328,13 @@ test(testCase, async (t: Test) => { ); } const { callOutput: getNameOut } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -345,13 +343,13 @@ test(testCase, async (t: Test) => { t2.equal(getNameOut, newName, `getName() output reflects the update OK`); const getNameOut2 = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, @@ -365,7 +363,7 @@ test(testCase, async (t: Test) => { test("invoke Web3SigningCredentialType.CACTUSKEYCHAINREF", async (t2: Test) => { const newName = `DrCactus${uuidV4()}`; - const web3SigningCredential: Web3SigningCredentialCactusKeychainRef = { + const signingCredential: Web3SigningCredentialCactusKeychainRef = { ethAccount: testEthAccount.address, keychainEntryKey, keychainId: keychainPlugin.getKeychainId(), @@ -373,33 +371,33 @@ test(testCase, async (t: Test) => { }; const setNameOut = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential, + signingCredential, nonce: 3, }); t2.ok(setNameOut, "setName() invocation #1 output is truthy OK"); try { const setNameOutInvalid = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: firstHighNetWorthAccount, secret: "", type: Web3SigningCredentialType.GETHKEYCHAINPASSWORD, }, nonce: 3, }); - t2.ifError(setNameOutInvalid); + t2.ifError(setNameOutInvalid.transactionReceipt); } catch (error) { t2.notStrictEqual( error, @@ -408,24 +406,24 @@ test(testCase, async (t: Test) => { ); } const { callOutput: getNameOut } = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential, + signingCredential, }); t2.equal(getNameOut, newName, `getName() output reflects the update OK`); const getNameOut2 = await connector.invokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, + keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential, + signingCredential, }); t2.ok(getNameOut2, "getName() invocation #2 output is truthy OK"); diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/invoke-contract-v2.test.ts b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/invoke-contract.test.ts similarity index 95% rename from packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/invoke-contract-v2.test.ts rename to packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/invoke-contract.test.ts index a30a637a47..8d8a98a726 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/invoke-contract-v2.test.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/invoke-contract.test.ts @@ -124,7 +124,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { "contractAddress typeof string OK", ); - const { callOutput: helloMsg } = await connector.invokeContractV2({ + const { callOutput: helloMsg } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, @@ -145,7 +145,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { test("invoke Web3SigningCredentialType.GETHKEYCHAINPASSWORD", async (t2: Test) => { const newName = `DrCactus${uuidV4()}`; - const setNameOut = await connector.invokeContractV2({ + const setNameOut = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -161,7 +161,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { t2.ok(setNameOut, "setName() invocation #1 output is truthy OK"); try { - const setNameOutInvalid = await connector.invokeContractV2({ + const setNameOutInvalid = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -184,7 +184,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { ); } - const getNameOut = await connector.invokeContractV2({ + const getNameOut = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -198,7 +198,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { }); t2.ok(getNameOut.success, `getName() SEND invocation produced receipt OK`); - const { callOutput: getNameOut2 } = await connector.invokeContractV2({ + const { callOutput: getNameOut2 } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, @@ -249,7 +249,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { test("invoke Web3SigningCredentialType.PRIVATEKEYHEX", async (t2: Test) => { const newName = `DrCactus${uuidV4()}`; - const setNameOut = await connector.invokeContractV2({ + const setNameOut = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -265,7 +265,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { t2.ok(setNameOut, "setName() invocation #1 output is truthy OK"); try { - const setNameOutInvalid = await connector.invokeContractV2({ + const setNameOutInvalid = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -287,7 +287,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { "setName() invocation with invalid nonce", ); } - const { callOutput: getNameOut } = await connector.invokeContractV2({ + const { callOutput: getNameOut } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, @@ -302,7 +302,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { }); t2.equal(getNameOut, newName, `getName() output reflects the update OK`); - const getNameOut2 = await connector.invokeContractV2({ + const getNameOut2 = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -330,7 +330,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { type: Web3SigningCredentialType.CACTUSKEYCHAINREF, }; - const setNameOut = await connector.invokeContractV2({ + const setNameOut = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -343,7 +343,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { t2.ok(setNameOut, "setName() invocation #1 output is truthy OK"); try { - const setNameOutInvalid = await connector.invokeContractV2({ + const setNameOutInvalid = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, @@ -365,7 +365,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { "setName() invocation with invalid nonce", ); } - const { callOutput: getNameOut } = await connector.invokeContractV2({ + const { callOutput: getNameOut } = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.CALL, @@ -376,7 +376,7 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { }); t2.equal(getNameOut, newName, `getName() output reflects the update OK`); - const getNameOut2 = await connector.invokeContractV2({ + const getNameOut2 = await connector.invokeContract({ contractName, keychainId: keychainPlugin.getKeychainId(), invocationType: EthContractInvocationType.SEND, diff --git a/packages/cactus-test-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.json b/packages/cactus-test-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.json index 754111157d..29f7eb9fc7 100644 --- a/packages/cactus-test-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.json +++ b/packages/cactus-test-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.json @@ -51,6 +51,7 @@ "name": "solc", "version": "0.7.2+commit.51b20bc0" }, + "networks":{}, "ast": { "absolutePath": "/home/peter/a/blockchain/blockchain-integration-framework/packages/cactus-test-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.sol", "exportedSymbols": { diff --git a/packages/cactus-test-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-via-web-service.test.ts b/packages/cactus-test-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-via-web-service.test.ts index 379e5e28a1..d1201b95a9 100644 --- a/packages/cactus-test-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-via-web-service.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-via-web-service.test.ts @@ -41,6 +41,8 @@ const log: Logger = LoggerProvider.getOrCreate({ level: logLevel, }); +const contractName = "HelloWorld"; + test("BEFORE " + testCase, async (t: Test) => { const pruning = pruneDockerAllIfGithubAction({ logLevel }); await t.doesNotReject(pruning, "Pruning didnt throw OK"); @@ -140,7 +142,6 @@ test(testCase, async (t: Test) => { // 8. Deploy smart contract by issuing REST API call const res = await client.apiV1QuorumDeployContractSolidityBytecode(req); - const contractAddress = res.data.transactionReceipt.contractAddress as string; t.ok(res, "Response for contract deployment is truthy"); t.ok(res.status > 199, "Response status code for contract deployment > 199"); @@ -171,14 +172,14 @@ test(testCase, async (t: Test) => { t2.equals(parseInt(balance, 10), 10e9, "Balance of test account OK"); const sayHelloRes = await client.apiV1QuorumInvokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, invocationType: EthContractInvocationType.CALL, methodName: "sayHello", params: [], - web3SigningCredential: { + signingCredential: { type: Web3SigningCredentialType.NONE, }, + keychainId: kvStoragePlugin.getKeychainId(), }); t2.ok(sayHelloRes, "sayHello() response is truthy"); t2.ok(sayHelloRes.status > 199, "Status for sayHello() res > 199"); @@ -196,17 +197,17 @@ test(testCase, async (t: Test) => { const newName = `DrCactus${uuidV4()}`; const setName1Res = await client.apiV1QuorumInvokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, invocationType: EthContractInvocationType.SEND, methodName: "setName", params: [newName], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, }, + keychainId: kvStoragePlugin.getKeychainId(), }); t2.ok(setName1Res, "setName1Res truthy OK"); t2.ok(setName1Res, "setName1Res truthy OK"); @@ -215,17 +216,17 @@ test(testCase, async (t: Test) => { t2.ok(setName1Res.data, "setName1Res.data is truthy OK"); const getName1Res = await client.apiV1QuorumInvokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, invocationType: EthContractInvocationType.CALL, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, }, + keychainId: kvStoragePlugin.getKeychainId(), }); t2.ok(getName1Res, `getName1Res truthy OK`); t2.true(getName1Res.status > 199, `getName1Res.status > 199 OK`); @@ -240,17 +241,17 @@ test(testCase, async (t: Test) => { t2.equal(getName1Res.data.callOutput, newName, `getName1Res truthy OK`); const getName2Res = await client.apiV1QuorumInvokeContract({ - contractAddress, - contractAbi: HelloWorldContractJson.abi, + contractName, invocationType: EthContractInvocationType.SEND, methodName: "getName", params: [], gas: 1000000, - web3SigningCredential: { + signingCredential: { ethAccount: testEthAccount.address, secret: testEthAccount.privateKey, type: Web3SigningCredentialType.PRIVATEKEYHEX, }, + keychainId: kvStoragePlugin.getKeychainId(), }); t2.ok(getName2Res, `getName2Res truthy OK`);