@@ -8,6 +8,7 @@ package jp.co.soramitsu.bootstrap.controller
88import com.d3.eth.sidechain.util.DeployHelper
99import com.d3.eth.sidechain.util.DeployHelperBuilder
1010import com.d3.eth.sidechain.util.hashToAddAndRemovePeer
11+ import com.fasterxml.jackson.databind.ObjectMapper
1112import jp.co.soramitsu.bootstrap.dto.*
1213import jp.co.soramitsu.bootstrap.utils.defaultByteHash
1314import jp.co.soramitsu.bootstrap.utils.defaultIrohaHash
@@ -17,9 +18,26 @@ import org.springframework.http.HttpStatus
1718import org.springframework.http.ResponseEntity
1819import org.springframework.web.bind.annotation.*
1920import org.web3j.crypto.*
20- import java.lang.IllegalArgumentException
21+ import org.web3j.crypto.CipherException
22+ import java.io.IOException
2123import 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" )
2543class 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
0 commit comments