Commit dd4d85c6 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'feat/dlt-service' into 'develop'

DLT component

See merge request teraflow-h2020/controller!43
parents 62f027b9 7b796a46
Loading
Loading
Loading
Loading

src/dlt/.gitignore

0 → 100644
+90 −0
Original line number Diff line number Diff line
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn.  Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# From https://github.com/github/gitignore/blob/master/Gradle.gitignore
/.gradle/
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

local.properties
wallet/
 No newline at end of file

src/dlt/README.md

0 → 100644
+84 −0
Original line number Diff line number Diff line
```
     NEC Laboratories Europe GmbH

     PROPRIETARY INFORMATION

 The software and its source code contain valuable trade secrets and
 shall be maintained in confidence and treated as confidential
 information. The software may only be used for evaluation and/or
 testing purposes, unless otherwise explicitly stated in a written
 agreement with NEC Laboratories Europe GmbH.

 Any unauthorized publication, transfer to third parties or
 duplication of the object or source code - either totally or in
 part - is strictly prohibited.

          Copyright (c) 2021 NEC Laboratories Europe GmbH
          All Rights Reserved.

 Authors: Konstantin Munichev <konstantin.munichev@neclab.eu>


 NEC Laboratories Europe GmbH DISCLAIMS ALL WARRANTIES, EITHER
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND THE
 WARRANTY AGAINST LATENT DEFECTS, WITH RESPECT TO THE PROGRAM AND
 THE ACCOMPANYING DOCUMENTATION.

 NO LIABILITIES FOR CONSEQUENTIAL DAMAGES: IN NO EVENT SHALL NEC
 Laboratories Europe GmbH or ANY OF ITS SUBSIDIARIES BE LIABLE FOR
 ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
 LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
 INFORMATION, OR OTHER PECUNIARY LOSS AND INDIRECT, CONSEQUENTIAL,
 INCIDENTAL, ECONOMIC OR PUNITIVE DAMAGES) ARISING OUT OF THE USE OF
 OR INABILITY TO USE THIS PROGRAM, EVEN IF NEC Laboratories Europe
 GmbH HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

 THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
 ```

# DLT module guide

## General information
The DLT module is used to provide access to the underlying Fabric deployment. It allows clients
to add, retrieve, modify and delete blockchain-backed data, essentially working as a key-value
database. External clients should use REST API to communicate with this service, its detailed
description available below.

## Code structure
The whole DLT module consists of several packages:
- fabric package
- http package
- proto package
- client example

### Fabric package
The most important class in this package is `FabricConnector`. First, it establishes connection
with the underlying Fabric network using Java Gateway SDK. After that, it could be used as a
CRUD interface.
Other files contain auxiliary code for `FabricConnector` which allows it to register/enroll
users and to obtain smart contract instances.

### HTTP package
Contains server side HTTP handler. It accepts requests from the outside and performs the
requested operation. For the detailed description see API description section.

### Proto package
The proto package contains `Config.proto` file which contains messages for REST API. The most
important ones are `DltConfig` (it defines the whole DLT configuration) and `DltRecord` which
represents data to store in the blockchain.

### Client example
This code is not necessary to the service, but it could be used to test the service. It contains
a sample REST client which connects the service and perform all the CRUD operations. 

## REST API description
| Method | URL | Input | Response code | Output |
| --- | ----------- | --- | --- | --- |
| POST | /dlt/configure | Configuration object | 201 or 400 | Status value | 
| GET | /dlt/configure | - | 200 or 404 | Configuration object |
| POST | /dlt/record | Record object | 200, 201, 400 or 404 | Status value |
| GET | /dlt/record | Record id | 200 or 404 | Record object |

