Skip to content

Commit 11f0109

Browse files
Merge pull request #470 from d3ledger/release/0.3.0
Release/0.3.0
2 parents a3c5dac + 4ba5727 commit 11f0109

File tree

488 files changed

+19198
-4768
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

488 files changed

+19198
-4768
lines changed

.gitignore

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ hs_err_pid*
7070
/btc-dw-bridge/gradle
7171
/btc-dw-bridge/gradlew
7272
/btc-dw-bridge/gradlew.bat
73+
/chain-adapter/build/
74+
/chain-adapter-integration-test/build/
75+
/chain-adapter-integration-test/gradle/
76+
/chain-adapter-integration-test/gradlew
77+
/bootstrap/build/
78+
/notary-registration/build/
79+
/notary-sora-integration-test/build/
7380
*gradlew.bat
7481

7582
# Ignore Gradle GUI config
@@ -145,14 +152,20 @@ deploy/ethereum/network
145152
deploy/ethereum/keys/test
146153

147154
# Bitcoin wallets, blockchain and etc.
148-
deploy/bitcoin/testnet/d3.wallet
149155
deploy/bitcoin/testnet/blocks/
156+
deploy/bitcoin/testnet/keys.d3.wallet
157+
deploy/bitcoin/testnet/transfers.d3.wallet
150158
deploy/bitcoin/regtest/blocks/
151-
deploy/bitcoin/regtest/d3.wallet
152-
deploy/bitcoin/testnet/d3.wallet
153-
deploy/bitcoin/regtest/d3-test.wallet
154159
deploy/bitcoin/mainnet/
155160

161+
# Chain-adapter files
162+
deploy/chain-adapter/
163+
164+
# Bitcoin test wallets
165+
deploy/bitcoin/regtest/test wallets/
166+
156167
# SMTP configs
157168
configs/smtp.properties
158169

170+
# Push API configs
171+
configs/push.properties

