Skip to content

Commit

Permalink
feat(quorum-connector): implement validator interface on go-quorum-co…
Browse files Browse the repository at this point in the history
…nnector

Add three new endpoints to quorum ledger connector achieve legacy
verifier compatibility. InvokeRawWeb3EthContractEndpoint can be used to
form any call to deployed contract. InvokeRawWeb3EthMethodEndpoint can
be used to call any web3.eth function. Both are marked as low-level
functions, should be used only when there's no designated endpoint for
given functionality yet. WatchBlocksV1Endpoint can be used to monitor
new block headers / data from the ledger. Type of the output is
determined from input option flag. Extend QuorumApiClient to support
Verifier interface, that is: block monitoring, and sending sync/async
requests. Sending requests is marked as deprecated, because user can use
direct REST calls from generated ApiClient, nevertheless this API was
requested by one of the teams. Added functional tests for two new,
request based endpoints. Moved verifier-besu integration test to
besu-test package. Added verifier-quorum integration test, it
supplements direct endpoint tests and provides a reference for API
usage. Added support for QuorumApiClient in Verifier.

Closes: hyperledger-cacti#1604
Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com>
  • Loading branch information
outSH committed Apr 7, 2022
1 parent fd10e27 commit d9ac942
Show file tree
Hide file tree
Showing 31 changed files with 3,002 additions and 69 deletions.
2 changes: 1 addition & 1 deletion packages/cactus-plugin-ledger-connector-quorum/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cactus-api-server:latest
FROM ghcr.io/hyperledger/cactus-cmd-api-server:v1.0.0

ARG NPM_PKG_VERSION=latest

Expand Down
84 changes: 69 additions & 15 deletions packages/cactus-plugin-ledger-connector-quorum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ your local machine for development and testing purposes.

In the root of the project to install the dependencies execute the command:
```sh
npm run comfigure
```

### Compiling

In the projects root folder, run this command to compile the plugin and create the dist directory:
```sh
npm run tsc
npm run configure
```

## Usage
Expand All @@ -47,12 +40,16 @@ To use this import public-api and create new **PluginLedgerConnectorQuorum**.
You can make calls through the connector to the plugin API:

