Skip to content

Commit 559a1f8

Browse files
Merge pull request #320 from d3ledger/master-release
release v0.2.0-alpha
2 parents 7b17964 + 8884aaa commit 559a1f8

File tree

312 files changed

+9173
-5621
lines changed

Some content is hidden

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

312 files changed

+9173
-5621
lines changed

.gitignore

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,46 @@ hs_err_pid*
2525
### Gradle template
2626
.gradle
2727
/build/
28-
/notary-integration-test/build/
29-
/notary-integration-test/gradle/
30-
/notary-integration-test/gradlew
3128
/btc/build/
3229
/btc/gradle/
3330
/btc/gradlew
31+
/btc-address-generation/build/
32+
/btc-address-generation/gradle/
33+
/btc-address-generation/gradlew
3434
/btc-deposit/build/
3535
/btc-deposit/gradle/
3636
/btc-deposit/gradlew
3737
/btc-registration/build/
3838
/btc-registration/gradle/
3939
/btc-registration/gradlew
40-
/btc-pregeneration/build/
41-
/btc-pregeneration/gradle/
42-
/btc-pregeneration/gradlew
43-
/d3testreport/gradle
44-
/d3testreport/gradlew
45-
/d3testreport/gradlew.bat
46-
/d3testreport/build
4740
/btc-withdrawal/build
4841
/btc-withdrawal/gradle
4942
/btc-withdrawal/gradlew
5043
/btc-withdrawal/gradlew.bat
44+
/d3testreport/gradle
45+
/d3testreport/gradlew
46+
/d3testreport/gradlew.bat
47+
/d3testreport/build
48+
/eth/build/
49+
/eth-erc20-registration/build/
50+
/eth-registration/build/
51+
/eth-vacuum/build/
52+
/eth-withdrawal/build/
53+
/notary-commons/build/
54+
/notary-btc-integration-test/build/
55+
/notary-btc-integration-test/gradle/
56+
/notary-btc-integration-test/gradlew
57+
/notary-eth-integration-test/build/
58+
/notary-eth-integration-test/gradle/
59+
/notary-eth-integration-test/gradlew
60+
/notary-iroha-integration-test/build/
61+
/notary-iroha-integration-test/gradle/
62+
/notary-iroha-integration-test/gradlew
63+
/test-longevity/build/
64+
/btc-dw-bridge/build
65+
/btc-dw-bridge/gradle
66+
/btc-dw-bridge/gradlew
67+
/btc-dw-bridge/gradlew.bat
5168
*gradlew.bat
5269

5370
# Ignore Gradle GUI config
@@ -124,9 +141,9 @@ deploy/ethereum/keys/test
124141

125142
# Bitcoin wallets, blockchain and etc.
126143
deploy/bitcoin/testnet/d3.wallet
127-
deploy/bitcoin/testnet/blocks/deposit/
128-
deploy/bitcoin/regtest/blocks/deposit/
129-
deploy/bitcoin/testnet/blocks/withdrawal/
130-
deploy/bitcoin/regtest/blocks/withdrawal/
144+
deploy/bitcoin/testnet/blocks/
145+
deploy/bitcoin/regtest/blocks/
131146
deploy/bitcoin/regtest/d3.wallet
147+
deploy/bitcoin/testnet/d3.wallet
132148
deploy/bitcoin/regtest/d3-test.wallet
149+
deploy/bitcoin/mainnet/

Jenkinsfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ pipeline {
8585
done < <(docker ps --filter "network=d3-${DOCKER_NETWORK}" --format "{{.ID}} {{.Names}}")
8686
"""
8787

88-
sh "tar -zcvf build-logs/notaryIntegrationTest.gz -C notary-integration-test/build/reports/tests integrationTest || true"
88+
sh "tar -zcvf build-logs/notaryIrohaIntegrationTest.gz -C notary-iroha-integration-test/build/reports/tests integrationTest || true"
89+
sh "tar -zcvf build-logs/notaryEthIntegrationTest.gz -C notary-eth-integration-test/build/reports/tests integrationTest || true"
90+
sh "tar -zcvf build-logs/notaryBtcIntegrationTest.gz -C notary-btc-integration-test/build/reports/tests integrationTest || true"
8991
sh "tar -zcvf build-logs/jacoco.gz -C build/reports jacoco || true"
9092
sh "tar -zcvf build-logs/dokka.gz -C build/reports dokka || true"
9193
archiveArtifacts artifacts: 'build-logs/*.gz'

btc-pregeneration/build.gradle renamed to btc-address-generation/build.gradle

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,30 @@ buildscript {
1212
apply plugin: 'application'
1313
apply plugin: "kotlin-spring" // See https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-spring-compiler-plugin
1414
apply plugin: 'org.springframework.boot'
15-
mainClassName = "pregeneration.btc.BtcPreGenerationMain"
15+
mainClassName = "generation.btc.BtcAddressGenerationMain"
1616

1717
dependencies {
1818
compile project(":btc")
1919
}
2020

21-
task runBtcPreGen(type: JavaExec) {
22-
main = 'pregeneration.btc.BtcPreGenerationMain'
21+
task runBtcAddressGeneration(type: JavaExec) {
22+
main = 'generation.btc.BtcAddressGenerationMain'
2323
classpath = sourceSets.main.runtimeClasspath
2424
setWorkingDir("$rootDir/")
2525
systemProperty 'java.library.path', getIrohaLibPath()
2626
environment "LD_LIBRARY_PATH", getIrohaLibPath()
2727
}
2828

29-
task runBtcPreGenTrigger(type: JavaExec) {
30-
main = 'pregeneration.btc.trigger.BtcPreGenerationTriggerMain'
29+
task generateBtcChangeAddress(type: JavaExec) {
30+
main = 'generation.btc.trigger.BtcChangeAddressGeneration'
31+
classpath = sourceSets.main.runtimeClasspath
32+
setWorkingDir("$rootDir/")
33+
systemProperty 'java.library.path', getIrohaLibPath()
34+
environment "LD_LIBRARY_PATH", getIrohaLibPath()
35+
}
36+
37+
task generateBtcFreeAddress(type: JavaExec) {
38+
main = 'generation.btc.trigger.BtcFreeAddressGeneration'
3139
classpath = sourceSets.main.runtimeClasspath
3240
setWorkingDir("$rootDir/")
3341
systemProperty 'java.library.path', getIrohaLibPath()
@@ -36,6 +44,6 @@ task runBtcPreGenTrigger(type: JavaExec) {
3644

3745
sonarqube {
3846
properties {
39-
property "sonar.projectKey", "notary:btc-pregeneration"
47+
property "sonar.projectKey", "notary:btc-addres-generation"
4048
}
41-
}
49+
}
Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package pregeneration.btc.config
1+
package generation.btc.config
22

33
import config.loadConfigs
44
import model.IrohaCredential
@@ -16,46 +16,50 @@ import sidechain.iroha.util.ModelUtil
1616
import wallet.WalletFile
1717
import java.io.File
1818

19-
val btcPreGenConfig =
20-
loadConfigs("btc-pregen", BtcPreGenConfig::class.java, "/btc/pregeneration.properties")
19+
val btcAddressGenerationConfig =
20+
loadConfigs(
21+
"btc-address-generation",
22+
BtcAddressGenerationConfig::class.java,
23+
"/btc/address_generation.properties"
24+
).get()
2125

2226
@Configuration
23-
class BtcPreGenerationAppConfiguration {
27+
class BtcAddressGenerationAppConfiguration {
2428

2529
private val registrationKeyPair =
2630
ModelUtil.loadKeypair(
27-
btcPreGenConfig.registrationAccount.pubkeyPath,
28-
btcPreGenConfig.registrationAccount.privkeyPath
31+
btcAddressGenerationConfig.registrationAccount.pubkeyPath,
32+
btcAddressGenerationConfig.registrationAccount.privkeyPath
2933
).fold({ keypair ->
3034
keypair
3135
}, { ex -> throw ex })
3236

3337
private val registrationCredential =
34-
IrohaCredential(btcPreGenConfig.registrationAccount.accountId, registrationKeyPair)
38+
IrohaCredential(btcAddressGenerationConfig.registrationAccount.accountId, registrationKeyPair)
3539

3640
private val mstRegistrationKeyPair =
3741
ModelUtil.loadKeypair(
38-
btcPreGenConfig.mstRegistrationAccount.pubkeyPath,
39-
btcPreGenConfig.mstRegistrationAccount.privkeyPath
42+
btcAddressGenerationConfig.mstRegistrationAccount.pubkeyPath,
43+
btcAddressGenerationConfig.mstRegistrationAccount.privkeyPath
4044
).fold({ keypair ->
4145
keypair
4246
}, { ex -> throw ex })
4347

4448
private val mstRegistrationCredential =
45-
IrohaCredential(btcPreGenConfig.mstRegistrationAccount.accountId, mstRegistrationKeyPair)
49+
IrohaCredential(btcAddressGenerationConfig.mstRegistrationAccount.accountId, mstRegistrationKeyPair)
4650

4751
@Bean
4852
fun irohaNetwork() = IrohaNetworkImpl(
49-
btcPreGenConfig.iroha.hostname,
50-
btcPreGenConfig.iroha.port
53+
btcAddressGenerationConfig.iroha.hostname,
54+
btcAddressGenerationConfig.iroha.port
5155
)
5256

5357
@Bean
54-
fun preGenConfig() = btcPreGenConfig
58+
fun btcAddressGenerationConfig() = btcAddressGenerationConfig
5559

5660
@Bean
5761
fun walletFile(): WalletFile {
58-
val walletFile = File(btcPreGenConfig.btcWalletFilePath)
62+
val walletFile = File(btcAddressGenerationConfig.btcWalletFilePath)
5963
val wallet = Wallet.loadFromFile(walletFile)
6064
return WalletFile(wallet, walletFile)
6165
}
@@ -66,8 +70,8 @@ class BtcPreGenerationAppConfiguration {
6670
return NotaryPeerListProviderImpl(
6771
registrationCredential,
6872
irohaNetwork,
69-
btcPreGenConfig.notaryListStorageAccount,
70-
btcPreGenConfig.notaryListSetterAccount
73+
btcAddressGenerationConfig.notaryListStorageAccount,
74+
btcAddressGenerationConfig.notaryListSetterAccount
7175
)
7276
}
7377

@@ -80,12 +84,15 @@ class BtcPreGenerationAppConfiguration {
8084
fun multiSigConsumer(irohaNetwork: IrohaNetwork) = IrohaConsumerImpl(mstRegistrationCredential, irohaNetwork)
8185

8286
@Bean
83-
fun notaryAccount() = btcPreGenConfig.notaryAccount
87+
fun notaryAccount() = btcAddressGenerationConfig.notaryAccount
88+
89+
@Bean
90+
fun changeAddressStorageAccount() = btcAddressGenerationConfig.changeAddressesStorageAccount
8491

8592
@Bean
8693
fun irohaChainListener() = IrohaChainListener(
87-
btcPreGenConfig.iroha.hostname,
88-
btcPreGenConfig.iroha.port,
94+
btcAddressGenerationConfig.iroha.hostname,
95+
btcAddressGenerationConfig.iroha.port,
8996
registrationCredential
9097
)
9198

btc-pregeneration/src/main/kotlin/pregeneration/btc/config/BtcPreGenConfig.kt renamed to btc-address-generation/src/main/kotlin/generation/btc/config/BtcAddressGenerationConfig.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package pregeneration.btc.config
1+
package generation.btc.config
22

33
import config.IrohaConfig
44
import config.IrohaCredentialConfig
55

6-
interface BtcPreGenConfig {
6+
interface BtcAddressGenerationConfig {
77
/*
88
Account for triggering.
9-
Triggering this account means starting BTC addresses pregeneration
9+
Triggering this account means starting BTC addresses generation
1010
*/
1111
val pubKeyTriggerAccount: String
1212

@@ -27,6 +27,9 @@ interface BtcPreGenConfig {
2727
//Account that stores all registered notaries
2828
val notaryListStorageAccount: String
2929

30+
//Account that stores change addresses
31+
val changeAddressesStorageAccount: String
32+
3033
//Account that sets registered notaries
3134
val notaryListSetterAccount: String
3235

btc-pregeneration/src/main/kotlin/pregeneration/btc/BtcPreGenInitialization.kt renamed to btc-address-generation/src/main/kotlin/generation/btc/init/BtcAddressGenerationInitialization.kt

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
package pregeneration.btc
1+
package generation.btc.init
22

33
import com.github.kittinunf.result.Result
44
import com.github.kittinunf.result.failure
55
import com.github.kittinunf.result.flatMap
66
import com.github.kittinunf.result.map
7+
import generation.btc.config.BtcAddressGenerationConfig
78
import healthcheck.HealthyService
89
import io.reactivex.Observable
910
import iroha.protocol.BlockOuterClass
11+
import iroha.protocol.Commands
1012
import model.IrohaCredential
1113
import mu.KLogging
1214
import org.springframework.beans.factory.annotation.Autowired
1315
import org.springframework.beans.factory.annotation.Qualifier
1416
import org.springframework.stereotype.Component
15-
import pregeneration.btc.config.BtcPreGenConfig
16-
import provider.btc.BtcPublicKeyProvider
17+
import provider.btc.generation.BtcPublicKeyProvider
18+
import provider.btc.address.BtcAddressType
19+
import provider.btc.address.getAddressTypeByAccountId
1720
import sidechain.iroha.IrohaChainListener
1821
import sidechain.iroha.consumer.IrohaNetwork
1922
import sidechain.iroha.util.getAccountDetails
2023
import sidechain.iroha.util.getSetDetailCommands
2124

2225
/*
23-
This class listens to special account to be triggered and starts pregeneration process
26+
This class listens to special account to be triggered and starts generation process
2427
*/
2528
@Component
26-
class BtcPreGenInitialization(
29+
class BtcAddressGenerationInitialization(
2730
@Qualifier("registrationCredential")
2831
@Autowired private val registrationCredential: IrohaCredential,
2932
@Autowired private val irohaNetwork: IrohaNetwork,
30-
@Autowired private val btcPreGenConfig: BtcPreGenConfig,
33+
@Autowired private val btcAddressGenerationConfig: BtcAddressGenerationConfig,
3134
@Autowired private val btcPublicKeyProvider: BtcPublicKeyProvider,
3235
@Autowired private val irohaChainListener: IrohaChainListener
3336
) : HealthyService() {
@@ -45,15 +48,16 @@ class BtcPreGenInitialization(
4548
private fun initIrohaObservable(irohaObservable: Observable<BlockOuterClass.Block>) {
4649
irohaObservable.subscribe({ block ->
4750
getSetDetailCommands(block).forEach { command ->
48-
if (command.setAccountDetail.accountId == btcPreGenConfig.pubKeyTriggerAccount) {
51+
if (isAddressGenerationTriggered(command)) {
4952
//add new public key to session account, if trigger account was changed
5053
val sessionAccountName = command.setAccountDetail.key
5154
onGenerateKey(sessionAccountName).fold(
5255
{ pubKey -> logger.info { "New public key $pubKey for BTC multisignature address was created" } },
5356
{ ex -> logger.error("Cannot generate public key for BTC multisignature address", ex) })
54-
} else if (command.setAccountDetail.accountId.endsWith("btcSession")) {
57+
} else if (isNewKey(command)) {
58+
val accountId = command.setAccountDetail.accountId
5559
//create multisignature address, if we have enough keys in session account
56-
onGenerateMultiSigAddress(command.setAccountDetail.accountId).failure { ex ->
60+
onGenerateMultiSigAddress(accountId, getAddressTypeByAccountId(accountId)).failure { ex ->
5761
logger.error(
5862
"Cannot generate multi signature address", ex
5963
)
@@ -66,26 +70,34 @@ class BtcPreGenInitialization(
6670
})
6771
}
6872

73+
// Checks if address generation account was triggered
74+
private fun isAddressGenerationTriggered(command: Commands.Command) =
75+
command.setAccountDetail.accountId == btcAddressGenerationConfig.pubKeyTriggerAccount
76+
77+
// Check if new key was added
78+
private fun isNewKey(command: Commands.Command) = command.setAccountDetail.accountId.endsWith("btcSession")
6979

7080
private fun onGenerateKey(sessionAccountName: String): Result<String, Exception> {
7181
return btcPublicKeyProvider.createKey(sessionAccountName)
7282
}
7383

74-
private fun onGenerateMultiSigAddress(sessionAccount: String): Result<Unit, Exception> {
84+
private fun onGenerateMultiSigAddress(
85+
sessionAccount: String,
86+
addressType: BtcAddressType
87+
): Result<Unit, Exception> {
7588
return getAccountDetails(
7689
registrationCredential,
7790
irohaNetwork,
7891
sessionAccount,
79-
btcPreGenConfig.registrationAccount.accountId
92+
btcAddressGenerationConfig.registrationAccount.accountId
8093
).flatMap { details ->
8194
val notaryKeys = details.values
82-
btcPublicKeyProvider.checkAndCreateMultiSigAddress(notaryKeys)
95+
btcPublicKeyProvider.checkAndCreateMultiSigAddress(notaryKeys, addressType)
8396
}
8497
}
8598

8699
/**
87100
* Logger
88101
*/
89102
companion object : KLogging()
90-
91103
}

0 commit comments

Comments
 (0)