Record and configuration object are defined in `proto` package.
+115 −0
Original line number Diff line number Diff line
//     NEC Laboratories Europe GmbH
//
//     PROPRIETARY INFORMATION
//
// The software and its source code contain valuable trade secrets and
// shall be maintained in confidence and treated as confidential
// information. The software may only be used for evaluation and/or
// testing purposes, unless otherwise explicitly stated in a written
// agreement with NEC Laboratories Europe GmbH.
//
// Any unauthorized publication, transfer to third parties or
// duplication of the object or source code - either totally or in
// part - is strictly prohibited.
//
//          Copyright (c) 2021 NEC Laboratories Europe GmbH
//          All Rights Reserved.
//
// Authors: Konstantin Munichev <konstantin.munichev@neclab.eu>
//
//
// NEC Laboratories Europe GmbH DISCLAIMS ALL WARRANTIES, EITHER
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND THE
// WARRANTY AGAINST LATENT DEFECTS, WITH RESPECT TO THE PROGRAM AND
// THE ACCOMPANYING DOCUMENTATION.
//
// NO LIABILITIES FOR CONSEQUENTIAL DAMAGES: IN NO EVENT SHALL NEC
// Laboratories Europe GmbH or ANY OF ITS SUBSIDIARIES BE LIABLE FOR
// ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR
// LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
// INFORMATION, OR OTHER PECUNIARY LOSS AND INDIRECT, CONSEQUENTIAL,
// INCIDENTAL, ECONOMIC OR PUNITIVE DAMAGES) ARISING OUT OF THE USE OF
// OR INABILITY TO USE THIS PROGRAM, EVEN IF NEC Laboratories Europe
// GmbH HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
//
// THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

import com.google.protobuf.gradle.generateProtoTasks
import com.google.protobuf.gradle.id
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc

ext["protobufVersion"] = "3.19.1"
ext["ktorVersion"] = "1.6.5"

plugins {
    kotlin("jvm") version "1.5.31"
    kotlin("plugin.serialization") version "1.4.21"
    id("com.google.protobuf") version "0.8.17"
    application
}

group = "eu.neclab"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation("org.jetbrains.kotlin:kotlin-test:1.5.31")
    implementation("org.hyperledger.fabric:fabric-gateway-java:2.2.2")
    api("com.google.protobuf:protobuf-kotlin:${rootProject.ext["protobufVersion"]}")
    implementation("io.ktor:ktor-server-core:${rootProject.ext["ktorVersion"]}")
    implementation("io.ktor:ktor-server-netty:${rootProject.ext["ktorVersion"]}")
    implementation("io.ktor:ktor-serialization:${rootProject.ext["ktorVersion"]}")
    implementation("io.ktor:ktor-client-serialization:${rootProject.ext["ktorVersion"]}")
    implementation("io.ktor:ktor-client-core:${rootProject.ext["ktorVersion"]}")
    implementation("io.ktor:ktor-client-cio:${rootProject.ext["ktorVersion"]}")
    implementation("ch.qos.logback:logback-classic:1.2.5")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.3.1")
}

tasks.test {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "11"
}

tasks.withType<KotlinCompile>().all {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn")
    }
}


application {
    mainClass.set("MainKt")
}

