Skip to content

Commit d818fd9

Browse files
authored
Merge pull request #705 from input-output-hk/feature/ETCM-126-rpc-cleanup
[ETCM-126] RPC cleanup
2 parents e73f77b + 6aed8b6 commit d818fd9

File tree

7 files changed

+1
-190
lines changed

7 files changed

+1
-190
lines changed

src/main/scala/io/iohk/ethereum/jsonrpc/JsonMethodsImplicits.scala

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -308,33 +308,4 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
308308
def encodeJson(t: LockAccountResponse): JValue =
309309
JBool(t.result)
310310
}
311-
312-
implicit val daedalus_deleteWallet = new Codec[DeleteWalletRequest, DeleteWalletResponse] {
313-
def decodeJson(params: Option[JArray]): Either[JsonRpcError, DeleteWalletRequest] = {
314-
params match {
315-
case Some(JArray(JString(addr) :: _)) =>
316-
extractAddress(addr).map(DeleteWalletRequest)
317-
case _ =>
318-
Left(InvalidParams())
319-
}
320-
}
321-
322-
def encodeJson(t: DeleteWalletResponse): JValue =
323-
JBool(t.result)
324-
}
325-
326-
implicit val daedalus_changePassphrase = new Codec[ChangePassphraseRequest, ChangePassphraseResponse] {
327-
def decodeJson(params: Option[JArray]): Either[JsonRpcError, ChangePassphraseRequest] = {
328-
params match {
329-
case Some(JArray(JString(addr) :: JString(oldPassphrase) :: JString(newPassphrase) :: _)) =>
330-
extractAddress(addr).map(a => ChangePassphraseRequest(a, oldPassphrase, newPassphrase))
331-
case _ =>
332-
Left(InvalidParams())
333-
}
334-
}
335-
336-
def encodeJson(t: ChangePassphraseResponse): JValue =
337-
JString("")
338-
}
339-
340311
}

