diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index edcdfc825b..546dbb6807 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1730,6 +1730,31 @@ jobs: # restore-keys: | # ${{ runner.os }}-yarn- # - run: ./tools/ci.sh + cactus-plugin-bungee-hermes: + continue-on-error: false + env: + FULL_BUILD_DISABLED: true + JEST_TEST_RUNNER_DISABLED: false + JEST_TEST_PATTERN: packages/cactus-plugin-bungee-hermes/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts + TAPE_TEST_RUNNER_DISABLED: true + needs: build-dev + runs-on: ubuntu-22.04 + steps: + - name: Use Node.js ${{ env.NODEJS_VERSION }} + uses: actions/setup-node@v3.6.0 + with: + node-version: ${{ env.NODEJS_VERSION }} + - uses: actions/checkout@v3.5.2 + + - id: yarn-cache + name: Restore Yarn Cache + uses: actions/cache@v3.3.1 + with: + key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} + path: ./.yarn/ + restore-keys: | + ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} + - run: ./tools/ci.sh cactus-test-api-client: continue-on-error: false env: diff --git a/CODEOWNERS b/CODEOWNERS index eba468f56e..b561fc8bde 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,6 +1,7 @@ * @petermetz @takeutak @izuru0 @jagpreetsinghsasan @vramakrishna @sandeepnRES @outSH packages/cactus-plugin-satp-hermes @RafaelAPB +packages/cactus-plugin-bungee-hermes @RafaelAPB examples/cactus-example-cbdc-bridging @RafaelAPB examples/cactus-example-cbdc-bridging-backend @RafaelAPB examples/cactus-example-cbdc-bridging-frontend @RafaelAPB diff --git a/packages/cactus-plugin-bungee-hermes/CHANGELOG.md b/packages/cactus-plugin-bungee-hermes/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/cactus-plugin-bungee-hermes/README.md b/packages/cactus-plugin-bungee-hermes/README.md new file mode 100644 index 0000000000..e176174ae2 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/README.md @@ -0,0 +1,159 @@ +# `@hyperledger/cactus-plugin-bungee-hermes` + +The package provides `Hyperledger Cacti` a way to create blockchain snapshots and views for different distributed ledgers currently supported by Cacti. The implementation follows the paper [BUNGEE](https://dl.acm.org/doi/pdf/10.1145/3643689) (Blockchain UNifier view GEnErator). + +The plugin will allow, as suggested in the paper, "new applications built on top +of dependable blockchain interoperability, such as stakeholder-centric snapshots for audits, cross-chain analysis, blockchain +migration, and combined on-chain-off-chain analytics". + +## Summary + +- [`@hyperledger/cactus-plugin-bungee-hermes`](#hyperledgercactus-plugin-bungee-hermes) + - [Summary](#summary) + - [Getting Started](#getting-started) + - [Prerequisites](#prerequisites) + - [Architecture](#architecture) + - [BUNGEE - Hermes API](#bungee---hermes-api) + - [Running the tests](#running-the-tests) + - [Usage](#usage) + - [Contributing](#contributing) + - [License](#license) + + +## Getting Started + +Clone the git repository on your local machine. Follow these instructions that will get you a copy of the project up and running on +your local machine for development and testing purposes. + +### Prerequisites + +In the root of the project to install the dependencies execute the command: +```sh +npm run configure +``` + +Know how to use the following plugins of the project: + + - [cactus-plugin-ledger-connector-fabric](https://github.com/hyperledger/cactus/tree/main/packages/cactus-plugin-ledger-connector-fabric) + - [cactus-plugin-ledger-connector-besu](https://github.com/hyperledger/cactus/tree/main/packages/cactus-plugin-ledger-connector-besu) + + +## Architecture + +The plugin interacts with a cactus ledger connector, using strategies with custom logic for each different network. + +Note that, so far, only strategies for Fabric and Besu networks were implemented. Smart-contracts in Fabric and Besu must implement the interface provided in the files ITraceableContract.ts and ITraceableContract.sol, in the test directory + +The plugin stands _behind_ a cacti-ledger-connector, which is used to fetch information from the ledger to create the snapshot. +```typescript +....................................... +. Cacti Node . +. . +. . +. .......... ............. . ......... +. . . . Cacti . . . . +. . BUNGEE . ---------- . Connector . -----------. _DLT . +. . . ............. . . . +. .......... . ......... +. . +. . +. . +....................................... +``` +The plugin can then serve multiple purposes, and thus serve also other plugins or apps in more complex deployment architectures (where we link bungee to other components). + +### BUNGEE - Hermes API + +This plugin uses OpenAPI to generate the API paths. +Endpoints exposed: + + - CreateViewV1 + - GetPublicKey + - GetAvailableStrategies + + +## Running the tests + - **besu-test-basic.test.ts**: A test using strategy-besu and a besu connector, testing creating views for different timeframes and states. + - **fabric-test-basic.test.ts**: A test using strategy-fabric and a fabric connector, testing creating views for different timeframes and states. + - **besu-test-pruning.test.ts**: A test using strategy-besu and a besu connector, testing creating views for specific timeframes. + - **fabric-test-pruning.test.ts**: A test using strategy-fabric and a fabric connector, testing creating views for specific timeframes. + - **bungee-api-test.test.ts**: A more complex test, using both besu and fabric strategies, fabric and besu connectors, and calls to bungee-hermes API. Tests bungee's API and functionality with multiple strategies. + +Tests developed using JEST testing framework. + +## Usage +Lets imagine we want bungee-hermes to create views for a besu ledger. +Let us consider a besu ledger connector, exposing its API on URL: http://localhost:4000 + + +Then we instantiate the plugin as follows: +```typescript +const pluginBungeeHermesOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + logLevel, +}; +const bungee = new PluginBungeeHermes(pluginBungeeHermesOptions); +``` + +We add the desired strategies: + +```typescript +bungee.addStrategy('BESU_STRATEGY', new StrategyBesu("INFO")); +``` + +Save network details for our target ledger: + +```typescript +const besuNetworkDetails: BesuNetworkDetails = { + signingCredential: besuSigningCredential, + contractName: besuContractName, + connectorApiPath: 'http://localhost:4000', + keychainId: besuKeychainPlugin.getKeychainId(), + contractAddress: besuContractAddress, + participant: accountAddress, + }; +``` + +And we can request views, after exposing the api: +```typescript +const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + bungeeServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 3000, + server: bungeeServer, + }; +const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; +const { address, port } = addressInfo; + +await bungee.getOrCreateWebServices(); +await bungee.registerWebServices(expressApp); +const bungeePath = `http://${address}:${port}`; + +const config = new Configuration({ basePath: bungeePath }); +const bungeeApi = new BungeeApi(config); + +const viewBesu = await bungeeApi.createViewV1({ + strategyId: 'BESU_STRATEGY', + networkDetails: besuNetworkDetails, + tI: undefined, //default to 0 (UNIX timestamp seconds) + tF: undefined, //default to Number.MAX_SAFE_INTEGER.toString() (UNIX timestamp seconds) + stateIds: undefined, //default to capture all assets + viewID: undefined, //plugin generates the id, if not given + } as CreateViewRequest); +``` + +Note that each strategy can be used to query different ledgers (ledgers of the same type, but on different locations), and BUNGEE also supports adding multiple strategies to each bungee-hermes-plugin instance. +Each strategy implements the logic to query information from each different ledger (i.e. capture set of asset states), while bungee-hermes plugin handles the snapshot and view creation. + + + +## Contributing +We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do! + +Please review [CONTIRBUTING.md](https://github.com/hyperledger/cactus/blob/main/CONTRIBUTING.md "CONTIRBUTING.md") to get started. + +## License +This distribution is published under the Apache License Version 2.0 found in the [LICENSE ](https://github.com/hyperledger/cactus/blob/main/LICENSE "LICENSE ")file. \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/openapitools.json b/packages/cactus-plugin-bungee-hermes/openapitools.json new file mode 100644 index 0000000000..225ff1aaae --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/openapitools.json @@ -0,0 +1,7 @@ +{ + "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", + "spaces": 2, + "generator-cli": { + "version": "6.6.0" + } +} diff --git a/packages/cactus-plugin-bungee-hermes/package.json b/packages/cactus-plugin-bungee-hermes/package.json new file mode 100644 index 0000000000..6c069f2a36 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/package.json @@ -0,0 +1,111 @@ +{ + "name": "@hyperledger/cactus-plugin-bungee-hermes", + "version": "2.0.0-alpha.2", + "description": "Allows Cactus nodes to create DLT views using Cactus connectors", + "keywords": [ + "Hyperledger", + "Cactus", + "Integration", + "Blockchain", + "Distributed Ledger Technology", + "View" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/hyperledger/cacti.git" + }, + "license": "Apache-2.0", + "author": { + "name": "Hyperledger Cactus Contributors", + "email": "cactus@lists.hyperledger.org", + "url": "https://www.hyperledger.org/use/cacti" + }, + "contributors": [ + { + "name": "Eduardo Vasques", + "email": "eduardovasques10@tecnico.ulisboa.pt", + "url": "https://github.com/eduv09" + }, + { + "name": "Rafael Belchior", + "email": "rafael.belchior@tecnico.ulisboa.pt", + "url": "https://rafaelapb.github.io/" + }, + { + "name": "André Augusto", + "email": "andre.augusto@tecnico.ulisboa.pt", + "url": "https://github.com/AndreAugusto11" + } + ], + "main": "dist/lib/main/typescript/index.js", + "module": "dist/lib/main/typescript/index.js", + "types": "dist/lib/main/typescript/index.d.ts", + "files": [ + "dist/*" + ], + "scripts": { + "codegen": "run-p 'codegen:*'", + "codegen:openapi": "npm run generate-sdk", + "generate-sdk": "run-p 'generate-sdk:*'", + "generate-sdk:kotlin": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g kotlin -o ./src/main/kotlin/generated/openapi/kotlin-client/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore", + "generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore", + "pretsc": "npm run generate-sdk", + "tsc": "tsc --project ./tsconfig.json", + "watch": "npm-watch" + }, + "dependencies": { + "@hyperledger/cactus-cmd-api-server": "2.0.0-alpha.2", + "@hyperledger/cactus-common": "2.0.0-alpha.2", + "@hyperledger/cactus-core": "2.0.0-alpha.2", + "@hyperledger/cactus-core-api": "2.0.0-alpha.2", + "@hyperledger/cactus-plugin-keychain-memory": "2.0.0-alpha.2", + "@hyperledger/cactus-plugin-ledger-connector-besu": "2.0.0-alpha.2", + "@hyperledger/cactus-plugin-ledger-connector-fabric": "2.0.0-alpha.2", + "@hyperledger/cactus-plugin-object-store-ipfs": "2.0.0-alpha.2", + "@hyperledger/cactus-test-tooling": "2.0.0-alpha.2", + "axios": "1.6.0", + "body-parser": "1.20.2", + "fs-extra": "10.1.0", + "key-encoder": "2.0.3", + "typescript-optional": "2.0.1", + "uuid": "9.0.1", + "web3": "1.6.1", + "web3-core": "1.6.1" + }, + "devDependencies": { + "@types/body-parser": "1.19.4", + "@types/crypto-js": "4.0.1", + "@types/express": "4.17.19", + "@types/fs-extra": "11.0.3", + "@types/tape": "4.13.4", + "@types/uuid": "9.0.6", + "express": "4.18.2", + "fabric-network": "2.2.20", + "socket.io": "4.5.4" + }, + "engines": { + "node": ">=18", + "npm": ">=8" + }, + "publishConfig": { + "access": "public" + }, + "watch": { + "tsc": { + "patterns": [ + "src/", + "src/*/json/**/openapi*" + ], + "ignore": [ + "src/**/generated/*" + ], + "extensions": [ + "ts", + "json" + ], + "quiet": true, + "verbose": false, + "runOnChangeOnly": true + } + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/json/openapi.json b/packages/cactus-plugin-bungee-hermes/src/main/json/openapi.json new file mode 100644 index 0000000000..f4cf10bc34 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/json/openapi.json @@ -0,0 +1,221 @@ +{ + "openapi": "3.0.3", + "servers": [ + { + "url": "http://{host}:{port}/api/v1/@hyperledger/cactus-plugin-satp-hermes", + "description": "Development server", + "variables": { + "host": { + "default": "localhost" + }, + "port": { + "default": "3000" + } + } + } + ], + + "info": { + "title": "Hyperledger Cactus Plugin - BUNGEE-Hermes", + "description": "Can create blockchain views of different networks", + "version": "2.0.0-alpha.2", + "license": { + "name": "Apache-2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "components": { + "schemas": { + "CreateViewRequest":{ + "type":"object", + "description": "Request object for createViewV1 endpoint", + "required": ["strategyId", "networkDetails"], + "properties": { + "stateIds":{ + "type":"array", + "items":{ + "type": "string", + "example": "id-of-asset-1" + }, + "example": ["id-of-asset-1", "id-of-asset-2"] + }, + "tI":{ + "type":"string", + "example": "0" + }, + "tF": { + "type": "string", + "example": "999999999999" + }, + "viewID": { + "type": "string", + "example": "view-1" + + }, + "strategyId": { + "type": "string", + "example": "fabric-strategy", + "nullable": false + }, + "networkDetails": { + "type": "object", + "nullable": false, + "required": ["connectorApiPath", "participant"], + "properties": { + "connectorApiPath":{ + "type": "string", + "nullable": false, + "example": "http://localhost:3000" + }, + "participant": { + "type": "string", + "nullable": false, + "example": "participant-1" + } + }, + "example": {"connectorApiPath": "http://localhost:3000", "participant": "participant-1"} + } + }, + "example": {"strategyId": "fabric-strategy", "networkDetails":{"connectorApiPath": "http://localhost:3000", "participant": "participant-1"}} + }, + "CreateViewResponse":{ + "type":"object", + "description": "This is the response for a viewRequests", + "properties": { + "view":{ + "type":"string", + "example": "Object" + }, + "signature":{ + "type": "string", + "example": "signature of Object" + } + }, + "example": {"view": "Object", "signature":"signature of Object"} + }, + "GetPublicKeyResponse": { + "type": "object", + "description": "public key from bungee-hermes plugin instance", + "properties": { + "pubKey":{ + "type": "string", + "example": "----BEGIN CERTIFICATE----random content...." + } + } + }, + "AvailableStrategiesResponse":{ + "type": "array", + "description": "Array with available strategy ids", + "items":{ + "type": "string", + "example": "strategy-fabric" + } + } + } + }, + "paths": { + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/create-view": { + "get": { + "x-hyperledger-cacti": { + "http": { + "verbLowerCase": "get", + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/create-view" + } + }, + "operationId": "createViewV1", + "summary": "Creates a Blockchain View.", + "description": "", + "parameters": [], + "requestBody": { + "required": true, + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateViewRequest" + } + } + } + }, + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateViewResponse" + }, + "example": {"view": "Object", "signature":"signature of Object"} + } + } + }, + "404": { + "description": "Could not complete request." + } + } + } + }, + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-public-key": { + "get": { + "x-hyperledger-cacti": { + "http": { + "verbLowerCase": "get", + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-public-key" + } + }, + "operationId": "GetPublicKey", + "summary": "Queries plugin's public key", + "description": "", + "parameters": [], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetPublicKeyResponse" + }, + "example": {"pubKey": "----BEGIN CERTIFICATE----random content...."} + } + + } + }, + "404": { + "description": "Could not complete request." + } + } + } + }, + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-available-strategies": { + "get": { + "x-hyperledger-cacti": { + "http": { + "verbLowerCase": "get", + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-available-strategies" + } + }, + "operationId": "GetAvailableStrategies", + "summary": "Queries plugin's available strategies for ledger capture", + "description": "", + "parameters": [], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AvailableStrategiesResponse" + }, + "example": ["strategy-fabric"] + } + + } + }, + "404": { + "description": "Could not complete request." + } + } + } + } + } +} \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/FILES b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/FILES new file mode 100644 index 0000000000..6aaf4cd1ed --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/FILES @@ -0,0 +1,27 @@ +README.md +build.gradle +gradlew +gradlew.bat +settings.gradle +src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt +src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt +src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt +src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt +src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt +src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt +src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt +src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt +src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt +src/main/kotlin/org/openapitools/client/models/CreateViewRequest.kt +src/main/kotlin/org/openapitools/client/models/CreateViewRequestNetworkDetails.kt +src/main/kotlin/org/openapitools/client/models/CreateViewResponse.kt +src/main/kotlin/org/openapitools/client/models/GetPublicKeyResponse.kt diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/VERSION b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/VERSION new file mode 100644 index 0000000000..cd802a1ec4 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.6.0 \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/README.md b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/README.md new file mode 100644 index 0000000000..0330f07fe0 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/README.md @@ -0,0 +1,65 @@ +# org.openapitools.client - Kotlin client library for Hyperledger Cactus Plugin - BUNGEE-Hermes + +Can create blockchain views of different networks + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. + +- API version: 2.0.0-alpha.2 +- Package version: +- Build package: org.openapitools.codegen.languages.KotlinClientCodegen + +## Requires + +* Kotlin 1.7.21 +* Gradle 7.5 + +## Build + +First, create the gradle wrapper script: + +``` +gradle wrapper +``` + +Then, run: + +``` +./gradlew check assemble +``` + +This runs all tests and packages the library. + +## Features/Implementation Notes + +* Supports JSON inputs/outputs, File inputs, and Form inputs. +* Supports collection formats for query parameters: csv, tsv, ssv, pipes. +* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions. +* Implementation of ApiClient is intended to reduce method counts, specifically to benefit Android targets. + + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost:3000/api/v1/@hyperledger/cactus-plugin-satp-hermes* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**createViewV1**](docs/DefaultApi.md#createviewv1) | **GET** /api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/create-view | Creates a Blockchain View. +*DefaultApi* | [**getAvailableStrategies**](docs/DefaultApi.md#getavailablestrategies) | **GET** /api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-available-strategies | Queries plugin's available strategies for ledger capture +*DefaultApi* | [**getPublicKey**](docs/DefaultApi.md#getpublickey) | **GET** /api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-public-key | Queries plugin's public key + + + +## Documentation for Models + + - [org.openapitools.client.models.CreateViewRequest](docs/CreateViewRequest.md) + - [org.openapitools.client.models.CreateViewRequestNetworkDetails](docs/CreateViewRequestNetworkDetails.md) + - [org.openapitools.client.models.CreateViewResponse](docs/CreateViewResponse.md) + - [org.openapitools.client.models.GetPublicKeyResponse](docs/GetPublicKeyResponse.md) + + + +## Documentation for Authorization + +Endpoints do not require authorization. + diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/build.gradle b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/build.gradle new file mode 100644 index 0000000000..66a3c68b89 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/build.gradle @@ -0,0 +1,38 @@ +group 'org.openapitools' +version '1.0.0' + +wrapper { + gradleVersion = '7.5' + distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" +} + +buildscript { + ext.kotlin_version = '1.7.21' + + repositories { + maven { url "https://repo1.maven.org/maven2" } + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' +apply plugin: 'maven-publish' + +repositories { + maven { url "https://repo1.maven.org/maven2" } +} + +test { + useJUnitPlatform() +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + implementation "com.squareup.moshi:moshi-kotlin:1.13.0" + implementation "com.squareup.moshi:moshi-adapters:1.13.0" + implementation "com.squareup.okhttp3:okhttp:4.10.0" + testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/gradlew b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/gradlew new file mode 100644 index 0000000000..aeb74cbb43 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/gradlew @@ -0,0 +1,245 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/gradlew.bat b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/gradlew.bat new file mode 100644 index 0000000000..93e3f59f13 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/settings.gradle b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/settings.gradle new file mode 100644 index 0000000000..391dcea81d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/settings.gradle @@ -0,0 +1,2 @@ + +rootProject.name = 'kotlin-client' \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt new file mode 100644 index 0000000000..aa283d52da --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/apis/DefaultApi.kt @@ -0,0 +1,261 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.apis + +import java.io.IOException +import okhttp3.OkHttpClient +import okhttp3.HttpUrl + +import org.openapitools.client.models.CreateViewRequest +import org.openapitools.client.models.CreateViewResponse +import org.openapitools.client.models.GetPublicKeyResponse + +import com.squareup.moshi.Json + +import org.openapitools.client.infrastructure.ApiClient +import org.openapitools.client.infrastructure.ApiResponse +import org.openapitools.client.infrastructure.ClientException +import org.openapitools.client.infrastructure.ClientError +import org.openapitools.client.infrastructure.ServerException +import org.openapitools.client.infrastructure.ServerError +import org.openapitools.client.infrastructure.MultiValueMap +import org.openapitools.client.infrastructure.PartConfig +import org.openapitools.client.infrastructure.RequestConfig +import org.openapitools.client.infrastructure.RequestMethod +import org.openapitools.client.infrastructure.ResponseType +import org.openapitools.client.infrastructure.Success +import org.openapitools.client.infrastructure.toMultiValue + +class DefaultApi(basePath: kotlin.String = defaultBasePath, client: OkHttpClient = ApiClient.defaultClient) : ApiClient(basePath, client) { + companion object { + @JvmStatic + val defaultBasePath: String by lazy { + System.getProperties().getProperty(ApiClient.baseUrlKey, "http://localhost:3000/api/v1/@hyperledger/cactus-plugin-satp-hermes") + } + } + + /** + * Creates a Blockchain View. + * + * @param createViewRequest + * @return CreateViewResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) + fun createViewV1(createViewRequest: CreateViewRequest) : CreateViewResponse { + val localVarResponse = createViewV1WithHttpInfo(createViewRequest = createViewRequest) + + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as CreateViewResponse + ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") + ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + } + } + + /** + * Creates a Blockchain View. + * + * @param createViewRequest + * @return ApiResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class) + fun createViewV1WithHttpInfo(createViewRequest: CreateViewRequest) : ApiResponse { + val localVariableConfig = createViewV1RequestConfig(createViewRequest = createViewRequest) + + return request( + localVariableConfig + ) + } + + /** + * To obtain the request config of the operation createViewV1 + * + * @param createViewRequest + * @return RequestConfig + */ + fun createViewV1RequestConfig(createViewRequest: CreateViewRequest) : RequestConfig { + val localVariableBody = createViewRequest + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Content-Type"] = "application/json" + localVariableHeaders["Accept"] = "application/json" + + return RequestConfig( + method = RequestMethod.GET, + path = "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/create-view", + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + + /** + * Queries plugin's available strategies for ledger capture + * + * @return kotlin.collections.List + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) + fun getAvailableStrategies() : kotlin.collections.List { + val localVarResponse = getAvailableStrategiesWithHttpInfo() + + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.collections.List + ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") + ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + } + } + + /** + * Queries plugin's available strategies for ledger capture + * + * @return ApiResponse?> + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class) + fun getAvailableStrategiesWithHttpInfo() : ApiResponse?> { + val localVariableConfig = getAvailableStrategiesRequestConfig() + + return request>( + localVariableConfig + ) + } + + /** + * To obtain the request config of the operation getAvailableStrategies + * + * @return RequestConfig + */ + fun getAvailableStrategiesRequestConfig() : RequestConfig { + val localVariableBody = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Accept"] = "application/json" + + return RequestConfig( + method = RequestMethod.GET, + path = "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-available-strategies", + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + + /** + * Queries plugin's public key + * + * @return GetPublicKeyResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) + fun getPublicKey() : GetPublicKeyResponse { + val localVarResponse = getPublicKeyWithHttpInfo() + + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as GetPublicKeyResponse + ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") + ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + } + } + } + + /** + * Queries plugin's public key + * + * @return ApiResponse + * @throws IllegalStateException If the request is not correctly configured + * @throws IOException Rethrows the OkHttp execute method exception + */ + @Suppress("UNCHECKED_CAST") + @Throws(IllegalStateException::class, IOException::class) + fun getPublicKeyWithHttpInfo() : ApiResponse { + val localVariableConfig = getPublicKeyRequestConfig() + + return request( + localVariableConfig + ) + } + + /** + * To obtain the request config of the operation getPublicKey + * + * @return RequestConfig + */ + fun getPublicKeyRequestConfig() : RequestConfig { + val localVariableBody = null + val localVariableQuery: MultiValueMap = mutableMapOf() + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders["Accept"] = "application/json" + + return RequestConfig( + method = RequestMethod.GET, + path = "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-public-key", + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = false, + body = localVariableBody + ) + } + + + private fun encodeURIComponent(uriComponent: kotlin.String): kotlin.String = + HttpUrl.Builder().scheme("http").host("localhost").addPathSegment(uriComponent).build().encodedPathSegments[0] +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt new file mode 100644 index 0000000000..ef7a8f1e1a --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt @@ -0,0 +1,23 @@ +package org.openapitools.client.infrastructure + +typealias MultiValueMap = MutableMap> + +fun collectionDelimiter(collectionFormat: String) = when(collectionFormat) { + "csv" -> "," + "tsv" -> "\t" + "pipe" -> "|" + "space" -> " " + else -> "" +} + +val defaultMultiValueConverter: (item: Any?) -> String = { item -> "$item" } + +fun toMultiValue(items: Array, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter) + = toMultiValue(items.asIterable(), collectionFormat, map) + +fun toMultiValue(items: Iterable, collectionFormat: String, map: (item: T) -> String = defaultMultiValueConverter): List { + return when(collectionFormat) { + "multi" -> items.map(map) + else -> listOf(items.joinToString(separator = collectionDelimiter(collectionFormat), transform = map)) + } +} \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt new file mode 100644 index 0000000000..ea4b7b6593 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -0,0 +1,245 @@ +package org.openapitools.client.infrastructure + +import okhttp3.OkHttpClient +import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.asRequestBody +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.FormBody +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import okhttp3.ResponseBody +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.Request +import okhttp3.Headers +import okhttp3.Headers.Companion.toHeaders +import okhttp3.MultipartBody +import okhttp3.Call +import okhttp3.Callback +import okhttp3.Response +import okhttp3.internal.EMPTY_REQUEST +import java.io.BufferedWriter +import java.io.File +import java.io.FileWriter +import java.io.IOException +import java.net.URLConnection +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.OffsetDateTime +import java.time.OffsetTime +import java.util.Locale +import com.squareup.moshi.adapter + +open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClient) { + companion object { + protected const val ContentType = "Content-Type" + protected const val Accept = "Accept" + protected const val Authorization = "Authorization" + protected const val JsonMediaType = "application/json" + protected const val FormDataMediaType = "multipart/form-data" + protected const val FormUrlEncMediaType = "application/x-www-form-urlencoded" + protected const val XmlMediaType = "application/xml" + + val apiKey: MutableMap = mutableMapOf() + val apiKeyPrefix: MutableMap = mutableMapOf() + var username: String? = null + var password: String? = null + var accessToken: String? = null + const val baseUrlKey = "org.openapitools.client.baseUrl" + + @JvmStatic + val defaultClient: OkHttpClient by lazy { + builder.build() + } + + @JvmStatic + val builder: OkHttpClient.Builder = OkHttpClient.Builder() + } + + /** + * Guess Content-Type header from the given file (defaults to "application/octet-stream"). + * + * @param file The given file + * @return The guessed Content-Type + */ + protected fun guessContentTypeFromFile(file: File): String { + val contentType = URLConnection.guessContentTypeFromName(file.name) + return contentType ?: "application/octet-stream" + } + + protected inline fun requestBody(content: T, mediaType: String?): RequestBody = + when { + content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) + mediaType == FormDataMediaType -> + MultipartBody.Builder() + .setType(MultipartBody.FORM) + .apply { + // content's type *must* be Map> + @Suppress("UNCHECKED_CAST") + (content as Map>).forEach { (name, part) -> + if (part.body is File) { + val partHeaders = part.headers.toMutableMap() + + ("Content-Disposition" to "form-data; name=\"$name\"; filename=\"${part.body.name}\"") + val fileMediaType = guessContentTypeFromFile(part.body).toMediaTypeOrNull() + addPart( + partHeaders.toHeaders(), + part.body.asRequestBody(fileMediaType) + ) + } else { + val partHeaders = part.headers.toMutableMap() + + ("Content-Disposition" to "form-data; name=\"$name\"") + addPart( + partHeaders.toHeaders(), + parameterToString(part.body).toRequestBody(null) + ) + } + } + }.build() + mediaType == FormUrlEncMediaType -> { + FormBody.Builder().apply { + // content's type *must* be Map> + @Suppress("UNCHECKED_CAST") + (content as Map>).forEach { (name, part) -> + add(name, parameterToString(part.body)) + } + }.build() + } + mediaType == null || mediaType.startsWith("application/") && mediaType.endsWith("json") -> + if (content == null) { + EMPTY_REQUEST + } else { + Serializer.moshi.adapter(T::class.java).toJson(content) + .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) + } + mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") + // TODO: this should be extended with other serializers + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.") + } + + @OptIn(ExperimentalStdlibApi::class) + protected inline fun responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? { + if(body == null) { + return null + } + if (T::class.java == File::class.java) { + // return tempFile + // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options + val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() + tempFile.deleteOnExit() + body.byteStream().use { inputStream -> + tempFile.outputStream().use { tempFileOutputStream -> + inputStream.copyTo(tempFileOutputStream) + } + } + return tempFile as T + } + val bodyContent = body.string() + if (bodyContent.isEmpty()) { + return null + } + return when { + mediaType==null || (mediaType.startsWith("application/") && mediaType.endsWith("json")) -> + Serializer.moshi.adapter().fromJson(bodyContent) + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + } + } + + + protected inline fun request(requestConfig: RequestConfig): ApiResponse { + val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") + + val url = httpUrl.newBuilder() + .addEncodedPathSegments(requestConfig.path.trimStart('/')) + .apply { + requestConfig.query.forEach { query -> + query.value.forEach { queryValue -> + addQueryParameter(query.key, queryValue) + } + } + }.build() + + // take content-type/accept from spec or set to default (application/json) if not defined + if (requestConfig.body != null && requestConfig.headers[ContentType].isNullOrEmpty()) { + requestConfig.headers[ContentType] = JsonMediaType + } + if (requestConfig.headers[Accept].isNullOrEmpty()) { + requestConfig.headers[Accept] = JsonMediaType + } + val headers = requestConfig.headers + + if (headers[Accept].isNullOrEmpty()) { + throw kotlin.IllegalStateException("Missing Accept header. This is required.") + } + + val contentType = if (headers[ContentType] != null) { + // TODO: support multiple contentType options here. + (headers[ContentType] as String).substringBefore(";").lowercase(Locale.US) + } else { + null + } + + val request = when (requestConfig.method) { + RequestMethod.DELETE -> Request.Builder().url(url).delete(requestBody(requestConfig.body, contentType)) + RequestMethod.GET -> Request.Builder().url(url) + RequestMethod.HEAD -> Request.Builder().url(url).head() + RequestMethod.PATCH -> Request.Builder().url(url).patch(requestBody(requestConfig.body, contentType)) + RequestMethod.PUT -> Request.Builder().url(url).put(requestBody(requestConfig.body, contentType)) + RequestMethod.POST -> Request.Builder().url(url).post(requestBody(requestConfig.body, contentType)) + RequestMethod.OPTIONS -> Request.Builder().url(url).method("OPTIONS", null) + }.apply { + headers.forEach { header -> addHeader(header.key, header.value) } + }.build() + + val response = client.newCall(request).execute() + + val accept = response.header(ContentType)?.substringBefore(";")?.lowercase(Locale.US) + + // TODO: handle specific mapping types. e.g. Map> + return when { + response.isRedirect -> Redirection( + response.code, + response.headers.toMultimap() + ) + response.isInformational -> Informational( + response.message, + response.code, + response.headers.toMultimap() + ) + response.isSuccessful -> Success( + responseBody(response.body, accept), + response.code, + response.headers.toMultimap() + ) + response.isClientError -> ClientError( + response.message, + response.body?.string(), + response.code, + response.headers.toMultimap() + ) + else -> ServerError( + response.message, + response.body?.string(), + response.code, + response.headers.toMultimap() + ) + } + } + + protected fun parameterToString(value: Any?): String = when (value) { + null -> "" + is Array<*> -> toMultiValue(value, "csv").toString() + is Iterable<*> -> toMultiValue(value, "csv").toString() + is OffsetDateTime, is OffsetTime, is LocalDateTime, is LocalDate, is LocalTime -> + parseDateToQueryString(value) + else -> value.toString() + } + + protected inline fun parseDateToQueryString(value : T): String { + /* + .replace("\"", "") converts the json object string to an actual string for the query parameter. + The moshi or gson adapter allows a more generic solution instead of trying to use a native + formatter. It also easily allows to provide a simple way to define a custom date format pattern + inside a gson/moshi adapter. + */ + return Serializer.moshi.adapter(T::class.java).toJson(value).replace("\"", "") + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt new file mode 100644 index 0000000000..cf2cfaa95d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ApiResponse.kt @@ -0,0 +1,43 @@ +package org.openapitools.client.infrastructure + +enum class ResponseType { + Success, Informational, Redirection, ClientError, ServerError +} + +interface Response + +abstract class ApiResponse(val responseType: ResponseType): Response { + abstract val statusCode: Int + abstract val headers: Map> +} + +class Success( + val data: T, + override val statusCode: Int = -1, + override val headers: Map> = mapOf() +): ApiResponse(ResponseType.Success) + +class Informational( + val statusText: String, + override val statusCode: Int = -1, + override val headers: Map> = mapOf() +) : ApiResponse(ResponseType.Informational) + +class Redirection( + override val statusCode: Int = -1, + override val headers: Map> = mapOf() +) : ApiResponse(ResponseType.Redirection) + +class ClientError( + val message: String? = null, + val body: Any? = null, + override val statusCode: Int = -1, + override val headers: Map> = mapOf() +) : ApiResponse(ResponseType.ClientError) + +class ServerError( + val message: String? = null, + val body: Any? = null, + override val statusCode: Int = -1, + override val headers: Map> +): ApiResponse(ResponseType.ServerError) diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt new file mode 100644 index 0000000000..064b57fc6b --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt @@ -0,0 +1,17 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.math.BigDecimal + +class BigDecimalAdapter { + @ToJson + fun toJson(value: BigDecimal): String { + return value.toPlainString() + } + + @FromJson + fun fromJson(value: String): BigDecimal { + return BigDecimal(value) + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt new file mode 100644 index 0000000000..7df6057b45 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt @@ -0,0 +1,17 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.math.BigInteger + +class BigIntegerAdapter { + @ToJson + fun toJson(value: BigInteger): String { + return value.toString() + } + + @FromJson + fun fromJson(value: String): BigInteger { + return BigInteger(value) + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt new file mode 100644 index 0000000000..ff5e2a81ee --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt @@ -0,0 +1,12 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson + +class ByteArrayAdapter { + @ToJson + fun toJson(data: ByteArray): String = String(data) + + @FromJson + fun fromJson(data: String): ByteArray = data.toByteArray() +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt new file mode 100644 index 0000000000..b5310e71f1 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -0,0 +1,18 @@ +@file:Suppress("unused") +package org.openapitools.client.infrastructure + +import java.lang.RuntimeException + +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { + + companion object { + private const val serialVersionUID: Long = 123L + } +} + +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { + + companion object { + private const val serialVersionUID: Long = 456L + } +} \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt new file mode 100644 index 0000000000..b2e1654479 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt @@ -0,0 +1,19 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.time.LocalDate +import java.time.format.DateTimeFormatter + +class LocalDateAdapter { + @ToJson + fun toJson(value: LocalDate): String { + return DateTimeFormatter.ISO_LOCAL_DATE.format(value) + } + + @FromJson + fun fromJson(value: String): LocalDate { + return LocalDate.parse(value, DateTimeFormatter.ISO_LOCAL_DATE) + } + +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt new file mode 100644 index 0000000000..e082db9481 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt @@ -0,0 +1,19 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter + +class LocalDateTimeAdapter { + @ToJson + fun toJson(value: LocalDateTime): String { + return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value) + } + + @FromJson + fun fromJson(value: String): LocalDateTime { + return LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME) + } + +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt new file mode 100644 index 0000000000..87437871a3 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt @@ -0,0 +1,19 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter + +class OffsetDateTimeAdapter { + @ToJson + fun toJson(value: OffsetDateTime): String { + return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value) + } + + @FromJson + fun fromJson(value: String): OffsetDateTime { + return OffsetDateTime.parse(value, DateTimeFormatter.ISO_OFFSET_DATE_TIME) + } + +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt new file mode 100644 index 0000000000..be00e38fba --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/PartConfig.kt @@ -0,0 +1,11 @@ +package org.openapitools.client.infrastructure + +/** + * Defines a config object for a given part of a multi-part request. + * NOTE: Headers is a Map because rfc2616 defines + * multi-valued headers as csv-only. + */ +data class PartConfig( + val headers: MutableMap = mutableMapOf(), + val body: T? = null +) diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt new file mode 100644 index 0000000000..625a19002b --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/RequestConfig.kt @@ -0,0 +1,18 @@ +package org.openapitools.client.infrastructure + +/** + * Defines a config object for a given request. + * NOTE: This object doesn't include 'body' because it + * allows for caching of the constructed object + * for many request definitions. + * NOTE: Headers is a Map because rfc2616 defines + * multi-valued headers as csv-only. + */ +data class RequestConfig( + val method: RequestMethod, + val path: String, + val headers: MutableMap = mutableMapOf(), + val query: MutableMap> = mutableMapOf(), + val requiresAuthentication: Boolean, + val body: T? = null +) \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt new file mode 100644 index 0000000000..931b12b8bd --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/RequestMethod.kt @@ -0,0 +1,8 @@ +package org.openapitools.client.infrastructure + +/** + * Provides enumerated HTTP verbs + */ +enum class RequestMethod { + GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT +} \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt new file mode 100644 index 0000000000..9bd2790dc1 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/ResponseExtensions.kt @@ -0,0 +1,24 @@ +package org.openapitools.client.infrastructure + +import okhttp3.Response + +/** + * Provides an extension to evaluation whether the response is a 1xx code + */ +val Response.isInformational : Boolean get() = this.code in 100..199 + +/** + * Provides an extension to evaluation whether the response is a 3xx code + */ +@Suppress("EXTENSION_SHADOWED_BY_MEMBER") +val Response.isRedirect : Boolean get() = this.code in 300..399 + +/** + * Provides an extension to evaluation whether the response is a 4xx code + */ +val Response.isClientError : Boolean get() = this.code in 400..499 + +/** + * Provides an extension to evaluation whether the response is a 5xx (Standard) through 999 (non-standard) code + */ +val Response.isServerError : Boolean get() = this.code in 500..999 diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt new file mode 100644 index 0000000000..e22592e47d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -0,0 +1,23 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory + +object Serializer { + @JvmStatic + val moshiBuilder: Moshi.Builder = Moshi.Builder() + .add(OffsetDateTimeAdapter()) + .add(LocalDateTimeAdapter()) + .add(LocalDateAdapter()) + .add(UUIDAdapter()) + .add(ByteArrayAdapter()) + .add(URIAdapter()) + .add(KotlinJsonAdapterFactory()) + .add(BigDecimalAdapter()) + .add(BigIntegerAdapter()) + + @JvmStatic + val moshi: Moshi by lazy { + moshiBuilder.build() + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt new file mode 100644 index 0000000000..927522757d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt @@ -0,0 +1,13 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.net.URI + +class URIAdapter { + @ToJson + fun toJson(uri: URI) = uri.toString() + + @FromJson + fun fromJson(s: String): URI = URI.create(s) +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt new file mode 100644 index 0000000000..7ccf7dc25d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt @@ -0,0 +1,13 @@ +package org.openapitools.client.infrastructure + +import com.squareup.moshi.FromJson +import com.squareup.moshi.ToJson +import java.util.UUID + +class UUIDAdapter { + @ToJson + fun toJson(uuid: UUID) = uuid.toString() + + @FromJson + fun fromJson(s: String): UUID = UUID.fromString(s) +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewRequest.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewRequest.kt new file mode 100644 index 0000000000..74f718ad22 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewRequest.kt @@ -0,0 +1,56 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + +import org.openapitools.client.models.CreateViewRequestNetworkDetails + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * Request object for createViewV1 endpoint + * + * @param strategyId + * @param networkDetails + * @param stateIds + * @param tI + * @param tF + * @param viewID + */ + + +data class CreateViewRequest ( + + @Json(name = "strategyId") + val strategyId: kotlin.String, + + @Json(name = "networkDetails") + val networkDetails: CreateViewRequestNetworkDetails, + + @Json(name = "stateIds") + val stateIds: kotlin.collections.List? = null, + + @Json(name = "tI") + val tI: kotlin.String? = null, + + @Json(name = "tF") + val tF: kotlin.String? = null, + + @Json(name = "viewID") + val viewID: kotlin.String? = null + +) + diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewRequestNetworkDetails.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewRequestNetworkDetails.kt new file mode 100644 index 0000000000..748c488a5a --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewRequestNetworkDetails.kt @@ -0,0 +1,39 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * + * + * @param connectorApiPath + * @param participant + */ + + +data class CreateViewRequestNetworkDetails ( + + @Json(name = "connectorApiPath") + val connectorApiPath: kotlin.String, + + @Json(name = "participant") + val participant: kotlin.String + +) + diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewResponse.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewResponse.kt new file mode 100644 index 0000000000..fd3bca7f79 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/CreateViewResponse.kt @@ -0,0 +1,39 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * This is the response for a viewRequests + * + * @param view + * @param signature + */ + + +data class CreateViewResponse ( + + @Json(name = "view") + val view: kotlin.String? = null, + + @Json(name = "signature") + val signature: kotlin.String? = null + +) + diff --git a/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetPublicKeyResponse.kt b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetPublicKeyResponse.kt new file mode 100644 index 0000000000..7131884f72 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetPublicKeyResponse.kt @@ -0,0 +1,35 @@ +/** + * + * Please note: + * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit this file manually. + * + */ + +@file:Suppress( + "ArrayInDataClass", + "EnumEntryName", + "RemoveRedundantQualifierName", + "UnusedImport" +) + +package org.openapitools.client.models + + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * public key from bungee-hermes plugin instance + * + * @param pubKey + */ + + +data class GetPublicKeyResponse ( + + @Json(name = "pubKey") + val pubKey: kotlin.String? = null + +) + diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/FILES b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/FILES new file mode 100644 index 0000000000..53250c0269 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/FILES @@ -0,0 +1,5 @@ +api.ts +base.ts +common.ts +configuration.ts +index.ts diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/VERSION b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/VERSION new file mode 100644 index 0000000000..cd802a1ec4 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.6.0 \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/api.ts new file mode 100644 index 0000000000..a1e5d31bc4 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -0,0 +1,347 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Hyperledger Cactus Plugin - BUNGEE-Hermes + * Can create blockchain views of different networks + * + * The version of the OpenAPI document: 2.0.0-alpha.2 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from './configuration'; +import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; +import globalAxios 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'; +import type { RequestArgs } from './base'; +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError } from './base'; + +/** + * Request object for createViewV1 endpoint + * @export + * @interface CreateViewRequest + */ +export interface CreateViewRequest { + /** + * + * @type {Array} + * @memberof CreateViewRequest + */ + 'stateIds'?: Array; + /** + * + * @type {string} + * @memberof CreateViewRequest + */ + 'tI'?: string; + /** + * + * @type {string} + * @memberof CreateViewRequest + */ + 'tF'?: string; + /** + * + * @type {string} + * @memberof CreateViewRequest + */ + 'viewID'?: string; + /** + * + * @type {string} + * @memberof CreateViewRequest + */ + 'strategyId': string; + /** + * + * @type {CreateViewRequestNetworkDetails} + * @memberof CreateViewRequest + */ + 'networkDetails': CreateViewRequestNetworkDetails; +} +/** + * + * @export + * @interface CreateViewRequestNetworkDetails + */ +export interface CreateViewRequestNetworkDetails { + /** + * + * @type {string} + * @memberof CreateViewRequestNetworkDetails + */ + 'connectorApiPath': string; + /** + * + * @type {string} + * @memberof CreateViewRequestNetworkDetails + */ + 'participant': string; +} +/** + * This is the response for a viewRequests + * @export + * @interface CreateViewResponse + */ +export interface CreateViewResponse { + /** + * + * @type {string} + * @memberof CreateViewResponse + */ + 'view'?: string; + /** + * + * @type {string} + * @memberof CreateViewResponse + */ + 'signature'?: string; +} +/** + * public key from bungee-hermes plugin instance + * @export + * @interface GetPublicKeyResponse + */ +export interface GetPublicKeyResponse { + /** + * + * @type {string} + * @memberof GetPublicKeyResponse + */ + 'pubKey'?: string; +} + +/** + * DefaultApi - axios parameter creator + * @export + */ +export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * + * @summary Creates a Blockchain View. + * @param {CreateViewRequest} createViewRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createViewV1: async (createViewRequest: CreateViewRequest, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'createViewRequest' is not null or undefined + assertParamExists('createViewV1', 'createViewRequest', createViewRequest) + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/create-view`; + // 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; + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(createViewRequest, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Queries plugin\'s available strategies for ledger capture + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getAvailableStrategies: async (options: AxiosRequestConfig = {}): Promise => { + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-available-strategies`; + // 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); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Queries plugin\'s public key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getPublicKey: async (options: AxiosRequestConfig = {}): Promise => { + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-public-key`; + // 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); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * DefaultApi - functional programming interface + * @export + */ +export const DefaultApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration) + return { + /** + * + * @summary Creates a Blockchain View. + * @param {CreateViewRequest} createViewRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async createViewV1(createViewRequest: CreateViewRequest, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.createViewV1(createViewRequest, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * + * @summary Queries plugin\'s available strategies for ledger capture + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getAvailableStrategies(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getAvailableStrategies(options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * + * @summary Queries plugin\'s public key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getPublicKey(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getPublicKey(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 Creates a Blockchain View. + * @param {CreateViewRequest} createViewRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createViewV1(createViewRequest: CreateViewRequest, options?: any): AxiosPromise { + return localVarFp.createViewV1(createViewRequest, options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary Queries plugin\'s available strategies for ledger capture + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getAvailableStrategies(options?: any): AxiosPromise> { + return localVarFp.getAvailableStrategies(options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary Queries plugin\'s public key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getPublicKey(options?: any): AxiosPromise { + return localVarFp.getPublicKey(options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * DefaultApi - object-oriented interface + * @export + * @class DefaultApi + * @extends {BaseAPI} + */ +export class DefaultApi extends BaseAPI { + /** + * + * @summary Creates a Blockchain View. + * @param {CreateViewRequest} createViewRequest + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public createViewV1(createViewRequest: CreateViewRequest, options?: AxiosRequestConfig) { + return DefaultApiFp(this.configuration).createViewV1(createViewRequest, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary Queries plugin\'s available strategies for ledger capture + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public getAvailableStrategies(options?: AxiosRequestConfig) { + return DefaultApiFp(this.configuration).getAvailableStrategies(options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary Queries plugin\'s public key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public getPublicKey(options?: AxiosRequestConfig) { + return DefaultApiFp(this.configuration).getPublicKey(options).then((request) => request(this.axios, this.basePath)); + } +} + + diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/base.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/base.ts new file mode 100644 index 0000000000..8114b7b05a --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/base.ts @@ -0,0 +1,72 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Hyperledger Cactus Plugin - BUNGEE-Hermes + * Can create blockchain views of different networks + * + * The version of the OpenAPI document: 2.0.0-alpha.2 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from './configuration'; +// Some imports not used depending on template conditions +// @ts-ignore +import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; +import globalAxios from 'axios'; + +export const BASE_PATH = "http://localhost:3000/api/v1/@hyperledger/cactus-plugin-satp-hermes".replace(/\/+$/, ""); + +/** + * + * @export + */ +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +/** + * + * @export + * @interface RequestArgs + */ +export interface RequestArgs { + url: string; + options: AxiosRequestConfig; +} + +/** + * + * @export + * @class BaseAPI + */ +export class BaseAPI { + protected configuration: Configuration | undefined; + + constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) { + if (configuration) { + this.configuration = configuration; + this.basePath = configuration.basePath || this.basePath; + } + } +}; + +/** + * + * @export + * @class RequiredError + * @extends {Error} + */ +export class RequiredError extends Error { + constructor(public field: string, msg?: string) { + super(msg); + this.name = "RequiredError" + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/common.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/common.ts new file mode 100644 index 0000000000..6a4c5f28c2 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/common.ts @@ -0,0 +1,150 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Hyperledger Cactus Plugin - BUNGEE-Hermes + * Can create blockchain views of different networks + * + * The version of the OpenAPI document: 2.0.0-alpha.2 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from "./configuration"; +import type { RequestArgs } from "./base"; +import type { AxiosInstance, AxiosResponse } from 'axios'; +import { RequiredError } from "./base"; + +/** + * + * @export + */ +export const DUMMY_BASE_URL = 'https://example.com' + +/** + * + * @throws {RequiredError} + * @export + */ +export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) { + if (paramValue === null || paramValue === undefined) { + throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`); + } +} + +/** + * + * @export + */ +export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) { + if (configuration && configuration.apiKey) { + const localVarApiKeyValue = typeof configuration.apiKey === 'function' + ? await configuration.apiKey(keyParamName) + : await configuration.apiKey; + object[keyParamName] = localVarApiKeyValue; + } +} + +/** + * + * @export + */ +export const setBasicAuthToObject = function (object: any, configuration?: Configuration) { + if (configuration && (configuration.username || configuration.password)) { + object["auth"] = { username: configuration.username, password: configuration.password }; + } +} + +/** + * + * @export + */ +export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) { + if (configuration && configuration.accessToken) { + const accessToken = typeof configuration.accessToken === 'function' + ? await configuration.accessToken() + : await configuration.accessToken; + object["Authorization"] = "Bearer " + accessToken; + } +} + +/** + * + * @export + */ +export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) { + if (configuration && configuration.accessToken) { + const localVarAccessTokenValue = typeof configuration.accessToken === 'function' + ? await configuration.accessToken(name, scopes) + : await configuration.accessToken; + object["Authorization"] = "Bearer " + localVarAccessTokenValue; + } +} + +function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void { + if (parameter == null) return; + if (typeof parameter === "object") { + if (Array.isArray(parameter)) { + (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); + } + else { + Object.keys(parameter).forEach(currentKey => + setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`) + ); + } + } + else { + if (urlSearchParams.has(key)) { + urlSearchParams.append(key, parameter); + } + else { + urlSearchParams.set(key, parameter); + } + } +} + +/** + * + * @export + */ +export const setSearchParams = function (url: URL, ...objects: any[]) { + const searchParams = new URLSearchParams(url.search); + setFlattenedQueryParams(searchParams, objects); + url.search = searchParams.toString(); +} + +/** + * + * @export + */ +export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) { + const nonString = typeof value !== 'string'; + const needsSerialization = nonString && configuration && configuration.isJsonMime + ? configuration.isJsonMime(requestOptions.headers['Content-Type']) + : nonString; + return needsSerialization + ? JSON.stringify(value !== undefined ? value : {}) + : (value || ""); +} + +/** + * + * @export + */ +export const toPathString = function (url: URL) { + return url.pathname + url.search + url.hash +} + +/** + * + * @export + */ +export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) { + return >(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url}; + return axios.request(axiosRequestArgs); + }; +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/configuration.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/configuration.ts new file mode 100644 index 0000000000..9d0f329544 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/configuration.ts @@ -0,0 +1,101 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Hyperledger Cactus Plugin - BUNGEE-Hermes + * Can create blockchain views of different networks + * + * The version of the OpenAPI document: 2.0.0-alpha.2 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface ConfigurationParameters { + apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); + username?: string; + password?: string; + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); + basePath?: string; + baseOptions?: any; + formDataCtor?: new () => any; +} + +export class Configuration { + /** + * parameter for apiKey security + * @param name security name + * @memberof Configuration + */ + apiKey?: string | Promise | ((name: string) => string) | ((name: string) => Promise); + /** + * parameter for basic security + * + * @type {string} + * @memberof Configuration + */ + username?: string; + /** + * parameter for basic security + * + * @type {string} + * @memberof Configuration + */ + password?: string; + /** + * parameter for oauth2 security + * @param name security name + * @param scopes oauth2 scope + * @memberof Configuration + */ + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); + /** + * override base path + * + * @type {string} + * @memberof Configuration + */ + basePath?: string; + /** + * base options for axios calls + * + * @type {any} + * @memberof Configuration + */ + baseOptions?: any; + /** + * The FormData constructor that will be used to create multipart form data + * requests. You can inject this here so that execution environments that + * do not support the FormData class can still run the generated client. + * + * @type {new () => FormData} + */ + formDataCtor?: new () => any; + + constructor(param: ConfigurationParameters = {}) { + this.apiKey = param.apiKey; + this.username = param.username; + this.password = param.password; + this.accessToken = param.accessToken; + this.basePath = param.basePath; + this.baseOptions = param.baseOptions; + this.formDataCtor = param.formDataCtor; + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + public isJsonMime(mime: string): boolean { + const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); + return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/index.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/index.ts new file mode 100644 index 0000000000..c51f822d4a --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/generated/openapi/typescript-axios/index.ts @@ -0,0 +1,18 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Hyperledger Cactus Plugin - BUNGEE-Hermes + * Can create blockchain views of different networks + * + * The version of the OpenAPI document: 2.0.0-alpha.2 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export * from "./api"; +export * from "./configuration"; + diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/index.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/index.ts new file mode 100755 index 0000000000..87cb558397 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/index.ts @@ -0,0 +1 @@ +export * from "./public-api"; diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/index.web.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/index.web.ts new file mode 100755 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/index.web.ts @@ -0,0 +1 @@ +export {}; diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/plugin-bungee-hermes.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/plugin-bungee-hermes.ts new file mode 100644 index 0000000000..8b0e906d68 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/plugin-bungee-hermes.ts @@ -0,0 +1,250 @@ +import { + Checks, + IJsObjectSignerOptions, + JsObjectSigner, + LogLevelDesc, + Logger, + LoggerProvider, + Secp256k1Keys, +} from "@hyperledger/cactus-common"; +import { v4 as uuidV4 } from "uuid"; +import { + ICactusPlugin, + ICactusPluginOptions, + IPluginWebService, + IWebServiceEndpoint, +} from "@hyperledger/cactus-core-api"; +import { State } from "./view-creation/state"; +import OAS from "../json/openapi.json"; +import type { Express } from "express"; +import { Optional } from "typescript-optional"; + +import { Server } from "http"; +import { Server as SecureServer } from "https"; +import { + CreateViewRequest, + CreateViewResponse, +} from "./generated/openapi/typescript-axios"; +import { Snapshot } from "./view-creation/snapshot"; +import { View } from "./view-creation/view"; +import { + NetworkDetails, + ObtainLedgerStrategy, +} from "./strategy/obtain-ledger-strategy"; +import { CreateViewEndpointV1 } from "./web-services/create-view-endpoint"; +import { GetPublicKeyEndpointV1 } from "./web-services/get-public-key-endpoint"; +import { GetAvailableStrategiesEndpointV1 } from "./web-services/get-available-strategies-endpoint"; + +export interface IKeyPair { + publicKey: Uint8Array; + privateKey: Uint8Array; +} + +export interface IPluginBungeeHermesOptions extends ICactusPluginOptions { + instanceId: string; + keyPair?: IKeyPair; + + logLevel?: LogLevelDesc; + + disableSignalHandlers?: true; +} + +export class PluginBungeeHermes implements ICactusPlugin, IPluginWebService { + public static readonly CLASS_NAME = "PluginBungeeHermes"; + private readonly instanceId: string; + + private log: Logger; + + private keyPair: IKeyPair; + private bungeeSigner: JsObjectSigner; + private privKeyBungee: string; + private pubKeyBungee: string; + + private strategies: Map; + + private level: LogLevelDesc; + private endpoints: IWebServiceEndpoint[] | undefined; + + constructor(public readonly options: IPluginBungeeHermesOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.instanceId, `${fnTag} options.instanceId`); + + this.level = options.logLevel || "INFO"; + this.strategies = new Map(); + const label = this.className; + const level = this.level; + + this.log = LoggerProvider.getOrCreate({ label, level }); + + this.instanceId = options.instanceId; + + this.keyPair = options.keyPair + ? options.keyPair + : Secp256k1Keys.generateKeyPairsBuffer(); + this.privKeyBungee = Buffer.from(this.keyPair.privateKey).toString("hex"); + this.pubKeyBungee = Buffer.from(this.keyPair.publicKey).toString("hex"); + const bungeeSignerOptions: IJsObjectSignerOptions = { + privateKey: this.privKeyBungee, + logLevel: "debug", + }; + this.bungeeSigner = new JsObjectSigner(bungeeSignerOptions); + } + + public get className(): string { + return PluginBungeeHermes.CLASS_NAME; + } + public get logger(): Logger { + return this.log; + } + + public getPublicKey(): string { + return this.pubKeyBungee; + } + + public addStrategy(strategyId: string, strategy: ObtainLedgerStrategy) { + if (this.strategies.get(strategyId) == undefined) { + this.strategies.set(strategyId, strategy); + } else { + throw Error("Strategy " + strategyId + " already exists."); + } + } + public getStrategy(strategyId: string): ObtainLedgerStrategy | undefined { + return this.strategies.get(strategyId); + } + public getAvailableStrategies(): string[] { + return Array.from(this.strategies.keys()); + } + + public getOpenApiSpec(): unknown { + return OAS; + } + + public async shutdown(): Promise { + this.log.info(`Shutting down ${this.className}...`); + } + public getPackageName(): string { + return `@hyperledger/cactus-plugin-bungee-hermes`; + } + + public async onPluginInit(): Promise { + return; + } + + async registerWebServices(app: Express): Promise { + const webServices = await this.getOrCreateWebServices(); + await Promise.all(webServices.map((ws) => ws.registerExpress(app))); + return webServices; + } + + public async getOrCreateWebServices(): Promise { + if (Array.isArray(this.endpoints)) { + return this.endpoints; + } + + const viewEndpoint = new CreateViewEndpointV1({ + bungee: this, + }); + const pubKeyEndpoint = new GetPublicKeyEndpointV1({ + bungee: this, + }); + const availableStrategiesEndpoint = new GetAvailableStrategiesEndpointV1({ + bungee: this, + }); + + this.endpoints = [ + viewEndpoint, + pubKeyEndpoint, + availableStrategiesEndpoint, + ]; + return this.endpoints; + } + + public getHttpServer(): Optional { + return Optional.empty(); + } + + public getInstanceId(): string { + return this.instanceId; + } + + async onCreateView(request: CreateViewRequest): Promise { + //ti and tf are unix timestamps, represented as strings + const ti: string = request.tI ? request.tI : "0"; + const tf: string = request.tF + ? request.tF + : Number.MAX_SAFE_INTEGER.toString(); + const stateIds: string[] = request.stateIds ? request.stateIds : []; + + const snapshot = await this.generateSnapshot( + stateIds, + request.strategyId, + request.networkDetails, + ); + this.logger.info("Generating view for request: ", request); + const response = JSON.stringify( + this.generateView(snapshot, ti, tf, request.viewID), + ); + return { + view: response, + }; + } + + public generateView( + snapshot: Snapshot, + tI: string, + tF: string, + id: string | undefined, + ): { view?: View; signature?: string } { + if ( + parseInt(tI) > parseInt(snapshot.getTF()) || + parseInt(tF) < parseInt(snapshot.getTI()) || + parseInt(tI) > parseInt(tF) + ) { + return {}; + } + const view = new View(tI, tF, snapshot, id); + snapshot.pruneStates(tI, tF); + + const signature = this.sign(JSON.stringify(view)); + + return { view: view, signature: signature }; + } + + sign(msg: string): string { + return Buffer.from(this.bungeeSigner.sign(msg)).toString("hex"); + } + + public async generateSnapshot( + stateIds: string[], + strategyId: string, + networkDetails: NetworkDetails, + ): Promise { + const strategy = this.getStrategy(strategyId); + if (strategy == undefined) { + throw Error("Strategy " + strategyId + " is undefined/unsupported"); + } + + const ledgerStates = await strategy.generateLedgerStates( + stateIds, + networkDetails, + ); + + const states: State[] = []; + for (const key of ledgerStates.keys()) { + if (stateIds.includes(key) || stateIds.length == 0) { + states.push(ledgerStates.get(key) as State); + } + } + + const snapShotId = uuidV4(); + const snapshot = new Snapshot( + snapShotId, + networkDetails.participant, + states, + ); + snapshot.update_TI_TF(); + + return snapshot; + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/plugin-factory-bungee-hermes.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/plugin-factory-bungee-hermes.ts new file mode 100644 index 0000000000..79f009bc29 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/plugin-factory-bungee-hermes.ts @@ -0,0 +1,19 @@ +import { + IPluginFactoryOptions, + PluginFactory, +} from "@hyperledger/cactus-core-api"; +import { + IPluginBungeeHermesOptions, + PluginBungeeHermes, +} from "./plugin-bungee-hermes"; +export class PluginFactoryBungeeHermes extends PluginFactory< + PluginBungeeHermes, + IPluginBungeeHermesOptions, + IPluginFactoryOptions +> { + async create( + pluginOptions: IPluginBungeeHermesOptions, + ): Promise { + return new PluginBungeeHermes(pluginOptions); + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/public-api.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/public-api.ts new file mode 100644 index 0000000000..ff3dd0e66d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/public-api.ts @@ -0,0 +1,13 @@ +import { IPluginFactoryOptions } from "@hyperledger/cactus-core-api"; +import { PluginFactoryBungeeHermes } from "./plugin-factory-bungee-hermes"; + +export { + PluginBungeeHermes, + IPluginBungeeHermesOptions, +} from "./plugin-bungee-hermes"; + +export async function createBungeePluginFactory( + pluginFactoryOptions: IPluginFactoryOptions, +): Promise { + return new PluginFactoryBungeeHermes(pluginFactoryOptions); +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/obtain-ledger-strategy.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/obtain-ledger-strategy.ts new file mode 100644 index 0000000000..eeb1b68aa1 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/obtain-ledger-strategy.ts @@ -0,0 +1,15 @@ +import { Logger } from "@hyperledger/cactus-common"; +import { State } from "../view-creation/state"; + +export interface NetworkDetails { + connectorApiPath: string; + participant: string; +} +export interface ObtainLedgerStrategy { + log: Logger; + + generateLedgerStates( + stateIds: string[], + networkDetails: NetworkDetails, + ): Promise>; +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/strategy-besu.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/strategy-besu.ts new file mode 100644 index 0000000000..42d45707be --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/strategy-besu.ts @@ -0,0 +1,188 @@ +import { NetworkDetails, ObtainLedgerStrategy } from "./obtain-ledger-strategy"; +import { + LogLevelDesc, + Logger, + LoggerProvider, +} from "@hyperledger/cactus-common"; +import { + DefaultApi as BesuApi, + EthContractInvocationType, + EvmBlock, + EvmLog, + GetBlockV1Request, + GetPastLogsV1Request, + GetTransactionV1Request, + InvokeContractV1Request, + Web3SigningCredential, +} from "@hyperledger/cactus-plugin-ledger-connector-besu"; +import { State } from "../view-creation/state"; +import { StateProof } from "../view-creation/state-proof"; +import { Configuration } from "@hyperledger/cactus-core-api"; +import { Transaction } from "../view-creation/transaction"; +import Web3 from "web3"; +import { Proof } from "../view-creation/proof"; +import { TransactionProof } from "../view-creation/transaction-proof"; + +export interface BesuNetworkDetails extends NetworkDetails { + signingCredential: Web3SigningCredential; + keychainId: string; + contractName: string; + contractAddress: string; +} +export class StrategyBesu implements ObtainLedgerStrategy { + public static readonly CLASS_NAME = "StrategyBesu"; + + public log: Logger; + + constructor(level: LogLevelDesc) { + this.log = LoggerProvider.getOrCreate({ + label: StrategyBesu.CLASS_NAME, + level, + }); + } + + public async generateLedgerStates( + stateIds: string[], + networkDetails: BesuNetworkDetails, + ): Promise> { + this.log.debug(`Generating ledger snapshot`); + const config = new Configuration({ + basePath: networkDetails.connectorApiPath, + }); + const besuApi = new BesuApi(config); + + const ledgerStates = new Map(); + const assetsKey = + stateIds.length == 0 + ? ((await this.getAllAssetsKey(networkDetails, besuApi)) as string[]) + : stateIds; + this.log.debug("Current assets detected to capture: " + assetsKey); + for (const assetKey of assetsKey) { + const { transactions, values, blocks } = await this.getAllInfoByKey( + assetKey, + networkDetails, + besuApi, + ); + + const state = new State(assetKey, values, transactions); + + const stateProof = new StateProof( + state.getValue(), + parseInt(state.getVersion()), + state.getId(), + ); + const blocksHash: string[] = []; + for (const block of blocks.values()) { + if (blocksHash.indexOf(block.hash as string) !== -1) { + continue; + } + blocksHash.push(block.hash as string); + stateProof.addBlock({ + blockHash: block.hash as string, + blockCreator: block.miner as string, + blockSigners: [], // FIXME: query blocksigners (blockchain specific) + }); + } + state.setStateProof([]); + ledgerStates.set(assetKey, state); + } + return ledgerStates; + } + + async getAllAssetsKey( + networkDetails: BesuNetworkDetails, + api: BesuApi, + ): Promise { + const parameters = { + contractName: networkDetails.contractName, + keychainId: networkDetails.keychainId, + invocationType: EthContractInvocationType.Call, + methodName: "getAllAssetsIDs", + params: [], + signingCredential: networkDetails.signingCredential, + gas: 1000000, + }; + const response = await api.invokeContractV1( + parameters as InvokeContractV1Request, + ); + if (response != undefined) { + return response.data.callOutput; + } + + return "response undefined"; + } + + async getAllInfoByKey( + key: string, + networkDetails: BesuNetworkDetails, + api: BesuApi, + ): Promise<{ + transactions: Transaction[]; + values: string[]; + blocks: Map; + }> { + const req = { + address: networkDetails.contractAddress, + topics: [[null], [Web3.utils.keccak256(key)]], //filter logs by asset key + }; + const response = await api.getPastLogsV1(req as GetPastLogsV1Request); + if (response == undefined) { + return { + transactions: [], + values: [], + blocks: new Map(), + }; + } + const decoded = response.data.logs as EvmLog[]; + const transactions: Transaction[] = []; + const blocks: Map = new Map(); + const values: string[] = []; + this.log.debug("Getting transaction logs for asset: " + key); + + for (const log of decoded) { + const txTx = await api.getTransactionV1({ + transactionHash: log.transactionHash, + } as GetTransactionV1Request); + + const txBlock = await api.getBlockV1({ + blockHashOrBlockNumber: log.blockHash, + } as GetBlockV1Request); + if (txTx == undefined || txBlock == undefined) { + this.log.debug( + "some error occurred fetching transaction or block info in ", + ); + return { + transactions: [], + values: [], + blocks: new Map(), + }; + } + this.log.debug( + "Transaction: " + + log.transactionHash + + "\nData: " + + JSON.stringify(log.data) + + "\n =========== \n", + ); + const proof = new Proof({ + creator: txTx.data.transaction.from as string, //no sig for besu + }); + const transaction: Transaction = new Transaction( + log.transactionHash, + txBlock.data.block.timestamp, + new TransactionProof(proof), + ); + transaction.setStateId(key); + transaction.setTarget(networkDetails.contractAddress as string); + transaction.setPayload( + txTx.data.transaction.input ? txTx.data.transaction.input : "", + ); //FIXME: payload = transaction input ? + transactions.push(transaction); + values.push(JSON.stringify(log.data)); + + blocks.set(transaction.getId(), txBlock.data.block); + } + + return { transactions: transactions, values: values, blocks: blocks }; + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/strategy-fabric.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/strategy-fabric.ts new file mode 100644 index 0000000000..1a9d61a4c7 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/strategy/strategy-fabric.ts @@ -0,0 +1,226 @@ +import { + FabricSigningCredential, + DefaultApi as FabricApi, + Configuration, + FabricContractInvocationType, + RunTransactionRequest, +} from "@hyperledger/cactus-plugin-ledger-connector-fabric"; +import { NetworkDetails, ObtainLedgerStrategy } from "./obtain-ledger-strategy"; +import { + LogLevelDesc, + Logger, + LoggerProvider, +} from "@hyperledger/cactus-common"; +import { Transaction } from "../view-creation/transaction"; +import { State } from "../view-creation/state"; +import { StateProof } from "../view-creation/state-proof"; +import { Proof } from "../view-creation/proof"; +import { TransactionProof } from "../view-creation/transaction-proof"; + +export interface FabricNetworkDetails extends NetworkDetails { + signingCredential: FabricSigningCredential; + contractName: string; + channelName: string; +} +export class StrategyFabric implements ObtainLedgerStrategy { + public static readonly CLASS_NAME = "StrategyFabric"; + + public log: Logger; + + constructor(level: LogLevelDesc) { + this.log = LoggerProvider.getOrCreate({ + label: StrategyFabric.CLASS_NAME, + level, + }); + } + + public async generateLedgerStates( + stateIds: string[], + networkDetails: FabricNetworkDetails, + ): Promise> { + this.log.info(`Generating ledger snapshot`); + + const config = new Configuration({ + basePath: networkDetails.connectorApiPath, + }); + const fabricApi = new FabricApi(config); + + const assetsKey = + stateIds.length == 0 + ? (await this.getAllAssetsKey(fabricApi, networkDetails)).split(",") + : stateIds; + const ledgerStates = new Map(); + //For each key in ledgerAssetsKey + for (const assetKey of assetsKey) { + const assetValues: string[] = []; + const txWithTimeS: Transaction[] = []; + + const txs = await this.getAllTxByKey(assetKey, fabricApi, networkDetails); + //For each tx get receipt + for (const tx of txs) { + const receipt = JSON.parse( + await this.fabricGetTxReceiptByTxIDV1( + tx.getId(), + fabricApi, + networkDetails, + ), + ); + + assetValues.push(JSON.parse(receipt.rwsetWriteData).Value.toString()); + tx.setStateId(assetKey); + //tx.setPayload(); //FIXME check what to assign here + //tx.setTarget(); + + for (const endorsement of receipt.transactionEndorsement) { + const signature64 = Buffer.from(endorsement.signature).toString( + "base64", + ); + tx.addEndorser( + new Proof({ + mspid: endorsement.mspid, + creator: endorsement.endorserID, + signature: signature64, + }), + ); + } + txWithTimeS.push(tx); + } + const block = await this.fabricGetBlockByTxID( + txs[txs.length - 1].getId(), + fabricApi, + networkDetails, + ); + + const state = new State(assetKey, assetValues, txWithTimeS); + ledgerStates.set(assetKey, state); + const stateProof = new StateProof( + state.getValue(), + parseInt(state.getVersion()), + state.getId(), + ); + //only adding last block for each state, in the state proof + stateProof.addBlock({ + blockHash: block.hash, + blockCreator: "", + blockSigners: block.signers, + }); + } + return ledgerStates; + } + + async fabricGetTxReceiptByTxIDV1( + transactionId: string, + api: FabricApi, + networkDetails: FabricNetworkDetails, + ): Promise { + const receiptLockRes = await api.getTransactionReceiptByTxIDV1({ + signingCredential: networkDetails.signingCredential, + channelName: networkDetails.channelName, + contractName: "qscc", + invocationType: FabricContractInvocationType.Call, + methodName: "GetBlockByTxID", + params: [networkDetails.channelName, transactionId], + } as RunTransactionRequest); + return JSON.stringify(receiptLockRes?.data); + } + + async fabricGetBlockByTxID( + txId: string, + api: FabricApi, + netwokDetails: FabricNetworkDetails, + ): Promise<{ hash: string; signers: string[] }> { + const gatewayOptions = { + identity: netwokDetails.signingCredential.keychainRef, + wallet: { + keychain: { + keychainId: netwokDetails.signingCredential.keychainId, + keychainRef: netwokDetails.signingCredential.keychainRef, + }, + }, + }; + const getBlockReq = { + channelName: netwokDetails.channelName as string, + gatewayOptions, + query: { + transactionId: txId, + }, + skipDecode: false, + }; + + const getBlockResponse = await api.getBlockV1(getBlockReq); + + const block = JSON.parse( + JSON.stringify(getBlockResponse?.data), + ).decodedBlock; + + const blockSig = block.metadata.metadata[0].signatures; + const sigs = []; + for (const sig of blockSig) { + sigs.push(JSON.stringify(sig)); + } + + return { + hash: Buffer.from(block.header.data_hash.data).toString("hex"), + signers: sigs, + }; + } + + async getAllAssetsKey( + api: FabricApi, + netwokDetails: FabricNetworkDetails, + ): Promise { + const response = await api.runTransactionV1({ + signingCredential: netwokDetails.signingCredential, + channelName: netwokDetails.channelName, + contractName: netwokDetails.contractName, + methodName: "GetAllAssetsKey", + invocationType: FabricContractInvocationType.Call, + params: [], + } as RunTransactionRequest); + + if (response != undefined) { + return response.data.functionOutput; + } + + return "response undefined"; + } + + async getAllTxByKey( + key: string, + api: FabricApi, + netwokDetails: FabricNetworkDetails, + ): Promise { + const response = await api.runTransactionV1({ + signingCredential: netwokDetails.signingCredential, + channelName: netwokDetails.channelName, + contractName: netwokDetails.contractName, + methodName: "GetAllTxByKey", + invocationType: FabricContractInvocationType.Call, + params: [key], + } as RunTransactionRequest); + + if (response != undefined) { + return this.txsStringToTxs(response.data.functionOutput); + } + + return []; + } + + // Receive transactions in string format and parses to Transaction [] + txsStringToTxs(txString: string): Transaction[] { + const transactions: Transaction[] = []; + const txs = JSON.parse(txString); + for (const tx of txs) { + const txId = tx.value.txId; + const ts = tx.value.timestamp.seconds; + transactions.push( + new Transaction( + txId, + ts, + new TransactionProof(new Proof({ creator: "" })), + ), + ); + } + return transactions.reverse(); + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/proof.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/proof.ts new file mode 100644 index 0000000000..69f18b79bc --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/proof.ts @@ -0,0 +1,53 @@ +// Proof is a general purpose type, used to represent signatures of diverse elements. +// Proof may be used, for example in Fabric, to represent an transaction endorsement +// Or simply the signature of a transaction upon is creation (in Besu) +export class Proof { + // The term creator refers to the ID of the entity who created the signature + // For example endorserID in Fabric (when Proof represents an endorsement) + // or a transaction creator ID(in TransactionProof.transactionCreator) + private creator: string; + private mspid?: string; + private signature?: string; + + constructor(settings: { + creator: string; + mspid?: string; + signature?: string; + }) { + this.creator = settings.creator; + this.mspid = settings.mspid ? settings.mspid : "undefined"; + this.signature = settings.signature ? settings.signature : "undefined"; + } + + public printEndorsement(): string { + return ( + "Endorsement: \n " + + this.creator + + " \n " + + this.mspid + + " \n " + + this.signature + ); + } + + public getEndorsementJson(): string { + const proof = { + creator: this.creator, + mspid: this.mspid, + signature: this.signature, + }; + return JSON.stringify(proof); + } + + public getCreator(): string { + return this.creator; + } + + public getMspid(): string | undefined { + return this.mspid; + } + + public getSignature(): string | undefined { + return this.signature; + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/snapshot.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/snapshot.ts new file mode 100644 index 0000000000..3ee8e1ce5d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/snapshot.ts @@ -0,0 +1,88 @@ +import { State } from "./state"; + +export class Snapshot { + private id: string; + private participant; + private stateBins: State[]; //set of state bins + private tI: string = ""; + private tF: string = ""; + + constructor(id: string, participant: string, stateBins: State[]) { + this.id = id; + this.participant = participant; + this.stateBins = stateBins; + } + public getParticipant(): string { + return this.participant; + } + private getId(): string { + return this.id; + } + + public getTI() { + return this.tI; + } + public getTF() { + return this.tF; + } + public setTF(tF: string) { + this.tF = tF; + } + + public setTI(tI: string) { + this.tI = tI; + } + + public update_TI_TF() { + let ti = 999999999999999; + let tf = 0; + for (const bin of this.stateBins) { + const tI = Number(bin.getInitialTime()); + const tF = Number(bin.getFinalTime()); + if (tf < tF) { + tf = tF; + } + if (ti > tI) { + ti = tI; + } + } + this.tF = tf.toString(); + this.tI = ti.toString(); + } + + public pruneStates(tI: string, tF: string): void { + for (const state of this.stateBins) { + state.pruneState(tI, tF); + } + } + + public getStateBins() { + return this.stateBins; + } + + public filterStates(tI: string, tF: string): void { + const finalT = parseInt(tF); + const initialT = parseInt(tI); + const stateBins: State[] = []; + for (const state of this.stateBins) { + if ( + parseInt(state.getInitialTime()) > finalT || + parseInt(state.getFinalTime()) < initialT + ) { + continue; + } + stateBins.push(state); + } + this.stateBins = stateBins; + } + + public getSnapshotJson(): string { + const snapshotJson = { + id: this.id, + participant: this.participant, + stateBins: this.stateBins, + }; + + return JSON.stringify(snapshotJson); + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/state-proof.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/state-proof.ts new file mode 100644 index 0000000000..0854254a88 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/state-proof.ts @@ -0,0 +1,32 @@ +export interface Block { + blockHash: string; + blockCreator: string; + blockSigners: string[]; +} + +export class StateProof { + private stateID: string; + private value: string; + private blocks: Block[]; + private version: number; + + constructor(value: string, version: number, stateID: string) { + this.blocks = []; + this.value = value; + this.version = version; + this.stateID = stateID; + } + + public getValue() { + return this.value; + } + public getVersion() { + return this.version; + } + public getStateID() { + return this.stateID; + } + public addBlock(block: Block) { + this.blocks.push(block); + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/state.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/state.ts new file mode 100644 index 0000000000..ba05fd50c1 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/state.ts @@ -0,0 +1,93 @@ +import { StateProof } from "./state-proof"; +import { Transaction } from "./transaction"; + +export class State { + private id: string; + private version: number; + private values: string[]; + private transactions: Transaction[]; + private stateProof: StateProof[] = []; + + constructor(id: string, stateBins: string[], transactions: Transaction[]) { + this.id = id; + this.version = transactions.length; + this.values = stateBins; + this.transactions = transactions; + } + + public getStateProof(): StateProof[] { + return this.stateProof; + } + public getId(): string { + return this.id; + } + + public getValues(): string[] { + return this.values; + } + + public setStateProof(proof: StateProof[]) { + this.stateProof = proof; + } + + public getStateJson(): string { + const txs: string[] = []; + const txEndorsements: string[] = []; + + for (const tx of this.transactions) { + txs.push(tx.getTxJson()); + txEndorsements.push(JSON.stringify(tx.getProof())); + } + + const jsonSnap = { + id: this.id, + version: this.getVersion(), + values: this.values, + transactions: txs, + proofs: txEndorsements, + }; + + return JSON.stringify(jsonSnap); + } + + public getTransactions() { + return this.transactions; + } + + public getInitialTime(): string { + if (this.transactions.length >= 1) { + return this.transactions[0].getTimeStamp(); + } + return ""; + } + + public getFinalTime(): string { + if (this.transactions.length >= 1) { + return this.transactions[this.transactions.length - 1].getTimeStamp(); + } + return ""; + } + public getValue(): string { + return this.values[this.values.length - 1]; + } + + public getVersion(): string { + return this.version.toString(); + } + + public pruneState(tI: string, tF: string): void { + const initialT = parseInt(tI); + const finalT = parseInt(tF); + // eslint-disable-next-line prefer-const + this.transactions.forEach((element, index) => { + if ( + parseInt(element.getTimeStamp()) < initialT || + parseInt(element.getTimeStamp()) > finalT + ) { + //this.version = this.version - 1; + this.transactions.splice(index, 1); //Remove tx + this.values?.splice(index, 1); //Remove state of tx + } + }); + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/transaction-proof.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/transaction-proof.ts new file mode 100644 index 0000000000..fe4b91a8b1 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/transaction-proof.ts @@ -0,0 +1,39 @@ +import { Proof } from "./proof"; + +export class TransactionProof { + private transactionCreator: Proof; + + //set of signed endorsements + //only existent for some ledgers (example Fabric) + private endorsements?: Proof[] = []; + + constructor(transactionCreator: Proof) { + this.transactionCreator = transactionCreator; + } + + public addEndorser(endorser: Proof) { + this.endorsements?.push(endorser); + } + + public printEndorsement(): string { + return ( + "Endorsement: \n " + this.transactionCreator + " \n " + this.endorsements + ); + } + + public getEndorsementJson(): string { + const proof = { + transactionCreator: this.transactionCreator, + endorsements: this.endorsements, + }; + return JSON.stringify(proof); + } + + public getCreator(): Proof { + return this.transactionCreator; + } + + public getEndorsements(): Proof[] | undefined { + return this.endorsements; + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/transaction.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/transaction.ts new file mode 100644 index 0000000000..07fbe6212f --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/transaction.ts @@ -0,0 +1,66 @@ +import { Proof } from "./proof"; +import { TransactionProof } from "./transaction-proof"; + +export class Transaction { + private id: string; + private timeStamp: string; + private proof: TransactionProof; + private stateId?: string; + private payload?: string; + private target?: string; + + constructor(id: string, timeStamp: string, proof: TransactionProof) { + this.id = id; + this.timeStamp = timeStamp; + this.proof = proof; + } + + public printTransaction(): string { + return "Transaction: \n " + this.id + " \n " + this.timeStamp; + } + + public addEndorser(endorser: Proof): void { + this.proof.addEndorser(endorser); + } + public getId(): string { + return this.id; + } + + public getTarget() { + return this.target; + } + public getPayload() { + return this.payload; + } + public getStateId() { + return this.stateId; + } + + //public setBlockN(n: number) { + // this.blockN = n; + //} + + public setTarget(target: string) { + this.target = target; + } + public setPayload(payload: string) { + this.payload = payload; + } + public setStateId(stateId: string) { + this.stateId = stateId; + } + + public getTxJson(): string { + const tx = { Id: this.id, TimeStamp: this.timeStamp }; + return JSON.stringify(tx); + } + + public getProof(): TransactionProof { + //const txProofs = { id: this.id, proof: this.proof }; + return this.proof; + } + + public getTimeStamp(): string { + return this.timeStamp; + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/view.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/view.ts new file mode 100644 index 0000000000..6c8db87fa0 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/view-creation/view.ts @@ -0,0 +1,36 @@ +import { v4 as uuidV4 } from "uuid"; +import { Snapshot } from "./snapshot"; + +export class View { + private key: string; + private snapshot: Snapshot; + private tI; + private tF; + private participant; + + constructor( + tI: string, + tF: string, + snapshot: Snapshot, + id: string | undefined, + ) { + this.key = id ? id : uuidV4(); // FIXME receive as input maybe + this.tI = tI; + this.tF = tF; + this.snapshot = snapshot; + this.participant = snapshot.getParticipant(); + snapshot.pruneStates(this.tI, this.tF); + } + public getKey() { + return this.key; + } + public getViewStr(): string { + const viewStr = { + tI: this.tI, + tF: this.tF, + snapshot: this.snapshot, + }; + return JSON.stringify(viewStr); + // return this.snapshot.getSnapshotJson(); + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/create-view-endpoint.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/create-view-endpoint.ts new file mode 100644 index 0000000000..24575259af --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/create-view-endpoint.ts @@ -0,0 +1,104 @@ +import type { Express, Request, Response } from "express"; + +import { + IWebServiceEndpoint, + IExpressRequestHandler, + IEndpointAuthzOptions, +} from "@hyperledger/cactus-core-api/"; + +import { + Logger, + Checks, + LogLevelDesc, + LoggerProvider, + IAsyncProvider, +} from "@hyperledger/cactus-common"; + +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginBungeeHermes } from "../plugin-bungee-hermes"; + +export interface CreateViewEndpointOptions { + logLevel?: LogLevelDesc; + bungee: PluginBungeeHermes; +} + +export class CreateViewEndpointV1 implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "ClientEndpointV1"; + + private readonly log: Logger; + + public get className(): string { + return CreateViewEndpointV1.CLASS_NAME; + } + + constructor(public readonly options: CreateViewEndpointOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.bungee, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getExpressRequestHandler(): IExpressRequestHandler { + return this.handleRequest.bind(this); + } + + public getPath(): string { + const apiPath = + OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/create-view" + ]; + return apiPath.get["x-hyperledger-cacti"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = + OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/create-view" + ]; + return apiPath.get["x-hyperledger-cacti"].http.verbLowerCase; + } + + public getOperationId(): string { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/create-view" + ].get.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 async handleRequest(req: Request, res: Response): Promise { + const fnTag = `${this.className}#handleRequest()`; + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + try { + const view = await this.options.bungee.onCreateView(req.body); + res.status(200).json(view); + } catch (ex: unknown) { + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); + } + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/get-available-strategies-endpoint.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/get-available-strategies-endpoint.ts new file mode 100644 index 0000000000..23fce2800d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/get-available-strategies-endpoint.ts @@ -0,0 +1,104 @@ +import type { Express, Request, Response } from "express"; + +import { + IWebServiceEndpoint, + IExpressRequestHandler, + IEndpointAuthzOptions, +} from "@hyperledger/cactus-core-api/"; + +import { + Logger, + Checks, + LogLevelDesc, + LoggerProvider, + IAsyncProvider, +} from "@hyperledger/cactus-common"; + +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginBungeeHermes } from "../plugin-bungee-hermes"; + +export interface GetAvailableStrategiesEndpointOptions { + logLevel?: LogLevelDesc; + bungee: PluginBungeeHermes; +} + +export class GetAvailableStrategiesEndpointV1 implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "ClientEndpointV1"; + + private readonly log: Logger; + + public get className(): string { + return GetAvailableStrategiesEndpointV1.CLASS_NAME; + } + + constructor(public readonly options: GetAvailableStrategiesEndpointOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.bungee, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getExpressRequestHandler(): IExpressRequestHandler { + return this.handleRequest.bind(this); + } + + public getPath(): string { + const apiPath = + OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-available-strategies" + ]; + return apiPath.get["x-hyperledger-cacti"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = + OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-available-strategies" + ]; + return apiPath.get["x-hyperledger-cacti"].http.verbLowerCase; + } + + public getOperationId(): string { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-available-strategies" + ].get.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 async handleRequest(_req: Request, res: Response): Promise { + const fnTag = `${this.className}#handleRequest()`; + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + try { + const strategies = this.options.bungee.getAvailableStrategies(); + res.status(200).json(strategies); + } catch (ex: unknown) { + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); + } + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/get-public-key-endpoint.ts b/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/get-public-key-endpoint.ts new file mode 100644 index 0000000000..836d1efa7d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/main/typescript/web-services/get-public-key-endpoint.ts @@ -0,0 +1,104 @@ +import type { Express, Request, Response } from "express"; + +import { + IWebServiceEndpoint, + IExpressRequestHandler, + IEndpointAuthzOptions, +} from "@hyperledger/cactus-core-api/"; + +import { + Logger, + Checks, + LogLevelDesc, + LoggerProvider, + IAsyncProvider, +} from "@hyperledger/cactus-common"; + +import { + handleRestEndpointException, + registerWebServiceEndpoint, +} from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginBungeeHermes } from "../plugin-bungee-hermes"; + +export interface GetPublicKeyEndpointOptions { + logLevel?: LogLevelDesc; + bungee: PluginBungeeHermes; +} + +export class GetPublicKeyEndpointV1 implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "ClientEndpointV1"; + + private readonly log: Logger; + + public get className(): string { + return GetPublicKeyEndpointV1.CLASS_NAME; + } + + constructor(public readonly options: GetPublicKeyEndpointOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.bungee, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getExpressRequestHandler(): IExpressRequestHandler { + return this.handleRequest.bind(this); + } + + public getPath(): string { + const apiPath = + OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-public-key" + ]; + return apiPath.get["x-hyperledger-cacti"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = + OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-public-key" + ]; + return apiPath.get["x-hyperledger-cacti"].http.verbLowerCase; + } + + public getOperationId(): string { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-bungee-hermes/get-public-key" + ].get.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 async handleRequest(_req: Request, res: Response): Promise { + const fnTag = `${this.className}#handleRequest()`; + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + try { + const pubKey = this.options.bungee.getPublicKey(); + res.status(200).json(pubKey); + } catch (ex: unknown) { + const errorMsg = `${fnTag} request handler fn crashed for: ${reqTag}`; + handleRestEndpointException({ errorMsg, log: this.log, error: ex, res }); + } + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/.gitignore b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/.gitignore new file mode 100644 index 0000000000..79bfe1a3e0 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/.gitignore @@ -0,0 +1,16 @@ +# +# SPDX-License-Identifier: Apache-2.0 +# + + +# Coverage directory used by tools like istanbul +coverage + +# Dependency directories +node_modules/ +jspm_packages/ +package-lock.json + +# Compiled TypeScript files +dist + diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/package.json b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/package.json new file mode 100644 index 0000000000..4ff4e9d9e5 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/package.json @@ -0,0 +1,50 @@ +{ + "name": "asset-transfer-basic", + "version": "1.0.0", + "description": "Asset Transfer Basic contract implemented in TypeScript", + "main": "dist/index.js", + "typings": "dist/index.d.ts", + "engines": { + "node": ">=12", + "npm": ">=5" + }, + "scripts": { + "start": "fabric-chaincode-node start", + "build": "tsc" + }, + "engineStrict": true, + "author": "Hyperledger", + "license": "Apache-2.0", + "dependencies": { + "fabric-contract-api": "2.2.2", + "fabric-shim": "2.2.2" + }, + "devDependencies": { + "@types/chai": "4.3.0", + "@types/mocha": "5.2.7", + "@types/node": "10.17.60", + "@types/sinon": "5.0.7", + "@types/sinon-chai": "3.2.8", + "typescript": "3.9.10" + }, + "nyc": { + "extension": [ + ".ts", + ".tsx" + ], + "exclude": [ + "coverage/**", + "dist/**" + ], + "reporter": [ + "text-summary", + "html" + ], + "all": true, + "check-coverage": true, + "statements": 100, + "branches": 100, + "functions": 100, + "lines": 100 + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/asset.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/asset.ts new file mode 100644 index 0000000000..f93f19710e --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/asset.ts @@ -0,0 +1,20 @@ +/* + SPDX-License-Identifier: Apache-2.0 +*/ + +import { Object, Property } from "fabric-contract-api"; + +@Object() +export class Asset { + @Property() + public docType?: string; + + @Property() + public ID: string; + + @Property() + public isLocked: boolean; + + @Property() + public size: number; +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/assetTransfer.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/assetTransfer.ts new file mode 100644 index 0000000000..a98006bfa5 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/assetTransfer.ts @@ -0,0 +1,182 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + Context, + Contract, + Info, + Returns, + Transaction, +} from "fabric-contract-api"; +import { Asset } from "./asset"; + +@Info({ + title: "AssetTransfer", + description: "Smart contract for trading assets", +}) +export class AssetTransferContract extends Contract { + @Transaction() + public async InitLedger(ctx: Context): Promise { + const assets: Asset[] = [ + { + ID: "asset1", + size: 5, + isLocked: false, + }, + { + ID: "asset2", + size: 5, + isLocked: false, + }, + ]; + + for (const asset of assets) { + asset.docType = "asset"; + await ctx.stub.putState(asset.ID, Buffer.from(JSON.stringify(asset))); + console.info(`Asset ${asset.ID} initialized`); + } + } + + // CreateAsset issues a new asset to the world state with given details. + @Transaction() + public async CreateAsset( + ctx: Context, + id: string, + size: number, + ): Promise { + const asset: Asset = { + ID: id, + size: size, + isLocked: false, + }; + await ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); + } + + // ReadAsset returns the asset stored in the world state with given id. + @Transaction(false) + public async ReadAsset(ctx: Context, id: string): Promise { + const assetJSON = await ctx.stub.getState(id); // get the asset from chaincode state + if (!assetJSON || assetJSON.length === 0) { + throw new Error(`The asset ${id} does not exist`); + } + return assetJSON.toString(); + } + + // UpdateAsset updates an existing asset in the world state with provided parameters. + @Transaction() + public async UpdateAsset( + ctx: Context, + id: string, + size: number, + ): Promise { + const exists = await this.AssetExists(ctx, id); + if (!exists) { + throw new Error(`The asset ${id} does not exist`); + } + + if (this.IsAssetLocked(ctx, id)) { + throw new Error(`The asset ${id} is locked`); + } + + // overwriting original asset with new asset + const assetString = await this.ReadAsset(ctx, id); + const asset: Asset = JSON.parse(assetString); + asset.size = size; + return ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); + } + + // DeleteAsset deletes an given asset from the world state. + @Transaction() + public async DeleteAsset(ctx: Context, id: string): Promise { + const exists = await this.AssetExists(ctx, id); + if (!exists) { + throw new Error(`The asset ${id} does not exist`); + } + + return ctx.stub.deleteState(id); + } + + // AssetExists returns true when asset with given ID exists in world state. + @Transaction(false) + @Returns("boolean") + public async AssetExists(ctx: Context, id: string): Promise { + const assetJSON = await ctx.stub.getState(id); + return assetJSON && assetJSON.length > 0; + } + + // IsAssetLocked returns true when asset with given ID is locked in world state. + @Transaction(false) + @Returns("boolean") + public async IsAssetLocked(ctx: Context, id: string): Promise { + const assetJSON = await ctx.stub.getState(id); + + if (assetJSON && assetJSON.length > 0) { + const asset = JSON.parse(assetJSON.toString()); + return asset.isLocked; + } else { + throw new Error(`The asset ${id} does not exist`); + } + } + + @Transaction(false) + @Returns("boolean") + public async LockAsset(ctx: Context, id: string): Promise { + const exists = await this.AssetExists(ctx, id); + + if (!exists) { + throw new Error(`The asset ${id} does not exist`); + } + + // if (this.IsAssetLocked(ctx, id)) { + // throw new Error(`The asset ${id} is already locked`); + // } + + const assetString = await this.ReadAsset(ctx, id); + const asset: Asset = JSON.parse(assetString); + asset.isLocked = true; + await ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); + return true; + } + + @Transaction(false) + @Returns("boolean") + public async UnlockAsset(ctx: Context, id: string): Promise { + const exists = await this.AssetExists(ctx, id); + + if (!exists) { + throw new Error(`The asset ${id} does not exist`); + } + + const assetString = await this.ReadAsset(ctx, id); + const asset: Asset = JSON.parse(assetString); + asset.isLocked = false; + await ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); + return true; + } + + // GetAllAssets returns all assets found in the world state. + @Transaction(false) + @Returns("string") + public async GetAllAssets(ctx: Context): Promise { + const allResults = []; + // range query with empty string for startKey and endKey does an open-ended query of all assets in the chaincode namespace. + const iterator = await ctx.stub.getStateByRange("", ""); + let result = await iterator.next(); + while (!result.done) { + const strValue = Buffer.from(result.value.value.toString()).toString( + "utf8", + ); + let record; + try { + record = JSON.parse(strValue); + } catch (err) { + console.log(err); + record = strValue; + } + allResults.push({ Key: result.value.key, Record: record }); + result = await iterator.next(); + } + return JSON.stringify(allResults); + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/index.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/index.ts new file mode 100644 index 0000000000..020a09f410 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/src/index.ts @@ -0,0 +1,9 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + */ + +import { AssetTransferContract } from "./assetTransfer"; + +export { AssetTransferContract } from "./assetTransfer"; + +export const contracts: any[] = [AssetTransferContract]; diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/tsconfig.json b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/tsconfig.json new file mode 100644 index 0000000000..80d8e12d8c --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/lock-asset/chaincode-typescript/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "outDir": "dist", + "target": "es2017", + "moduleResolution": "node", + "module": "commonjs", + "declaration": true, + "sourceMap": true + }, + "include": [ + "./src/**/*" + ], + "exclude": [ + "./src/**/*.spec.ts" + ] +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/.gitignore b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/.gitignore new file mode 100644 index 0000000000..79bfe1a3e0 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/.gitignore @@ -0,0 +1,16 @@ +# +# SPDX-License-Identifier: Apache-2.0 +# + + +# Coverage directory used by tools like istanbul +coverage + +# Dependency directories +node_modules/ +jspm_packages/ +package-lock.json + +# Compiled TypeScript files +dist + diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/package.json b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/package.json new file mode 100644 index 0000000000..b8e57d28de --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/package.json @@ -0,0 +1,50 @@ +{ + "name": "asset-transfer-basic", + "version": "1.0.0", + "description": "Asset Transfer Basic contract implemented in TypeScript", + "main": "dist/index.js", + "typings": "dist/index.d.ts", + "engines": { + "node": ">=12", + "npm": ">=5" + }, + "scripts": { + "start": "fabric-chaincode-node start", + "build": "tsc" + }, + "engineStrict": true, + "author": "Hyperledger", + "license": "Apache-2.0", + "dependencies": { + "fabric-contract-api": "2.2.2", + "fabric-shim": "2.2.2" + }, + "devDependencies": { + "@types/chai": "4.3.0", + "@types/mocha": "5.2.7", + "@types/node": "18.11.9", + "@types/sinon": "5.0.7", + "@types/sinon-chai": "3.2.8", + "typescript": "5.3.3" + }, + "nyc": { + "extension": [ + ".ts", + ".tsx" + ], + "exclude": [ + "coverage/**", + "dist/**" + ], + "reporter": [ + "text-summary", + "html" + ], + "all": true, + "check-coverage": true, + "statements": 100, + "branches": 100, + "functions": 100, + "lines": 100 + } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/ITraceableContract.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/ITraceableContract.ts new file mode 100644 index 0000000000..f0596b3843 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/ITraceableContract.ts @@ -0,0 +1,13 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Context } from "fabric-contract-api"; + +export interface ITraceableContract { + // GetAllAssetsKey returns all assets key found in the world state. + GetAllAssetsKey(ctx: Context): Promise; + + // GetAllTxByKey returns all transations for a specific key. + GetAllTxByKey(ctx: Context, key: string): Promise; +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/asset.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/asset.ts new file mode 100644 index 0000000000..a4336c9e7f --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/asset.ts @@ -0,0 +1,17 @@ +/* + SPDX-License-Identifier: Apache-2.0 +*/ + +import { Object, Property } from "fabric-contract-api"; + +@Object() +export class Asset { + @Property() + public docType?: string; + + @Property() + public ID: string; + + @Property() + public Value: number; +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/assetTransfer.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/assetTransfer.ts new file mode 100644 index 0000000000..89bfdb7a71 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/assetTransfer.ts @@ -0,0 +1,200 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + */ +import { ITraceableContract } from "./ITraceableContract"; +import { + Context, + Contract, + Info, + Returns, + Transaction, +} from "fabric-contract-api"; +import { Asset } from "./asset"; + +@Info({ + title: "AssetTransfer", + description: "Smart contract for trading assets", +}) +export class AssetTransferContract + extends Contract + implements ITraceableContract +{ + @Transaction() + public async InitLedger(ctx: Context): Promise { + const assets: Asset[] = [ + { + ID: "asset1", + Value: 1, + }, + { + ID: "asset2", + Value: 2, + }, + { + ID: "asset3", + Value: 3, + }, + { + ID: "asset4", + Value: 4, + }, + { + ID: "asset5", + Value: 5, + }, + { + ID: "asset6", + Value: 6, + }, + ]; + + for (const asset of assets) { + asset.docType = "asset"; + await ctx.stub.putState(asset.ID, Buffer.from(JSON.stringify(asset))); + console.info(`Asset ${asset.ID} initialized`); + } + } + + @Transaction() + public async InitLedgerV2(ctx: Context): Promise { + const assets: Asset[] = []; + for (let asset = 0; asset < 10; asset++) { + const assetName = "ASSET" + asset; + for (let state = 0; state < 10; state++) { + assets.push({ + ID: assetName, + Value: state, + }); + } + } + + for (const asset of assets) { + asset.docType = "asset"; + await ctx.stub.putState(asset.ID, Buffer.from(JSON.stringify(asset))); + console.info(`Asset ${asset.ID} initialized`); + } + } + // AssetExists returns true when asset with given ID exists in world state. + @Transaction(false) + @Returns("boolean") + public async AssetExists(ctx: Context, id: string): Promise { + const assetJSON = await ctx.stub.getState(id); + return assetJSON && assetJSON.length > 0; + } + + // CreateAsset issues a new asset to the world state with given details. + @Transaction() + public async CreateAsset( + ctx: Context, + id: string, + value: number, + ): Promise { + const asset = { + ID: id, + Value: value, + }; + await ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); + } + + // ReadAsset returns the asset stored in the world state with given id. + @Transaction(false) + public async ReadAsset(ctx: Context, id: string): Promise { + const assetJSON = await ctx.stub.getState(id); // get the asset from chaincode state + if (!assetJSON || assetJSON.length === 0) { + throw new Error(`The asset ${id} does not exist`); + } + return assetJSON.toString(); + } + + // UpdateAsset updates an existing asset in the world state with provided parameters. + @Transaction() + public async UpdateAsset( + ctx: Context, + id: string, + value: number, + ): Promise { + const exists = await this.AssetExists(ctx, id); + if (!exists) { + throw new Error(`The asset ${id} does not exist`); + } + + // overwriting original asset with new asset + const assetString = await this.ReadAsset(ctx, id); + const asset: Asset = JSON.parse(assetString); + asset.Value = value; + return ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); + } + + // GetAllAssets returns all assets found in the world state. + @Transaction(false) + @Returns("string") + public async GetAllAssets(ctx: Context): Promise { + const allResults = []; + // range query with empty string for startKey and endKey does an open-ended query of all assets in the chaincode namespace. + const iterator = await ctx.stub.getStateByRange("", ""); + let result = await iterator.next(); + while (!result.done) { + const strValue = Buffer.from(result.value.value.toString()).toString( + "utf8", + ); + let record; + try { + record = JSON.parse(strValue); + } catch (err) { + console.log(err); + record = strValue; + } + allResults.push({ Key: result.value.key, Record: record }); + result = await iterator.next(); + } + return JSON.stringify(allResults); + } + + // GetAllAssetsKey returns all assets key found in the world state. + @Transaction(false) + @Returns("string") + public async GetAllAssetsKey(ctx: Context): Promise { + const allResults = []; + // range query with empty string for startKey and endKey does an open-ended query of all assets in the chaincode namespace. + const iterator = await ctx.stub.getStateByRange("", ""); + let result = await iterator.next(); + while (!result.done) { + allResults.push(result.value.key); + result = await iterator.next(); + } + return allResults.toString(); + } + + // GetAllTxByKey returns all transations for a specific key. + @Transaction(false) + @Returns("string") + public async GetAllTxByKey(ctx: Context, key: string): Promise { + const allResults = []; + const iterator = await ctx.stub.getHistoryForKey(key); + let result = await iterator.next(); + while (!result.done) { + const strValue = JSON.stringify(result); + let record; + try { + record = JSON.parse(strValue); + } catch (err) { + console.log(err); + record = strValue; + } + allResults.push(record); + result = await iterator.next(); + } + return JSON.stringify(allResults); + } + + // // CreateAsset issues a new asset to the world state with given details. + // @Transaction() + // public async GetTransations(ctx: Context, id: string): Promise { + // const asset = { + // ID: id, + // }; + + // await ctx.stub.get; + // // await ctx.stub.putState(id, Buffer.from(JSON.stringify(asset))); + // } +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/index.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/index.ts new file mode 100644 index 0000000000..020a09f410 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/src/index.ts @@ -0,0 +1,9 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + */ + +import { AssetTransferContract } from "./assetTransfer"; + +export { AssetTransferContract } from "./assetTransfer"; + +export const contracts: any[] = [AssetTransferContract]; diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/tsconfig.json b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/tsconfig.json new file mode 100644 index 0000000000..80d8e12d8c --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/fabric-contracts/simple-asset/chaincode-typescript/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "outDir": "dist", + "target": "es2017", + "moduleResolution": "node", + "module": "commonjs", + "declaration": true, + "sourceMap": true + }, + "include": [ + "./src/**/*" + ], + "exclude": [ + "./src/**/*.spec.ts" + ] +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/besu-test-basic.test.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/besu-test-basic.test.ts new file mode 100644 index 0000000000..b9967b9c7e --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/besu-test-basic.test.ts @@ -0,0 +1,362 @@ +import { + IListenOptions, + LogLevelDesc, + LoggerProvider, + Secp256k1Keys, + Servers, +} from "@hyperledger/cactus-common"; +import "jest-extended"; +import LockAssetContractJson from "../solidity/lock-asset-contract/LockAsset.json"; + +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +import bodyParser from "body-parser"; + +import http, { Server } from "http"; +import { Server as SocketIoServer } from "socket.io"; + +import express from "express"; +import { AddressInfo } from "net"; +import { v4 as uuidv4 } from "uuid"; +import { + BesuTestLedger, + pruneDockerAllIfGithubAction, + Containers, +} from "@hyperledger/cactus-test-tooling"; +import { Constants } from "@hyperledger/cactus-core-api"; +import { + Web3SigningCredentialType, + PluginLedgerConnectorBesu, + EthContractInvocationType, + ReceiptType, + IPluginLedgerConnectorBesuOptions, + Web3SigningCredential, +} from "@hyperledger/cactus-plugin-ledger-connector-besu"; +import Web3 from "web3"; +import { Account } from "web3-core"; +import { + PluginBungeeHermes, + IPluginBungeeHermesOptions, +} from "../../../main/typescript/plugin-bungee-hermes"; + +import { + BesuNetworkDetails, + StrategyBesu, +} from "../../../main/typescript/strategy/strategy-besu"; + +const logLevel: LogLevelDesc = "INFO"; + +let besuLedger: BesuTestLedger; +let contractName: string; +//let besuServer: Server; + +let rpcApiHttpHost: string; +let rpcApiWsHost: string; +let web3: Web3; +let firstHighNetWorthAccount: string; +let connector: PluginLedgerConnectorBesu; +let besuKeyPair: { privateKey: string }; +let testEthAccount: Account; +const BESU_ASSET_ID = uuidv4(); + +const log = LoggerProvider.getOrCreate({ + level: logLevel, + label: "BUNGEE - Hermes", +}); +let besuPath: string; +let pluginBungeeHermesOptions: IPluginBungeeHermesOptions; +let besuServer: Server; + +let bungeeSigningCredential: Web3SigningCredential; +let bungeeKeychainId: string; +let bungeeContractAddress: string; + +let keychainPlugin: PluginKeychainMemory; + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + + { + besuLedger = new BesuTestLedger({ + logLevel, + emitContainerLogs: true, + envVars: ["BESU_NETWORK=dev"], + }); + await besuLedger.start(); + + rpcApiHttpHost = await besuLedger.getRpcApiHttpHost(); + rpcApiWsHost = await besuLedger.getRpcApiWsHost(); + web3 = new Web3(rpcApiHttpHost); + firstHighNetWorthAccount = besuLedger.getGenesisAccountPubKey(); + + testEthAccount = await besuLedger.createEthTestAccount(); + + besuKeyPair = { + privateKey: besuLedger.getGenesisAccountPrivKey(), + }; + + contractName = "LockAsset"; + + const keychainEntryValue = besuKeyPair.privateKey; + const keychainEntryKey = uuidv4(); + keychainPlugin = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + keychainPlugin.set( + LockAssetContractJson.contractName, + JSON.stringify(LockAssetContractJson), + ); + + const pluginRegistry = new PluginRegistry({ + plugins: [keychainPlugin], + }); + + const options: IPluginLedgerConnectorBesuOptions = { + instanceId: uuidv4(), + rpcApiHttpHost, + rpcApiWsHost, + pluginRegistry, + logLevel, + }; + connector = new PluginLedgerConnectorBesu(options); + pluginRegistry.add(connector); + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + besuServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 4000, + server: besuServer, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await connector.getOrCreateWebServices(); + const wsApi = new SocketIoServer(besuServer, { + path: Constants.SocketIoConnectionPathV1, + }); + await connector.registerWebServices(expressApp, wsApi); + besuPath = `http://${address}:${port}`; + + await connector.transact({ + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + consistencyStrategy: { + blockConfirmations: 0, + receiptType: ReceiptType.NodeTxPoolAck, + }, + transactionConfig: { + from: firstHighNetWorthAccount, + to: testEthAccount.address, + value: 10e9, + gas: 1000000, + }, + }); + const balance = await web3.eth.getBalance(testEthAccount.address); + expect(balance).toBeTruthy(); + expect(parseInt(balance, 10)).toBeGreaterThan(10e9); + + log.info("Connector initialized"); + + const deployOut = await connector.deployContract({ + keychainId: keychainPlugin.getKeychainId(), + contractName: LockAssetContractJson.contractName, + contractAbi: LockAssetContractJson.abi, + constructorArgs: [], + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + bytecode: LockAssetContractJson.bytecode, + gas: 1000000, + }); + expect(deployOut).toBeTruthy(); + expect(deployOut.transactionReceipt).toBeTruthy(); + expect(deployOut.transactionReceipt.contractAddress).toBeTruthy(); + log.info("Contract Deployed successfully"); + + const res = await connector.invokeContract({ + contractName, + keychainId: keychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "createAsset", + params: [BESU_ASSET_ID, 19], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + expect(res).toBeTruthy(); + expect(res.success).toBeTruthy(); + + const res3 = await connector.invokeContract({ + contractName, + keychainId: keychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Call, + methodName: "getAsset", + params: [BESU_ASSET_ID], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + expect(res3).toBeTruthy(); + expect(res3.success).toBeTruthy(); + expect(res3.callOutput.toString()).toBeTruthy(); + + bungeeSigningCredential = { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }; + bungeeKeychainId = keychainPlugin.getKeychainId(); + + bungeeContractAddress = deployOut.transactionReceipt + .contractAddress as string; + + pluginBungeeHermesOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + logLevel, + }; + } +}); + +test("test creation of views for different timeframes and states", async () => { + const bungee = new PluginBungeeHermes(pluginBungeeHermesOptions); + const strategy = "BESU"; + bungee.addStrategy(strategy, new StrategyBesu("INFO")); + const networkDetails: BesuNetworkDetails = { + signingCredential: bungeeSigningCredential, + contractName, + connectorApiPath: besuPath, + keychainId: bungeeKeychainId, + contractAddress: bungeeContractAddress, + participant: firstHighNetWorthAccount, + }; + + const snapshot = await bungee.generateSnapshot([], strategy, networkDetails); + const view = bungee.generateView( + snapshot, + "0", + Number.MAX_SAFE_INTEGER.toString(), + undefined, + ); + //expect to return a view + expect(view.view).toBeTruthy(); + expect(view.signature).toBeTruthy(); + + //expect the view to have capture the new asset BESU_ASSET_ID, and attributes to match + expect(snapshot.getStateBins().length).toEqual(1); + expect(snapshot.getStateBins()[0].getId()).toEqual(BESU_ASSET_ID); + expect(snapshot.getStateBins()[0].getTransactions().length).toEqual(1); + + const view1 = bungee.generateView(snapshot, "0", "9999", undefined); + + //expects nothing to limit time of 9999 + expect(view1.view).toBeUndefined(); + expect(view1.signature).toBeUndefined(); + + //changing BESU_ASSET_ID value + const lockAsset = await connector.invokeContract({ + contractName, + keychainId: keychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "lockAsset", + params: [BESU_ASSET_ID], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + expect(lockAsset).not.toBeUndefined(); + expect(lockAsset.success).toBeTrue(); + + //creating new asset + const new_asset_id = uuidv4(); + const depNew = await connector.invokeContract({ + contractName, + keychainId: keychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "createAsset", + params: [new_asset_id, 10], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + expect(depNew).not.toBeUndefined(); + expect(depNew.success).toBeTrue(); + + const snapshot1 = await bungee.generateSnapshot([], strategy, networkDetails); + const view2 = bungee.generateView( + snapshot1, + "0", + Number.MAX_SAFE_INTEGER.toString(), + undefined, + ); + //expect to return a view + expect(view2.view).toBeTruthy(); + expect(view2.signature).toBeTruthy(); + + const stateBins = snapshot1.getStateBins(); + expect(stateBins.length).toEqual(2); //expect to have captured state for both assets + + const bins = [stateBins[0].getId(), stateBins[1].getId()]; + + //checks if values match: + // - new value of BESU_ASSET_ID state in new snapshot different than value from old snapshot) + // - successfully captured transaction that created the new asset + if (bins[0] === BESU_ASSET_ID) { + expect(snapshot1.getStateBins()[0].getTransactions().length).toEqual(2); + expect(snapshot1.getStateBins()[0].getValue()).not.toEqual( + snapshot.getStateBins()[0].getValue(), + ); + expect(snapshot1.getStateBins()[1].getTransactions().length).toEqual(1); + } else { + expect(snapshot1.getStateBins()[0].getTransactions().length).toEqual(1); + expect(snapshot1.getStateBins()[1].getTransactions().length).toEqual(2); + expect(snapshot1.getStateBins()[1].getValue()).not.toEqual( + snapshot.getStateBins()[0].getValue(), + ); + } +}); + +afterAll(async () => { + await Servers.shutdown(besuServer); + await besuLedger.stop(); + await besuLedger.destroy(); + + await pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/besu-test-pruning.test.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/besu-test-pruning.test.ts new file mode 100644 index 0000000000..4171629bd0 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/besu-test-pruning.test.ts @@ -0,0 +1,333 @@ +import { + IListenOptions, + LogLevelDesc, + LoggerProvider, + Secp256k1Keys, + Servers, +} from "@hyperledger/cactus-common"; +import "jest-extended"; +import LockAssetContractJson from "../solidity/lock-asset-contract/LockAsset.json"; + +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +import bodyParser from "body-parser"; + +import http, { Server } from "http"; +import { Server as SocketIoServer } from "socket.io"; + +import express from "express"; +import { AddressInfo } from "net"; +import { v4 as uuidv4 } from "uuid"; +import { + BesuTestLedger, + pruneDockerAllIfGithubAction, + Containers, +} from "@hyperledger/cactus-test-tooling"; +import { Constants } from "@hyperledger/cactus-core-api"; +import { + Web3SigningCredentialType, + PluginLedgerConnectorBesu, + EthContractInvocationType, + ReceiptType, + IPluginLedgerConnectorBesuOptions, + Web3SigningCredential, +} from "@hyperledger/cactus-plugin-ledger-connector-besu"; +import Web3 from "web3"; +import { Account } from "web3-core"; +import { + PluginBungeeHermes, + IPluginBungeeHermesOptions, +} from "../../../main/typescript/plugin-bungee-hermes"; + +import { + BesuNetworkDetails, + StrategyBesu, +} from "../../../main/typescript/strategy/strategy-besu"; + +const logLevel: LogLevelDesc = "INFO"; + +let besuLedger: BesuTestLedger; +let contractName: string; +//let besuServer: Server; + +let rpcApiHttpHost: string; +let rpcApiWsHost: string; +let web3: Web3; +let firstHighNetWorthAccount: string; +let connector: PluginLedgerConnectorBesu; +let besuKeyPair: { privateKey: string }; +let testEthAccount: Account; +const BESU_ASSET_ID = uuidv4(); + +const log = LoggerProvider.getOrCreate({ + level: logLevel, + label: "BUNGEE - Hermes", +}); +let besuPath: string; +let pluginBungeeHermesOptions: IPluginBungeeHermesOptions; +let besuServer: Server; + +let bungeeSigningCredential: Web3SigningCredential; +let bungeeKeychainId: string; +let bungeeContractAddress: string; + +let keychainPlugin: PluginKeychainMemory; + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + + { + besuLedger = new BesuTestLedger({ + logLevel, + emitContainerLogs: true, + envVars: ["BESU_NETWORK=dev"], + }); + await besuLedger.start(); + + rpcApiHttpHost = await besuLedger.getRpcApiHttpHost(); + rpcApiWsHost = await besuLedger.getRpcApiWsHost(); + web3 = new Web3(rpcApiHttpHost); + firstHighNetWorthAccount = besuLedger.getGenesisAccountPubKey(); + + testEthAccount = await besuLedger.createEthTestAccount(); + + besuKeyPair = { + privateKey: besuLedger.getGenesisAccountPrivKey(), + }; + + contractName = "LockAsset"; + + const keychainEntryValue = besuKeyPair.privateKey; + const keychainEntryKey = uuidv4(); + keychainPlugin = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + keychainPlugin.set( + LockAssetContractJson.contractName, + JSON.stringify(LockAssetContractJson), + ); + + const pluginRegistry = new PluginRegistry({ + plugins: [keychainPlugin], + }); + + const options: IPluginLedgerConnectorBesuOptions = { + instanceId: uuidv4(), + rpcApiHttpHost, + rpcApiWsHost, + pluginRegistry, + logLevel, + }; + connector = new PluginLedgerConnectorBesu(options); + pluginRegistry.add(connector); + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + besuServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 4000, + server: besuServer, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await connector.getOrCreateWebServices(); + const wsApi = new SocketIoServer(besuServer, { + path: Constants.SocketIoConnectionPathV1, + }); + await connector.registerWebServices(expressApp, wsApi); + besuPath = `http://${address}:${port}`; + + await connector.transact({ + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + consistencyStrategy: { + blockConfirmations: 0, + receiptType: ReceiptType.NodeTxPoolAck, + }, + transactionConfig: { + from: firstHighNetWorthAccount, + to: testEthAccount.address, + value: 10e9, + gas: 1000000, + }, + }); + const balance = await web3.eth.getBalance(testEthAccount.address); + expect(balance).toBeTruthy(); + expect(parseInt(balance, 10)).toBeGreaterThan(10e9); + + log.info("Connector initialized"); + + const deployOut = await connector.deployContract({ + keychainId: keychainPlugin.getKeychainId(), + contractName: LockAssetContractJson.contractName, + contractAbi: LockAssetContractJson.abi, + constructorArgs: [], + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + bytecode: LockAssetContractJson.bytecode, + gas: 1000000, + }); + expect(deployOut).toBeTruthy(); + expect(deployOut.transactionReceipt).toBeTruthy(); + expect(deployOut.transactionReceipt.contractAddress).toBeTruthy(); + log.info("Contract Deployed successfully"); + + const res = await connector.invokeContract({ + contractName, + keychainId: keychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "createAsset", + params: [BESU_ASSET_ID, 19], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + expect(res).toBeTruthy(); + expect(res.success).toBeTruthy(); + + const res3 = await connector.invokeContract({ + contractName, + keychainId: keychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Call, + methodName: "getAsset", + params: [BESU_ASSET_ID], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + expect(res3).toBeTruthy(); + expect(res3.success).toBeTruthy(); + expect(res3.callOutput.toString()).toBeTruthy(); + + bungeeSigningCredential = { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }; + bungeeKeychainId = keychainPlugin.getKeychainId(); + + bungeeContractAddress = deployOut.transactionReceipt + .contractAddress as string; + + pluginBungeeHermesOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + logLevel, + }; + } +}); + +test("test creation of views for specific timeframes", async () => { + const bungee = new PluginBungeeHermes(pluginBungeeHermesOptions); + const strategy = "BESU"; + bungee.addStrategy(strategy, new StrategyBesu("INFO")); + const netwokDetails: BesuNetworkDetails = { + signingCredential: bungeeSigningCredential, + contractName, + connectorApiPath: besuPath, + keychainId: bungeeKeychainId, + contractAddress: bungeeContractAddress, + participant: firstHighNetWorthAccount, + }; + + const snapshot = await bungee.generateSnapshot([], strategy, netwokDetails); + const view = bungee.generateView( + snapshot, + "0", + Number.MAX_SAFE_INTEGER.toString(), + undefined, + ); + + //expect to return a view + expect(view.view).toBeTruthy(); + expect(view.signature).toBeTruthy(); + + //expect the view to have capture the new asset BESU_ASSET_ID, and attributes to match + expect(snapshot.getStateBins().length).toEqual(1); + expect(snapshot.getStateBins()[0].getId()).toEqual(BESU_ASSET_ID); + expect(snapshot.getStateBins()[0].getTransactions().length).toEqual(1); + + //changing BESU_ASSET_ID value + const lockAsset = await connector.invokeContract({ + contractName, + keychainId: keychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "lockAsset", + params: [BESU_ASSET_ID], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + expect(lockAsset).not.toBeUndefined(); + expect(lockAsset.success).toBeTrue(); + + const snapshot1 = await bungee.generateSnapshot([], strategy, netwokDetails); + + //tI is the time of the first transaction + 1 + const tI = ( + parseInt(snapshot.getStateBins()[0].getTransactions()[0].getTimeStamp()) + 1 + ).toString(); + + const view1 = bungee.generateView( + snapshot1, + tI, + Number.MAX_SAFE_INTEGER.toString(), + undefined, + ); + + //expect to return a view + expect(view1.view).toBeTruthy(); + expect(view1.signature).toBeTruthy(); + + expect(snapshot1.getStateBins().length).toEqual(1); + expect(snapshot1.getStateBins()[0].getId()).toEqual(BESU_ASSET_ID); + //expect the view to not include first transaction (made before tI) + expect(snapshot1.getStateBins()[0].getTransactions().length).toEqual(1); + //expect old and new snapshot state values to differ + expect(snapshot1.getStateBins()[0].getValue()).not.toEqual( + snapshot.getStateBins()[0].getValue(), + ); +}); + +afterAll(async () => { + await Servers.shutdown(besuServer); + await besuLedger.stop(); + await besuLedger.destroy(); + + await pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/bungee-api-test.test.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/bungee-api-test.test.ts new file mode 100644 index 0000000000..6f2af71084 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/bungee-api-test.test.ts @@ -0,0 +1,600 @@ +import { + IListenOptions, + LogLevelDesc, + LoggerProvider, + Secp256k1Keys, + Servers, +} from "@hyperledger/cactus-common"; +import "jest-extended"; +import LockAssetContractJson from "../solidity/lock-asset-contract/LockAsset.json"; + +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +import bodyParser from "body-parser"; + +import http, { Server } from "http"; +import { Server as SocketIoServer } from "socket.io"; +import fs from "fs-extra"; +import express from "express"; +import { AddressInfo } from "net"; +import { v4 as uuidv4 } from "uuid"; +import { + BesuTestLedger, + pruneDockerAllIfGithubAction, + Containers, + FabricTestLedgerV1, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, +} from "@hyperledger/cactus-test-tooling"; +import { Configuration, Constants } from "@hyperledger/cactus-core-api"; +import { + Web3SigningCredentialType, + PluginLedgerConnectorBesu, + EthContractInvocationType, + ReceiptType, + IPluginLedgerConnectorBesuOptions, + Web3SigningCredential, +} from "@hyperledger/cactus-plugin-ledger-connector-besu"; +import Web3 from "web3"; +import { Account } from "web3-core"; +import { + PluginBungeeHermes, + IPluginBungeeHermesOptions, +} from "../../../main/typescript/plugin-bungee-hermes"; +import { DefaultApi as BungeeApi } from "../../../main/typescript/generated/openapi/typescript-axios/api"; +import { + FabricSigningCredential, + PluginLedgerConnectorFabric, + DefaultApi as FabricApi, + DefaultEventHandlerStrategy, + IPluginLedgerConnectorFabricOptions, + ChainCodeProgrammingLanguage, + FabricContractInvocationType, + FileBase64, +} from "@hyperledger/cactus-plugin-ledger-connector-fabric"; +import path from "path"; +import { DiscoveryOptions } from "fabric-network"; +import { + FabricNetworkDetails, + StrategyFabric, +} from "../../../main/typescript/strategy/strategy-fabric"; +import { + BesuNetworkDetails, + StrategyBesu, +} from "../../../main/typescript/strategy/strategy-besu"; + +const logLevel: LogLevelDesc = "INFO"; + +let besuLedger: BesuTestLedger; +let besuContractName: string; +let besuPath: string; +let besuServer: Server; +let besuConnector: PluginLedgerConnectorBesu; +let besuKeyPair: { privateKey: string }; +let testEthAccount: Account; +let firstHighNetWorthAccount: string; +let besuKeychainPlugin: PluginKeychainMemory; +let besuSigningCredential: Web3SigningCredential; +let besuContractAddress: string; + +let rpcApiHttpHost: string; +let rpcApiWsHost: string; +let web3: Web3; +const BESU_ASSET_ID = uuidv4(); + +const log = LoggerProvider.getOrCreate({ + level: logLevel, + label: "BUNGEE - Hermes", +}); + +let fabricKeychainPlugin: PluginKeychainMemory; +let configFabric: Configuration; +let fabricLedger: FabricTestLedgerV1; +let fabricSigningCredential: FabricSigningCredential; +let fabricConnector: PluginLedgerConnectorFabric; +let fabricContractName: string; +let fabricChannelName: string; +let fabricPath: string; +let fabricApi: FabricApi; +let fabricServer: Server; +const FABRIC_ASSET_ID = uuidv4(); + +let pluginBungeeHermesOptions: IPluginBungeeHermesOptions; +let bungeeServer: Server; + +const BESU_STRATEGY = "BESU"; +const FABRIC_STRATEGY = "FABRIC"; + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + + { + log.info(await setupFabricTestLedger()); + log.info(await setupBesuTestLedger()); + } +}); + +test("tests bungee api using different strategies", async () => { + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + pluginBungeeHermesOptions = { + keyPair, + instanceId: uuidv4(), + logLevel, + }; + const bungee = new PluginBungeeHermes(pluginBungeeHermesOptions); + + //add both strategies to BUNGEE - Hermes + bungee.addStrategy(FABRIC_STRATEGY, new StrategyFabric("INFO")); + bungee.addStrategy(BESU_STRATEGY, new StrategyBesu("INFO")); + + //store network details for both networks + const besuNetworkDetails: BesuNetworkDetails = { + signingCredential: besuSigningCredential, + contractName: besuContractName, + connectorApiPath: besuPath, + keychainId: besuKeychainPlugin.getKeychainId(), + contractAddress: besuContractAddress, + participant: firstHighNetWorthAccount, + }; + const fabricNetworkDetails: FabricNetworkDetails = { + connectorApiPath: fabricPath, + signingCredential: fabricSigningCredential, + channelName: fabricChannelName, + contractName: fabricContractName, + participant: "Org1MSP", + }; + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + bungeeServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 3000, + server: bungeeServer, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await bungee.getOrCreateWebServices(); + await bungee.registerWebServices(expressApp); + const bungeePath = `http://${address}:${port}`; + + const config = new Configuration({ basePath: bungeePath }); + const bungeeApi = new BungeeApi(config); + + //View creation for both networks, using the respective strategies + + const viewFabric = await bungeeApi.createViewV1({ + strategyId: FABRIC_STRATEGY, + networkDetails: fabricNetworkDetails, + }); + //expect to return a view + expect(viewFabric.status).toEqual(200); + expect(viewFabric.data.view).toBeTruthy(); + + const viewBesu = await bungeeApi.createViewV1({ + strategyId: BESU_STRATEGY, + networkDetails: besuNetworkDetails, + }); + //expect to return a view + expect(viewBesu.status).toEqual(200); + expect(viewBesu.data.view).toBeTruthy(); + + const strategyReq = await bungeeApi.getAvailableStrategies(); + const pubKeyReq = await bungeeApi.getPublicKey(); + for (const strategy of strategyReq.data) { + expect([BESU_STRATEGY, FABRIC_STRATEGY]).toInclude(strategy); + } + expect(pubKeyReq.data).toEqual( + Buffer.from(keyPair.publicKey).toString("hex"), + ); +}); + +afterAll(async () => { + await Servers.shutdown(besuServer); + await Servers.shutdown(fabricServer); + await Servers.shutdown(bungeeServer); + await besuLedger.stop(); + await besuLedger.destroy(); + await fabricLedger.stop(); + await fabricLedger.destroy(); + + await pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); + +async function setupFabricTestLedger(): Promise { + const channelId = "mychannel"; + fabricChannelName = channelId; + + fabricLedger = new FabricTestLedgerV1({ + emitContainerLogs: true, + publishAllPorts: true, + imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), + logLevel, + }); + await fabricLedger.start(); + log.info("Fabric Ledger started"); + + const connectionProfile = await fabricLedger.getConnectionProfileOrg1(); + expect(connectionProfile).not.toBeUndefined(); + + const enrollAdminOut = await fabricLedger.enrollAdmin(); + const adminWallet = enrollAdminOut[1]; + const [userIdentity] = await fabricLedger.enrollUser(adminWallet); + const sshConfig = await fabricLedger.getSshConfig(); + + log.info("enrolled admin"); + + const keychainInstanceId = uuidv4(); + const keychainId = uuidv4(); + const keychainEntryKey = "user1"; + const keychainEntryValue = JSON.stringify(userIdentity); + + fabricKeychainPlugin = new PluginKeychainMemory({ + instanceId: keychainInstanceId, + keychainId, + logLevel, + backend: new Map([ + [keychainEntryKey, keychainEntryValue], + ["some-other-entry-key", "some-other-entry-value"], + ]), + }); + + const pluginRegistry = new PluginRegistry({ + plugins: [fabricKeychainPlugin], + }); + + const discoveryOptions: DiscoveryOptions = { + enabled: true, + asLocalhost: true, + }; + + const pluginOptions: IPluginLedgerConnectorFabricOptions = { + instanceId: uuidv4(), + dockerBinary: "/usr/local/bin/docker", + peerBinary: "/fabric-samples/bin/peer", + goBinary: "/usr/local/go/bin/go", + pluginRegistry, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + sshConfig, + logLevel: "INFO", + connectionProfile, + discoveryOptions, + eventHandlerOptions: { + strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx, + commitTimeout: 300, + }, + }; + + fabricConnector = new PluginLedgerConnectorFabric(pluginOptions); + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + fabricServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 4100, + server: fabricServer, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await fabricConnector.getOrCreateWebServices(); + await fabricConnector.registerWebServices(expressApp); + + log.info("Fabric Ledger connector check"); + + const apiUrl = `http://${address}:${port}`; + + fabricPath = apiUrl; + configFabric = new Configuration({ basePath: apiUrl }); + + fabricApi = new FabricApi(configFabric); + + fabricContractName = "basic-asset-transfer-2"; + const contractRelPath = + "../fabric-contracts/simple-asset/chaincode-typescript"; + const contractDir = path.join(__dirname, contractRelPath); + + // ├── package.json + // ├── src + // │ ├── assetTransfer.ts + // │ ├── asset.ts + // │ ├── index.ts + // │ └── ITraceableContract.ts + // ├── tsconfig.json + // -------- + const sourceFiles: FileBase64[] = []; + { + const filename = "./tsconfig.json"; + const relativePath = "./"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./package.json"; + const relativePath = "./"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./index.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./asset.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./assetTransfer.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./ITraceableContract.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + + const res = await fabricApi.deployContractV1({ + channelId, + ccVersion: "1.0.0", + sourceFiles, + ccName: fabricContractName, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, + ccLabel: "basic-asset-transfer-2", + ccLang: ChainCodeProgrammingLanguage.Typescript, + ccSequence: 1, + orderer: "orderer.example.com:7050", + ordererTLSHostnameOverride: "orderer.example.com", + connTimeout: 60, + }); + + const { packageIds, lifecycle, success } = res.data; + expect(res.status).toBe(200); + expect(success).toBe(true); + expect(lifecycle).not.toBeUndefined(); + + const { + approveForMyOrgList, + installList, + queryInstalledList, + commit, + packaging, + queryCommitted, + } = lifecycle; + + expect(packageIds).toBeTruthy(); + expect(packageIds).toBeArray(); + + expect(approveForMyOrgList).toBeTruthy(); + expect(approveForMyOrgList).toBeArray(); + + expect(installList).toBeTruthy(); + expect(installList).toBeArray(); + expect(queryInstalledList).toBeTruthy(); + expect(queryInstalledList).toBeArray(); + + expect(commit).toBeTruthy(); + expect(packaging).toBeTruthy(); + expect(queryCommitted).toBeTruthy(); + log.info("Fabric Contract deployed"); + + fabricSigningCredential = { + keychainId, + keychainRef: keychainEntryKey, + }; + + const createResponse = await fabricApi.runTransactionV1({ + contractName: fabricContractName, + channelName: fabricChannelName, + params: [FABRIC_ASSET_ID, "19"], + methodName: "CreateAsset", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(createResponse).not.toBeUndefined(); + expect(createResponse.status).toBeGreaterThan(199); + expect(createResponse.status).toBeLessThan(300); + + log.info( + `BassicAssetTransfer.Create(): ${JSON.stringify(createResponse.data)}`, + ); + return "Fabric Network setup successful"; +} +async function setupBesuTestLedger(): Promise { + besuLedger = new BesuTestLedger({ + logLevel, + emitContainerLogs: true, + envVars: ["BESU_NETWORK=dev"], + }); + await besuLedger.start(); + log.info("Besu test ledger initialized"); + rpcApiHttpHost = await besuLedger.getRpcApiHttpHost(); + rpcApiWsHost = await besuLedger.getRpcApiWsHost(); + web3 = new Web3(rpcApiHttpHost); + firstHighNetWorthAccount = besuLedger.getGenesisAccountPubKey(); + + testEthAccount = await besuLedger.createEthTestAccount(); + + besuKeyPair = { + privateKey: besuLedger.getGenesisAccountPrivKey(), + }; + + besuContractName = "LockAsset"; + + const keychainEntryValue = besuKeyPair.privateKey; + const keychainEntryKey = uuidv4(); + besuKeychainPlugin = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + + besuKeychainPlugin.set( + besuContractName, + JSON.stringify(LockAssetContractJson), + ); + + const pluginRegistry = new PluginRegistry({ + plugins: [besuKeychainPlugin], + }); + + const options: IPluginLedgerConnectorBesuOptions = { + instanceId: uuidv4(), + rpcApiHttpHost, + rpcApiWsHost, + pluginRegistry, + logLevel, + }; + + besuConnector = new PluginLedgerConnectorBesu(options); + pluginRegistry.add(besuConnector); + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + besuServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 4000, + server: besuServer, + }; + + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await besuConnector.getOrCreateWebServices(); + const wsApi = new SocketIoServer(besuServer, { + path: Constants.SocketIoConnectionPathV1, + }); + await besuConnector.registerWebServices(expressApp, wsApi); + besuPath = `http://${address}:${port}`; + log.info("Besu connector initialized"); + + await besuConnector.transact({ + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + consistencyStrategy: { + blockConfirmations: 0, + receiptType: ReceiptType.NodeTxPoolAck, + }, + transactionConfig: { + from: firstHighNetWorthAccount, + to: testEthAccount.address, + value: 10e9, + gas: 1000000, + }, + }); + const balance = await web3.eth.getBalance(testEthAccount.address); + expect(balance).toBeTruthy(); + expect(parseInt(balance, 10)).toBeGreaterThan(10e9); + + const deployOut = await besuConnector.deployContract({ + keychainId: besuKeychainPlugin.getKeychainId(), + contractName: besuContractName, + contractAbi: LockAssetContractJson.abi, + constructorArgs: [], + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + bytecode: LockAssetContractJson.bytecode, + gas: 1000000, + }); + expect(deployOut).toBeTruthy(); + expect(deployOut.transactionReceipt).toBeTruthy(); + expect(deployOut.transactionReceipt.contractAddress).toBeTruthy(); + log.info("Besu contract Deployed successfully"); + + const res = await besuConnector.invokeContract({ + contractName: besuContractName, + keychainId: besuKeychainPlugin.getKeychainId(), + invocationType: EthContractInvocationType.Send, + methodName: "createAsset", + params: [BESU_ASSET_ID, 19], + signingCredential: { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + gas: 1000000, + }); + expect(res).toBeTruthy(); + expect(res.success).toBeTruthy(); + + log.info("Besu asset created successfully"); + + besuSigningCredential = { + ethAccount: firstHighNetWorthAccount, + secret: besuKeyPair.privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }; + besuContractAddress = deployOut.transactionReceipt.contractAddress as string; + return "Besu Network setup successful"; +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/fabric-test-basic.test.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/fabric-test-basic.test.ts new file mode 100644 index 0000000000..08c49cbf6a --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/fabric-test-basic.test.ts @@ -0,0 +1,462 @@ +import { + IListenOptions, + LogLevelDesc, + LoggerProvider, + Secp256k1Keys, + Servers, +} from "@hyperledger/cactus-common"; +import "jest-extended"; + +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +import { DiscoveryOptions } from "fabric-network"; +import bodyParser from "body-parser"; +import path from "path"; + +import http, { Server } from "http"; + +import fs from "fs-extra"; + +import { + Configuration, + DefaultEventHandlerStrategy, + FabricSigningCredential, + IPluginLedgerConnectorFabricOptions, + PluginLedgerConnectorFabric, + DefaultApi as FabricApi, + FileBase64, + ChainCodeProgrammingLanguage, + FabricContractInvocationType, +} from "@hyperledger/cactus-plugin-ledger-connector-fabric"; +import { + Containers, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + FabricTestLedgerV1, + pruneDockerAllIfGithubAction, +} from "@hyperledger/cactus-test-tooling"; +import express from "express"; +import { AddressInfo } from "net"; + +import { v4 as uuidv4 } from "uuid"; +import { + PluginBungeeHermes, + IPluginBungeeHermesOptions, +} from "../../../main/typescript/plugin-bungee-hermes"; +import { + FabricNetworkDetails, + StrategyFabric, +} from "../../../main/typescript/strategy/strategy-fabric"; + +let fabricServer: Server; + +let fabricSigningCredential: FabricSigningCredential; +const logLevel: LogLevelDesc = "INFO"; + +let fabricLedger: FabricTestLedgerV1; +let fabricContractName: string; +let fabricChannelName: string; +let fabricPath: string; + +let configFabric: Configuration; +let apiClient: FabricApi; + +let fabricConnector: PluginLedgerConnectorFabric; +let pluginBungeeFabricOptions: IPluginBungeeHermesOptions; +let pluginBungee: PluginBungeeHermes; +const FABRIC_ASSET_ID = uuidv4(); + +let networkDetails: FabricNetworkDetails; + +const log = LoggerProvider.getOrCreate({ + level: logLevel, + label: "BUNGEE - Hermes", +}); + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + + { + // Fabric ledger connection + const channelId = "mychannel"; + fabricChannelName = channelId; + + fabricLedger = new FabricTestLedgerV1({ + emitContainerLogs: true, + publishAllPorts: true, + imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), + logLevel, + }); + + await fabricLedger.start(); + log.info("Fabric Ledger started"); + + const connectionProfile = await fabricLedger.getConnectionProfileOrg1(); + expect(connectionProfile).not.toBeUndefined(); + + const enrollAdminOut = await fabricLedger.enrollAdmin(); + const adminWallet = enrollAdminOut[1]; + const [userIdentity] = await fabricLedger.enrollUser(adminWallet); + const sshConfig = await fabricLedger.getSshConfig(); + + log.info("enrolled admin"); + + const keychainInstanceId = uuidv4(); + const keychainId = uuidv4(); + const keychainEntryKey = "user1"; + const keychainEntryValue = JSON.stringify(userIdentity); + + const keychainPlugin = new PluginKeychainMemory({ + instanceId: keychainInstanceId, + keychainId, + logLevel, + backend: new Map([ + [keychainEntryKey, keychainEntryValue], + ["some-other-entry-key", "some-other-entry-value"], + ]), + }); + + const pluginRegistry = new PluginRegistry({ plugins: [keychainPlugin] }); + + const discoveryOptions: DiscoveryOptions = { + enabled: true, + asLocalhost: true, + }; + + const pluginOptions: IPluginLedgerConnectorFabricOptions = { + instanceId: uuidv4(), + dockerBinary: "/usr/local/bin/docker", + peerBinary: "/fabric-samples/bin/peer", + goBinary: "/usr/local/go/bin/go", + pluginRegistry, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + sshConfig, + logLevel: "INFO", + connectionProfile, + discoveryOptions, + eventHandlerOptions: { + strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx, + commitTimeout: 300, + }, + }; + + fabricConnector = new PluginLedgerConnectorFabric(pluginOptions); + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + fabricServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 3000, + server: fabricServer, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await fabricConnector.getOrCreateWebServices(); + await fabricConnector.registerWebServices(expressApp); + + log.info("Fabric Ledger connector check"); + + const apiUrl = `http://${address}:${port}`; + + fabricPath = apiUrl; + configFabric = new Configuration({ basePath: apiUrl }); + + apiClient = new FabricApi(configFabric); + + // deploy contracts ... + fabricContractName = "basic-asset-transfer-2"; + const contractRelPath = + "../fabric-contracts/simple-asset/chaincode-typescript"; + const contractDir = path.join(__dirname, contractRelPath); + + // ├── package.json + // ├── src + // │ ├── assetTransfer.ts + // │ ├── asset.ts + // │ ├── index.ts + // │ └── ITraceableContract.ts + // ├── tsconfig.json + // -------- + const sourceFiles: FileBase64[] = []; + { + const filename = "./tsconfig.json"; + const relativePath = "./"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./package.json"; + const relativePath = "./"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./index.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./asset.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./assetTransfer.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./ITraceableContract.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + + const res = await apiClient.deployContractV1({ + channelId, + ccVersion: "1.0.0", + sourceFiles, + ccName: fabricContractName, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, + ccLabel: "basic-asset-transfer-2", + ccLang: ChainCodeProgrammingLanguage.Typescript, + ccSequence: 1, + orderer: "orderer.example.com:7050", + ordererTLSHostnameOverride: "orderer.example.com", + connTimeout: 60, + }); + + const { packageIds, lifecycle, success } = res.data; + expect(res.status).toBe(200); + expect(success).toBe(true); + expect(lifecycle).not.toBeUndefined(); + + const { + approveForMyOrgList, + installList, + queryInstalledList, + commit, + packaging, + queryCommitted, + } = lifecycle; + + expect(packageIds).toBeTruthy(); + expect(packageIds).toBeArray(); + + expect(approveForMyOrgList).toBeTruthy(); + expect(approveForMyOrgList).toBeArray(); + + expect(installList).toBeTruthy(); + expect(installList).toBeArray(); + expect(queryInstalledList).toBeTruthy(); + expect(queryInstalledList).toBeArray(); + + expect(commit).toBeTruthy(); + expect(packaging).toBeTruthy(); + expect(queryCommitted).toBeTruthy(); + log.info("Contract deployed"); + + fabricSigningCredential = { + keychainId, + keychainRef: keychainEntryKey, + }; + const createResponse = await apiClient.runTransactionV1({ + contractName: fabricContractName, + channelName: fabricChannelName, + params: [FABRIC_ASSET_ID, "19"], + methodName: "CreateAsset", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(createResponse).not.toBeUndefined(); + expect(createResponse.status).toBeGreaterThan(199); + expect(createResponse.status).toBeLessThan(300); + + log.info( + `BassicAssetTransfer.Create(): ${JSON.stringify(createResponse.data)}`, + ); + + pluginBungeeFabricOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + }; + + networkDetails = { + connectorApiPath: fabricPath, + signingCredential: fabricSigningCredential, + channelName: fabricChannelName, + contractName: fabricContractName, + participant: "Org1MSP", + }; + + pluginBungee = new PluginBungeeHermes(pluginBungeeFabricOptions); + } +}); + +test("test creation of views for different timeframes and states", async () => { + const strategy = "FABRIC"; + pluginBungee.addStrategy(strategy, new StrategyFabric("INFO")); + + const snapshot = await pluginBungee.generateSnapshot( + [], + strategy, + networkDetails, + ); + const view = pluginBungee.generateView( + snapshot, + "0", + Number.MAX_SAFE_INTEGER.toString(), + undefined, + ); + + //expect to return a view + expect(view.view).toBeTruthy(); + expect(view.signature).toBeTruthy(); + + //expect the view to have capture the new asset Fabric_ASSET_ID, and attributes to match + expect(snapshot.getStateBins().length).toEqual(1); + expect(snapshot.getStateBins()[0].getId()).toEqual(FABRIC_ASSET_ID); + expect(snapshot.getStateBins()[0].getTransactions().length).toEqual(1); + + //fabric transaction proofs include endorsements + expect( + snapshot.getStateBins()[0].getTransactions()[0].getProof().getEndorsements() + ?.length, + ).toEqual(2); + + //no valid states for this time frame + const view1 = pluginBungee.generateView(snapshot, "0", "9999", undefined); + expect(view1.view).toBeUndefined(); + expect(view1.signature).toBeUndefined(); + + //creating new asset + const new_asset_id = uuidv4(); + const createResponse = await apiClient.runTransactionV1({ + contractName: fabricContractName, + channelName: fabricChannelName, + params: [new_asset_id, "10"], + methodName: "CreateAsset", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + expect(createResponse).not.toBeUndefined(); + expect(createResponse.status).toBeGreaterThan(199); + expect(createResponse.status).toBeLessThan(300); + + //changing FABRIC_ASSET_ID value + const modifyResponse = await apiClient.runTransactionV1({ + contractName: fabricContractName, + channelName: fabricChannelName, + params: [FABRIC_ASSET_ID, "18"], + methodName: "UpdateAsset", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + expect(modifyResponse).not.toBeUndefined(); + expect(modifyResponse.status).toBeGreaterThan(199); + expect(modifyResponse.status).toBeLessThan(300); + + const snapshot1 = await pluginBungee.generateSnapshot( + [], + strategy, + networkDetails, + ); + const view2 = pluginBungee.generateView( + snapshot1, + "0", + Number.MAX_SAFE_INTEGER.toString(), + undefined, + ); + + //expect to return a view + expect(view2.view).toBeTruthy(); + expect(view2.signature).toBeTruthy(); + + //expect to have captured state for both assets + const stateBins = snapshot1.getStateBins(); + expect(stateBins.length).toEqual(2); + const bins = [stateBins[0].getId(), stateBins[1].getId()]; + + expect(bins.includes(FABRIC_ASSET_ID)).toBeTrue(); + expect(bins.includes(new_asset_id)).toBeTrue(); + + //checks if values match: + // - new value of FABRIC_ASSET_ID state in new snapshot equals to new value) + // - successfully captured transaction that created the new asset + if (bins[0] === FABRIC_ASSET_ID) { + expect(snapshot1.getStateBins()[0].getTransactions().length).toEqual(2); + expect(snapshot1.getStateBins()[0].getValue()).toEqual("18"); + expect(snapshot1.getStateBins()[1].getTransactions().length).toEqual(1); + } else { + expect(snapshot1.getStateBins()[0].getTransactions().length).toEqual(1); + expect(snapshot1.getStateBins()[1].getTransactions().length).toEqual(2); + expect(snapshot1.getStateBins()[1].getValue()).toEqual("18"); + } +}); + +afterAll(async () => { + await fabricLedger.stop(); + await fabricLedger.destroy(); + await Servers.shutdown(fabricServer); + + await pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/fabric-test-pruning.test.ts b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/fabric-test-pruning.test.ts new file mode 100644 index 0000000000..4bc26c4727 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/integration/fabric-test-pruning.test.ts @@ -0,0 +1,441 @@ +import { + IListenOptions, + LogLevelDesc, + LoggerProvider, + Secp256k1Keys, + Servers, +} from "@hyperledger/cactus-common"; +import "jest-extended"; + +import { PluginRegistry } from "@hyperledger/cactus-core"; +import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +import { DiscoveryOptions } from "fabric-network"; +import bodyParser from "body-parser"; +import path from "path"; + +import http, { Server } from "http"; + +import fs from "fs-extra"; + +import { + Configuration, + DefaultEventHandlerStrategy, + FabricSigningCredential, + IPluginLedgerConnectorFabricOptions, + PluginLedgerConnectorFabric, + DefaultApi as FabricApi, + FileBase64, + ChainCodeProgrammingLanguage, + FabricContractInvocationType, +} from "@hyperledger/cactus-plugin-ledger-connector-fabric"; +import { + Containers, + FABRIC_25_LTS_AIO_FABRIC_VERSION, + FABRIC_25_LTS_AIO_IMAGE_VERSION, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + FabricTestLedgerV1, + pruneDockerAllIfGithubAction, +} from "@hyperledger/cactus-test-tooling"; +import express from "express"; +import { AddressInfo } from "net"; + +import { v4 as uuidv4 } from "uuid"; +import { + FabricNetworkDetails, + StrategyFabric, +} from "../../../main/typescript/strategy/strategy-fabric"; +import { + IPluginBungeeHermesOptions, + PluginBungeeHermes, +} from "../../../main/typescript/plugin-bungee-hermes"; + +let fabricServer: Server; + +let fabricSigningCredential: FabricSigningCredential; +const logLevel: LogLevelDesc = "INFO"; + +let fabricLedger: FabricTestLedgerV1; +let fabricContractName: string; +let fabricChannelName: string; +let fabricPath: string; + +let configFabric: Configuration; +let apiClient: FabricApi; + +let fabricConnector: PluginLedgerConnectorFabric; +let pluginBungeeFabricOptions: IPluginBungeeHermesOptions; +let pluginBungee: PluginBungeeHermes; +const FABRIC_ASSET_ID = uuidv4(); + +let networkDetails: FabricNetworkDetails; + +const log = LoggerProvider.getOrCreate({ + level: logLevel, + label: "BUNGEE - Hermes", +}); + +beforeAll(async () => { + pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); + + { + // Fabric ledger connection + const channelId = "mychannel"; + fabricChannelName = channelId; + + fabricLedger = new FabricTestLedgerV1({ + emitContainerLogs: true, + publishAllPorts: true, + imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one", + imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION, + envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]), + logLevel, + }); + + await fabricLedger.start(); + log.info("Fabric Ledger started"); + + const connectionProfile = await fabricLedger.getConnectionProfileOrg1(); + expect(connectionProfile).not.toBeUndefined(); + + const enrollAdminOut = await fabricLedger.enrollAdmin(); + const adminWallet = enrollAdminOut[1]; + const [userIdentity] = await fabricLedger.enrollUser(adminWallet); + const sshConfig = await fabricLedger.getSshConfig(); + + log.info("enrolled admin"); + + const keychainInstanceId = uuidv4(); + const keychainId = uuidv4(); + const keychainEntryKey = "user1"; + const keychainEntryValue = JSON.stringify(userIdentity); + + const keychainPlugin = new PluginKeychainMemory({ + instanceId: keychainInstanceId, + keychainId, + logLevel, + backend: new Map([ + [keychainEntryKey, keychainEntryValue], + ["some-other-entry-key", "some-other-entry-value"], + ]), + }); + + const pluginRegistry = new PluginRegistry({ plugins: [keychainPlugin] }); + + const discoveryOptions: DiscoveryOptions = { + enabled: true, + asLocalhost: true, + }; + + const pluginOptions: IPluginLedgerConnectorFabricOptions = { + instanceId: uuidv4(), + dockerBinary: "/usr/local/bin/docker", + peerBinary: "/fabric-samples/bin/peer", + goBinary: "/usr/local/go/bin/go", + pluginRegistry, + cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + sshConfig, + logLevel: "INFO", + connectionProfile, + discoveryOptions, + eventHandlerOptions: { + strategy: DefaultEventHandlerStrategy.NetworkScopeAllfortx, + commitTimeout: 300, + }, + }; + + fabricConnector = new PluginLedgerConnectorFabric(pluginOptions); + + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + fabricServer = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "127.0.0.1", + port: 3000, + server: fabricServer, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + const { address, port } = addressInfo; + + await fabricConnector.getOrCreateWebServices(); + await fabricConnector.registerWebServices(expressApp); + + log.info("Fabric Ledger connector check"); + + const apiUrl = `http://${address}:${port}`; + + fabricPath = apiUrl; + configFabric = new Configuration({ basePath: apiUrl }); + + apiClient = new FabricApi(configFabric); + + // deploy contracts ... + fabricContractName = "basic-asset-transfer-2"; + const contractRelPath = + "../fabric-contracts/simple-asset/chaincode-typescript"; + const contractDir = path.join(__dirname, contractRelPath); + + // ├── package.json + // ├── src + // │ ├── assetTransfer.ts + // │ ├── asset.ts + // │ ├── index.ts + // │ └── ITraceableContract.ts + // ├── tsconfig.json + // -------- + const sourceFiles: FileBase64[] = []; + { + const filename = "./tsconfig.json"; + const relativePath = "./"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./package.json"; + const relativePath = "./"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./index.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./asset.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./assetTransfer.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + { + const filename = "./ITraceableContract.ts"; + const relativePath = "./src/"; + const filePath = path.join(contractDir, relativePath, filename); + const buffer = await fs.readFile(filePath); + sourceFiles.push({ + body: buffer.toString("base64"), + filepath: relativePath, + filename, + }); + } + + const res = await apiClient.deployContractV1({ + channelId, + ccVersion: "1.0.0", + sourceFiles, + ccName: fabricContractName, + targetOrganizations: [ + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1, + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2, + ], + caFile: + FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE, + ccLabel: "basic-asset-transfer-2", + ccLang: ChainCodeProgrammingLanguage.Typescript, + ccSequence: 1, + orderer: "orderer.example.com:7050", + ordererTLSHostnameOverride: "orderer.example.com", + connTimeout: 60, + }); + + const { packageIds, lifecycle, success } = res.data; + expect(res.status).toBe(200); + expect(success).toBe(true); + expect(lifecycle).not.toBeUndefined(); + + const { + approveForMyOrgList, + installList, + queryInstalledList, + commit, + packaging, + queryCommitted, + } = lifecycle; + + expect(packageIds).toBeTruthy(); + expect(packageIds).toBeArray(); + + expect(approveForMyOrgList).toBeTruthy(); + expect(approveForMyOrgList).toBeArray(); + + expect(installList).toBeTruthy(); + expect(installList).toBeArray(); + expect(queryInstalledList).toBeTruthy(); + expect(queryInstalledList).toBeArray(); + + expect(commit).toBeTruthy(); + expect(packaging).toBeTruthy(); + expect(queryCommitted).toBeTruthy(); + log.info("Contract deployed"); + + fabricSigningCredential = { + keychainId, + keychainRef: keychainEntryKey, + }; + const createResponse = await apiClient.runTransactionV1({ + contractName: fabricContractName, + channelName: fabricChannelName, + params: [FABRIC_ASSET_ID, "19"], + methodName: "CreateAsset", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + + expect(createResponse).not.toBeUndefined(); + expect(createResponse.status).toBeGreaterThan(199); + expect(createResponse.status).toBeLessThan(300); + + log.info( + `BassicAssetTransfer.Create(): ${JSON.stringify(createResponse.data)}`, + ); + + pluginBungeeFabricOptions = { + keyPair: Secp256k1Keys.generateKeyPairsBuffer(), + instanceId: uuidv4(), + }; + + networkDetails = { + connectorApiPath: fabricPath, + signingCredential: fabricSigningCredential, + channelName: fabricChannelName, + contractName: fabricContractName, + participant: "Org1MSP", + }; + + pluginBungee = new PluginBungeeHermes(pluginBungeeFabricOptions); + } +}); + +test("test creation of views for specific timeframes", async () => { + const strategy = "FABRIC"; + pluginBungee.addStrategy(strategy, new StrategyFabric("INFO")); + + const snapshot = await pluginBungee.generateSnapshot( + [], + strategy, + networkDetails, + ); + const view = pluginBungee.generateView( + snapshot, + "0", + Number.MAX_SAFE_INTEGER.toString(), + undefined, + ); + //expect to return a view + expect(view.view).toBeTruthy(); + expect(view.signature).toBeTruthy(); + + //expect the view to have capture the new asset FABRIC_ASSET_ID, and attributes to match + expect(snapshot.getStateBins().length).toEqual(1); + expect(snapshot.getStateBins()[0].getId()).toEqual(FABRIC_ASSET_ID); + expect(snapshot.getStateBins()[0].getTransactions().length).toEqual(1); + //fabric transaction proofs include endorsements + expect( + snapshot.getStateBins()[0].getTransactions()[0].getProof().getEndorsements() + ?.length, + ).toEqual(2); + + //changing FABRIC_ASSET_ID value + const modifyResponse = await apiClient.runTransactionV1({ + contractName: fabricContractName, + channelName: fabricChannelName, + params: [FABRIC_ASSET_ID, "18"], + methodName: "UpdateAsset", + invocationType: FabricContractInvocationType.Send, + signingCredential: fabricSigningCredential, + }); + expect(modifyResponse).not.toBeUndefined(); + expect(modifyResponse.status).toBeGreaterThan(199); + expect(modifyResponse.status).toBeLessThan(300); + + const snapshot1 = await pluginBungee.generateSnapshot( + [], + strategy, + networkDetails, + ); + + //tI is the time of the first transaction +1 + const tI = ( + parseInt(snapshot.getStateBins()[0].getTransactions()[0].getTimeStamp()) + 1 + ).toString(); + + expect(snapshot1.getStateBins().length).toEqual(1); + expect(snapshot1.getStateBins()[0].getId()).toEqual(FABRIC_ASSET_ID); + expect(snapshot1.getStateBins()[0].getTransactions().length).toEqual(2); + expect(snapshot1.getStateBins()[0].getValue()).not.toEqual( + snapshot.getStateBins()[0].getValue(), + ); + const view1 = pluginBungee.generateView( + snapshot1, + tI, + Number.MAX_SAFE_INTEGER.toString(), + undefined, + ); + + //expect to return a view + expect(view1.view).toBeTruthy(); + expect(view1.signature).toBeTruthy(); + + expect(snapshot1.getStateBins().length).toEqual(1); + expect(snapshot1.getStateBins()[0].getId()).toEqual(FABRIC_ASSET_ID); + //expect the view to not include first transaction (made before tI) + expect(snapshot1.getStateBins()[0].getTransactions().length).toEqual(1); + //expect old and new snapshot state values to differ + expect(snapshot1.getStateBins()[0].getValue()).not.toEqual( + snapshot.getStateBins()[0].getValue(), + ); +}); + +afterAll(async () => { + await fabricLedger.stop(); + await fabricLedger.destroy(); + await Servers.shutdown(fabricServer); + + await pruneDockerAllIfGithubAction({ logLevel }) + .then(() => { + log.info("Pruning throw OK"); + }) + .catch(async () => { + await Containers.logDiagnostics({ logLevel }); + fail("Pruning didn't throw OK"); + }); +}); diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/ITraceableContract.sol b/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/ITraceableContract.sol new file mode 100644 index 0000000000..1e10d5f55d --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/ITraceableContract.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: UNKNOWN +pragma solidity >=0.7.0; + +interface ITraceableContract { + //All transactions that change the state of and asset, should emmit this event + event Changed(string indexed id, bytes[] value); + + //Should return a list of asset IDs to be tracked by Bungee + function getAllAssetsIDs() external view returns (string[] memory); +} diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/LockAsset.json b/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/LockAsset.json new file mode 100644 index 0000000000..69cde87a01 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/LockAsset.json @@ -0,0 +1,3865 @@ +{ + "contractName": "LockAsset", + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "string", + "name": "id", + "type": "string" + }, + { + "indexed": false, + "internalType": "address", + "name": "creator", + "type": "address" + }, + { + "indexed": false, + "internalType": "bool", + "name": "isLock", + "type": "bool" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "size", + "type": "uint256" + } + ], + "name": "Transaction", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "id", + "type": "string" + }, + { + "internalType": "uint256", + "name": "size", + "type": "uint256" + } + ], + "name": "createAsset", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "id", + "type": "string" + } + ], + "name": "deleteAsset", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getAllAssetsIDs", + "outputs": [ + { + "internalType": "string[]", + "name": "", + "type": "string[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "id", + "type": "string" + } + ], + "name": "getAsset", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "creator", + "type": "address" + }, + { + "internalType": "bool", + "name": "isLock", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "size", + "type": "uint256" + } + ], + "internalType": "struct Asset", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "id", + "type": "string" + } + ], + "name": "isAssetLocked", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "id", + "type": "string" + } + ], + "name": "isPresent", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "id", + "type": "string" + } + ], + "name": "lockAsset", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "id", + "type": "string" + } + ], + "name": "unLockAsset", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "metadata": "{\"compiler\":{\"version\":\"0.8.19+commit.7dd6d404\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"string\",\"name\":\"id\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"creator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"isLock\",\"type\":\"bool\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"size\",\"type\":\"uint256\"}],\"name\":\"Transaction\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"id\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"size\",\"type\":\"uint256\"}],\"name\":\"createAsset\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"id\",\"type\":\"string\"}],\"name\":\"deleteAsset\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getAllAssetsIDs\",\"outputs\":[{\"internalType\":\"string[]\",\"name\":\"\",\"type\":\"string[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"id\",\"type\":\"string\"}],\"name\":\"getAsset\",\"outputs\":[{\"components\":[{\"internalType\":\"address\",\"name\":\"creator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"isLock\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"size\",\"type\":\"uint256\"}],\"internalType\":\"struct Asset\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"id\",\"type\":\"string\"}],\"name\":\"isAssetLocked\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"id\",\"type\":\"string\"}],\"name\":\"isPresent\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"id\",\"type\":\"string\"}],\"name\":\"lockAsset\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"id\",\"type\":\"string\"}],\"name\":\"unLockAsset\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"/workspaces/blockchain-integration-framework/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/lock-asset.sol\":\"LockAsset\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"/workspaces/blockchain-integration-framework/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/lock-asset.sol\":{\"keccak256\":\"0x8666cf45ca92a56370f20b5391bb801cd826f57cbfde5e717dadade9d5ed5582\",\"urls\":[\"bzz-raw://91cc30b4b79e7d9219ee39dc6d24abadc78d66d0dd650af3818cb406cf60b083\",\"dweb:/ipfs/QmV7pQLQ6WPGgEwFa1dAzn4ZxDm8ZwyikiG9aB2Dn7bbCe\"]}},\"version\":1}", + "bytecode": "608060405234801561001057600080fd5b50610b16806100206000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c8063cd5286d01161005b578063cd5286d0146100f2578063db9cc41014610132578063def60e0d14610145578063e24aa37c1461015857600080fd5b80631ae4eb681461008d5780635137b8a7146100b55780635e82d0a6146100ca578063bc548275146100df575b600080fd5b6100a061009b366004610850565b61016b565b60405190151581526020015b60405180910390f35b6100bd6101d5565b6040516100ac9190610892565b6100dd6100d8366004610850565b6102ae565b005b6100a06100ed366004610850565b610404565b610105610100366004610850565b610433565b6040805182516001600160a01b0316815260208084015115159082015291810151908201526060016100ac565b6100dd610140366004610924565b6104ab565b6100dd610153366004610850565b610606565b6100dd610166366004610850565b61064c565b60008060018484604051610180929190610970565b9081526040519081900360200190205460ff1690508061019f57600080fd5b600084846040516101b1929190610970565b9081526040519081900360200190205460ff600160a01b9091041691505092915050565b60606002805480602002602001604051908101604052809291908181526020016000905b828210156102a557838290600052602060002001805461021890610980565b80601f016020809104026020016040519081016040528092919081815260200182805461024490610980565b80156102915780601f1061026657610100808354040283529160200191610291565b820191906000526020600020905b81548152906001019060200180831161027457829003601f168201915b5050505050815260200190600101906101f9565b50505050905090565b6000600183836040516102c2929190610970565b9081526040519081900360200190205460ff169050806102e157600080fd5b6001600084846040516102f5929190610970565b9081526040519081900360200181208054921515600160a01b0260ff60a01b199093169290921790915561032c9084908490610970565b60405180910390207f9db172bd887aec98e834d86fb9ff0f1549ae602b8ca8ba1ee50902e4d502b9a060008585604051610367929190610970565b908152604051908190036020018120546001600160a01b0316906000906103919088908890610970565b9081526040519081900360200181205460ff600160a01b90910416906000906103bd9089908990610970565b908152604051908190036020018120600101546103f79392916001600160a01b039390931683529015156020830152604082015260600190565b60405180910390a2505050565b600060018383604051610418929190610970565b9081526040519081900360200190205460ff16905092915050565b604080516060810182526000808252602082018190529181019190915260008383604051610462929190610970565b908152604080516020928190038301812060608201835280546001600160a01b0381168352600160a01b900460ff16151593820193909352600190920154908201529392505050565b600081116104b857600080fd5b80600084846040516104cb929190610970565b90815260200160405180910390206001018190555033600084846040516104f3929190610970565b90815260405190819003602001812080546001600160a01b03939093166001600160a01b03199093169290921790915560009081906105359086908690610970565b9081526040519081900360200181208054921515600160a01b0260ff60a01b199093169290921790915560019061056f9085908590610970565b9081526040519081900360200190205460ff166105c557600280546001810182556000919091527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace016105c3838583610a1f565b505b60018084846040516105d8929190610970565b908152604051908190036020018120805492151560ff199093169290921790915561032c9084908490610970565b60006001838360405161061a929190610970565b9081526040519081900360200190205460ff1690508061063957600080fd5b60008084846040516102f5929190610970565b600060018383604051610660929190610970565b9081526040519081900360200190205460ff1690508061067f57600080fd5b6000808484604051610692929190610970565b9081526040519081900360200190205460ff600160a01b909104169050806106b957600080fd5b600084846040516106cb929190610970565b90815260405190819003602001812080546001600160a81b031916815560006001918201819055916107009087908790610970565b908152604051908190036020018120805492151560ff199093169290921790915561072e9085908590610970565b60405180910390207f9db172bd887aec98e834d86fb9ff0f1549ae602b8ca8ba1ee50902e4d502b9a060008686604051610769929190610970565b908152604051908190036020018120546001600160a01b0316906000906107939089908990610970565b9081526040519081900360200181205460ff600160a01b90910416906000906107bf908a908a90610970565b908152604051908190036020018120600101546107f99392916001600160a01b039390931683529015156020830152604082015260600190565b60405180910390a250505050565b60008083601f84011261081957600080fd5b50813567ffffffffffffffff81111561083157600080fd5b60208301915083602082850101111561084957600080fd5b9250929050565b6000806020838503121561086357600080fd5b823567ffffffffffffffff81111561087a57600080fd5b61088685828601610807565b90969095509350505050565b6000602080830181845280855180835260408601915060408160051b87010192508387016000805b8381101561091657888603603f1901855282518051808852835b818110156108ef578281018a01518982018b015289016108d4565b508781018901849052601f01601f19169096018701955093860193918601916001016108ba565b509398975050505050505050565b60008060006040848603121561093957600080fd5b833567ffffffffffffffff81111561095057600080fd5b61095c86828701610807565b909790965060209590950135949350505050565b8183823760009101908152919050565b600181811c9082168061099457607f821691505b6020821081036109b457634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b601f821115610a1a57600081815260208120601f850160051c810160208610156109f75750805b601f850160051c820191505b81811015610a1657828155600101610a03565b5050505b505050565b67ffffffffffffffff831115610a3757610a376109ba565b610a4b83610a458354610980565b836109d0565b6000601f841160018114610a7f5760008515610a675750838201355b600019600387901b1c1916600186901b178355610ad9565b600083815260209020601f19861690835b82811015610ab05786850135825560209485019460019092019101610a90565b5086821015610acd5760001960f88860031b161c19848701351681555b505060018560011b0183555b505050505056fea26469706673582212204c18d4a504a078fca73e2c1077682b64833c90d807d1ce81a44c14d72869897d64736f6c63430008130033", + "deployedBytecode": "608060405234801561001057600080fd5b50600436106100885760003560e01c8063cd5286d01161005b578063cd5286d0146100f2578063db9cc41014610132578063def60e0d14610145578063e24aa37c1461015857600080fd5b80631ae4eb681461008d5780635137b8a7146100b55780635e82d0a6146100ca578063bc548275146100df575b600080fd5b6100a061009b366004610850565b61016b565b60405190151581526020015b60405180910390f35b6100bd6101d5565b6040516100ac9190610892565b6100dd6100d8366004610850565b6102ae565b005b6100a06100ed366004610850565b610404565b610105610100366004610850565b610433565b6040805182516001600160a01b0316815260208084015115159082015291810151908201526060016100ac565b6100dd610140366004610924565b6104ab565b6100dd610153366004610850565b610606565b6100dd610166366004610850565b61064c565b60008060018484604051610180929190610970565b9081526040519081900360200190205460ff1690508061019f57600080fd5b600084846040516101b1929190610970565b9081526040519081900360200190205460ff600160a01b9091041691505092915050565b60606002805480602002602001604051908101604052809291908181526020016000905b828210156102a557838290600052602060002001805461021890610980565b80601f016020809104026020016040519081016040528092919081815260200182805461024490610980565b80156102915780601f1061026657610100808354040283529160200191610291565b820191906000526020600020905b81548152906001019060200180831161027457829003601f168201915b5050505050815260200190600101906101f9565b50505050905090565b6000600183836040516102c2929190610970565b9081526040519081900360200190205460ff169050806102e157600080fd5b6001600084846040516102f5929190610970565b9081526040519081900360200181208054921515600160a01b0260ff60a01b199093169290921790915561032c9084908490610970565b60405180910390207f9db172bd887aec98e834d86fb9ff0f1549ae602b8ca8ba1ee50902e4d502b9a060008585604051610367929190610970565b908152604051908190036020018120546001600160a01b0316906000906103919088908890610970565b9081526040519081900360200181205460ff600160a01b90910416906000906103bd9089908990610970565b908152604051908190036020018120600101546103f79392916001600160a01b039390931683529015156020830152604082015260600190565b60405180910390a2505050565b600060018383604051610418929190610970565b9081526040519081900360200190205460ff16905092915050565b604080516060810182526000808252602082018190529181019190915260008383604051610462929190610970565b908152604080516020928190038301812060608201835280546001600160a01b0381168352600160a01b900460ff16151593820193909352600190920154908201529392505050565b600081116104b857600080fd5b80600084846040516104cb929190610970565b90815260200160405180910390206001018190555033600084846040516104f3929190610970565b90815260405190819003602001812080546001600160a01b03939093166001600160a01b03199093169290921790915560009081906105359086908690610970565b9081526040519081900360200181208054921515600160a01b0260ff60a01b199093169290921790915560019061056f9085908590610970565b9081526040519081900360200190205460ff166105c557600280546001810182556000919091527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace016105c3838583610a1f565b505b60018084846040516105d8929190610970565b908152604051908190036020018120805492151560ff199093169290921790915561032c9084908490610970565b60006001838360405161061a929190610970565b9081526040519081900360200190205460ff1690508061063957600080fd5b60008084846040516102f5929190610970565b600060018383604051610660929190610970565b9081526040519081900360200190205460ff1690508061067f57600080fd5b6000808484604051610692929190610970565b9081526040519081900360200190205460ff600160a01b909104169050806106b957600080fd5b600084846040516106cb929190610970565b90815260405190819003602001812080546001600160a81b031916815560006001918201819055916107009087908790610970565b908152604051908190036020018120805492151560ff199093169290921790915561072e9085908590610970565b60405180910390207f9db172bd887aec98e834d86fb9ff0f1549ae602b8ca8ba1ee50902e4d502b9a060008686604051610769929190610970565b908152604051908190036020018120546001600160a01b0316906000906107939089908990610970565b9081526040519081900360200181205460ff600160a01b90910416906000906107bf908a908a90610970565b908152604051908190036020018120600101546107f99392916001600160a01b039390931683529015156020830152604082015260600190565b60405180910390a250505050565b60008083601f84011261081957600080fd5b50813567ffffffffffffffff81111561083157600080fd5b60208301915083602082850101111561084957600080fd5b9250929050565b6000806020838503121561086357600080fd5b823567ffffffffffffffff81111561087a57600080fd5b61088685828601610807565b90969095509350505050565b6000602080830181845280855180835260408601915060408160051b87010192508387016000805b8381101561091657888603603f1901855282518051808852835b818110156108ef578281018a01518982018b015289016108d4565b508781018901849052601f01601f19169096018701955093860193918601916001016108ba565b509398975050505050505050565b60008060006040848603121561093957600080fd5b833567ffffffffffffffff81111561095057600080fd5b61095c86828701610807565b909790965060209590950135949350505050565b8183823760009101908152919050565b600181811c9082168061099457607f821691505b6020821081036109b457634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b601f821115610a1a57600081815260208120601f850160051c810160208610156109f75750805b601f850160051c820191505b81811015610a1657828155600101610a03565b5050505b505050565b67ffffffffffffffff831115610a3757610a376109ba565b610a4b83610a458354610980565b836109d0565b6000601f841160018114610a7f5760008515610a675750838201355b600019600387901b1c1916600186901b178355610ad9565b600083815260209020601f19861690835b82811015610ab05786850135825560209485019460019092019101610a90565b5086821015610acd5760001960f88860031b161c19848701351681555b505060018560011b0183555b505050505056fea26469706673582212204c18d4a504a078fca73e2c1077682b64833c90d807d1ce81a44c14d72869897d64736f6c63430008130033", + "sourceMap": "543:2046:0:-:0;;;;;;;;;;;;;;;;;;;", + "deployedSourceMap": "543:2046:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2267:231;;;;;;:::i;:::-;;:::i;:::-;;;948:14:1;;941:22;923:41;;911:2;896:18;2267:231:0;;;;;;;;2502:85;;;:::i;:::-;;;;;;;:::i;1253:229::-;;;;;;:::i;:::-;;:::i;:::-;;2162:101;;;;;;:::i;:::-;;:::i;1107:103::-;;;;;;:::i;:::-;;:::i;:::-;;;;2391:13:1;;-1:-1:-1;;;;;2387:39:1;2369:58;;2497:4;2485:17;;;2479:24;2472:32;2465:40;2443:20;;;2436:70;2550:17;;;2544:24;2522:20;;;2515:54;2357:2;2342:18;1107:103:0;2183:392:1;743:360:0;;;;;;:::i;:::-;;:::i;1527:232::-;;;;;;:::i;:::-;;:::i;1763:395::-;;;;;;:::i;:::-;;:::i;2267:231::-;2331:4;2345:11;2359;2371:2;;2359:15;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;-1:-1:-1;2359:15:0;2382;;;;;;2476:6;2483:2;;2476:10;;;;;;;:::i;:::-;;;;;;;;;;;;;;:17;;-1:-1:-1;;;2476:17:0;;;;;-1:-1:-1;;2267:231:0;;;;:::o;2502:85::-;2550:15;2579:3;2572:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2502:85;:::o;1253:229::-;1307:11;1321;1333:2;;1321:15;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;-1:-1:-1;1321:15:0;1344;;;;;;1388:4;1368:6;1375:2;;1368:10;;;;;;;:::i;:::-;;;;;;;;;;;;;;:24;;;;;-1:-1:-1;;;1368:24:0;-1:-1:-1;;;;1368:24:0;;;;;;;;;;1405:71;;1417:2;;;;1405:71;:::i;:::-;;;;;;;;;1421:6;1428:2;;1421:10;;;;;;;:::i;:::-;;;;;;;;;;;;;;:18;-1:-1:-1;;;;;1421:18:0;;;;1441:10;;1448:2;;;;1441:10;:::i;:::-;;;;;;;;;;;;;;:17;;-1:-1:-1;;;1441:17:0;;;;;;;1460:10;;1467:2;;;;1460:10;:::i;:::-;;;;;;;;;;;;;;:15;;;1405:71;;;;-1:-1:-1;;;;;3941:32:1;;;;3923:51;;4017:14;;4010:22;4005:2;3990:18;;3983:50;4064:2;4049:18;;4042:34;3911:2;3896:18;;3727:355;1405:71:0;;;;;;;;1299:183;1253:229;;:::o;2162:101::-;2222:4;2243:11;2255:2;;2243:15;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;-1:-1:-1;2162:101:0;;;;:::o;1107:103::-;-1:-1:-1;;;;;;;;;;;;;;;;;;;;;;;;;1195:6:0;1202:2;;1195:10;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;1188:17;;;;;;;-1:-1:-1;;;;;1188:17:0;;;;-1:-1:-1;;;1188:17:0;;;;;;;;;;;;;;;;;;;;;;1195:10;1107:103;-1:-1:-1;;;1107:103:0:o;743:360::-;822:1;817:4;:6;809:15;;;;;;849:4;832:6;839:2;;832:10;;;;;;;:::i;:::-;;;;;;;;;;;;;:15;;:21;;;;882:10;861:6;868:2;;861:10;;;;;;;:::i;:::-;;;;;;;;;;;;;;:31;;-1:-1:-1;;;;;861:31:0;;;;-1:-1:-1;;;;;;861:31:0;;;;;;;;;;:18;;;;900:10;;907:2;;;;900:10;:::i;:::-;;;;;;;;;;;;;;:25;;;;;-1:-1:-1;;;900:25:0;-1:-1:-1;;;;900:25:0;;;;;;;;;;-1:-1:-1;;938:15:0;;950:2;;;;938:15;:::i;:::-;;;;;;;;;;;;;;;;;933:52;;964:3;:12;;;;;;;-1:-1:-1;964:12:0;;;;;;;973:2;;964:12;;:::i;:::-;;933:52;1010:4;992:11;1004:2;;992:15;;;;;;;:::i;:::-;;;;;;;;;;;;;;:22;;;;;-1:-1:-1;;992:22:0;;;;;;;;;;1027:71;;1039:2;;;;1027:71;:::i;1527:232::-;1583:11;1597;1609:2;;1597:15;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;-1:-1:-1;1597:15:0;1620;;;;;;1664:5;1644:6;1651:2;;1644:10;;;;;;;:::i;1763:395::-;1819:11;1833;1845:2;;1833:15;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;-1:-1:-1;1833:15:0;1856;;;;;;1943:18;1964:6;1971:2;;1964:10;;;;;;;:::i;:::-;;;;;;;;;;;;;;:17;;-1:-1:-1;;;1964:17:0;;;;;-1:-1:-1;1964:17:0;1989:22;;;;;;2027:6;2034:2;;2027:10;;;;;;;:::i;:::-;;;;;;;;;;;;;;2020:17;;-1:-1:-1;;;;;;2020:17:0;;;2027:10;2020:17;;;;;;;2027:10;2045:15;;2057:2;;;;2045:15;:::i;:::-;;;;;;;;;;;;;;:23;;;;;-1:-1:-1;;2045:23:0;;;;;;;;;;2081:71;;2093:2;;;;2081:71;:::i;:::-;;;;;;;;;2097:6;2104:2;;2097:10;;;;;;;:::i;:::-;;;;;;;;;;;;;;:18;-1:-1:-1;;;;;2097:18:0;;;;2117:10;;2124:2;;;;2117:10;:::i;:::-;;;;;;;;;;;;;;:17;;-1:-1:-1;;;2117:17:0;;;;;;;2136:10;;2143:2;;;;2136:10;:::i;:::-;;;;;;;;;;;;;;:15;;;2081:71;;;;-1:-1:-1;;;;;3941:32:1;;;;3923:51;;4017:14;;4010:22;4005:2;3990:18;;3983:50;4064:2;4049:18;;4042:34;3911:2;3896:18;;3727:355;2081:71:0;;;;;;;;1811:347;;1763:395;;:::o;14:348:1:-;66:8;76:6;130:3;123:4;115:6;111:17;107:27;97:55;;148:1;145;138:12;97:55;-1:-1:-1;171:20:1;;214:18;203:30;;200:50;;;246:1;243;236:12;200:50;283:4;275:6;271:17;259:29;;335:3;328:4;319:6;311;307:19;303:30;300:39;297:59;;;352:1;349;342:12;297:59;14:348;;;;;:::o;367:411::-;438:6;446;499:2;487:9;478:7;474:23;470:32;467:52;;;515:1;512;505:12;467:52;555:9;542:23;588:18;580:6;577:30;574:50;;;620:1;617;610:12;574:50;659:59;710:7;701:6;690:9;686:22;659:59;:::i;:::-;737:8;;633:85;;-1:-1:-1;367:411:1;-1:-1:-1;;;;367:411:1:o;975:1203::-;1137:4;1166:2;1206;1195:9;1191:18;1236:2;1225:9;1218:21;1259:6;1294;1288:13;1325:6;1317;1310:22;1363:2;1352:9;1348:18;1341:25;;1425:2;1415:6;1412:1;1408:14;1397:9;1393:30;1389:39;1375:53;;1463:2;1455:6;1451:15;1484:1;1505;1515:634;1531:6;1526:3;1523:15;1515:634;;;1600:22;;;-1:-1:-1;;1596:36:1;1584:49;;1656:13;;1698:9;;1720:24;;;1768:1;1782:157;1798:8;1793:3;1790:17;1782:157;;;1906:12;;;1902:21;;1896:28;1873:16;;;1869:25;;1862:63;1817:12;;1782:157;;;-1:-1:-1;1963:21:1;;;1959:30;;1952:41;;;2059:2;2036:17;-1:-1:-1;;2032:31:1;2020:44;;;2016:53;;;-1:-1:-1;2127:12:1;;;;2092:15;;;;1557:1;1548:11;1515:634;;;-1:-1:-1;2166:6:1;;975:1203;-1:-1:-1;;;;;;;;975:1203:1:o;2580:479::-;2660:6;2668;2676;2729:2;2717:9;2708:7;2704:23;2700:32;2697:52;;;2745:1;2742;2735:12;2697:52;2785:9;2772:23;2818:18;2810:6;2807:30;2804:50;;;2850:1;2847;2840:12;2804:50;2889:59;2940:7;2931:6;2920:9;2916:22;2889:59;:::i;:::-;2967:8;;2863:85;;-1:-1:-1;3049:2:1;3034:18;;;;3021:32;;2580:479;-1:-1:-1;;;;2580:479:1:o;3064:273::-;3249:6;3241;3236:3;3223:33;3205:3;3275:16;;3300:13;;;3275:16;3064:273;-1:-1:-1;3064:273:1:o;3342:380::-;3421:1;3417:12;;;;3464;;;3485:61;;3539:4;3531:6;3527:17;3517:27;;3485:61;3592:2;3584:6;3581:14;3561:18;3558:38;3555:161;;3638:10;3633:3;3629:20;3626:1;3619:31;3673:4;3670:1;3663:15;3701:4;3698:1;3691:15;3555:161;;3342:380;;;:::o;4087:127::-;4148:10;4143:3;4139:20;4136:1;4129:31;4179:4;4176:1;4169:15;4203:4;4200:1;4193:15;4345:545;4447:2;4442:3;4439:11;4436:448;;;4483:1;4508:5;4504:2;4497:17;4553:4;4549:2;4539:19;4623:2;4611:10;4607:19;4604:1;4600:27;4594:4;4590:38;4659:4;4647:10;4644:20;4641:47;;;-1:-1:-1;4682:4:1;4641:47;4737:2;4732:3;4728:12;4725:1;4721:20;4715:4;4711:31;4701:41;;4792:82;4810:2;4803:5;4800:13;4792:82;;;4855:17;;;4836:1;4825:13;4792:82;;;4796:3;;;4436:448;4345:545;;;:::o;5066:1206::-;5190:18;5185:3;5182:27;5179:53;;;5212:18;;:::i;:::-;5241:94;5331:3;5291:38;5323:4;5317:11;5291:38;:::i;:::-;5285:4;5241:94;:::i;:::-;5361:1;5386:2;5381:3;5378:11;5403:1;5398:616;;;;6058:1;6075:3;6072:93;;;-1:-1:-1;6131:19:1;;;6118:33;6072:93;-1:-1:-1;;5023:1:1;5019:11;;;5015:24;5011:29;5001:40;5047:1;5043:11;;;4998:57;6178:78;;5371:895;;5398:616;4292:1;4285:14;;;4329:4;4316:18;;-1:-1:-1;;5434:17:1;;;5535:9;5557:229;5571:7;5568:1;5565:14;5557:229;;;5660:19;;;5647:33;5632:49;;5767:4;5752:20;;;;5720:1;5708:14;;;;5587:12;5557:229;;;5561:3;5814;5805:7;5802:16;5799:159;;;5938:1;5934:6;5928:3;5922;5919:1;5915:11;5911:21;5907:34;5903:39;5890:9;5885:3;5881:19;5868:33;5864:79;5856:6;5849:95;5799:159;;;6001:1;5995:3;5992:1;5988:11;5984:19;5978:4;5971:33;5371:895;;;5066:1206;;;:::o", + "sourcePath": "/workspaces/blockchain-integration-framework/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/lock-asset.sol", + "compiler": { + "name": "solc", + "version": "0.8.19+commit.7dd6d404" + }, + "ast": { + "absolutePath": "/workspaces/blockchain-integration-framework/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/lock-asset.sol", + "exportedSymbols": { + "Asset": [ + 8 + ], + "LockAsset": [ + 290 + ] + }, + "id": 291, + "nodeType": "SourceUnit", + "nodes": [ + { + "id": 1, + "literals": [ + "solidity", + ">=", + "0.7", + ".0" + ], + "nodeType": "PragmaDirective", + "src": "413:24:0" + }, + { + "canonicalName": "Asset", + "id": 8, + "members": [ + { + "constant": false, + "id": 3, + "mutability": "mutable", + "name": "creator", + "nameLocation": "464:7:0", + "nodeType": "VariableDeclaration", + "scope": 8, + "src": "456:15:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + }, + "typeName": { + "id": 2, + "name": "address", + "nodeType": "ElementaryTypeName", + "src": "456:7:0", + "stateMutability": "nonpayable", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + "visibility": "internal" + }, + { + "constant": false, + "id": 5, + "mutability": "mutable", + "name": "isLock", + "nameLocation": "482:6:0", + "nodeType": "VariableDeclaration", + "scope": 8, + "src": "477:11:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 4, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "477:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + }, + { + "constant": false, + "id": 7, + "mutability": "mutable", + "name": "size", + "nameLocation": "499:4:0", + "nodeType": "VariableDeclaration", + "scope": 8, + "src": "494:9:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + }, + "typeName": { + "id": 6, + "name": "uint", + "nodeType": "ElementaryTypeName", + "src": "494:4:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "visibility": "internal" + } + ], + "name": "Asset", + "nameLocation": "445:5:0", + "nodeType": "StructDefinition", + "scope": 291, + "src": "438:68:0", + "visibility": "public" + }, + { + "abstract": false, + "baseContracts": [], + "canonicalName": "LockAsset", + "contractDependencies": [], + "contractKind": "contract", + "fullyImplemented": true, + "id": 290, + "linearizedBaseContracts": [ + 290 + ], + "name": "LockAsset", + "nameLocation": "552:9:0", + "nodeType": "ContractDefinition", + "nodes": [ + { + "constant": false, + "id": 13, + "mutability": "mutable", + "name": "assets", + "nameLocation": "592:6:0", + "nodeType": "VariableDeclaration", + "scope": 290, + "src": "566:32:0", + "stateVariable": true, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string => struct Asset)" + }, + "typeName": { + "id": 12, + "keyName": "", + "keyNameLocation": "-1:-1:-1", + "keyType": { + "id": 9, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "575:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "nodeType": "Mapping", + "src": "566:25:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string => struct Asset)" + }, + "valueName": "", + "valueNameLocation": "-1:-1:-1", + "valueType": { + "id": 11, + "nodeType": "UserDefinedTypeName", + "pathNode": { + "id": 10, + "name": "Asset", + "nameLocations": [ + "585:5:0" + ], + "nodeType": "IdentifierPath", + "referencedDeclaration": 8, + "src": "585:5:0" + }, + "referencedDeclaration": 8, + "src": "585:5:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage_ptr", + "typeString": "struct Asset" + } + } + }, + "visibility": "internal" + }, + { + "constant": false, + "id": 17, + "mutability": "mutable", + "name": "assetExists", + "nameLocation": "627:11:0", + "nodeType": "VariableDeclaration", + "scope": 290, + "src": "602:36:0", + "stateVariable": true, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string => bool)" + }, + "typeName": { + "id": 16, + "keyName": "", + "keyNameLocation": "-1:-1:-1", + "keyType": { + "id": 14, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "611:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "nodeType": "Mapping", + "src": "602:24:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string => bool)" + }, + "valueName": "", + "valueNameLocation": "-1:-1:-1", + "valueType": { + "id": 15, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "621:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + } + }, + "visibility": "internal" + }, + { + "constant": false, + "id": 20, + "mutability": "mutable", + "name": "ids", + "nameLocation": "651:3:0", + "nodeType": "VariableDeclaration", + "scope": 290, + "src": "642:12:0", + "stateVariable": true, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_array$_t_string_storage_$dyn_storage", + "typeString": "string[]" + }, + "typeName": { + "baseType": { + "id": 18, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "642:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "id": 19, + "nodeType": "ArrayTypeName", + "src": "642:8:0", + "typeDescriptions": { + "typeIdentifier": "t_array$_t_string_storage_$dyn_storage_ptr", + "typeString": "string[]" + } + }, + "visibility": "internal" + }, + { + "anonymous": false, + "eventSelector": "9db172bd887aec98e834d86fb9ff0f1549ae602b8ca8ba1ee50902e4d502b9a0", + "id": 30, + "name": "Transaction", + "nameLocation": "667:11:0", + "nodeType": "EventDefinition", + "parameters": { + "id": 29, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 22, + "indexed": true, + "mutability": "mutable", + "name": "id", + "nameLocation": "694:2:0", + "nodeType": "VariableDeclaration", + "scope": 30, + "src": "679:17:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_string_memory_ptr", + "typeString": "string" + }, + "typeName": { + "id": 21, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "679:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + }, + { + "constant": false, + "id": 24, + "indexed": false, + "mutability": "mutable", + "name": "creator", + "nameLocation": "706:7:0", + "nodeType": "VariableDeclaration", + "scope": 30, + "src": "698:15:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + }, + "typeName": { + "id": 23, + "name": "address", + "nodeType": "ElementaryTypeName", + "src": "698:7:0", + "stateMutability": "nonpayable", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + "visibility": "internal" + }, + { + "constant": false, + "id": 26, + "indexed": false, + "mutability": "mutable", + "name": "isLock", + "nameLocation": "720:6:0", + "nodeType": "VariableDeclaration", + "scope": 30, + "src": "715:11:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 25, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "715:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + }, + { + "constant": false, + "id": 28, + "indexed": false, + "mutability": "mutable", + "name": "size", + "nameLocation": "733:4:0", + "nodeType": "VariableDeclaration", + "scope": 30, + "src": "728:9:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + }, + "typeName": { + "id": 27, + "name": "uint", + "nodeType": "ElementaryTypeName", + "src": "728:4:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "visibility": "internal" + } + ], + "src": "678:60:0" + }, + "src": "661:78:0" + }, + { + "body": { + "id": 99, + "nodeType": "Block", + "src": "801:302:0", + "statements": [ + { + "expression": { + "arguments": [ + { + "commonType": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + }, + "id": 40, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftExpression": { + "id": 38, + "name": "size", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 34, + "src": "817:4:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "nodeType": "BinaryOperation", + "operator": ">", + "rightExpression": { + "hexValue": "30", + "id": 39, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "number", + "lValueRequested": false, + "nodeType": "Literal", + "src": "822:1:0", + "typeDescriptions": { + "typeIdentifier": "t_rational_0_by_1", + "typeString": "int_const 0" + }, + "value": "0" + }, + "src": "817:6:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + ], + "id": 37, + "name": "require", + "nodeType": "Identifier", + "overloadedDeclarations": [ + 4294967278, + 4294967278 + ], + "referencedDeclaration": 4294967278, + "src": "809:7:0", + "typeDescriptions": { + "typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$", + "typeString": "function (bool) pure" + } + }, + "id": 41, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "809:15:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 42, + "nodeType": "ExpressionStatement", + "src": "809:15:0" + }, + { + "expression": { + "id": 48, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftHandSide": { + "expression": { + "baseExpression": { + "id": 43, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "832:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 45, + "indexExpression": { + "id": 44, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "839:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "832:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 46, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": true, + "memberLocation": "843:4:0", + "memberName": "size", + "nodeType": "MemberAccess", + "referencedDeclaration": 7, + "src": "832:15:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "nodeType": "Assignment", + "operator": "=", + "rightHandSide": { + "id": 47, + "name": "size", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 34, + "src": "849:4:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "src": "832:21:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "id": 49, + "nodeType": "ExpressionStatement", + "src": "832:21:0" + }, + { + "expression": { + "id": 56, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftHandSide": { + "expression": { + "baseExpression": { + "id": 50, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "861:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 52, + "indexExpression": { + "id": 51, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "868:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "861:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 53, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": true, + "memberLocation": "872:7:0", + "memberName": "creator", + "nodeType": "MemberAccess", + "referencedDeclaration": 3, + "src": "861:18:0", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + "nodeType": "Assignment", + "operator": "=", + "rightHandSide": { + "expression": { + "id": 54, + "name": "msg", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 4294967281, + "src": "882:3:0", + "typeDescriptions": { + "typeIdentifier": "t_magic_message", + "typeString": "msg" + } + }, + "id": 55, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "memberLocation": "886:6:0", + "memberName": "sender", + "nodeType": "MemberAccess", + "src": "882:10:0", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + "src": "861:31:0", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + "id": 57, + "nodeType": "ExpressionStatement", + "src": "861:31:0" + }, + { + "expression": { + "id": 63, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftHandSide": { + "expression": { + "baseExpression": { + "id": 58, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "900:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 60, + "indexExpression": { + "id": 59, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "907:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "900:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 61, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": true, + "memberLocation": "911:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "900:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "Assignment", + "operator": "=", + "rightHandSide": { + "hexValue": "66616c7365", + "id": 62, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "bool", + "lValueRequested": false, + "nodeType": "Literal", + "src": "920:5:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "value": "false" + }, + "src": "900:25:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "id": 64, + "nodeType": "ExpressionStatement", + "src": "900:25:0" + }, + { + "condition": { + "id": 68, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "nodeType": "UnaryOperation", + "operator": "!", + "prefix": true, + "src": "937:16:0", + "subExpression": { + "baseExpression": { + "id": 65, + "name": "assetExists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 17, + "src": "938:11:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string memory => bool)" + } + }, + "id": 67, + "indexExpression": { + "id": 66, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "950:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "938:15:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "id": 76, + "nodeType": "IfStatement", + "src": "933:52:0", + "trueBody": { + "id": 75, + "nodeType": "Block", + "src": "954:31:0", + "statements": [ + { + "expression": { + "arguments": [ + { + "id": 72, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "973:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + ], + "expression": { + "id": 69, + "name": "ids", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 20, + "src": "964:3:0", + "typeDescriptions": { + "typeIdentifier": "t_array$_t_string_storage_$dyn_storage", + "typeString": "string storage ref[] storage ref" + } + }, + "id": 71, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "memberLocation": "968:4:0", + "memberName": "push", + "nodeType": "MemberAccess", + "src": "964:8:0", + "typeDescriptions": { + "typeIdentifier": "t_function_arraypush_nonpayable$_t_array$_t_string_storage_$dyn_storage_ptr_$_t_string_storage_$returns$__$attached_to$_t_array$_t_string_storage_$dyn_storage_ptr_$", + "typeString": "function (string storage ref[] storage pointer,string storage ref)" + } + }, + "id": 73, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "964:12:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 74, + "nodeType": "ExpressionStatement", + "src": "964:12:0" + } + ] + } + }, + { + "expression": { + "id": 81, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftHandSide": { + "baseExpression": { + "id": 77, + "name": "assetExists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 17, + "src": "992:11:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string memory => bool)" + } + }, + "id": 79, + "indexExpression": { + "id": 78, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "1004:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": true, + "nodeType": "IndexAccess", + "src": "992:15:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "Assignment", + "operator": "=", + "rightHandSide": { + "hexValue": "74727565", + "id": 80, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "bool", + "lValueRequested": false, + "nodeType": "Literal", + "src": "1010:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "value": "true" + }, + "src": "992:22:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "id": 82, + "nodeType": "ExpressionStatement", + "src": "992:22:0" + }, + { + "eventCall": { + "arguments": [ + { + "id": 84, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "1039:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + { + "expression": { + "baseExpression": { + "id": 85, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1043:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 87, + "indexExpression": { + "id": 86, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "1050:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1043:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 88, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1054:7:0", + "memberName": "creator", + "nodeType": "MemberAccess", + "referencedDeclaration": 3, + "src": "1043:18:0", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + { + "expression": { + "baseExpression": { + "id": 89, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1063:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 91, + "indexExpression": { + "id": 90, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "1070:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1063:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 92, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1074:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "1063:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + { + "expression": { + "baseExpression": { + "id": 93, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1082:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 95, + "indexExpression": { + "id": 94, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 32, + "src": "1089:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1082:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 96, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1093:4:0", + "memberName": "size", + "nodeType": "MemberAccess", + "referencedDeclaration": 7, + "src": "1082:15:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + }, + { + "typeIdentifier": "t_address", + "typeString": "address" + }, + { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + ], + "id": 83, + "name": "Transaction", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 30, + "src": "1027:11:0", + "typeDescriptions": { + "typeIdentifier": "t_function_event_nonpayable$_t_string_memory_ptr_$_t_address_$_t_bool_$_t_uint256_$returns$__$", + "typeString": "function (string memory,address,bool,uint256)" + } + }, + "id": 97, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "1027:71:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 98, + "nodeType": "EmitStatement", + "src": "1022:76:0" + } + ] + }, + "functionSelector": "db9cc410", + "id": 100, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "createAsset", + "nameLocation": "752:11:0", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 35, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 32, + "mutability": "mutable", + "name": "id", + "nameLocation": "780:2:0", + "nodeType": "VariableDeclaration", + "scope": 100, + "src": "764:18:0", + "stateVariable": false, + "storageLocation": "calldata", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string" + }, + "typeName": { + "id": 31, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "764:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + }, + { + "constant": false, + "id": 34, + "mutability": "mutable", + "name": "size", + "nameLocation": "789:4:0", + "nodeType": "VariableDeclaration", + "scope": 100, + "src": "784:9:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + }, + "typeName": { + "id": 33, + "name": "uint", + "nodeType": "ElementaryTypeName", + "src": "784:4:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + }, + "visibility": "internal" + } + ], + "src": "763:31:0" + }, + "returnParameters": { + "id": 36, + "nodeType": "ParameterList", + "parameters": [], + "src": "801:0:0" + }, + "scope": 290, + "src": "743:360:0", + "stateMutability": "nonpayable", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 112, + "nodeType": "Block", + "src": "1180:30:0", + "statements": [ + { + "expression": { + "baseExpression": { + "id": 108, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1195:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 110, + "indexExpression": { + "id": 109, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 102, + "src": "1202:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1195:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "functionReturnParameters": 107, + "id": 111, + "nodeType": "Return", + "src": "1188:17:0" + } + ] + }, + "functionSelector": "cd5286d0", + "id": 113, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "getAsset", + "nameLocation": "1116:8:0", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 103, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 102, + "mutability": "mutable", + "name": "id", + "nameLocation": "1141:2:0", + "nodeType": "VariableDeclaration", + "scope": 113, + "src": "1125:18:0", + "stateVariable": false, + "storageLocation": "calldata", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string" + }, + "typeName": { + "id": 101, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "1125:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "1124:20:0" + }, + "returnParameters": { + "id": 107, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 106, + "mutability": "mutable", + "name": "", + "nameLocation": "-1:-1:-1", + "nodeType": "VariableDeclaration", + "scope": 113, + "src": "1166:12:0", + "stateVariable": false, + "storageLocation": "memory", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_memory_ptr", + "typeString": "struct Asset" + }, + "typeName": { + "id": 105, + "nodeType": "UserDefinedTypeName", + "pathNode": { + "id": 104, + "name": "Asset", + "nameLocations": [ + "1166:5:0" + ], + "nodeType": "IdentifierPath", + "referencedDeclaration": 8, + "src": "1166:5:0" + }, + "referencedDeclaration": 8, + "src": "1166:5:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage_ptr", + "typeString": "struct Asset" + } + }, + "visibility": "internal" + } + ], + "src": "1165:14:0" + }, + "scope": 290, + "src": "1107:103:0", + "stateMutability": "view", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 151, + "nodeType": "Block", + "src": "1299:183:0", + "statements": [ + { + "assignments": [ + 119 + ], + "declarations": [ + { + "constant": false, + "id": 119, + "mutability": "mutable", + "name": "exists", + "nameLocation": "1312:6:0", + "nodeType": "VariableDeclaration", + "scope": 151, + "src": "1307:11:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 118, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "1307:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + } + ], + "id": 123, + "initialValue": { + "baseExpression": { + "id": 120, + "name": "assetExists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 17, + "src": "1321:11:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string memory => bool)" + } + }, + "id": 122, + "indexExpression": { + "id": 121, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 115, + "src": "1333:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1321:15:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "VariableDeclarationStatement", + "src": "1307:29:0" + }, + { + "expression": { + "arguments": [ + { + "id": 125, + "name": "exists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 119, + "src": "1352:6:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + ], + "id": 124, + "name": "require", + "nodeType": "Identifier", + "overloadedDeclarations": [ + 4294967278, + 4294967278 + ], + "referencedDeclaration": 4294967278, + "src": "1344:7:0", + "typeDescriptions": { + "typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$", + "typeString": "function (bool) pure" + } + }, + "id": 126, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "1344:15:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 127, + "nodeType": "ExpressionStatement", + "src": "1344:15:0" + }, + { + "expression": { + "id": 133, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftHandSide": { + "expression": { + "baseExpression": { + "id": 128, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1368:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 130, + "indexExpression": { + "id": 129, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 115, + "src": "1375:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1368:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 131, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": true, + "memberLocation": "1379:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "1368:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "Assignment", + "operator": "=", + "rightHandSide": { + "hexValue": "74727565", + "id": 132, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "bool", + "lValueRequested": false, + "nodeType": "Literal", + "src": "1388:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "value": "true" + }, + "src": "1368:24:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "id": 134, + "nodeType": "ExpressionStatement", + "src": "1368:24:0" + }, + { + "eventCall": { + "arguments": [ + { + "id": 136, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 115, + "src": "1417:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + { + "expression": { + "baseExpression": { + "id": 137, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1421:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 139, + "indexExpression": { + "id": 138, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 115, + "src": "1428:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1421:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 140, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1432:7:0", + "memberName": "creator", + "nodeType": "MemberAccess", + "referencedDeclaration": 3, + "src": "1421:18:0", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + { + "expression": { + "baseExpression": { + "id": 141, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1441:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 143, + "indexExpression": { + "id": 142, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 115, + "src": "1448:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1441:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 144, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1452:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "1441:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + { + "expression": { + "baseExpression": { + "id": 145, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1460:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 147, + "indexExpression": { + "id": 146, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 115, + "src": "1467:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1460:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 148, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1471:4:0", + "memberName": "size", + "nodeType": "MemberAccess", + "referencedDeclaration": 7, + "src": "1460:15:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + }, + { + "typeIdentifier": "t_address", + "typeString": "address" + }, + { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + ], + "id": 135, + "name": "Transaction", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 30, + "src": "1405:11:0", + "typeDescriptions": { + "typeIdentifier": "t_function_event_nonpayable$_t_string_memory_ptr_$_t_address_$_t_bool_$_t_uint256_$returns$__$", + "typeString": "function (string memory,address,bool,uint256)" + } + }, + "id": 149, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "1405:71:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 150, + "nodeType": "EmitStatement", + "src": "1400:76:0" + } + ] + }, + "functionSelector": "5e82d0a6", + "id": 152, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "lockAsset", + "nameLocation": "1262:9:0", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 116, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 115, + "mutability": "mutable", + "name": "id", + "nameLocation": "1288:2:0", + "nodeType": "VariableDeclaration", + "scope": 152, + "src": "1272:18:0", + "stateVariable": false, + "storageLocation": "calldata", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string" + }, + "typeName": { + "id": 114, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "1272:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "1271:20:0" + }, + "returnParameters": { + "id": 117, + "nodeType": "ParameterList", + "parameters": [], + "src": "1299:0:0" + }, + "scope": 290, + "src": "1253:229:0", + "stateMutability": "nonpayable", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 190, + "nodeType": "Block", + "src": "1575:184:0", + "statements": [ + { + "assignments": [ + 158 + ], + "declarations": [ + { + "constant": false, + "id": 158, + "mutability": "mutable", + "name": "exists", + "nameLocation": "1588:6:0", + "nodeType": "VariableDeclaration", + "scope": 190, + "src": "1583:11:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 157, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "1583:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + } + ], + "id": 162, + "initialValue": { + "baseExpression": { + "id": 159, + "name": "assetExists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 17, + "src": "1597:11:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string memory => bool)" + } + }, + "id": 161, + "indexExpression": { + "id": 160, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 154, + "src": "1609:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1597:15:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "VariableDeclarationStatement", + "src": "1583:29:0" + }, + { + "expression": { + "arguments": [ + { + "id": 164, + "name": "exists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 158, + "src": "1628:6:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + ], + "id": 163, + "name": "require", + "nodeType": "Identifier", + "overloadedDeclarations": [ + 4294967278, + 4294967278 + ], + "referencedDeclaration": 4294967278, + "src": "1620:7:0", + "typeDescriptions": { + "typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$", + "typeString": "function (bool) pure" + } + }, + "id": 165, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "1620:15:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 166, + "nodeType": "ExpressionStatement", + "src": "1620:15:0" + }, + { + "expression": { + "id": 172, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftHandSide": { + "expression": { + "baseExpression": { + "id": 167, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1644:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 169, + "indexExpression": { + "id": 168, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 154, + "src": "1651:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1644:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 170, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": true, + "memberLocation": "1655:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "1644:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "Assignment", + "operator": "=", + "rightHandSide": { + "hexValue": "66616c7365", + "id": 171, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "bool", + "lValueRequested": false, + "nodeType": "Literal", + "src": "1664:5:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "value": "false" + }, + "src": "1644:25:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "id": 173, + "nodeType": "ExpressionStatement", + "src": "1644:25:0" + }, + { + "eventCall": { + "arguments": [ + { + "id": 175, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 154, + "src": "1694:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + { + "expression": { + "baseExpression": { + "id": 176, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1698:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 178, + "indexExpression": { + "id": 177, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 154, + "src": "1705:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1698:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 179, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1709:7:0", + "memberName": "creator", + "nodeType": "MemberAccess", + "referencedDeclaration": 3, + "src": "1698:18:0", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + { + "expression": { + "baseExpression": { + "id": 180, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1718:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 182, + "indexExpression": { + "id": 181, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 154, + "src": "1725:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1718:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 183, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1729:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "1718:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + { + "expression": { + "baseExpression": { + "id": 184, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1737:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 186, + "indexExpression": { + "id": 185, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 154, + "src": "1744:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1737:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 187, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1748:4:0", + "memberName": "size", + "nodeType": "MemberAccess", + "referencedDeclaration": 7, + "src": "1737:15:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + }, + { + "typeIdentifier": "t_address", + "typeString": "address" + }, + { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + ], + "id": 174, + "name": "Transaction", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 30, + "src": "1682:11:0", + "typeDescriptions": { + "typeIdentifier": "t_function_event_nonpayable$_t_string_memory_ptr_$_t_address_$_t_bool_$_t_uint256_$returns$__$", + "typeString": "function (string memory,address,bool,uint256)" + } + }, + "id": 188, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "1682:71:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 189, + "nodeType": "EmitStatement", + "src": "1677:76:0" + } + ] + }, + "functionSelector": "def60e0d", + "id": 191, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "unLockAsset", + "nameLocation": "1536:11:0", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 155, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 154, + "mutability": "mutable", + "name": "id", + "nameLocation": "1564:2:0", + "nodeType": "VariableDeclaration", + "scope": 191, + "src": "1548:18:0", + "stateVariable": false, + "storageLocation": "calldata", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string" + }, + "typeName": { + "id": 153, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "1548:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "1547:20:0" + }, + "returnParameters": { + "id": 156, + "nodeType": "ParameterList", + "parameters": [], + "src": "1575:0:0" + }, + "scope": 290, + "src": "1527:232:0", + "stateMutability": "nonpayable", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 244, + "nodeType": "Block", + "src": "1811:347:0", + "statements": [ + { + "assignments": [ + 197 + ], + "declarations": [ + { + "constant": false, + "id": 197, + "mutability": "mutable", + "name": "exists", + "nameLocation": "1824:6:0", + "nodeType": "VariableDeclaration", + "scope": 244, + "src": "1819:11:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 196, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "1819:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + } + ], + "id": 201, + "initialValue": { + "baseExpression": { + "id": 198, + "name": "assetExists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 17, + "src": "1833:11:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string memory => bool)" + } + }, + "id": 200, + "indexExpression": { + "id": 199, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 193, + "src": "1845:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1833:15:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "VariableDeclarationStatement", + "src": "1819:29:0" + }, + { + "expression": { + "arguments": [ + { + "id": 203, + "name": "exists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 197, + "src": "1864:6:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + ], + "id": 202, + "name": "require", + "nodeType": "Identifier", + "overloadedDeclarations": [ + 4294967278, + 4294967278 + ], + "referencedDeclaration": 4294967278, + "src": "1856:7:0", + "typeDescriptions": { + "typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$", + "typeString": "function (bool) pure" + } + }, + "id": 204, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "1856:15:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 205, + "nodeType": "ExpressionStatement", + "src": "1856:15:0" + }, + { + "assignments": [ + 207 + ], + "declarations": [ + { + "constant": false, + "id": 207, + "mutability": "mutable", + "name": "assetIsLocked", + "nameLocation": "1948:13:0", + "nodeType": "VariableDeclaration", + "scope": 244, + "src": "1943:18:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 206, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "1943:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + } + ], + "id": 212, + "initialValue": { + "expression": { + "baseExpression": { + "id": 208, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "1964:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 210, + "indexExpression": { + "id": 209, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 193, + "src": "1971:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "1964:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 211, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "1975:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "1964:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "VariableDeclarationStatement", + "src": "1943:38:0" + }, + { + "expression": { + "arguments": [ + { + "id": 214, + "name": "assetIsLocked", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 207, + "src": "1997:13:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + ], + "id": 213, + "name": "require", + "nodeType": "Identifier", + "overloadedDeclarations": [ + 4294967278, + 4294967278 + ], + "referencedDeclaration": 4294967278, + "src": "1989:7:0", + "typeDescriptions": { + "typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$", + "typeString": "function (bool) pure" + } + }, + "id": 215, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "1989:22:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 216, + "nodeType": "ExpressionStatement", + "src": "1989:22:0" + }, + { + "expression": { + "id": 220, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "nodeType": "UnaryOperation", + "operator": "delete", + "prefix": true, + "src": "2020:17:0", + "subExpression": { + "baseExpression": { + "id": 217, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "2027:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 219, + "indexExpression": { + "id": 218, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 193, + "src": "2034:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": true, + "nodeType": "IndexAccess", + "src": "2027:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 221, + "nodeType": "ExpressionStatement", + "src": "2020:17:0" + }, + { + "expression": { + "id": 226, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftHandSide": { + "baseExpression": { + "id": 222, + "name": "assetExists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 17, + "src": "2045:11:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string memory => bool)" + } + }, + "id": 224, + "indexExpression": { + "id": 223, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 193, + "src": "2057:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": true, + "nodeType": "IndexAccess", + "src": "2045:15:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "Assignment", + "operator": "=", + "rightHandSide": { + "hexValue": "66616c7365", + "id": 225, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "bool", + "lValueRequested": false, + "nodeType": "Literal", + "src": "2063:5:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "value": "false" + }, + "src": "2045:23:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "id": 227, + "nodeType": "ExpressionStatement", + "src": "2045:23:0" + }, + { + "eventCall": { + "arguments": [ + { + "id": 229, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 193, + "src": "2093:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + { + "expression": { + "baseExpression": { + "id": 230, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "2097:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 232, + "indexExpression": { + "id": 231, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 193, + "src": "2104:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "2097:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 233, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "2108:7:0", + "memberName": "creator", + "nodeType": "MemberAccess", + "referencedDeclaration": 3, + "src": "2097:18:0", + "typeDescriptions": { + "typeIdentifier": "t_address", + "typeString": "address" + } + }, + { + "expression": { + "baseExpression": { + "id": 234, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "2117:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 236, + "indexExpression": { + "id": 235, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 193, + "src": "2124:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "2117:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 237, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "2128:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "2117:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + { + "expression": { + "baseExpression": { + "id": 238, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "2136:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 240, + "indexExpression": { + "id": 239, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 193, + "src": "2143:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "2136:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 241, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "2147:4:0", + "memberName": "size", + "nodeType": "MemberAccess", + "referencedDeclaration": 7, + "src": "2136:15:0", + "typeDescriptions": { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + }, + { + "typeIdentifier": "t_address", + "typeString": "address" + }, + { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + { + "typeIdentifier": "t_uint256", + "typeString": "uint256" + } + ], + "id": 228, + "name": "Transaction", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 30, + "src": "2081:11:0", + "typeDescriptions": { + "typeIdentifier": "t_function_event_nonpayable$_t_string_memory_ptr_$_t_address_$_t_bool_$_t_uint256_$returns$__$", + "typeString": "function (string memory,address,bool,uint256)" + } + }, + "id": 242, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "2081:71:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 243, + "nodeType": "EmitStatement", + "src": "2076:76:0" + } + ] + }, + "functionSelector": "e24aa37c", + "id": 245, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "deleteAsset", + "nameLocation": "1772:11:0", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 194, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 193, + "mutability": "mutable", + "name": "id", + "nameLocation": "1800:2:0", + "nodeType": "VariableDeclaration", + "scope": 245, + "src": "1784:18:0", + "stateVariable": false, + "storageLocation": "calldata", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string" + }, + "typeName": { + "id": 192, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "1784:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "1783:20:0" + }, + "returnParameters": { + "id": 195, + "nodeType": "ParameterList", + "parameters": [], + "src": "1811:0:0" + }, + "scope": 290, + "src": "1763:395:0", + "stateMutability": "nonpayable", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 256, + "nodeType": "Block", + "src": "2228:35:0", + "statements": [ + { + "expression": { + "baseExpression": { + "id": 252, + "name": "assetExists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 17, + "src": "2243:11:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string memory => bool)" + } + }, + "id": 254, + "indexExpression": { + "id": 253, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 247, + "src": "2255:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "2243:15:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "functionReturnParameters": 251, + "id": 255, + "nodeType": "Return", + "src": "2236:22:0" + } + ] + }, + "functionSelector": "bc548275", + "id": 257, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "isPresent", + "nameLocation": "2171:9:0", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 248, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 247, + "mutability": "mutable", + "name": "id", + "nameLocation": "2197:2:0", + "nodeType": "VariableDeclaration", + "scope": 257, + "src": "2181:18:0", + "stateVariable": false, + "storageLocation": "calldata", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string" + }, + "typeName": { + "id": 246, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "2181:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "2180:20:0" + }, + "returnParameters": { + "id": 251, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 250, + "mutability": "mutable", + "name": "", + "nameLocation": "-1:-1:-1", + "nodeType": "VariableDeclaration", + "scope": 257, + "src": "2222:4:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 249, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "2222:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + } + ], + "src": "2221:6:0" + }, + "scope": 290, + "src": "2162:101:0", + "stateMutability": "view", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 279, + "nodeType": "Block", + "src": "2337:161:0", + "statements": [ + { + "assignments": [ + 265 + ], + "declarations": [ + { + "constant": false, + "id": 265, + "mutability": "mutable", + "name": "exists", + "nameLocation": "2350:6:0", + "nodeType": "VariableDeclaration", + "scope": 279, + "src": "2345:11:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 264, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "2345:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + } + ], + "id": 269, + "initialValue": { + "baseExpression": { + "id": 266, + "name": "assetExists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 17, + "src": "2359:11:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_bool_$", + "typeString": "mapping(string memory => bool)" + } + }, + "id": 268, + "indexExpression": { + "id": 267, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 259, + "src": "2371:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "2359:15:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "nodeType": "VariableDeclarationStatement", + "src": "2345:29:0" + }, + { + "expression": { + "arguments": [ + { + "id": 271, + "name": "exists", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 265, + "src": "2390:6:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + } + ], + "expression": { + "argumentTypes": [ + { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + ], + "id": 270, + "name": "require", + "nodeType": "Identifier", + "overloadedDeclarations": [ + 4294967278, + 4294967278 + ], + "referencedDeclaration": 4294967278, + "src": "2382:7:0", + "typeDescriptions": { + "typeIdentifier": "t_function_require_pure$_t_bool_$returns$__$", + "typeString": "function (bool) pure" + } + }, + "id": 272, + "isConstant": false, + "isLValue": false, + "isPure": false, + "kind": "functionCall", + "lValueRequested": false, + "nameLocations": [], + "names": [], + "nodeType": "FunctionCall", + "src": "2382:15:0", + "tryCall": false, + "typeDescriptions": { + "typeIdentifier": "t_tuple$__$", + "typeString": "tuple()" + } + }, + "id": 273, + "nodeType": "ExpressionStatement", + "src": "2382:15:0" + }, + { + "expression": { + "expression": { + "baseExpression": { + "id": 274, + "name": "assets", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 13, + "src": "2476:6:0", + "typeDescriptions": { + "typeIdentifier": "t_mapping$_t_string_memory_ptr_$_t_struct$_Asset_$8_storage_$", + "typeString": "mapping(string memory => struct Asset storage ref)" + } + }, + "id": 276, + "indexExpression": { + "id": 275, + "name": "id", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 259, + "src": "2483:2:0", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string calldata" + } + }, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "nodeType": "IndexAccess", + "src": "2476:10:0", + "typeDescriptions": { + "typeIdentifier": "t_struct$_Asset_$8_storage", + "typeString": "struct Asset storage ref" + } + }, + "id": 277, + "isConstant": false, + "isLValue": true, + "isPure": false, + "lValueRequested": false, + "memberLocation": "2487:6:0", + "memberName": "isLock", + "nodeType": "MemberAccess", + "referencedDeclaration": 5, + "src": "2476:17:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "functionReturnParameters": 263, + "id": 278, + "nodeType": "Return", + "src": "2469:24:0" + } + ] + }, + "functionSelector": "1ae4eb68", + "id": 280, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "isAssetLocked", + "nameLocation": "2276:13:0", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 260, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 259, + "mutability": "mutable", + "name": "id", + "nameLocation": "2306:2:0", + "nodeType": "VariableDeclaration", + "scope": 280, + "src": "2290:18:0", + "stateVariable": false, + "storageLocation": "calldata", + "typeDescriptions": { + "typeIdentifier": "t_string_calldata_ptr", + "typeString": "string" + }, + "typeName": { + "id": 258, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "2290:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "2289:20:0" + }, + "returnParameters": { + "id": 263, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 262, + "mutability": "mutable", + "name": "", + "nameLocation": "-1:-1:-1", + "nodeType": "VariableDeclaration", + "scope": 280, + "src": "2331:4:0", + "stateVariable": false, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + }, + "typeName": { + "id": 261, + "name": "bool", + "nodeType": "ElementaryTypeName", + "src": "2331:4:0", + "typeDescriptions": { + "typeIdentifier": "t_bool", + "typeString": "bool" + } + }, + "visibility": "internal" + } + ], + "src": "2330:6:0" + }, + "scope": 290, + "src": "2267:231:0", + "stateMutability": "view", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 288, + "nodeType": "Block", + "src": "2566:21:0", + "statements": [ + { + "expression": { + "id": 286, + "name": "ids", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 20, + "src": "2579:3:0", + "typeDescriptions": { + "typeIdentifier": "t_array$_t_string_storage_$dyn_storage", + "typeString": "string storage ref[] storage ref" + } + }, + "functionReturnParameters": 285, + "id": 287, + "nodeType": "Return", + "src": "2572:10:0" + } + ] + }, + "functionSelector": "5137b8a7", + "id": 289, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "getAllAssetsIDs", + "nameLocation": "2511:15:0", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 281, + "nodeType": "ParameterList", + "parameters": [], + "src": "2526:2:0" + }, + "returnParameters": { + "id": 285, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 284, + "mutability": "mutable", + "name": "", + "nameLocation": "-1:-1:-1", + "nodeType": "VariableDeclaration", + "scope": 289, + "src": "2550:15:0", + "stateVariable": false, + "storageLocation": "memory", + "typeDescriptions": { + "typeIdentifier": "t_array$_t_string_memory_ptr_$dyn_memory_ptr", + "typeString": "string[]" + }, + "typeName": { + "baseType": { + "id": 282, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "2550:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "id": 283, + "nodeType": "ArrayTypeName", + "src": "2550:8:0", + "typeDescriptions": { + "typeIdentifier": "t_array$_t_string_storage_$dyn_storage_ptr", + "typeString": "string[]" + } + }, + "visibility": "internal" + } + ], + "src": "2549:17:0" + }, + "scope": 290, + "src": "2502:85:0", + "stateMutability": "view", + "virtual": false, + "visibility": "public" + } + ], + "scope": 291, + "src": "543:2046:0", + "usedErrors": [] + } + ], + "src": "413:2177:0" + }, + "functionHashes": { + "createAsset(string,uint256)": "db9cc410", + "deleteAsset(string)": "e24aa37c", + "getAllAssetsIDs()": "5137b8a7", + "getAsset(string)": "cd5286d0", + "isAssetLocked(string)": "1ae4eb68", + "isPresent(string)": "bc548275", + "lockAsset(string)": "5e82d0a6", + "unLockAsset(string)": "def60e0d" + }, + "gasEstimates": { + "creation": { + "codeDepositCost": "567600", + "executionCost": "600", + "totalCost": "568200" + }, + "external": { + "createAsset(string,uint256)": "infinite", + "deleteAsset(string)": "infinite", + "getAllAssetsIDs()": "infinite", + "getAsset(string)": "infinite", + "isAssetLocked(string)": "infinite", + "isPresent(string)": "infinite", + "lockAsset(string)": "infinite", + "unLockAsset(string)": "infinite" + } + } +} \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/lock-asset.sol b/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/lock-asset.sol new file mode 100644 index 0000000000..76a43258f4 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/src/test/typescript/solidity/lock-asset-contract/lock-asset.sol @@ -0,0 +1,81 @@ + +pragma solidity >=0.7.0; +struct Asset{ + address creator; + bool isLock; + uint size; +} +//TODO: DETEMINE CALLDATA VS MEMORY +contract LockAsset { + mapping (string => Asset) assets; + mapping (string => bool) assetExists; + string[] ids; + + event Transaction(string indexed id, address creator, bool isLock, uint size); + + function createAsset(string calldata id, uint size) public{ + require(size>0); + assets[id].size= size; + assets[id].creator = msg.sender; + assets[id].isLock = false; + if (!assetExists[id]){ + ids.push(id); + } + assetExists[id] = true; + emit Transaction(id, assets[id].creator, assets[id].isLock, assets[id].size); + } + + function getAsset(string calldata id) public view returns (Asset memory) { + return assets[id]; + } + + //Don't care if it is already locked + function lockAsset(string calldata id) public { + bool exists = assetExists[id]; + require(exists); + + assets[id].isLock = true; + emit Transaction(id, assets[id].creator, assets[id].isLock, assets[id].size); + + } + + //Don't care if it is already unlocked + function unLockAsset(string calldata id) public { + bool exists = assetExists[id]; + require(exists); + + assets[id].isLock = false; + emit Transaction(id, assets[id].creator, assets[id].isLock, assets[id].size); + + } + + function deleteAsset(string calldata id) public { + bool exists = assetExists[id]; + require(exists); + + //an asset could only be deleted if it is already locked + bool assetIsLocked = assets[id].isLock; + require(assetIsLocked); + + delete assets[id]; + assetExists[id] = false; + emit Transaction(id, assets[id].creator, assets[id].isLock, assets[id].size); + + } + + function isPresent(string calldata id) public view returns (bool) { + return assetExists[id]; + } + + function isAssetLocked(string calldata id) public view returns (bool) { + bool exists = assetExists[id]; + require(exists); + + //an asset could only be deleted if it is already locked + return assets[id].isLock; + } + + function getAllAssetsIDs() public view returns (string[] memory){ + return ids; + } +} \ No newline at end of file diff --git a/packages/cactus-plugin-bungee-hermes/tsconfig.json b/packages/cactus-plugin-bungee-hermes/tsconfig.json new file mode 100644 index 0000000000..22c39860a8 --- /dev/null +++ b/packages/cactus-plugin-bungee-hermes/tsconfig.json @@ -0,0 +1,41 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outDir": "./dist/lib/", /* Redirect output structure to the directory. */ + "declarationDir": "dist/lib", + "resolveJsonModule": true, + "allowJs": false, + "skipLibCheck": true, + "rootDir": "./src/", + "tsBuildInfoFile": "../../.build-cache/cactus-plugin-bungee-hermes.tsbuildinfo", + "moduleResolution": "Node" + }, + "ts-node": { + "files": true + }, + "include": [ + "./src", + "src/**/*.json" + ], + "exclude":[ + "./src/test/typescript/fabric-contracts/**/*.ts" + ], + "references": [ + { + "path": "../cactus-plugin-ledger-connector-fabric/tsconfig.json" + }, + { + "path": "../cactus-plugin-ledger-connector-besu/tsconfig.json" + }, + { + "path": "../cactus-test-tooling/tsconfig.json" + }, + { + "path": "../cactus-core/tsconfig.json" + }, + { + "path": "../../extensions/cactus-plugin-object-store-ipfs/tsconfig.json" + } + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 880dddb651..faccdaff95 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,9 @@ { "path": "./packages/cactus-core-api/tsconfig.json" }, + { + "path": "./packages/cactus-plugin-bungee-hermes/tsconfig.json" + }, { "path": "./packages/cactus-plugin-consortium-manual/tsconfig.json" }, diff --git a/yarn.lock b/yarn.lock index 2aee408cae..55c4c235fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8127,6 +8127,39 @@ __metadata: languageName: unknown linkType: soft +"@hyperledger/cactus-plugin-bungee-hermes@workspace:packages/cactus-plugin-bungee-hermes": + version: 0.0.0-use.local + resolution: "@hyperledger/cactus-plugin-bungee-hermes@workspace:packages/cactus-plugin-bungee-hermes" + dependencies: + "@hyperledger/cactus-cmd-api-server": "npm:2.0.0-alpha.2" + "@hyperledger/cactus-common": "npm:2.0.0-alpha.2" + "@hyperledger/cactus-core": "npm:2.0.0-alpha.2" + "@hyperledger/cactus-core-api": "npm:2.0.0-alpha.2" + "@hyperledger/cactus-plugin-keychain-memory": "npm:2.0.0-alpha.2" + "@hyperledger/cactus-plugin-ledger-connector-besu": "npm:2.0.0-alpha.2" + "@hyperledger/cactus-plugin-ledger-connector-fabric": "npm:2.0.0-alpha.2" + "@hyperledger/cactus-plugin-object-store-ipfs": "npm:2.0.0-alpha.2" + "@hyperledger/cactus-test-tooling": "npm:2.0.0-alpha.2" + "@types/body-parser": "npm:1.19.4" + "@types/crypto-js": "npm:4.0.1" + "@types/express": "npm:4.17.19" + "@types/fs-extra": "npm:11.0.3" + "@types/tape": "npm:4.13.4" + "@types/uuid": "npm:9.0.6" + axios: "npm:1.6.0" + body-parser: "npm:1.20.2" + express: "npm:4.18.2" + fabric-network: "npm:2.2.20" + fs-extra: "npm:10.1.0" + key-encoder: "npm:2.0.3" + socket.io: "npm:4.5.4" + typescript-optional: "npm:2.0.1" + uuid: "npm:9.0.1" + web3: "npm:1.6.1" + web3-core: "npm:1.6.1" + languageName: unknown + linkType: soft + "@hyperledger/cactus-plugin-consortium-manual@npm:2.0.0-alpha.2, @hyperledger/cactus-plugin-consortium-manual@workspace:packages/cactus-plugin-consortium-manual": version: 0.0.0-use.local resolution: "@hyperledger/cactus-plugin-consortium-manual@workspace:packages/cactus-plugin-consortium-manual" @@ -15817,6 +15850,13 @@ __metadata: languageName: node linkType: hard +"@types/uuid@npm:9.0.6": + version: 9.0.6 + resolution: "@types/uuid@npm:9.0.6" + checksum: 10/739dcb2e620ff097fa916edeab455eb75640c4883a850784fdb15b32f67b719e05275c6d6419bb6da11350d26bd14ed05ba5e992ff228411cdd98cbc772d71ef + languageName: node + linkType: hard + "@types/uuid@npm:9.0.8": version: 9.0.8 resolution: "@types/uuid@npm:9.0.8" @@ -26541,16 +26581,16 @@ __metadata: languageName: node linkType: hard -"express@npm:4.19.2": - version: 4.19.2 - resolution: "express@npm:4.19.2" +"express@npm:4.18.2, express@npm:^4.10.6, express@npm:^4.14.0, express@npm:^4.16.3, express@npm:^4.17.1, express@npm:^4.17.3": + version: 4.18.2 + resolution: "express@npm:4.18.2" dependencies: accepts: "npm:~1.3.8" array-flatten: "npm:1.1.1" - body-parser: "npm:1.20.2" + body-parser: "npm:1.20.1" content-disposition: "npm:0.5.4" content-type: "npm:~1.0.4" - cookie: "npm:0.6.0" + cookie: "npm:0.5.0" cookie-signature: "npm:1.0.6" debug: "npm:2.6.9" depd: "npm:2.0.0" @@ -26576,20 +26616,20 @@ __metadata: type-is: "npm:~1.6.18" utils-merge: "npm:1.0.1" vary: "npm:~1.1.2" - checksum: 10/3fcd792536f802c059789ef48db3851b87e78fba103423e524144d79af37da7952a2b8d4e1a007f423329c7377d686d9476ac42e7d9ea413b80345d495e30a3a + checksum: 10/869ae89ed6ff4bed7b373079dc58e5dddcf2915a2669b36037ff78c99d675ae930e5fe052b35c24f56557d28a023bb1cbe3e2f2fb87eaab96a1cedd7e597809d languageName: node linkType: hard -"express@npm:^4.10.6, express@npm:^4.14.0, express@npm:^4.16.3, express@npm:^4.17.1, express@npm:^4.17.3": - version: 4.18.2 - resolution: "express@npm:4.18.2" +"express@npm:4.19.2": + version: 4.19.2 + resolution: "express@npm:4.19.2" dependencies: accepts: "npm:~1.3.8" array-flatten: "npm:1.1.1" - body-parser: "npm:1.20.1" + body-parser: "npm:1.20.2" content-disposition: "npm:0.5.4" content-type: "npm:~1.0.4" - cookie: "npm:0.5.0" + cookie: "npm:0.6.0" cookie-signature: "npm:1.0.6" debug: "npm:2.6.9" depd: "npm:2.0.0" @@ -26615,7 +26655,7 @@ __metadata: type-is: "npm:~1.6.18" utils-merge: "npm:1.0.1" vary: "npm:~1.1.2" - checksum: 10/869ae89ed6ff4bed7b373079dc58e5dddcf2915a2669b36037ff78c99d675ae930e5fe052b35c24f56557d28a023bb1cbe3e2f2fb87eaab96a1cedd7e597809d + checksum: 10/3fcd792536f802c059789ef48db3851b87e78fba103423e524144d79af37da7952a2b8d4e1a007f423329c7377d686d9476ac42e7d9ea413b80345d495e30a3a languageName: node linkType: hard