sourceSets {
    main {
        proto {
            srcDir("src/main/kotlin/proto")
        }
    }
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:${rootProject.ext["protobufVersion"]}"
    }
    generateProtoTasks {
        all().forEach {
            it.builtins {
                id("kotlin")
            }
        }
    }
}
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
-----BEGIN CERTIFICATE-----
MIICJjCCAc2gAwIBAgIULDVQiqifWHypuW50LhHXSJeeFG0wCgYIKoZIzj0EAwIw
cDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYDVQQH
EwZEdXJoYW0xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh
Lm9yZzEuZXhhbXBsZS5jb20wHhcNMjExMTIzMTIzNzAwWhcNMzYxMTE5MTIzNzAw
WjBwMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGggQ2Fyb2xpbmExDzANBgNV
BAcTBkR1cmhhbTEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMT
Y2Eub3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABFNi
ggnkzv5qQSkIAQ05Y9DUq4teNjbMTdqD0IwdQe+lcYI0wgkR9wpBn5fj2pN093+P
l2crhgyNqZyAuqaylvCjRTBDMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG
AQH/AgEBMB0GA1UdDgQWBBS44tGlbJ5GIBwATL383Hw0vz8jHDAKBggqhkjOPQQD
AgNHADBEAiAlkKikh7eG8lf0uI7NwBi0QrbnnY4vHf9ErceKwUhZWgIgS9Z9AzBc
n9RAK3v/freT3Exs7b+MK13UeDdejRWS+RE=
-----END CERTIFICATE-----
+73 −0
Original line number Diff line number Diff line
{
    "name": "test-network-org1",
    "version": "1.0.0",
    "client": {
        "organization": "Org1",
        "connection": {
            "timeout": {
                "peer": {
                    "endorser": "300"
                }
            }
        }
    },
    "organizations": {
        "Org1": {
            "mspid": "Org1MSP",
            "peers": [
                "peer0.org1.example.com"
            ],
            "certificateAuthorities": [
                "ca.org1.example.com"
            ]
        }
    },
    "peers": {
        "peer0.org1.example.com": {
            "url": "grpcs://s2:7051",
            "tlsCACerts": {
                "pem": "-----BEGIN CERTIFICATE-----\nMIICJjCCAc2gAwIBAgIULDVQiqifWHypuW50LhHXSJeeFG0wCgYIKoZIzj0EAwIw\ncDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYDVQQH\nEwZEdXJoYW0xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzEuZXhhbXBsZS5jb20wHhcNMjExMTIzMTIzNzAwWhcNMzYxMTE5MTIzNzAw\nWjBwMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGggQ2Fyb2xpbmExDzANBgNV\nBAcTBkR1cmhhbTEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMT\nY2Eub3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABFNi\nggnkzv5qQSkIAQ05Y9DUq4teNjbMTdqD0IwdQe+lcYI0wgkR9wpBn5fj2pN093+P\nl2crhgyNqZyAuqaylvCjRTBDMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG\nAQH/AgEBMB0GA1UdDgQWBBS44tGlbJ5GIBwATL383Hw0vz8jHDAKBggqhkjOPQQD\nAgNHADBEAiAlkKikh7eG8lf0uI7NwBi0QrbnnY4vHf9ErceKwUhZWgIgS9Z9AzBc\nn9RAK3v/freT3Exs7b+MK13UeDdejRWS+RE=\n-----END CERTIFICATE-----\n"
            },
            "grpcOptions": {
                "ssl-target-name-override": "peer0.org1.example.com",
                "hostnameOverride": "peer0.org1.example.com"
            }
        },
        "peer0.org2.example.com": {
            "url": "grpcs://s2:9051",
            "tlsCACerts": {
                "pem": "-----BEGIN CERTIFICATE-----\nMIICHzCCAcWgAwIBAgIUJiJ5815YVes2sG95oFzj0QWWBKswCgYIKoZIzj0EAwIw\nbDELMAkGA1UEBhMCVUsxEjAQBgNVBAgTCUhhbXBzaGlyZTEQMA4GA1UEBxMHSHVy\nc2xleTEZMBcGA1UEChMQb3JnMi5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eub3Jn\nMi5leGFtcGxlLmNvbTAeFw0yMTExMjMxMjM3MDBaFw0zNjExMTkxMjM3MDBaMGwx\nCzAJBgNVBAYTAlVLMRIwEAYDVQQIEwlIYW1wc2hpcmUxEDAOBgNVBAcTB0h1cnNs\nZXkxGTAXBgNVBAoTEG9yZzIuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2NhLm9yZzIu\nZXhhbXBsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATdQw+PQyT3Ql5M\nv/xvafYFhU5Jtl0CwYyrXTtRajpPnlPnNvXUqVMxmdSR+4m2WBYyBdZ8IhGaayb/\nrOro8Mpko0UwQzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQUrsPP1HIS6O+JeWL2ct/ujkfP7dEwCgYIKoZIzj0EAwIDSAAwRQIh\nAMynA2Q/cbMXEHihnQdpdEz/83jGAokp7dKMHst02b3gAiA0XReJWdc0AUXZtbSq\nZG8mXOJeZu0Zro9DuQUEDPBfDQ==\n-----END CERTIFICATE-----\n"
            },
            "grpcOptions": {
                "ssl-target-name-override": "peer0.org2.example.com",
                "hostnameOverride": "peer0.org2.example.com"
            }
        }
    },
    "certificateAuthorities": {
        "ca.org1.example.com": {
            "url": "https://s2:7054",
            "caName": "ca-org1",
            "tlsCACerts": {
                "pem": [
                    "-----BEGIN CERTIFICATE-----\nMIICJjCCAc2gAwIBAgIULDVQiqifWHypuW50LhHXSJeeFG0wCgYIKoZIzj0EAwIw\ncDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYDVQQH\nEwZEdXJoYW0xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzEuZXhhbXBsZS5jb20wHhcNMjExMTIzMTIzNzAwWhcNMzYxMTE5MTIzNzAw\nWjBwMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGggQ2Fyb2xpbmExDzANBgNV\nBAcTBkR1cmhhbTEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMT\nY2Eub3JnMS5leGFtcGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABFNi\nggnkzv5qQSkIAQ05Y9DUq4teNjbMTdqD0IwdQe+lcYI0wgkR9wpBn5fj2pN093+P\nl2crhgyNqZyAuqaylvCjRTBDMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG\nAQH/AgEBMB0GA1UdDgQWBBS44tGlbJ5GIBwATL383Hw0vz8jHDAKBggqhkjOPQQD\nAgNHADBEAiAlkKikh7eG8lf0uI7NwBi0QrbnnY4vHf9ErceKwUhZWgIgS9Z9AzBc\nn9RAK3v/freT3Exs7b+MK13UeDdejRWS+RE=\n-----END CERTIFICATE-----\n"
                ]
            },
            "httpOptions": {
                "verify": false
            }
        }
    },
    "orderers": {
        "orderer0.example.com": {
            "url": "grpcs://s2:7050",
            "tlsCACerts": {
                "pem": "-----BEGIN CERTIFICATE-----\nMIICCzCCAbGgAwIBAgIUDr4RiMRC/q95iWAfWiZTLTdDoDUwCgYIKoZIzj0EAwIw\nYjELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE5ldyBZb3JrMREwDwYDVQQHEwhOZXcg\nWW9yazEUMBIGA1UEChMLZXhhbXBsZS5jb20xFzAVBgNVBAMTDmNhLmV4YW1wbGUu\nY29tMB4XDTIxMTEyMzEyMzcwMFoXDTM2MTExOTEyMzcwMFowYjELMAkGA1UEBhMC\nVVMxETAPBgNVBAgTCE5ldyBZb3JrMREwDwYDVQQHEwhOZXcgWW9yazEUMBIGA1UE\nChMLZXhhbXBsZS5jb20xFzAVBgNVBAMTDmNhLmV4YW1wbGUuY29tMFkwEwYHKoZI\nzj0CAQYIKoZIzj0DAQcDQgAE4ErISW/k5iZv0n7n1qpbOZcRMNmn8VqAOX4UIELm\nQ51neULt9T3pxdGEsq7B5O1ncB/RdZwf+3dihBHjngXerKNFMEMwDgYDVR0PAQH/\nBAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYEFP2/1CHK9OdPjs/9\np1mh3t+pyujsMAoGCCqGSM49BAMCA0gAMEUCIQDETOC8hB9EaEvdc2sdEtcNeyXu\nYryyf6I5tJC13E2hOQIgef+ymHy6eXf0jNkY6DXz041THa/67dSrXaZGgaTh4LI=\n-----END CERTIFICATE-----\n"
            },
            "grpcOptions": {
                "ssl-target-name-override": "orderer0.example.com",
                "hostnameOverride": "orderer0.example.com"
            }
        }
    }
}
Loading