src/main/scala/io/iohk/ethereum/jsonrpc/JsonRpcController.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,6 @@ class JsonRpcController(
327327
private def handleDaedalusRequest: PartialFunction[JsonRpcRequest, Future[JsonRpcResponse]] = {
328328
case req @ JsonRpcRequest(_, "daedalus_getAccountTransactions", _, _) =>
329329
handle[GetAccountTransactionsRequest, GetAccountTransactionsResponse](ethService.getAccountTransactions, req)
330-
331-
case req @ JsonRpcRequest(_, "daedalus_deleteWallet", _, _) =>
332-
handle[DeleteWalletRequest, DeleteWalletResponse](personalService.deleteWallet, req)
333-
334-
case req @ JsonRpcRequest(_, "daedalus_changePassphrase", _, _) =>
335-
handle[ChangePassphraseRequest, ChangePassphraseResponse](personalService.changePassphrase, req)
336330
}
337331

338332
private def handleQARequest: PartialFunction[JsonRpcRequest, Future[JsonRpcResponse]] = {
@@ -402,5 +396,4 @@ class JsonRpcController(
402396

403397
private def errorResponse[T](req: JsonRpcRequest, error: JsonRpcError): JsonRpcResponse =
404398
JsonRpcResponse(req.jsonrpc, None, Some(error), req.id.getOrElse(0))
405-
406399
}

src/main/scala/io/iohk/ethereum/jsonrpc/PersonalService.scala

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ object PersonalService {
5555
case class EcRecoverRequest(message: ByteString, signature: ECDSASignature)
5656
case class EcRecoverResponse(address: Address)
5757

58-
case class DeleteWalletRequest(address: Address)
59-
case class DeleteWalletResponse(result: Boolean)
60-
61-
case class ChangePassphraseRequest(address: Address, oldPassphrase: String, newPassphrase: String)
62-
case class ChangePassphraseResponse()
63-
6458
val InvalidKey = InvalidParams("Invalid key provided, expected 32 bytes (64 hex digits)")
6559
val InvalidAddress = InvalidParams("Invalid address, expected 20 bytes (40 hex digits)")
6660
val InvalidPassphrase = LogicError("Could not decrypt key with given passphrase")
@@ -181,21 +175,6 @@ class PersonalService(
181175
}
182176
}
183177

184-
def deleteWallet(request: DeleteWalletRequest): ServiceResponse[DeleteWalletResponse] = Future {
185-
unlockedWallets.remove(request.address)
186-
187-
keyStore.deleteWallet(request.address)
188-
.map(DeleteWalletResponse.apply)
189-
.left.map(handleError)
190-
}
191-
192-
def changePassphrase(request: ChangePassphraseRequest): ServiceResponse[ChangePassphraseResponse] = Future {
193-
import request._
194-
keyStore.changePassphrase(address, oldPassphrase, newPassphrase)
195-
.map(_ => ChangePassphraseResponse())
196-
.left.map(handleError)
197-
}
198-
199178
private def sendTransaction(request: TransactionRequest, wallet: Wallet): Future[ByteString] = {
200179
implicit val timeout = Timeout(txPoolConfig.pendingTxManagerQueryTimeout)
201180

src/main/scala/io/iohk/ethereum/keystore/KeyStore.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ trait KeyStore {
3535
def listAccounts(): Either[KeyStoreError, List[Address]]
3636

3737
def unlockAccount(address: Address, passphrase: String): Either[KeyStoreError, Wallet]
38-
39-
def deleteWallet(address: Address): Either[KeyStoreError, Boolean]
40-
41-
def changePassphrase(address: Address, oldPassphrase: String, newPassphrase: String): Either[KeyStoreError, Unit]
4238
}
4339

4440
class KeyStoreImpl(keyStoreConfig: KeyStoreConfig, secureRandom: SecureRandom) extends KeyStore with Logger {
@@ -95,11 +91,6 @@ class KeyStoreImpl(keyStoreConfig: KeyStoreConfig, secureRandom: SecureRandom) e
9591
def unlockAccount(address: Address, passphrase: String): Either[KeyStoreError, Wallet] =
9692
load(address).flatMap(_.decrypt(passphrase).left.map(_ => DecryptionFailed)).map(key => Wallet(address, key))
9793

98-
def deleteWallet(address: Address): Either[KeyStoreError, Boolean] = for {
99-
fileName <- findKeyFileName(address)
100-
deleted <- deleteFile(fileName)
101-
} yield deleted
102-
10394
def changePassphrase(address: Address, oldPassphrase: String, newPassphrase: String): Either[KeyStoreError, Unit] = for {
10495
_ <- validateNewPassPhrase(newPassphrase)
10596
oldEncKey <- load(address)

src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerSpec.scala

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -573,42 +573,6 @@ class JsonRpcControllerSpec
573573
response.result shouldBe Some(JArray(peers.map(info => JString(info.toString))))
574574
}
575575

576-
it should "daedalus_deleteWallet" in new TestSetup {
577-
val address = Address(42)
578-
val params = JArray(JString(address.toString) :: Nil)
579-
580-
(personalService.deleteWallet _)
581-
.expects(DeleteWalletRequest(address))
582-
.returning(Future.successful(Right(DeleteWalletResponse(true))))
583-
584-
val rpcRequest = JsonRpcRequest("2.0", "daedalus_deleteWallet", Some(params), Some(1))
585-
val response = jsonRpcController.handleRequest(rpcRequest).futureValue
586-
587-
response.jsonrpc shouldBe "2.0"
588-
response.id shouldBe JInt(1)
589-
response.error shouldBe None
590-
response.result shouldBe Some(JBool(true))
591-
}
592-
593-
it should "daedalus_changePassphrase" in new TestSetup {
594-
val address = Address(42)
595-
val oldPassphrase = "weakpass"
596-
val newPassphrase = "very5tr0ng&l0ngp4s5phr4s3"
597-
val params = JArray(JString(address.toString) :: JString(oldPassphrase) :: JString(newPassphrase) :: Nil)
598-
599-
(personalService.changePassphrase _)
600-
.expects(ChangePassphraseRequest(address, oldPassphrase, newPassphrase))
601-
.returning(Future.successful(Right(ChangePassphraseResponse())))
602-
603-
val rpcRequest = JsonRpcRequest("2.0", "daedalus_changePassphrase", Some(params), Some(1))
604-
val response = jsonRpcController.handleRequest(rpcRequest).futureValue
605-
606-
response.jsonrpc shouldBe "2.0"
607-
response.id shouldBe JInt(1)
608-
response.error shouldBe None
609-
response.result shouldBe Some(JString(""))
610-
}
611-
612576
it should "eth_sendTransaction" in new TestSetup {
613577
val params = JArray(
614578
JObject(

src/test/scala/io/iohk/ethereum/jsonrpc/PersonalServiceSpec.scala

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.iohk.ethereum.db.storage.AppStateStorage
1111
import io.iohk.ethereum.domain.{UInt256, _}
1212
import io.iohk.ethereum.jsonrpc.JsonRpcErrors._
1313
import io.iohk.ethereum.jsonrpc.PersonalService._
14-
import io.iohk.ethereum.keystore.KeyStore.{DecryptionFailed, IOError, KeyStoreError}
14+
import io.iohk.ethereum.keystore.KeyStore.{DecryptionFailed, IOError}
1515
import io.iohk.ethereum.keystore.{KeyStore, Wallet}
1616
import io.iohk.ethereum.transactions.PendingTransactionsManager._
1717
import io.iohk.ethereum.utils.{BlockchainConfig, MonetaryPolicyConfig, TxPoolConfig}
@@ -390,48 +390,6 @@ class PersonalServiceSpec
390390
}
391391
}
392392

393-
it should "delete existing wallet" in new TestSetup {
394-
(keyStore.deleteWallet _)
395-
.expects(address)
396-
.returning(Right(true))
397-
398-
val delRes = personal.deleteWallet(DeleteWalletRequest(address)).futureValue
399-
delRes shouldEqual Right(DeleteWalletResponse(true))
400-
}
401-
402-
it should "return error when deleting not existing wallet" in new TestSetup {
403-
(keyStore.deleteWallet _)
404-
.expects(address)
405-
.returning(Left(KeyStore.KeyNotFound))
406-
407-
val delRes = personal.deleteWallet(DeleteWalletRequest(address)).futureValue
408-
delRes shouldEqual Left(KeyNotFound)
409-
}
410-
411-
it should "handle changing passwords" in new TestSetup {
412-
type KeyStoreRes = Either[KeyStoreError, Unit]
413-
type ServiceRes = Either[JsonRpcError, ChangePassphraseResponse]
414-
415-
val table = Table[KeyStoreRes, ServiceRes](
416-
("keyStoreResult", "serviceResult"),
417-
(Right(()), Right(ChangePassphraseResponse())),
418-
(Left(KeyStore.KeyNotFound), Left(KeyNotFound)),
419-
(Left(KeyStore.DecryptionFailed), Left(InvalidPassphrase))
420-
)
421-
422-
val request = ChangePassphraseRequest(address, "weakpass", "very5tr0ng&l0ngp4s5phr4s3")
423-
424-
forAll(table) { (keyStoreResult, serviceResult) =>
425-
(keyStore.changePassphrase _)
426-
.expects(address, request.oldPassphrase, request.newPassphrase)
427-
.returning(keyStoreResult)
428-
429-
val result = personal.changePassphrase(request).futureValue
430-
result shouldEqual serviceResult
431-
}
432-
433-
}
434-
435393
trait TestSetup {
436394
val prvKey = ByteString(Hex.decode("7a44789ed3cd85861c0bbf9693c7e1de1862dd4396c390147ecf1275099c6e6f"))
437395
val address = Address(Hex.decode("aa6826f00d01fe4085f0c3dd12778e206ce4e2ac"))

src/test/scala/io/iohk/ethereum/keystore/KeyStoreImplSpec.scala

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ class KeyStoreImplSpec extends AnyFlatSpec with Matchers with BeforeAndAfter wit
108108

109109
val res3 = keyStore.listAccounts()
110110
res3 should matchPattern { case Left(IOError(_)) => }
111-
112-
val res4 = keyStore.deleteWallet(Address(key))
113-
res4 should matchPattern { case Left(IOError(_)) => }
114111
}
115112

116113
it should "unlock an account provided a correct passphrase" in new TestSetup {
@@ -131,48 +128,6 @@ class KeyStoreImplSpec extends AnyFlatSpec with Matchers with BeforeAndAfter wit
131128
res shouldEqual Left(KeyNotFound)
132129
}
133130

134-
it should "return an error deleting not existing wallet" in new TestSetup {
135-
val res = keyStore.deleteWallet(addr1)
136-
res shouldEqual Left(KeyNotFound)
137-
}
138-
139-
it should "delete existing wallet " in new TestSetup {
140-
val newAddr1 = keyStore.newAccount("aaaaaaaa").right.get
141-
val listOfNewAccounts = keyStore.listAccounts().right.get
142-
listOfNewAccounts.toSet shouldEqual Set(newAddr1)
143-
144-
145-
val res = keyStore.deleteWallet(newAddr1).right.get
146-
res shouldBe true
147-
148-
val listOfNewAccountsAfterDelete = keyStore.listAccounts().right.get
149-
listOfNewAccountsAfterDelete.toSet shouldEqual Set.empty
150-
}
151-
152-
it should "change passphrase of an existing wallet" in new TestSetup {
153-
val oldPassphrase = "weakpass"
154-
val newPassphrase = "very5tr0ng&l0ngp4s5phr4s3"
155-
156-
keyStore.importPrivateKey(key1, oldPassphrase)
157-
keyStore.changePassphrase(addr1, oldPassphrase, newPassphrase) shouldEqual Right(())
158-
159-
keyStore.unlockAccount(addr1, newPassphrase) shouldEqual Right(Wallet(addr1, key1))
160-
}
161-
162-
it should "return an error when changing passphrase of an non-existent wallet" in new TestSetup {
163-
keyStore.changePassphrase(addr1, "oldpass", "newpasss") shouldEqual Left(KeyNotFound)
164-
}
165-
166-
it should "return an error when changing passphrase and provided with invalid old passphrase" in new TestSetup {
167-
keyStore.importPrivateKey(key1, "oldpasss")
168-
keyStore.changePassphrase(addr1, "wrongpass", "newpasss") shouldEqual Left(DecryptionFailed)
169-
}
170-
171-
it should "return an error when changing passphrase and provided with too short new passphrase" in new TestSetup {
172-
keyStore.importPrivateKey(key1, "oldpass")
173-
keyStore.changePassphrase(addr1, "wrongpass", "newpass") shouldEqual Left(PassPhraseTooShort(keyStoreConfig.minimalPassphraseLength))
174-
}
175-
176131
trait TestSetup {
177132
val keyStoreConfig = KeyStoreConfig(Config.config)
178133

0 commit comments

Comments
 (0)