Jenkinsfile

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,24 @@ pipeline {
3434
steps {
3535
script {
3636
def scmVars = checkout scm
37+
tmp = docker.image("openjdk:8-jdk")
38+
env.WORKSPACE = pwd()
39+
40+
tmp.inside("-e JVM_OPTS='-Xmx3200m' -e TERM='dumb' -v ${env.WORKSPACE}/chain-adapter/build/libs:/home/out") {
41+
sh "./gradlew chain-adapter:shadowJar"
42+
43+
}
44+
3745
DOCKER_NETWORK = "${scmVars.CHANGE_ID}-${scmVars.GIT_COMMIT}-${BUILD_NUMBER}"
3846
writeFile file: ".env", text: "SUBNET=${DOCKER_NETWORK}"
39-
sh "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml pull"
40-
sh(returnStdout: true, script: "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml up --build -d")
41-
sh "docker cp d3-btc-node0-${DOCKER_NETWORK}:/usr/bin/bitcoin-cli deploy/bitcoin/"
47+
withCredentials([usernamePassword(credentialsId: 'nexus-d3-docker', usernameVariable: 'login', passwordVariable: 'password')]) {
48+
sh "docker login nexus.iroha.tech:19002 -u ${login} -p '${password}'"
49+
50+
sh "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml pull"
51+
sh(returnStdout: true, script: "docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.ci.yml up --build -d")
52+
sh "docker cp d3-btc-node0-${DOCKER_NETWORK}:/usr/bin/bitcoin-cli deploy/bitcoin/"
53+
}
54+
4255
iC = docker.image("openjdk:8-jdk")
4356
iC.inside("--network='d3-${DOCKER_NETWORK}' -e JVM_OPTS='-Xmx3200m' -e TERM='dumb'") {
4457
sh "ln -s deploy/bitcoin/bitcoin-cli /usr/bin/bitcoin-cli"
@@ -116,6 +129,7 @@ pipeline {
116129
sh "./gradlew eth-withdrawal:shadowJar"
117130
sh "./gradlew eth-registration:shadowJar"
118131
sh "./gradlew eth-vacuum:shadowJar"
132+
sh "./gradlew chain-adapter:shadowJar"
119133

120134
sh "./gradlew btc-address-generation:shadowJar"
121135
sh "./gradlew btc-registration:shadowJar"
@@ -127,13 +141,15 @@ pipeline {
127141

128142
ethRelay = docker.build("nexus.iroha.tech:19002/${login}/eth-relay:${TAG}", "-f docker/eth-relay.dockerfile .")
129143
ethRegistration = docker.build("nexus.iroha.tech:19002/${login}/eth-registration:${TAG}", "-f docker/eth-registration.dockerfile .")
130-
notary = docker.build("nexus.iroha.tech:19002/${login}/notary:${TAG}", "-f docker/notary.dockerfile .")
144+
notary = docker.build("nexus.iroha.tech:19002/${login}/notary:${TAG}", "-f docker/eth-deposit.dockerfile .")
131145
ethWithdrawal = docker.build("nexus.iroha.tech:19002/${login}/eth-withdrawal:${TAG}", "-f docker/eth-withdrawal.dockerfile .")
132146

133147
btcAddressGeneration = docker.build("nexus.iroha.tech:19002/${login}/btc-address-generation:${TAG}", "-f docker/btc-address-generation.dockerfile .")
134148
btcRegistration = docker.build("nexus.iroha.tech:19002/${login}/btc-registration:${TAG}", "-f docker/btc-registration.dockerfile .")
135149
btcDwBridge = docker.build("nexus.iroha.tech:19002/${login}/btc-dw-bridge:${TAG}", "-f docker/btc-dw-bridge.dockerfile .")
136150

151+
chainAdapter = docker.build("nexus.iroha.tech:19002/d3-deploy/chain-adapter:${TAG}", "-f docker/chain-adapter.dockerfile .")
152+
137153
notaryRegistration.push("${TAG}")
138154

139155
ethRelay.push("${TAG}")
@@ -145,6 +161,8 @@ pipeline {
145161
btcRegistration.push("${TAG}")
146162
btcDwBridge.push("${TAG}")
147163

164+
chainAdapter.push("${TAG}")
165+
148166
}
149167
}
150168
}

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Now you can register clients and launch subsystems.
1616
## How to run notary application and services in Ethereum main net
1717
1) Run common services
1818
2) Provide ethereum passwords `configs/eth/ethereum_password_mainnet.properties` (ask someone from maintainers team about the format)
19-
3) Deploy Ethereum master contract and relay registry contract, provide notary ethereum accounts `gradle runPreDeployEthereum --args="0x6826d84158e516f631bbf14586a9be7e255b2d23"`
20-
4) Run notary service `PROFILE=mainnet gradle runEthNotary`
21-
5) Run registration service `PROFILE=mainnet gradle runEthRegistration`
22-
6) Run withdrawal service `PROFILE=mainnet gradle runWithdrawal`
23-
7) Deploy relay smart contract (one relay per one client registration) `PROFILE=mainnet gradle runDeployRelay`. Ensure relay is deployed on etherscan.io
19+
3) Deploy Ethereum master contract and relay registry contract, provide notary ethereum accounts `./gradlew runPreDeployEthereum --args="0x6826d84158e516f631bbf14586a9be7e255b2d23"`
20+
4) Run deposit service `PROFILE=mainnet ./gradlew runEthDeposit`
21+
5) Run registration service `PROFILE=mainnet ./gradlew runEthRegistration`
22+
6) Run withdrawal service `PROFILE=mainnet ./gradlew runWithdrawal`
23+
7) Deploy relay smart contract (one relay per one client registration) `PROFILE=mainnet ./gradlew runDeployRelay`. Ensure relay is deployed on etherscan.io
2424

2525
Great! So now you can move on and connect frontend application (check back-office repo in d3ledger)
2626

@@ -29,7 +29,7 @@ Passwords for Ethereum network may be set in 3 different ways:
2929

