Skip to content

Commit 68ed0a3

Browse files
endpoint accepts ethereum credentials as JSON strings
Signed-off-by: Alexey Chernyshov <alexey.n.chernyshov@gmail.com>
1 parent 3f9dfc6 commit 68ed0a3

3 files changed

Lines changed: 57 additions & 18 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ buildscript {
55
ext.springfoxSwagger2Version = '2.9.2'
66
ext.springBootVersion = '2.1.3.RELEASE'
77
ext.kotlinVersion = '1.3.10'
8-
ext.notary_version='428c4ae8c6ad99d35efc9b8099fa994fa4613c36'
9-
ext.d3EthVersion = '9b302a5fcb211878b9754a426195bba012b630f2'
8+
ext.notary_version='7dc5f678ea0e2450ffc9078ec33fa8f0af6f9016'
9+
ext.d3EthVersion = '0b6cf3625db33ccd8e779b3212aca784e884adcf'
1010

1111
repositories {
1212
mavenCentral()

src/main/kotlin/jp/co/soramitsu/bootstrap/controller/EthController.kt

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package jp.co.soramitsu.bootstrap.controller
88
import com.d3.eth.sidechain.util.DeployHelper
99
import com.d3.eth.sidechain.util.DeployHelperBuilder
1010
import com.d3.eth.sidechain.util.hashToAddAndRemovePeer
11+
import com.fasterxml.jackson.databind.ObjectMapper
1112
import jp.co.soramitsu.bootstrap.dto.*
1213
import jp.co.soramitsu.bootstrap.utils.defaultByteHash
1314
import jp.co.soramitsu.bootstrap.utils.defaultIrohaHash
@@ -17,9 +18,26 @@ import org.springframework.http.HttpStatus
1718
import org.springframework.http.ResponseEntity
1819
import org.springframework.web.bind.annotation.*
1920
import org.web3j.crypto.*
20-
import java.lang.IllegalArgumentException
21+
import org.web3j.crypto.CipherException
22+
import java.io.IOException
2123
import javax.validation.constraints.NotNull
2224

25+
/**
26+
* TODO remove after merge of https://github.com/web3j/web3j/pull/1010
27+
* Load credentials from JSON wallet string.
28+
* @param password - password to decrypt JSON wallet string
29+
* @param content - JSON wallet content string
30+
* @return Ethereum credentials
31+
* @throws CipherException if the underlying cipher is not available
32+
* @throws IOException if a low-level I/O problem (unexpected end-of-input,
33+
* network error) occurs
34+
*/
35+
@Throws(IOException::class, CipherException::class)
36+
fun loadJsonCredentials(password: String, content: String): Credentials {
37+
val walletFile = ObjectMapper().readValue(content, WalletFile::class.java)
38+
return Credentials.create(Wallet.decrypt(password, walletFile))
39+
}
40+
2341
@RestController
2442
@RequestMapping("/eth")
2543
class EthController {
@@ -28,9 +46,15 @@ class EthController {
2846
@PostMapping("/deploy/D3/masterContract/update")
2947
fun addPeerToMasterContract(@NotNull @RequestBody request: UpdateMasterContractRequest): ResponseEntity<UpdateMasterContractResponse> {
3048
try {
49+
val credentials = loadJsonCredentials(
50+
request.network.ethereumCredentials.credentialsPassword,
51+
request.network.ethereumCredentials.credentials
52+
)
3153
val deployHelper = DeployHelperBuilder(
3254
request.network.ethereumConfig,
33-
request.network.ethPasswords
55+
request.network.ethereumCredentials.nodeLogin,
56+
request.network.ethereumCredentials.nodePassword,
57+
credentials
3458
).setFastTransactionManager()
3559
.build()
3660
if (request.masterContract.address != null) {
@@ -43,9 +67,11 @@ class EthController {
4367
)
4468
}.map { it.ecKeyPair }
4569

46-
if(ecKeyPairs.isEmpty()){
47-
throw IllegalArgumentException("Provide paths to wallets of notaries, " +
48-
"registered in smart contract for signature creation")
70+
if (ecKeyPairs.isEmpty()) {
71+
throw IllegalArgumentException(
72+
"Provide paths to wallets of notaries, " +
73+
"registered in smart contract for signature creation"
74+
)
4975
}
5076

5177
var addResult = true
@@ -205,10 +231,17 @@ class EthController {
205231
}
206232

207233
private fun createSmartContractDeployHelper(network: EthereumNetworkProperties): DeployHelper {
234+
val credentials = loadJsonCredentials(
235+
network.ethereumCredentials.credentialsPassword,
236+
network.ethereumCredentials.credentials
237+
)
208238
return DeployHelperBuilder(
209239
network.ethereumConfig,
210-
network.ethPasswords
211-
).setFastTransactionManager()
240+
network.ethereumCredentials.nodeLogin,
241+
network.ethereumCredentials.nodePassword,
242+
credentials
243+
)
244+
.setFastTransactionManager()
212245
.build()
213246
}
214247

src/main/kotlin/jp/co/soramitsu/bootstrap/dto/EthereumModel.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,33 @@
55

66
package jp.co.soramitsu.bootstrap.dto
77

8-
import com.d3.commons.config.EthereumConfig
9-
import com.d3.commons.config.EthereumPasswords
8+
import integration.eth.config.EthereumConfig
109
import org.web3j.crypto.WalletFile
1110

1211
data class EthereumNetworkProperties(
13-
val ethPasswords: EthereumPasswordsImpl = EthereumPasswordsImpl(),
12+
val ethereumCredentials: EthereumCredentials = EthereumCredentials(),
1413
val ethereumConfig: EthereumConfigImpl = EthereumConfigImpl()
1514
)
1615

17-
data class EthereumPasswordsImpl(
18-
override val credentialsPassword: String = "user",
19-
override val nodeLogin: String? = null,
20-
override val nodePassword: String? = null
21-
) : EthereumPasswords
16+
/**
17+
* Credentials for Ethereum network
18+
* @param credentials - encrypted ethereum credentials in JSON
19+
* @param credentialsPassword - password to decrypt credentials
20+
* @param nodeLogin - login to Ethereum node
21+
* @param nodePassword - password to Ethereum node
22+
*/
23+
data class EthereumCredentials(
24+
val credentials: String = "",
25+
val credentialsPassword: String = "user",
26+
val nodeLogin: String? = null,
27+
val nodePassword: String? = null
28+
)
2229

2330
/**
2431
* Default parameters are Ropsten testnet parameters
2532
*/
2633
data class EthereumConfigImpl(
2734
override val url: String = "http://parity-d3.test.iroha.tech:8545",
28-
override val credentialsPath: String = "some\\path\\to\\genesis.key",
2935
override val gasPrice: Long = 100000000000,
3036
override val gasLimit: Long = 4500000,
3137
override val confirmationPeriod: Long = 0

0 commit comments

Comments
 (0)