From 869c48ba4d8000b50d1d64a8a0897b50dde21d5d Mon Sep 17 00:00:00 2001 From: Tommesha Wiggins Date: Fri, 2 Jul 2021 15:02:40 -0500 Subject: [PATCH] feat(connector-besu): add getBlock web service #1065 fixes #1065 Signed-off-by: Tommesha Wiggins --- .../package-lock.json | 73 +- .../src/main/json/openapi.json | 120 +- .../generated/openapi/typescript-axios/api.ts | 1519 ----------------- .../plugin-ledger-connector-besu.ts | 21 +- .../web-services/get-block-v1-endpoint-.ts | 101 ++ .../deploy-contract/get-block.test.ts | 63 + .../package-lock.json | 230 ++- .../get-block-endpoint.test.ts | 147 ++ 8 files changed, 627 insertions(+), 1647 deletions(-) create mode 100644 packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-block-v1-endpoint-.ts create mode 100644 packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-block.test.ts create mode 100644 packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts diff --git a/packages/cactus-plugin-ledger-connector-besu/package-lock.json b/packages/cactus-plugin-ledger-connector-besu/package-lock.json index a544cbef54..d105b19f8b 100644 --- a/packages/cactus-plugin-ledger-connector-besu/package-lock.json +++ b/packages/cactus-plugin-ledger-connector-besu/package-lock.json @@ -441,6 +441,17 @@ "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=" }, + "node_modules/bufferutil": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.3.tgz", + "integrity": "sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw==", + "hasInstallScript": true, + "optional": true, + "peer": true, + "dependencies": { + "node-gyp-build": "^4.2.0" + } + }, "node_modules/bytes": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", @@ -1863,9 +1874,9 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "node_modules/nan": { - "version": "2.14.1", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz", - "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==" + "version": "2.14.2", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", + "integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==" }, "node_modules/nano-json-stream-parser": { "version": "0.1.2", @@ -1885,6 +1896,18 @@ "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" }, + "node_modules/node-gyp-build": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", + "integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==", + "optional": true, + "peer": true, + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/normalize-url": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", @@ -2859,6 +2882,17 @@ "node": ">= 4" } }, + "node_modules/utf-8-validate": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.5.tgz", + "integrity": "sha512-+pnxRYsS/axEpkrrEpzYfNZGXp0IjC/9RIxwM5gntY4Koi8SHmUGSfxfWqxZdRxrtaoVstuOzUp/rbs3JSPELQ==", + "hasInstallScript": true, + "optional": true, + "peer": true, + "dependencies": { + "node-gyp-build": "^4.2.0" + } + }, "node_modules/utf8": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", @@ -3741,6 +3775,16 @@ "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=" }, + "bufferutil": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.3.tgz", + "integrity": "sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw==", + "optional": true, + "peer": true, + "requires": { + "node-gyp-build": "^4.2.0" + } + }, "bytes": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", @@ -4946,9 +4990,9 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "nan": { - "version": "2.14.1", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz", - "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==" + "version": "2.14.2", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", + "integrity": "sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==" }, "nano-json-stream-parser": { "version": "0.1.2", @@ -4965,6 +5009,13 @@ "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" }, + "node-gyp-build": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", + "integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==", + "optional": true, + "peer": true + }, "normalize-url": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", @@ -5768,6 +5819,16 @@ "resolved": "https://registry.npmjs.org/url-to-options/-/url-to-options-1.0.1.tgz", "integrity": "sha1-FQWgOiiaSMvXpDTvuu7FBV9WM6k=" }, + "utf-8-validate": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.5.tgz", + "integrity": "sha512-+pnxRYsS/axEpkrrEpzYfNZGXp0IjC/9RIxwM5gntY4Koi8SHmUGSfxfWqxZdRxrtaoVstuOzUp/rbs3JSPELQ==", + "optional": true, + "peer": true, + "requires": { + "node-gyp-build": "^4.2.0" + } + }, "utf8": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", 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 6919eb643b..f7311d7e85 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 @@ -55,7 +55,78 @@ } } }, + "EvmBlock":{ + "type":"object", + "properties":{ + "number":{ + "type":"number" + }, + "hash":{ + "type":"string" + }, + "parentHash":{ + "type":"string" + }, + "nonce":{ + "type":"string" + }, + "sha3Uncles":{ + "type":"string" + }, + "logsBloom":{ + "type":"string" + }, + "transactionsRoot":{ + "type":"string" + }, + "stateRoot":{ + "type":"string" + }, + "miner":{ + "type":"string" + }, + "difficulty":{ + "type":"number" + }, + "totalDifficulty":{ + "type":"number" + }, + "extraData":{ + "type":"string" + }, + "size":{ + "type":"number" + }, + "gasLimit":{ + "type":"number" + }, + "gasUsed":{ + "type":"number" + }, + "timestamp":{ + }, + "transactions":{ + "type":"array", + "items":{} + }, + "uncles":{ + "type":"array", + "items":{} + } + } + }, + "GetBlockV1Response": { + "type": "object", + "required": [ + "block" + ], + "properties": { + "block": { + "$ref":"#/components/schemas/EvmBlock" + } + } + }, "EvmTransaction":{ "type":"object", "properties":{ @@ -98,9 +169,8 @@ "properties": { "transaction": { "$ref":"#/components/schemas/EvmTransaction" - } } - + } }, "GetTransactionV1Request": { "type": "object", @@ -108,9 +178,9 @@ "properties": { "transactionHash":{ "type": "string" - } } - }, + } + }, "GetPastLogsV1Response": { "type": "object", "required": [ @@ -188,6 +258,14 @@ } } }, + "GetBlockV1Request": { + "required": ["blockHashOrBlockNumber"], + "type": "object", + "properties": { + "blockHashOrBlockNumber": { + } + } + }, "WatchBlocksV1": { "type": "string", "enum": [ @@ -956,6 +1034,40 @@ } } }, + "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-block": { + "post": { + "x-hyperledger-cactus": { + "http": { + "verbLowerCase": "post", + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-block" + } + }, + "operationId": "getBlockV1", + "summary": "Returns a block matching the block", + "parameters": [], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetBlockV1Request" + } + } + } + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetBlockV1Response" + } + } + } + } + } + } + }, "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/run-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 2e4630a093..e69de29bb2 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 @@ -1,1519 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Hyperledger Cactus Plugin - Connector Besu - * Can perform basic tasks on a Besu ledger - * - * The version of the OpenAPI document: 0.0.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -import { Configuration } from './configuration'; -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; -// Some imports not used depending on template conditions -// @ts-ignore -import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common'; -// @ts-ignore -import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base'; - -/** - * - * @export - * @interface BesuTransactionConfig - */ -export interface BesuTransactionConfig { - [key: string]: object | any; - - /** - * - * @type {string} - * @memberof BesuTransactionConfig - */ - rawTransaction?: string; - /** - * - * @type {string | number} - * @memberof BesuTransactionConfig - */ - from?: string | number; - /** - * - * @type {string} - * @memberof BesuTransactionConfig - */ - to?: string; - /** - * - * @type {string | number} - * @memberof BesuTransactionConfig - */ - value?: string | number; - /** - * - * @type {string | number} - * @memberof BesuTransactionConfig - */ - gas?: string | number; - /** - * - * @type {string | number} - * @memberof BesuTransactionConfig - */ - gasPrice?: string | number; - /** - * - * @type {number} - * @memberof BesuTransactionConfig - */ - nonce?: number; - /** - * - * @type {string} - * @memberof BesuTransactionConfig - */ - data?: string; -} -/** - * - * @export - * @interface ConsistencyStrategy - */ -export interface ConsistencyStrategy { - /** - * - * @type {ReceiptType} - * @memberof ConsistencyStrategy - */ - receiptType: ReceiptType; - /** - * The amount of milliseconds to wait for the receipt to arrive to the connector. Defaults to 0 which means to wait for an unlimited amount of time. Note that this wait may be interrupted still by other parts of the infrastructure such as load balancers cutting of HTTP requests after some time even if they are the type that is supposed to be kept alive. The question of re-entrance is a broader topic not in scope to discuss here, but it is important to mention it. - * @type {number} - * @memberof ConsistencyStrategy - */ - timeoutMs?: number; - /** - * The number of blocks to wait to be confirmed in addition to the block containing the transaction in question. Note that if the receipt type is set to only wait for node transaction pool ACK and this parameter is set to anything, but zero then the API will not accept the request due to conflicting parameters. - * @type {number} - * @memberof ConsistencyStrategy - */ - blockConfirmations: number; -} -/** - * - * @export - * @interface DeployContractSolidityBytecodeV1Request - */ -export interface DeployContractSolidityBytecodeV1Request { - /** - * The contract name for retrieve the contracts json on the keychain. - * @type {string} - * @memberof DeployContractSolidityBytecodeV1Request - */ - contractName: string; - /** - * The application binary interface of the solidity contract - * @type {Array} - * @memberof DeployContractSolidityBytecodeV1Request - */ - contractAbi: Array; - /** - * - * @type {Array} - * @memberof DeployContractSolidityBytecodeV1Request - */ - constructorArgs: Array; - /** - * - * @type {Web3SigningCredential} - * @memberof DeployContractSolidityBytecodeV1Request - */ - web3SigningCredential: Web3SigningCredential; - /** - * See https://ethereum.stackexchange.com/a/47556 regarding the maximum length of the bytecode - * @type {string} - * @memberof DeployContractSolidityBytecodeV1Request - */ - bytecode: string; - /** - * The keychainId for retrieve the contracts json. - * @type {string} - * @memberof DeployContractSolidityBytecodeV1Request - */ - keychainId: string; - /** - * - * @type {number} - * @memberof DeployContractSolidityBytecodeV1Request - */ - gas?: number; - /** - * - * @type {string} - * @memberof DeployContractSolidityBytecodeV1Request - */ - gasPrice?: string; - /** - * The amount of milliseconds to wait for a transaction receipt with theaddress of the contract(which indicates successful deployment) beforegiving up and crashing. - * @type {number} - * @memberof DeployContractSolidityBytecodeV1Request - */ - timeoutMs?: number; -} -/** - * - * @export - * @interface DeployContractSolidityBytecodeV1Response - */ -export interface DeployContractSolidityBytecodeV1Response { - /** - * - * @type {Web3TransactionReceipt} - * @memberof DeployContractSolidityBytecodeV1Response - */ - transactionReceipt: Web3TransactionReceipt; -} -/** - * - * @export - * @enum {string} - */ -export enum EthContractInvocationType { - Send = 'SEND', - Call = 'CALL' -} - -/** - * - * @export - * @interface EvmLog - */ -export interface EvmLog { - /** - * - * @type {string} - * @memberof EvmLog - */ - address: string; - /** - * - * @type {string} - * @memberof EvmLog - */ - data: string; - /** - * - * @type {string} - * @memberof EvmLog - */ - blockHash: string; - /** - * - * @type {string} - * @memberof EvmLog - */ - transactionHash: string; - /** - * - * @type {Array} - * @memberof EvmLog - */ - topics: Array; - /** - * - * @type {number} - * @memberof EvmLog - */ - logIndex: number; - /** - * - * @type {number} - * @memberof EvmLog - */ - transactionIndex: number; - /** - * - * @type {number} - * @memberof EvmLog - */ - blockNumber: number; -} -/** - * - * @export - * @interface EvmTransaction - */ -export interface EvmTransaction { - /** - * - * @type {string} - * @memberof EvmTransaction - */ - hash?: string; - /** - * - * @type {number} - * @memberof EvmTransaction - */ - nonce?: number; - /** - * - * @type {any} - * @memberof EvmTransaction - */ - blockHash?: any | null; - /** - * - * @type {any} - * @memberof EvmTransaction - */ - blockNumber?: any | null; - /** - * - * @type {any} - * @memberof EvmTransaction - */ - transactionIndex?: any | null; - /** - * - * @type {string} - * @memberof EvmTransaction - */ - from?: string; - /** - * - * @type {any} - * @memberof EvmTransaction - */ - to?: any | null; - /** - * - * @type {string} - * @memberof EvmTransaction - */ - value?: string; - /** - * - * @type {string} - * @memberof EvmTransaction - */ - gasPrice?: string; - /** - * - * @type {number} - * @memberof EvmTransaction - */ - gas?: number; - /** - * - * @type {string} - * @memberof EvmTransaction - */ - input?: string; -} -/** - * - * @export - * @interface GetBalanceV1Request - */ -export interface GetBalanceV1Request { - /** - * - * @type {string} - * @memberof GetBalanceV1Request - */ - address: string; - /** - * - * @type {any} - * @memberof GetBalanceV1Request - */ - defaultBlock?: any | null; -} -/** - * - * @export - * @interface GetBalanceV1Response - */ -export interface GetBalanceV1Response { - /** - * - * @type {string} - * @memberof GetBalanceV1Response - */ - balance: string; -} -/** - * - * @export - * @interface GetPastLogsV1Request - */ -export interface GetPastLogsV1Request { - /** - * - * @type {any} - * @memberof GetPastLogsV1Request - */ - toBlock?: any | null; - /** - * - * @type {any} - * @memberof GetPastLogsV1Request - */ - fromBlock?: any | null; - /** - * - * @type {any} - * @memberof GetPastLogsV1Request - */ - address?: any | null; - /** - * - * @type {Array} - * @memberof GetPastLogsV1Request - */ - topics?: Array; -} -/** - * - * @export - * @interface GetPastLogsV1Response - */ -export interface GetPastLogsV1Response { - /** - * - * @type {Array} - * @memberof GetPastLogsV1Response - */ - logs: Array; -} -/** - * - * @export - * @interface GetTransactionV1Request - */ -export interface GetTransactionV1Request { - /** - * - * @type {string} - * @memberof GetTransactionV1Request - */ - transactionHash: string; -} -/** - * - * @export - * @interface GetTransactionV1Response - */ -export interface GetTransactionV1Response { - /** - * - * @type {EvmTransaction} - * @memberof GetTransactionV1Response - */ - transaction: EvmTransaction; -} -/** - * - * @export - * @interface InvokeContractV1Request - */ -export interface InvokeContractV1Request { - /** - * - * @type {string} - * @memberof InvokeContractV1Request - */ - contractName: string; - /** - * - * @type {Web3SigningCredential} - * @memberof InvokeContractV1Request - */ - signingCredential: Web3SigningCredential; - /** - * - * @type {EthContractInvocationType} - * @memberof InvokeContractV1Request - */ - invocationType: EthContractInvocationType; - /** - * The name of the contract method to invoke. - * @type {string} - * @memberof InvokeContractV1Request - */ - methodName: string; - /** - * The list of arguments to pass in to the contract method being invoked. - * @type {Array} - * @memberof InvokeContractV1Request - */ - params: Array; - /** - * The application binary interface of the solidity contract, optional parameter - * @type {Array} - * @memberof InvokeContractV1Request - */ - contractAbi?: Array; - /** - * Address of the solidity contract, optional parameter - * @type {string} - * @memberof InvokeContractV1Request - */ - contractAddress?: string; - /** - * - * @type {string | number} - * @memberof InvokeContractV1Request - */ - value?: string | number; - /** - * - * @type {string | number} - * @memberof InvokeContractV1Request - */ - gas?: string | number; - /** - * - * @type {string | number} - * @memberof InvokeContractV1Request - */ - gasPrice?: string | number; - /** - * - * @type {number} - * @memberof InvokeContractV1Request - */ - 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 InvokeContractV1Request - */ - timeoutMs?: number; - /** - * The keychainId for retrieve the contracts json. - * @type {string} - * @memberof InvokeContractV1Request - */ - keychainId?: string; -} -/** - * - * @export - * @interface InvokeContractV1Response - */ -export interface InvokeContractV1Response { - /** - * - * @type {Web3TransactionReceipt} - * @memberof InvokeContractV1Response - */ - transactionReceipt?: Web3TransactionReceipt; - /** - * - * @type {any} - * @memberof InvokeContractV1Response - */ - callOutput?: any | null; - /** - * - * @type {boolean} - * @memberof InvokeContractV1Response - */ - success: boolean; -} -/** - * Enumerates the possible types of receipts that can be waited for by someone or something that has requested the execution of a transaction on a ledger. - * @export - * @enum {string} - */ -export enum ReceiptType { - NodeTxPoolAck = 'NODE_TX_POOL_ACK', - LedgerBlockAck = 'LEDGER_BLOCK_ACK' -} - -/** - * - * @export - * @interface RunTransactionRequest - */ -export interface RunTransactionRequest { - /** - * - * @type {Web3SigningCredential} - * @memberof RunTransactionRequest - */ - web3SigningCredential: Web3SigningCredential; - /** - * - * @type {BesuTransactionConfig} - * @memberof RunTransactionRequest - */ - transactionConfig: BesuTransactionConfig; - /** - * - * @type {ConsistencyStrategy} - * @memberof RunTransactionRequest - */ - consistencyStrategy: ConsistencyStrategy; -} -/** - * - * @export - * @interface RunTransactionResponse - */ -export interface RunTransactionResponse { - /** - * - * @type {Web3TransactionReceipt} - * @memberof RunTransactionResponse - */ - transactionReceipt: Web3TransactionReceipt; -} -/** - * - * @export - * @interface SignTransactionRequest - */ -export interface SignTransactionRequest { - /** - * - * @type {string} - * @memberof SignTransactionRequest - */ - keychainId: string; - /** - * - * @type {string} - * @memberof SignTransactionRequest - */ - keychainRef: string; - /** - * The transaction hash of ledger will be used to fetch the contain. - * @type {string} - * @memberof SignTransactionRequest - */ - transactionHash: string; -} -/** - * - * @export - * @interface SignTransactionResponse - */ -export interface SignTransactionResponse { - /** - * The signatures of ledger from the corresponding transaction hash. - * @type {string} - * @memberof SignTransactionResponse - */ - signature: string; -} -/** - * - * @export - * @interface SolidityContractJsonArtifact - */ -export interface SolidityContractJsonArtifact { - /** - * - * @type {string} - * @memberof SolidityContractJsonArtifact - */ - contractName: string; - /** - * - * @type {string} - * @memberof SolidityContractJsonArtifact - */ - metadata?: string; - /** - * - * @type {string} - * @memberof SolidityContractJsonArtifact - */ - bytecode?: string; - /** - * - * @type {string} - * @memberof SolidityContractJsonArtifact - */ - deployedBytecode?: string; - /** - * - * @type {string} - * @memberof SolidityContractJsonArtifact - */ - sourceMap?: string; - /** - * - * @type {string} - * @memberof SolidityContractJsonArtifact - */ - deployedSourceMap?: string; - /** - * - * @type {string} - * @memberof SolidityContractJsonArtifact - */ - sourcePath?: string; - /** - * - * @type {{ [key: string]: object; }} - * @memberof SolidityContractJsonArtifact - */ - compiler?: { [key: string]: object; }; - /** - * - * @type {{ [key: string]: object; }} - * @memberof SolidityContractJsonArtifact - */ - functionHashes?: { [key: string]: object; }; - /** - * - * @type {object} - * @memberof SolidityContractJsonArtifact - */ - gasEstimates?: object; -} -/** - * - * @export - * @enum {string} - */ -export enum WatchBlocksV1 { - Subscribe = 'org.hyperledger.cactus.api.async.besu.WatchBlocksV1.Subscribe', - Next = 'org.hyperledger.cactus.api.async.besu.WatchBlocksV1.Next', - Unsubscribe = 'org.hyperledger.cactus.api.async.besu.WatchBlocksV1.Unsubscribe', - Error = 'org.hyperledger.cactus.api.async.besu.WatchBlocksV1.Error', - Complete = 'org.hyperledger.cactus.api.async.besu.WatchBlocksV1.Complete' -} - -/** - * - * @export - * @interface WatchBlocksV1Progress - */ -export interface WatchBlocksV1Progress { - /** - * - * @type {Web3BlockHeader} - * @memberof WatchBlocksV1Progress - */ - blockHeader: Web3BlockHeader; -} -/** - * - * @export - * @interface Web3BlockHeader - */ -export interface Web3BlockHeader { - /** - * - * @type {number} - * @memberof Web3BlockHeader - */ - number: number; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - hash: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - parentHash: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - nonce: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - sha3Uncles: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - logsBloom: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - transactionRoot: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - stateRoot: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - receiptRoot: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - miner: string; - /** - * - * @type {string} - * @memberof Web3BlockHeader - */ - extraData: string; - /** - * - * @type {number} - * @memberof Web3BlockHeader - */ - gasLimit: number; - /** - * - * @type {number} - * @memberof Web3BlockHeader - */ - gasUsed: number; - /** - * - * @type {string | number} - * @memberof Web3BlockHeader - */ - timestamp: string | number; -} -/** - * @type Web3SigningCredential - * @export - */ -export type Web3SigningCredential = Web3SigningCredentialCactusKeychainRef | Web3SigningCredentialNone | Web3SigningCredentialPrivateKeyHex; - -/** - * - * @export - * @interface Web3SigningCredentialCactusKeychainRef - */ -export interface Web3SigningCredentialCactusKeychainRef { - /** - * - * @type {Web3SigningCredentialType} - * @memberof Web3SigningCredentialCactusKeychainRef - */ - type: Web3SigningCredentialType; - /** - * The ethereum account (public key) that the credential belongs to. Basically the username in the traditional terminology of authentication. - * @type {string} - * @memberof Web3SigningCredentialCactusKeychainRef - */ - ethAccount: string; - /** - * The key to use when looking up the the keychain entry holding the secret pointed to by the keychainEntryKey parameter. - * @type {string} - * @memberof Web3SigningCredentialCactusKeychainRef - */ - keychainEntryKey: string; - /** - * The keychain ID to use when looking up the the keychain plugin instance that will be used to retrieve the secret pointed to by the keychainEntryKey parameter. - * @type {string} - * @memberof Web3SigningCredentialCactusKeychainRef - */ - keychainId: string; -} -/** - * Using this denotes that there is no signing required because the transaction is pre-signed. - * @export - * @interface Web3SigningCredentialNone - */ -export interface Web3SigningCredentialNone { - /** - * - * @type {Web3SigningCredentialType} - * @memberof Web3SigningCredentialNone - */ - type: Web3SigningCredentialType; -} -/** - * - * @export - * @interface Web3SigningCredentialPrivateKeyHex - */ -export interface Web3SigningCredentialPrivateKeyHex { - /** - * - * @type {Web3SigningCredentialType} - * @memberof Web3SigningCredentialPrivateKeyHex - */ - type: Web3SigningCredentialType; - /** - * The ethereum account (public key) that the credential belongs to. Basically the username in the traditional terminology of authentication. - * @type {string} - * @memberof Web3SigningCredentialPrivateKeyHex - */ - ethAccount: string; - /** - * The HEX encoded private key of an eth account. - * @type {string} - * @memberof Web3SigningCredentialPrivateKeyHex - */ - secret: string; -} -/** - * - * @export - * @enum {string} - */ -export enum Web3SigningCredentialType { - CactusKeychainRef = 'CACTUS_KEYCHAIN_REF', - GethKeychainPassword = 'GETH_KEYCHAIN_PASSWORD', - PrivateKeyHex = 'PRIVATE_KEY_HEX', - None = 'NONE' -} - -/** - * - * @export - * @interface Web3TransactionReceipt - */ -export interface Web3TransactionReceipt { - [key: string]: object | any; - - /** - * - * @type {boolean} - * @memberof Web3TransactionReceipt - */ - status: boolean; - /** - * - * @type {string} - * @memberof Web3TransactionReceipt - */ - transactionHash: string; - /** - * - * @type {number} - * @memberof Web3TransactionReceipt - */ - transactionIndex: number; - /** - * - * @type {string} - * @memberof Web3TransactionReceipt - */ - blockHash: string; - /** - * - * @type {number} - * @memberof Web3TransactionReceipt - */ - blockNumber: number; - /** - * - * @type {number} - * @memberof Web3TransactionReceipt - */ - gasUsed: number; - /** - * - * @type {string} - * @memberof Web3TransactionReceipt - */ - contractAddress?: string | null; - /** - * - * @type {string} - * @memberof Web3TransactionReceipt - */ - from: string; - /** - * - * @type {string} - * @memberof Web3TransactionReceipt - */ - to: string; -} - -/** - * DefaultApi - axios parameter creator - * @export - */ -export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) { - return { - /** - * - * @summary Deploys the bytecode of a Solidity contract. - * @param {DeployContractSolidityBytecodeV1Request} [deployContractSolidityBytecodeV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV1BesuDeployContractSolidityBytecode: async (deployContractSolidityBytecodeV1Request?: DeployContractSolidityBytecodeV1Request, options: any = {}): Promise => { - const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/deploy-contract-solidity-bytecode`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - 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'; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(deployContractSolidityBytecodeV1Request, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * - * @summary Invokes a contract on a besu ledger - * @param {InvokeContractV1Request} [invokeContractV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV1BesuInvokeContract: async (invokeContractV1Request?: InvokeContractV1Request, options: any = {}): Promise => { - const localVarPath = `/api/v1/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, DUMMY_BASE_URL); - 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'; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(invokeContractV1Request, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * - * @summary Executes a transaction on a besu ledger - * @param {RunTransactionRequest} [runTransactionRequest] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV1BesuRunTransaction: async (runTransactionRequest?: RunTransactionRequest, options: any = {}): Promise => { - const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/run-transaction`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - 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'; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(runTransactionRequest, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * - * @summary Gets past logs, matching the given options. - * @param {GetPastLogsV1Request} [getPastLogsV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getPastLogsV1: async (getPastLogsV1Request?: GetPastLogsV1Request, options: any = {}): Promise => { - const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-past-logs`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - 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'; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(getPastLogsV1Request, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * - * @summary Get the Prometheus Metrics - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getPrometheusExporterMetricsV1: async (options: any = {}): Promise => { - const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-prometheus-exporter-metrics`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * - * @summary Executes a transaction on a besu ledger - * @param {GetTransactionV1Request} [getTransactionV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getTransaction: async (getTransactionV1Request?: GetTransactionV1Request, options: any = {}): Promise => { - const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-transaction`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - 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'; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(getTransactionV1Request, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * - * @summary Return balance of an address of a given block - * @param {GetBalanceV1Request} [getBalanceV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getbalanceV1: async (getBalanceV1Request?: GetBalanceV1Request, options: any = {}): Promise => { - const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-balance`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - 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'; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(getBalanceV1Request, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * Obtain signatures of ledger from the corresponding transaction hash. - * @summary Obtain signatures of ledger from the corresponding transaction hash. - * @param {SignTransactionRequest} signTransactionRequest - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - signTransactionV1: async (signTransactionRequest: SignTransactionRequest, options: any = {}): Promise => { - // verify required parameter 'signTransactionRequest' is not null or undefined - assertParamExists('signTransactionV1', 'signTransactionRequest', signTransactionRequest) - const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/sign-transaction`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - 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'; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(signTransactionRequest, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - } -}; - -/** - * DefaultApi - functional programming interface - * @export - */ -export const DefaultApiFp = function(configuration?: Configuration) { - const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration) - return { - /** - * - * @summary Deploys the bytecode of a Solidity contract. - * @param {DeployContractSolidityBytecodeV1Request} [deployContractSolidityBytecodeV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async apiV1BesuDeployContractSolidityBytecode(deployContractSolidityBytecodeV1Request?: DeployContractSolidityBytecodeV1Request, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1BesuDeployContractSolidityBytecode(deployContractSolidityBytecodeV1Request, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * - * @summary Invokes a contract on a besu ledger - * @param {InvokeContractV1Request} [invokeContractV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async apiV1BesuInvokeContract(invokeContractV1Request?: InvokeContractV1Request, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1BesuInvokeContract(invokeContractV1Request, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * - * @summary Executes a transaction on a besu ledger - * @param {RunTransactionRequest} [runTransactionRequest] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async apiV1BesuRunTransaction(runTransactionRequest?: RunTransactionRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.apiV1BesuRunTransaction(runTransactionRequest, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * - * @summary Gets past logs, matching the given options. - * @param {GetPastLogsV1Request} [getPastLogsV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async getPastLogsV1(getPastLogsV1Request?: GetPastLogsV1Request, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.getPastLogsV1(getPastLogsV1Request, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * - * @summary Get the Prometheus Metrics - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async getPrometheusExporterMetricsV1(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.getPrometheusExporterMetricsV1(options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * - * @summary Executes a transaction on a besu ledger - * @param {GetTransactionV1Request} [getTransactionV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async getTransaction(getTransactionV1Request?: GetTransactionV1Request, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.getTransaction(getTransactionV1Request, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * - * @summary Return balance of an address of a given block - * @param {GetBalanceV1Request} [getBalanceV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async getbalanceV1(getBalanceV1Request?: GetBalanceV1Request, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.getbalanceV1(getBalanceV1Request, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * Obtain signatures of ledger from the corresponding transaction hash. - * @summary Obtain signatures of ledger from the corresponding transaction hash. - * @param {SignTransactionRequest} signTransactionRequest - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async signTransactionV1(signTransactionRequest: SignTransactionRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.signTransactionV1(signTransactionRequest, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - } -}; - -/** - * DefaultApi - factory interface - * @export - */ -export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { - const localVarFp = DefaultApiFp(configuration) - return { - /** - * - * @summary Deploys the bytecode of a Solidity contract. - * @param {DeployContractSolidityBytecodeV1Request} [deployContractSolidityBytecodeV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV1BesuDeployContractSolidityBytecode(deployContractSolidityBytecodeV1Request?: DeployContractSolidityBytecodeV1Request, options?: any): AxiosPromise { - return localVarFp.apiV1BesuDeployContractSolidityBytecode(deployContractSolidityBytecodeV1Request, options).then((request) => request(axios, basePath)); - }, - /** - * - * @summary Invokes a contract on a besu ledger - * @param {InvokeContractV1Request} [invokeContractV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV1BesuInvokeContract(invokeContractV1Request?: InvokeContractV1Request, options?: any): AxiosPromise { - return localVarFp.apiV1BesuInvokeContract(invokeContractV1Request, options).then((request) => request(axios, basePath)); - }, - /** - * - * @summary Executes a transaction on a besu ledger - * @param {RunTransactionRequest} [runTransactionRequest] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - apiV1BesuRunTransaction(runTransactionRequest?: RunTransactionRequest, options?: any): AxiosPromise { - return localVarFp.apiV1BesuRunTransaction(runTransactionRequest, options).then((request) => request(axios, basePath)); - }, - /** - * - * @summary Gets past logs, matching the given options. - * @param {GetPastLogsV1Request} [getPastLogsV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getPastLogsV1(getPastLogsV1Request?: GetPastLogsV1Request, options?: any): AxiosPromise { - return localVarFp.getPastLogsV1(getPastLogsV1Request, options).then((request) => request(axios, basePath)); - }, - /** - * - * @summary Get the Prometheus Metrics - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getPrometheusExporterMetricsV1(options?: any): AxiosPromise { - return localVarFp.getPrometheusExporterMetricsV1(options).then((request) => request(axios, basePath)); - }, - /** - * - * @summary Executes a transaction on a besu ledger - * @param {GetTransactionV1Request} [getTransactionV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getTransaction(getTransactionV1Request?: GetTransactionV1Request, options?: any): AxiosPromise { - return localVarFp.getTransaction(getTransactionV1Request, options).then((request) => request(axios, basePath)); - }, - /** - * - * @summary Return balance of an address of a given block - * @param {GetBalanceV1Request} [getBalanceV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getbalanceV1(getBalanceV1Request?: GetBalanceV1Request, options?: any): AxiosPromise { - return localVarFp.getbalanceV1(getBalanceV1Request, options).then((request) => request(axios, basePath)); - }, - /** - * Obtain signatures of ledger from the corresponding transaction hash. - * @summary Obtain signatures of ledger from the corresponding transaction hash. - * @param {SignTransactionRequest} signTransactionRequest - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - signTransactionV1(signTransactionRequest: SignTransactionRequest, options?: any): AxiosPromise { - return localVarFp.signTransactionV1(signTransactionRequest, options).then((request) => request(axios, basePath)); - }, - }; -}; - -/** - * DefaultApi - object-oriented interface - * @export - * @class DefaultApi - * @extends {BaseAPI} - */ -export class DefaultApi extends BaseAPI { - /** - * - * @summary Deploys the bytecode of a Solidity contract. - * @param {DeployContractSolidityBytecodeV1Request} [deployContractSolidityBytecodeV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public apiV1BesuDeployContractSolidityBytecode(deployContractSolidityBytecodeV1Request?: DeployContractSolidityBytecodeV1Request, options?: any) { - return DefaultApiFp(this.configuration).apiV1BesuDeployContractSolidityBytecode(deployContractSolidityBytecodeV1Request, options).then((request) => request(this.axios, this.basePath)); - } - - /** - * - * @summary Invokes a contract on a besu ledger - * @param {InvokeContractV1Request} [invokeContractV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public apiV1BesuInvokeContract(invokeContractV1Request?: InvokeContractV1Request, options?: any) { - return DefaultApiFp(this.configuration).apiV1BesuInvokeContract(invokeContractV1Request, options).then((request) => request(this.axios, this.basePath)); - } - - /** - * - * @summary Executes a transaction on a besu ledger - * @param {RunTransactionRequest} [runTransactionRequest] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public apiV1BesuRunTransaction(runTransactionRequest?: RunTransactionRequest, options?: any) { - return DefaultApiFp(this.configuration).apiV1BesuRunTransaction(runTransactionRequest, options).then((request) => request(this.axios, this.basePath)); - } - - /** - * - * @summary Gets past logs, matching the given options. - * @param {GetPastLogsV1Request} [getPastLogsV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public getPastLogsV1(getPastLogsV1Request?: GetPastLogsV1Request, options?: any) { - return DefaultApiFp(this.configuration).getPastLogsV1(getPastLogsV1Request, options).then((request) => request(this.axios, this.basePath)); - } - - /** - * - * @summary Get the Prometheus Metrics - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public getPrometheusExporterMetricsV1(options?: any) { - return DefaultApiFp(this.configuration).getPrometheusExporterMetricsV1(options).then((request) => request(this.axios, this.basePath)); - } - - /** - * - * @summary Executes a transaction on a besu ledger - * @param {GetTransactionV1Request} [getTransactionV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public getTransaction(getTransactionV1Request?: GetTransactionV1Request, options?: any) { - return DefaultApiFp(this.configuration).getTransaction(getTransactionV1Request, options).then((request) => request(this.axios, this.basePath)); - } - - /** - * - * @summary Return balance of an address of a given block - * @param {GetBalanceV1Request} [getBalanceV1Request] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public getbalanceV1(getBalanceV1Request?: GetBalanceV1Request, options?: any) { - return DefaultApiFp(this.configuration).getbalanceV1(getBalanceV1Request, options).then((request) => request(this.axios, this.basePath)); - } - - /** - * Obtain signatures of ledger from the corresponding transaction hash. - * @summary Obtain signatures of ledger from the corresponding transaction hash. - * @param {SignTransactionRequest} signTransactionRequest - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof DefaultApi - */ - public signTransactionV1(signTransactionRequest: SignTransactionRequest, options?: any) { - return DefaultApiFp(this.configuration).signTransactionV1(signTransactionRequest, options).then((request) => request(this.axios, this.basePath)); - } -} - - 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 a2c8f8c60d..cdc18b25e7 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 @@ -66,9 +66,10 @@ import { Web3SigningCredentialType, GetTransactionV1Request, GetTransactionV1Response, -} from "./generated/openapi/typescript-axios/"; + GetBlockV1Request, + GetBlockV1Response, +} from "./generated/openapi/typescript-axios"; -import { RunTransactionEndpoint } from "./web-services/run-transaction-endpoint"; import { InvokeContractEndpoint } from "./web-services/invoke-contract-endpoint"; import { isWeb3SigningCredentialNone } from "./model-type-guards"; import { BesuSignTransactionEndpointV1 } from "./web-services/sign-transaction-endpoint-v1"; @@ -81,6 +82,8 @@ import { WatchBlocksV1Endpoint } from "./web-services/watch-blocks-v1-endpoint"; import { GetBalanceEndpoint } from "./web-services/get-balance-endpoint"; import { GetTransactionEndpoint } from "./web-services/get-transaction-endpoint"; import { GetPastLogsEndpoint } from "./web-services/get-past-logs-endpoint"; +import { RunTransactionEndpoint } from "./web-services/run-transaction-endpoint"; +import { GetBlockEndpoint } from "./web-services/get-block-v1-endpoint-"; export const E_KEYCHAIN_NOT_FOUND = "cactus.connector.besu.keychain_not_found"; @@ -240,6 +243,13 @@ export class PluginLedgerConnectorBesu }); endpoints.push(endpoint); } + { + const endpoint = new GetBlockEndpoint({ + connector: this, + logLevel: this.options.logLevel, + }); + endpoints.push(endpoint); + } { const endpoint = new InvokeContractEndpoint({ connector: this, @@ -757,4 +767,11 @@ export class PluginLedgerConnectorBesu const logs = await this.web3.eth.getPastLogs(request); return { logs }; } + + public async getBlock( + request: GetBlockV1Request, + ): Promise { + const block = await this.web3.eth.getBlock(request.blockHashOrBlockNumber); + return { block }; + } } diff --git a/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-block-v1-endpoint-.ts b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-block-v1-endpoint-.ts new file mode 100644 index 0000000000..7c8cee0e6b --- /dev/null +++ b/packages/cactus-plugin-ledger-connector-besu/src/main/typescript/web-services/get-block-v1-endpoint-.ts @@ -0,0 +1,101 @@ +import { Express, Request, Response } from "express"; + +import { + Logger, + Checks, + LogLevelDesc, + LoggerProvider, + IAsyncProvider, +} from "@hyperledger/cactus-common"; +import { + IEndpointAuthzOptions, + 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 IGetBlockEndpointOptions { + logLevel?: LogLevelDesc; + connector: PluginLedgerConnectorBesu; +} + +export class GetBlockEndpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "GetBlockEndpoint"; + + private readonly log: Logger; + + public get className(): string { + return GetBlockEndpoint.CLASS_NAME; + } + + constructor(public readonly options: IGetBlockEndpointOptions) { + 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/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-block" + ]; + } + + 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; + } + + getAuthorizationOptionsProvider(): IAsyncProvider { + // TODO: make this an injectable dependency in the constructor + return { + get: async () => ({ + isProtected: true, + requiredRoles: [], + }), + }; + } + + public async registerExpress( + expressApp: Express, + ): Promise { + await registerWebServiceEndpoint(expressApp, 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.getBlock(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/get-block.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-block.test.ts new file mode 100644 index 0000000000..91c7221e72 --- /dev/null +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-block.test.ts @@ -0,0 +1,63 @@ +import test, { Test } from "tape"; +import { v4 as uuidv4 } from "uuid"; +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { + PluginLedgerConnectorBesu, + PluginFactoryLedgerConnector, + GetBlockV1Request, +} from "../../../../../main/typescript/public-api"; +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +import { BesuTestLedger } from "@hyperledger/cactus-test-tooling"; +import { LogLevelDesc } from "@hyperledger/cactus-common"; +import HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json"; +import Web3 from "web3"; +import { PluginImportType } from "@hyperledger/cactus-core-api"; + +test("can get block from blockchain", async (t: Test) => { + const logLevel: LogLevelDesc = "TRACE"; + const besuTestLedger = new BesuTestLedger(); + await besuTestLedger.start(); + + test.onFinish(async () => { + await besuTestLedger.stop(); + await besuTestLedger.destroy(); + }); + + const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost(); + const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost(); + const web3 = new Web3(rpcApiHttpHost); + const testEthAccount = web3.eth.accounts.create(uuidv4()); + + const keychainEntryKey = uuidv4(); + const keychainEntryValue = testEthAccount.privateKey; + const keychainPlugin = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + // pre-provision keychain with mock backend holding the private key of the + // test account that we'll reference while sending requests with the + // signing credential pointing to this keychain entry. + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + keychainPlugin.set( + HelloWorldContractJson.contractName, + HelloWorldContractJson, + ); + const factory = new PluginFactoryLedgerConnector({ + pluginImportType: PluginImportType.Local, + }); + const connector: PluginLedgerConnectorBesu = await factory.create({ + rpcApiHttpHost, + rpcApiWsHost, + instanceId: uuidv4(), + pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }), + }); + + const request: GetBlockV1Request = { blockHashOrBlockNumber: 0 }; + const currentBlock = await connector.getBlock(request.blockHashOrBlockNumber); + t.comment(JSON.stringify(currentBlock)); + //makes the information in to string + t.ok(currentBlock, " Block response is OK :-)"); + t.equal(typeof currentBlock, "object", "Block response type is OK :-)"); + t.end(); +}); diff --git a/packages/cactus-test-plugin-ledger-connector-besu/package-lock.json b/packages/cactus-test-plugin-ledger-connector-besu/package-lock.json index e5cfeaf700..300dd28425 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/package-lock.json +++ b/packages/cactus-test-plugin-ledger-connector-besu/package-lock.json @@ -505,6 +505,26 @@ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==" }, + "node_modules/body-parser": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", + "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", + "dependencies": { + "bytes": "3.1.0", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.2", + "http-errors": "1.7.2", + "iconv-lite": "0.4.24", + "on-finished": "~2.3.0", + "qs": "6.7.0", + "raw-body": "2.4.0", + "type-is": "~1.6.17" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/brorand": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", @@ -1422,6 +1442,46 @@ "safe-buffer": "^5.1.1" } }, + "node_modules/express": { + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", + "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", + "dependencies": { + "accepts": "~1.3.7", + "array-flatten": "1.1.1", + "body-parser": "1.19.0", + "content-disposition": "0.5.3", + "content-type": "~1.0.4", + "cookie": "0.4.0", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.1.2", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.5", + "qs": "6.7.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.1.2", + "send": "0.17.1", + "serve-static": "1.14.1", + "setprototypeof": "1.1.1", + "statuses": "~1.5.0", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + } + }, "node_modules/ext": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", @@ -2712,66 +2772,6 @@ "node": ">=6" } }, - "node_modules/servify/node_modules/body-parser": { - "version": "1.19.0", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", - "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", - "dependencies": { - "bytes": "3.1.0", - "content-type": "~1.0.4", - "debug": "2.6.9", - "depd": "~1.1.2", - "http-errors": "1.7.2", - "iconv-lite": "0.4.24", - "on-finished": "~2.3.0", - "qs": "6.7.0", - "raw-body": "2.4.0", - "type-is": "~1.6.17" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/servify/node_modules/express": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", - "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", - "dependencies": { - "accepts": "~1.3.7", - "array-flatten": "1.1.1", - "body-parser": "1.19.0", - "content-disposition": "0.5.3", - "content-type": "~1.0.4", - "cookie": "0.4.0", - "cookie-signature": "1.0.6", - "debug": "2.6.9", - "depd": "~1.1.2", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "~1.1.2", - "fresh": "0.5.2", - "merge-descriptors": "1.0.1", - "methods": "~1.1.2", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", - "path-to-regexp": "0.1.7", - "proxy-addr": "~2.0.5", - "qs": "6.7.0", - "range-parser": "~1.2.1", - "safe-buffer": "5.1.2", - "send": "0.17.1", - "serve-static": "1.14.1", - "setprototypeof": "1.1.1", - "statuses": "~1.5.0", - "type-is": "~1.6.18", - "utils-merge": "1.0.1", - "vary": "~1.1.2" - }, - "engines": { - "node": ">= 0.10.0" - } - }, "node_modules/setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", @@ -4706,6 +4706,23 @@ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==" }, + "body-parser": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", + "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", + "requires": { + "bytes": "3.1.0", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.2", + "http-errors": "1.7.2", + "iconv-lite": "0.4.24", + "on-finished": "~2.3.0", + "qs": "6.7.0", + "raw-body": "2.4.0", + "type-is": "~1.6.17" + } + }, "brorand": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", @@ -5539,6 +5556,43 @@ "safe-buffer": "^5.1.1" } }, + "express": { + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", + "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", + "requires": { + "accepts": "~1.3.7", + "array-flatten": "1.1.1", + "body-parser": "1.19.0", + "content-disposition": "0.5.3", + "content-type": "~1.0.4", + "cookie": "0.4.0", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.1.2", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.5", + "qs": "6.7.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.1.2", + "send": "0.17.1", + "serve-static": "1.14.1", + "setprototypeof": "1.1.1", + "statuses": "~1.5.0", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + } + }, "ext": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", @@ -6612,62 +6666,6 @@ "express": "^4.14.0", "request": "^2.79.0", "xhr": "^2.3.3" - }, - "dependencies": { - "body-parser": { - "version": "1.19.0", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", - "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", - "requires": { - "bytes": "3.1.0", - "content-type": "~1.0.4", - "debug": "2.6.9", - "depd": "~1.1.2", - "http-errors": "1.7.2", - "iconv-lite": "0.4.24", - "on-finished": "~2.3.0", - "qs": "6.7.0", - "raw-body": "2.4.0", - "type-is": "~1.6.17" - } - }, - "express": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", - "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", - "requires": { - "accepts": "~1.3.7", - "array-flatten": "1.1.1", - "body-parser": "1.19.0", - "content-disposition": "0.5.3", - "content-type": "~1.0.4", - "cookie": "0.4.0", - "cookie-signature": "1.0.6", - "debug": "2.6.9", - "depd": "~1.1.2", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "~1.1.2", - "fresh": "0.5.2", - "merge-descriptors": "1.0.1", - "methods": "~1.1.2", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", - "path-to-regexp": "0.1.7", - "proxy-addr": "~2.0.5", - "qs": "6.7.0", - "range-parser": "~1.2.1", - "safe-buffer": "5.1.2", - "send": "0.17.1", - "serve-static": "1.14.1", - "setprototypeof": "1.1.1", - "statuses": "~1.5.0", - "type-is": "~1.6.18", - "utils-merge": "1.0.1", - "vary": "~1.1.2" - } - } } }, "setimmediate": { diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts new file mode 100644 index 0000000000..7ba80ad2a0 --- /dev/null +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts @@ -0,0 +1,147 @@ +import test, { Test } from "tape-promise/tape"; + +import { v4 as uuidv4 } from "uuid"; +import { createServer } from "http"; +import KeyEncoder from "key-encoder"; +import { AddressInfo } from "net"; + +import { + ApiServer, + AuthorizationProtocol, + ConfigService, +} from "@hyperledger/cactus-cmd-api-server"; +import { + Secp256k1Keys, + KeyFormat, + LogLevelDesc, +} from "@hyperledger/cactus-common"; + +import { + BesuTestLedger, + pruneDockerAllIfGithubAction, +} from "@hyperledger/cactus-test-tooling"; + +import { + BesuApiClientOptions, + BesuApiClient, + IPluginLedgerConnectorBesuOptions, + PluginLedgerConnectorBesu, + GetBlockV1Request, +} from "@hyperledger/cactus-plugin-ledger-connector-besu"; + +import { PluginRegistry } from "@hyperledger/cactus-core"; + +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; + +const testCase = "Test sign transaction endpoint"; +const logLevel: LogLevelDesc = "TRACE"; + +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didn't throw OK"); + t.end(); +}); + +test(testCase, async (t: Test) => { + const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); + const keychainId = uuidv4(); + const keychainRef = uuidv4(); + + const { privateKey } = Secp256k1Keys.generateKeyPairsBuffer(); + const keyHex = privateKey.toString("hex"); + const pem = keyEncoder.encodePrivate(keyHex, KeyFormat.Raw, KeyFormat.PEM); + + const keychain = new PluginKeychainMemory({ + backend: new Map([[keychainRef, pem]]), + keychainId, + logLevel, + instanceId: uuidv4(), + }); + + const httpServer1 = createServer(); + await new Promise((resolve, reject) => { + httpServer1.once("error", reject); + httpServer1.once("listening", resolve); + httpServer1.listen(0, "127.0.0.1"); + }); + const addressInfo1 = httpServer1.address() as AddressInfo; + t.comment(`HttpServer1 AddressInfo: ${JSON.stringify(addressInfo1)}`); + const node1Host = `http://${addressInfo1.address}:${addressInfo1.port}`; + t.comment(`Cactus Node 1 Host: ${node1Host}`); + + const besuTestLedger = new BesuTestLedger(); + await besuTestLedger.start(); + + const tearDown = async () => { + await besuTestLedger.stop(); + await besuTestLedger.destroy(); + }; + + test.onFinish(tearDown); + + const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost(); + const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost(); + + // 2. Instantiate plugin registry which will provide the web service plugin with the key value storage plugin + const pluginRegistry = new PluginRegistry({ plugins: [keychain] }); + + // 3. Instantiate the web service consortium plugin + const options: IPluginLedgerConnectorBesuOptions = { + instanceId: uuidv4(), + rpcApiHttpHost, + rpcApiWsHost, + pluginRegistry, + logLevel, + }; + const pluginValidatorBesu = new PluginLedgerConnectorBesu(options); + + // 4. Create the API Server object that we embed in this test + const configService = new ConfigService(); + const apiServerOptions = configService.newExampleConfig(); + apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE; + apiServerOptions.configFile = ""; + apiServerOptions.apiCorsDomainCsv = "*"; + apiServerOptions.apiPort = addressInfo1.port; + apiServerOptions.cockpitPort = 0; + apiServerOptions.apiTlsEnabled = false; + const config = configService.newExampleConfigConvict(apiServerOptions); + + pluginRegistry.add(pluginValidatorBesu); + + const apiServer = new ApiServer({ + httpServerApi: httpServer1, + config: config.getProperties(), + pluginRegistry, + }); + + // 5. make sure the API server is shut down when the testing if finished. + test.onFinish(() => apiServer.shutdown()); + + // 6. Start the API server which is now listening on port A and it's healthcheck works through the main SDK + await apiServer.start(); + + // 7. Instantiate the main SDK dynamically with whatever port the API server ended up bound to (port 0) + t.comment(`AddressInfo: ${JSON.stringify(addressInfo1)}`); + + const request: GetBlockV1Request = { + blockHashOrBlockNumber: 0, + }; + + const configuration = new BesuApiClientOptions({ basePath: node1Host }); + const api = new BesuApiClient(configuration); + + // Test for 200 valid response test case + const res = await api.getBlockV1(request); + + const { status, data } = res; + t.true(status >= 200, "status GTE 200 OK"); + t.true(status < 300, "status LT 300 OK"); + t.ok(data, "GetBlockResponse Truthy OK"); + t.true(typeof data.block === "object", "Response data is OK"); +}); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didn't throw OK"); + t.end(); +});