3030
1) Using `eth/ethereum_password.properties` file.
3131
2) Using environment variables(`ETH_CREDENTIALS_PASSWORD`, `ETH_NODE_LOGIN` and `ETH_NODE_PASSWORD`).
32-
3) Using command line arguments. For example `gradle runEthNotary -PcredentialsPassword=test -PnodeLogin=login -PnodePassword=password`
32+
3) Using command line arguments. For example `./gradlew runEthDeposit -PcredentialsPassword=test -PnodeLogin=login -PnodePassword=password`
3333

3434
Configurations have the following priority:
3535

@@ -38,21 +38,34 @@ Command line args > Environment variables > Properties file
3838
## How to run notary application and services in Bitcoin main net
3939
1) Run common services
4040
2) Create `.wallet` file (ask maintainers how to do that) and put it to desired location
41-
3) Run address generation process using `PROFILE=mainnet gradlew runBtcAddressGeneration`
42-
4) Create change address by running `gradlew generateBtcChangeAddress`
43-
5) Create few free addresses(addresses that may be registered by clients lately) `gradlew generateBtcFreeAddress`
44-
6) Run registration service `PROFILE=mainnet gradle runBtcRegistration`
45-
7) Run notary service `PROFILE=mainnet gradle runBtcDepositWithdrawal`
46-
41+
3) Run address generation process using `PROFILE=mainnet ./gradlew runBtcAddressGeneration`
42+
4) Create change address by running `./gradlew generateBtcChangeAddress`
43+
5) Create few free addresses(addresses that may be registered by clients lately) `./gradlew generateBtcFreeAddress`
44+
6) Run registration service `PROFILE=mainnet ./gradlew runBtcRegistration`
45+
7) Run notary service `PROFILE=mainnet ./gradlew runBtcDepositWithdrawal`
46+
47+
## How to run notification services
48+
1) Create SMTP configuration file located at `configs/smtp.properties`(see test example `configs/smtp_test.properties`). This file contains SMTP server credentials.
49+
2) Create Push API configuration file located at `configs/push.properties`(see test example `configs/push_test.properties`). This file contains VAPID keys. You can generate keys by yourself using [webpush-libs tutorial](https://github.com/web-push-libs/webpush-java/wiki/VAPID).
50+
3) Run gralde command `./gradlew runNotifications`
51+
52+
## AWS SES Integration
53+
SMTP configuration file `configs/smtp.properties` must be modified in order to be able to send email notifications via AWS SES.
54+
```
55+
smtp.host=email-smtp.eu-west-1.amazonaws.com
56+
smtp.port=25
57+
smtp.userName=ask maintainers
58+
smtp.password=ask maintainers
59+
```
4760
## Testing
48-
`gradle test` for unit tests
61+
`./gradlew test` for unit tests
4962

50-
`gradle integrationTest` for integation tests
63+
`./gradlew integrationTest` for integation tests
5164

5265
## Testing Bitcoin
53-
`gradlew btcSendToAddress -Paddress=<address> -PamountBtc=<amount>` — sends `<amount>` BTC to `<address>` in Bitcoin regtest network
66+
`./gradlew btcSendToAddress -Paddress=<address> -PamountBtc=<amount>` — sends `<amount>` BTC to `<address>` in Bitcoin regtest network
5467

55-
`gradlew btcGenerateBlocks -Pblocks=<blocks>` — generates `<blocks>` in Bitcoin regtest network
68+
`./gradlew btcGenerateBlocks -Pblocks=<blocks>` — generates `<blocks>` in Bitcoin regtest network
5669

5770
## Troubleshooting
5871

