From 2b2dfe2a03cee590b8b25a2637c0fa0f54ae32ee Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Fri, 4 Dec 2020 10:38:51 -0800 Subject: [PATCH] feat(core-api): getConsensusAlgorithmFamily() on connector API The method is called getConsensusAlgorithmFamily() because we don't need (for now) the level of granularity that is provided by having a method that points to the exact algorithm used by the ledger (can be added later). Why? Because for now we are mostly interested in whether an algorithm family guarantees transaction finality or not and this can be determined just from the family since for example it does not make much of a difference if you are talking about Bitcon's or Ethereum 1's proof of work, they both just do not guarantee transaction finality the same way for all our intents and purposes at present. The added benefit of only dealing in families instead of specific algorithms is that we can hardcode the answers instead of having to query the ledger or rely on operators to provide this information via configuration (again, we'll probably end up needing this in the future anyway, but for the upcoming work the families should be enough). Fixes #355 Signed-off-by: Peter Somogyvari --- .../plugin/ledger-connector/i-plugin-ledger-connector.ts | 9 +++++++++ .../src/main/typescript/plugin-ledger-connector-besu.ts | 7 +++++++ .../main/typescript/plugin-ledger-connector-fabric.ts | 7 +++++++ .../main/typescript/plugin-ledger-connector-quorum.ts | 7 +++++++ 4 files changed, 30 insertions(+) diff --git a/packages/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector.ts b/packages/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector.ts index 30ed1a154b8..f700d1b8039 100644 --- a/packages/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector.ts +++ b/packages/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector.ts @@ -1,4 +1,5 @@ import { ICactusPlugin } from "../i-cactus-plugin"; +import { ConsensusAlgorithmFamily } from "../../generated/openapi/typescript-axios/api"; /** * Common interface to be implemented by plugins which are implementing the connection to ledgers. @@ -21,4 +22,12 @@ export interface IPluginLedgerConnector< * type of ledger this connectir is targeted at. */ transact(options?: TransactIn): Promise; + + /** + * Returns the family of algorithms in which the consensus algorithm used + * by the ledger (this connector is associated with) belongs in. + * + * @see {ConsensusAlgorithmFamily} + */ + getConsensusAlgorithmFamily(): Promise; } 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 9a58255d6f2..f39b90e9a44 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 @@ -10,6 +10,7 @@ import { ContractSendMethod } from "web3-eth-contract"; import { TransactionReceipt } from "web3-eth"; import { + ConsensusAlgorithmFamily, IPluginLedgerConnector, IWebServiceEndpoint, IPluginWebService, @@ -169,6 +170,12 @@ export class PluginLedgerConnectorBesu return PluginAspect.LEDGER_CONNECTOR; } + public async getConsensusAlgorithmFamily(): Promise< + ConsensusAlgorithmFamily + > { + return ConsensusAlgorithmFamily.AUTHORITY; + } + public async invokeContract( req: InvokeContractV1Request ): Promise { diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts index 4b99a88359c..bd8f43025ad 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts @@ -16,6 +16,7 @@ import { import { Optional } from "typescript-optional"; import { + ConsensusAlgorithmFamily, IPluginLedgerConnector, PluginAspect, IPluginWebService, @@ -116,6 +117,12 @@ export class PluginLedgerConnectorFabric return Optional.empty(); } + public async getConsensusAlgorithmFamily(): Promise< + ConsensusAlgorithmFamily + > { + return ConsensusAlgorithmFamily.AUTHORITY; + } + /** * FIXME: Implement this feature of the connector. * 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 8dea6031185..f36dba8b210 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 @@ -10,6 +10,7 @@ import { ContractSendMethod } from "web3-eth-contract"; import { TransactionReceipt } from "web3-eth"; import { + ConsensusAlgorithmFamily, IPluginLedgerConnector, IWebServiceEndpoint, IPluginWebService, @@ -152,6 +153,12 @@ export class PluginLedgerConnectorQuorum return PluginAspect.LEDGER_CONNECTOR; } + public async getConsensusAlgorithmFamily(): Promise< + ConsensusAlgorithmFamily + > { + return ConsensusAlgorithmFamily.AUTHORITY; + } + public async invokeContract( req: InvokeContractV1Request ): Promise {