```typescript
async invokeContract(req: InvokeContractV1Request):Promise<InvokeContractV1Response>;
async invokeContract(req: InvokeContractJsonObjectV1Request):Promise<InvokeContractV1Response>;
async transact(req: RunTransactionRequest): Promise<RunTransactionResponse>;
async transactSigned(rawTransaction: string): Promise<RunTransactionResponse>;
async transactGethKeychain(txIn: RunTransactionRequest): Promise<RunTransactionResponse>;
async transactPrivateKey(req: RunTransactionRequest): Promise<RunTransactionResponse>;
async transactCactusKeychainRef(req: RunTransactionRequest):Promise<RunTransactionResponse>;
async deployContract(req: DeployContractSolidityBytecodeV1Request):Promise<RunTransactionResponse>;
async signTransaction(req: SignTransactionRequest):Promise<Optional<SignTransactionResponse>>;
async deployContract(req: DeployContractSolidityBytecodeV1Request :Promise<DeployContractSolidityBytecodeV1Response>;
async deployContractJsonObject(req: DeployContractSolidityBytecodeJsonObjectV1Request): Promise<DeployContractSolidityBytecodeV1Response>
async invokeRawWeb3EthMethod(req: InvokeRawWeb3EthMethodV1Request): Promise<any>;
async invokeRawWeb3EthContract(req: InvokeRawWeb3EthContractV1Request): Promise<any>;
```
Call example to deploy a contract:
Expand All @@ -78,6 +75,59 @@ enum Web3SigningCredentialType {
```
> Extensive documentation and examples in the [readthedocs](https://readthedocs.org/projects/hyperledger-cactus/) (WIP)
## QuorumApiClient
All connector API endpoints are defined in [open-api specification](./src/main/json/openapi.json). You can use [QuorumApiClient](./src/main/typescript/api-client) to call remote quorum connector functions. It also contain additional utility functions to ease integration.
### REST Functions
See [DefaultApi](./src/main/typescript/generated/openapi/typescript-axios/api.ts) for up-to-date listing of supported endpoints.
- deployContractSolBytecodeJsonObjectV1
- deployContractSolBytecodeV1
- getPrometheusMetricsV1
- invokeContractV1
- invokeContractV1NoKeychain
- invokeRawWeb3EthContractV1
- invokeRawWeb3EthMethodV1
- runTransactionV1
### Asynchronous Functions (socket.io)
- watchBlocksV1
### Send Request Methods
Both methods are deprecated, async version returns immediately while sync respond with Promise of a call results.
- `sendAsyncRequest`
- `sendSyncRequest`
#### Supported Requests
- `web3Eth`: Calls `invokeRawWeb3EthMethodV1`
- `web3EthContract`: Calls `invokeRawWeb3EthContractV1`
#### Arguments
- The same for both async and sync methods.
- Arguments interpretation depends on `method.type` (i.e. request type)
``` typescript
// Contract definition for web3EthContract request, ignored otherwise
contract: {
abi?: AbiItem[],
address?: string
},

// Request definition
method: {
type: "web3Eth" | "web3EthContract",
command: string // web3 method
function?: string; // contract function
params?: any[]; // contract parameters
}

// web3 method arguments
args: {
{
args?: any[] | Record<string, unknown>;
}
},
```
## Running the tests
To check that all has been installed correctly and that the pugin has no errors, there are two options to run the tests:
Expand Down Expand Up @@ -108,6 +158,8 @@ docker run \
--rm \
--publish 3000:3000 \
--publish 4000:4000 \
--env AUTHORIZATION_PROTOCOL='NONE' \
--env AUTHORIZATION_CONFIG_JSON='{}' \
--env PLUGINS='[{"packageName": "@hyperledger/cactus-plugin-ledger-connector-quorum", "type": "org.hyperledger.cactus.plugin_import_type.LOCAL", "action": "org.hyperledger.cactus.plugin_import_action.INSTALL", "options": {"rpcApiHttpHost": "http://localhost:8545", "instanceId": "some-unique-quorum-connector-instance-id"}}]' \
cplcb
```
Expand All @@ -119,22 +171,24 @@ docker run \
--publish 3000:3000 \
--publish 4000:4000 \
cplcb \
./node_modules/.bin/cactusapi \
./node_modules/@hyperledger/cactus-cmd-api-server/dist/lib/main/typescript/cmd/cactus-api.js \
--authorization-protocol='NONE' \
--authorization-config-json='{}' \
--plugins='[{"packageName": "@hyperledger/cactus-plugin-ledger-connector-quorum", "type": "org.hyperledger.cactus.plugin_import_type.LOCAL", "action": "org.hyperledger.cactus.plugin_import_action.INSTALL", "options": {"rpcApiHttpHost": "http://localhost:8545", "instanceId": "some-unique-quorum-connector-instance-id"}}]'
```
Launch container with **configuration file** mounted from host machine:
```sh

echo '[{"packageName": "@hyperledger/cactus-plugin-ledger-connector-quorum", "type": "org.hyperledger.cactus.plugin_import_type.LOCAL", "action": "org.hyperledger.cactus.plugin_import_action.INSTALL", "options": {"rpcApiHttpHost": "http://localhost:8545", "instanceId": "some-unique-quorum-connector-instance-id"}}]' > cactus.json
echo '{"authorizationProtocol":"NONE","authorizationConfigJson":{},"plugins":[{"packageName":"@hyperledger/cactus-plugin-ledger-connector-quorum","type":"org.hyperledger.cactus.plugin_import_type.LOCAL","action":"org.hyperledger.cactus.plugin_import_action.INSTALL","options":{"rpcApiHttpHost":"http://localhost:8545","instanceId":"some-unique-quorum-connector-instance-id"}}]}' > cactus.json

docker run \
--rm \
--publish 3000:3000 \
--publish 4000:4000 \
--mount type=bind,source="$(pwd)"/cactus.json,target=/cactus.json \
cplcb \
./node_modules/.bin/cactusapi \
./node_modules/@hyperledger/cactus-cmd-api-server/dist/lib/main/typescript/cmd/cactus-api.js \
--config-file=/cactus.json
```
Expand Down Expand Up @@ -263,5 +317,5 @@ Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started.

This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file.

## Acknowledgments
## Acknowledgments
```
6 changes: 5 additions & 1 deletion packages/cactus-plugin-ledger-connector-quorum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@
"axios": "0.21.4",
"express": "4.17.1",
"prom-client": "13.2.0",
"rxjs": "7.3.0",
"sanitize-html": "2.7.0",
"typescript-optional": "2.0.1",
"web3": "1.5.2",
"web3-eth-contract": "1.5.2"
"web3-eth-contract": "1.5.2",
"run-time-error": "1.4.0"
},
"devDependencies": {
"@hyperledger/cactus-plugin-keychain-memory": "1.0.0",
"@hyperledger/cactus-test-tooling": "1.0.0",
"@types/express": "4.17.13",
"@types/sanitize-html": "2.6.2",
"web3-eth": "1.5.2"
},
"engines": {
Expand Down
Loading

0 comments on commit d9ac942

Please sign in to comment.