@@ -65,4 +78,7 @@ Command line args > Environment variables > Properties file
6578
127.0.0.1 d3-notary
6679
127.0.0.1 d3-eth-node0
6780
127.0.0.1 d3-btc-node0
81+
127.0.0.1 d3-rmq
82+
127.0.0.1 d3-brvs
83+
127.0.0.1 d3-brvs-mongodb
6884
```

bootstrap/ReadMe.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Bootstrap service
2+
3+
## API documentation
4+
* SwaggerUI - 'http://localhost:8080/swagger-ui.html' In SwaggerUi it is also possible to make test calls through browser
5+
* Json representation - 'http://localhost:8080/v2/api-docs' In Firefox json is more readable, so try to use it.
6+
7+
8+
## Description
9+
Service provides possibilities to automate DevOps activities.
10+
11+
It is usable for test environments and production. Only difference is that for test environments we
12+
may generate blockchain credentials using this service but for production owners of private keys
13+
should provide public keys for us.
14+
15+
Functionality:
16+
* Creation of Iroha credentials (private and public keys)
17+
* Creation of Iroha Genesis Block
18+
19+
## Startup Configuration
20+
You should provide environment parameter `btc.network` with one of three values: `TestNet3, MainNet, RegTest`
21+
Else `btc.network` parameter will be taken from application.properties file
22+
23+
## How to develop
24+
To Add generation of genesis block for new project and/or environment Create a class which should
25+
implement `GenesisInterface`
26+
27+
* `fun getProject(): String` - should provide name of project
28+
* `fun getEnvironment(): String` - should provide name of environment eg 'local_my', 'test', 'prod'
29+
* `fun createGenesisBlock(accounts:List<IrohaAccountDto>, peers:List<Peer>, blockVersion:String = "1"): String`
30+
This function should return string json representatin of genesis block. It takes Iroha peers and accounts as arguments from API request.
31+
* `fun getAccountsNeeded(): List<AccountPrototype>` - This function should return Accounts which have to present in genesis block to generate credentials for.
32+
33+
Example realisation for D3: `genesis.d3.D3TestGenesisFactory`

bootstrap/build.gradle

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
group 'd3'
2+
version '1.0'
3+
4+
buildscript {
5+
repositories {
6+
mavenCentral()
7+
jcenter()
8+
}
9+
dependencies {
10+
//Spring-boot
11+
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
12+
}
13+
}
14+
15+
apply plugin: 'application'
16+
apply plugin: "kotlin-spring" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-spring-compiler-plugin
17+
apply plugin: 'com.github.johnrengelman.shadow'
18+
shadowDistZip.classifier = 'shadow'
19+
shadowDistTar.classifier = 'shadow'
20+
21+
dependencies {
22+
23+
final def springfoxSwagger2Version = '2.9.2'
24+
final def springBootVersion = '2.1.3.RELEASE'
25+
final def kotlinVersion = '1.3.10'
26+
27+
implementation project(":notary-commons")
28+
implementation project(":eth")
29+
30+
// kotlin related
31+
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
32+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1'
33+
compile 'io.github.microutils:kotlin-logging:1.6.24'
34+
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"
35+
36+
//Iroha-java related
37+
implementation('com.github.hyperledger.iroha-java:testcontainers:3.2.1') {
38+
exclude group: 'org.slf4j'
39+
}
40+
41+
//Spring-boot
42+
implementation("org.springframework.boot:spring-boot-starter:$springBootVersion") {
43+
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
44+
}
45+
implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion") {
46+
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
47+
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
48+
exclude group: 'org.hibernate'
49+
}
50+
implementation "io.springfox:springfox-swagger2:$springfoxSwagger2Version"
51+
implementation "io.springfox:springfox-swagger-ui:$springfoxSwagger2Version"
52+
53+
//TODO this is very dirty hack. This dependency must be removed after migration to newer version of Spring Boot
54+
// https://mvnrepository.com/artifact/org.hibernate/hibernate-validator
55+
56+
implementation 'org.hibernate:hibernate-validator:6.0.14.Final'
57+
58+
implementation "org.springframework.boot:spring-boot-starter-jetty:$springBootVersion"
59+
60+
implementation "commons-logging:commons-logging:1.2"
61+
62+
compile 'com.google.protobuf:protobuf-java-util:3.6.1'
63+
compile 'org.bitcoinj:bitcoinj-core:0.14.7'
64+
65+
//Web3j
66+
compile 'org.web3j:crypto:4.1.1'
67+
compile 'org.web3j:core:4.1.1'
68+
69+
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
70+
71+
}
72+
73+
sourceCompatibility = 1.8
74+
75+
76+
mainClassName = "jp.co.soramitsu.bootstrap.BootstrapMain"
77+
78+
task runBootstrap(type: JavaExec ) {
79+
main = mainClassName
80+
classpath = sourceSets.main.runtimeClasspath
81+
setWorkingDir("$rootDir/")
82+
}
83+
84+
sonarqube {
85+
properties {
86+
property "sonar.projectKey", "bootstrap"
87+
}
88+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
@file:JvmName("BootstrapMain")
3+
4+
package jp.co.soramitsu.bootstrap
5+
6+
import mu.KLogging
7+
import org.springframework.boot.SpringApplication
8+
import org.springframework.boot.autoconfigure.SpringBootApplication
9+
import org.springframework.context.annotation.ComponentScan
10+
11+
@SpringBootApplication
12+
@ComponentScan(basePackages = ["jp.co.soramitsu.bootstrap"])
13+
class Application
14+
15+
private val logger = KLogging().logger
16+
17+
fun main(args: Array<String>) {
18+
val app = SpringApplication(Application::class.java)
19+
app.run(*args)
20+
}
21+
22+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package jp.co.soramitsu.bootstrap.config
2+
3+
import jp.co.soramitsu.bootstrap.genesis.d3.D3TestGenesisFactory
4+
import jp.co.soramitsu.bootstrap.genesis.GenesisInterface
5+
import org.springframework.context.annotation.Bean
6+
import org.springframework.context.annotation.Configuration
7+
import springfox.documentation.swagger2.annotations.EnableSwagger2
8+
9+
@Configuration
10+
@EnableSwagger2
11+
class BootstrapConfig {
12+
13+
@Bean
14+
fun genesisFactories(): List<GenesisInterface> {
15+
return listOf(D3TestGenesisFactory())
16+
}
17+
}
18+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package jp.co.soramitsu.bootstrap.controller
2+
3+
import jp.co.soramitsu.bootstrap.dto.BtcNetwork
4+
import jp.co.soramitsu.bootstrap.dto.BtcWallet
5+
import mu.KLogging
6+
import org.bitcoinj.core.NetworkParameters
7+
import org.bitcoinj.wallet.Wallet
8+
import org.springframework.beans.factory.annotation.Value
9+
import org.springframework.http.HttpStatus
10+
import org.springframework.http.ResponseEntity
11+
import org.springframework.web.bind.annotation.GetMapping
12+
import org.springframework.web.bind.annotation.RequestMapping
13+
import org.springframework.web.bind.annotation.RestController
14+
import java.io.ByteArrayOutputStream
15+
import javax.xml.bind.DatatypeConverter
16+
17+
@RestController
18+
@RequestMapping("/btc")
19+
class BtcController {
20+
21+
private val log = KLogging().logger
22+
@Value("\${btc.network}")
23+
private lateinit var network: BtcNetwork
24+
25+
@GetMapping("/create/wallet")
26+
fun createWallet(): ResponseEntity<BtcWallet> {
27+
try {
28+
return ResponseEntity.ok<BtcWallet>(createWallet(network.params))
29+
} catch (e: Exception) {
30+
log.error("Error creating Bitcoin wallet", e)
31+
val response = BtcWallet(network = network)
32+
response.errorCode = e.javaClass.simpleName
33+
response.message = e.message
34+
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response)
35+
}
36+
}
37+
38+
private fun createWallet(netParams: NetworkParameters): BtcWallet {
39+
val wallet = Wallet(netParams)
40+
41+
val out = ByteArrayOutputStream(1024)
42+
wallet.saveToFileStream(out)
43+
val walletBytes = out.toByteArray()
44+
out.reset()
45+
return BtcWallet(DatatypeConverter.printBase64Binary(walletBytes), network)
46+
}
47+
}

0 commit comments

Comments
 (0)