Skip to content

Commit

Permalink
feat(bungee-hermes): ability to use connectors without instanciating …
Browse files Browse the repository at this point in the history
…APIs

Signed-off-by: Carlos Amaro <[email protected]>

refactor(bungee): besu strategy error handling and input validation

Notice a few things:
1. The http-errors-enhanced-cjs library is being used to encode information
about whether an error is consdiered (by us) as a user error or a bug in our
code (e.g. it signals who do we think are at fault which is the important
question when handling errors.). If we think the input was valid an we should
hae succeeded with the function execution, then we throw an InternalServerError.
Otherwise if we think the input was not in the required format, we throw a
BadRequestError notifying the user (or developer who is calling our function)
that they need to fix their input that they provided us with.
2. The error handling code and the output validation code are flattened out
as much as possible so that it's easier to read and understand what the code
does in what scenario and as the execution progresses the possible bad situations
are slowly but surely eliminated and by the end we are confident that the output
was in the expected format and that we can return it as-is and we don't need to
have any type casting at all.
3. I also added the `pluginRegistry` parameter to the bungee plugin's options
because this is an object that the API server passes in to every plugin that
it instanties which is meant to facilitate the cross-plugin interaction, e.g.
you can use in each plugin the passed in pluginRegistry to look up other plugins
instances directly and invoke them without needing an API client object for doing
so (which also adds a huge overhead of network latency)
The relevant piece of code to be aware of to see why this is working is in the
API server class, as pasted below where you can see that the pluginRegistry gets
appended to all the plugin options regardless of which kind of plugin it is:
```typescript
  private async instantiatePlugin(
    pluginImport: PluginImport,
    registry: PluginRegistry,
  ): Promise<ICactusPlugin> {
    const fnTag = `${this.className}#instantiatePlugin`;
    const { logLevel } = this.options.config;
    const { packageName, options } = pluginImport;
    this.log.info(`Creating plugin from package: ${packageName}`, options);
    const pluginOptions = { ...options, logLevel, pluginRegistry: registry };
```

Signed-off-by: Peter Somogyvari <[email protected]>

refactor(bungee): besu, ethereum and fabric strategy error handling and input validation

Signed-off-by: Carlos Amaro <[email protected]>
  • Loading branch information
LordKubaya committed Jul 17, 2024
1 parent 5660c4e commit 0148801
Show file tree
Hide file tree
Showing 15 changed files with 1,694 additions and 963 deletions.
6 changes: 6 additions & 0 deletions packages/cactus-plugin-bungee-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"name": "André Augusto",
"email": "[email protected]",
"url": "https://github.com/AndreAugusto11"
},
{
"name": "Carlos Amaro",
"email": "[email protected]",
"url": "https://github.com/LordKubaya"
}
],
"main": "dist/lib/main/typescript/index.js",
Expand Down Expand Up @@ -64,6 +69,7 @@
"axios": "1.7.2",
"body-parser": "1.20.2",
"fs-extra": "11.2.0",
"http-errors-enhanced-cjs": "2.0.1",
"key-encoder": "2.0.3",
"merkletreejs": "0.3.11",
"typescript-optional": "2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { MergeViewsEndpointV1 } from "./web-services/merge-views-endpoint";
import { ProcessViewEndpointV1 } from "./web-services/process-view-endpoint";

import { PrivacyPolicies } from "./view-creation/privacy-policies";
import { PluginRegistry } from "@hyperledger/cactus-core";

export interface IKeyPair {
publicKey: Uint8Array;
Expand All @@ -56,6 +57,7 @@ export interface IKeyPair {

export interface IPluginBungeeHermesOptions extends ICactusPluginOptions {
instanceId: string;
readonly pluginRegistry: PluginRegistry;
keyPair?: IKeyPair;

logLevel?: LogLevelDesc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Logger } from "@hyperledger/cactus-common";
import { State } from "../view-creation/state";
import { IPluginLedgerConnector } from "@hyperledger/cactus-core-api/src/main/typescript/plugin/ledger-connector/i-plugin-ledger-connector";

export interface NetworkDetails {
connectorApiPath: string;
connectorApiPath?: string;
connector?: IPluginLedgerConnector<unknown, unknown, unknown, unknown>;
participant: string;
}
export interface ObtainLedgerStrategy {
Expand Down
Loading

0 comments on commit 0148801

Please sign in to comment.