@@ -6,30 +6,21 @@ import akka.util.ByteString
66import io .iohk .ethereum .crypto .ECDSASignature
77import io .iohk .ethereum .domain .Address
88import io .iohk .ethereum .jsonrpc .EthService .BlockParam
9- import io .iohk .ethereum .jsonrpc .JsonRpcController .JsonDecoder .NoParamsDecoder
10- import io .iohk .ethereum .jsonrpc .JsonRpcController .{Codec , JsonDecoder , JsonEncoder }
119import io .iohk .ethereum .jsonrpc .JsonRpcError .InvalidParams
12- import io .iohk .ethereum .jsonrpc .JsonSerializers .{
13- AddressJsonSerializer ,
14- OptionNoneToJNullSerializer ,
15- QuantitiesSerializer ,
16- UnformattedDataJsonSerializer
17- }
1810import io .iohk .ethereum .jsonrpc .NetService ._
1911import io .iohk .ethereum .jsonrpc .PersonalService ._
2012import io .iohk .ethereum .jsonrpc .Web3Service .{ClientVersionRequest , ClientVersionResponse , Sha3Request , Sha3Response }
13+ import io .iohk .ethereum .jsonrpc .serialization .JsonMethodDecoder .NoParamsMethodDecoder
14+ import io .iohk .ethereum .jsonrpc .serialization .{JsonEncoder , JsonMethodCodec , JsonMethodDecoder , JsonSerializers }
2115import io .iohk .ethereum .utils .BigIntExtensionMethods .BigIntAsUnsigned
16+ import org .bouncycastle .util .encoders .Hex
2217import org .json4s .JsonAST ._
2318import org .json4s .JsonDSL ._
24- import org .json4s .{DefaultFormats , Formats }
25- import org .bouncycastle .util .encoders .Hex
2619
2720import scala .util .Try
2821
2922trait JsonMethodsImplicits {
30-
31- implicit val formats : Formats = DefaultFormats .preservingEmptyValues + OptionNoneToJNullSerializer +
32- QuantitiesSerializer + UnformattedDataJsonSerializer + AddressJsonSerializer
23+ implicit val formats = JsonSerializers .formats
3324
3425 protected def encodeAsHex (input : ByteString ): JString =
3526 JString (s " 0x ${Hex .toHexString(input.toArray[Byte ])}" )
@@ -154,7 +145,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
154145
155146 import JsonRpcError ._
156147
157- implicit val web3_sha3 = new JsonDecoder [Sha3Request ] with JsonEncoder [Sha3Response ] {
148+ implicit val web3_sha3 = new JsonMethodDecoder [Sha3Request ] with JsonEncoder [Sha3Response ] {
158149 override def decodeJson (params : Option [JArray ]): Either [JsonRpcError , Sha3Request ] =
159150 params match {
160151 case Some (JArray ((input : JString ) :: Nil )) => extractBytes(input).map(Sha3Request )
@@ -164,24 +155,25 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
164155 override def encodeJson (t : Sha3Response ): JValue = encodeAsHex(t.data)
165156 }
166157
167- implicit val web3_clientVersion = new NoParamsDecoder (ClientVersionRequest ())
158+ implicit val web3_clientVersion = new NoParamsMethodDecoder (ClientVersionRequest ())
168159 with JsonEncoder [ClientVersionResponse ] {
169160 override def encodeJson (t : ClientVersionResponse ): JValue = t.value
170161 }
171162
172- implicit val net_version = new NoParamsDecoder (VersionRequest ()) with JsonEncoder [VersionResponse ] {
163+ implicit val net_version = new NoParamsMethodDecoder (VersionRequest ()) with JsonEncoder [VersionResponse ] {
173164 override def encodeJson (t : VersionResponse ): JValue = t.value
174165 }
175166
176- implicit val net_listening = new NoParamsDecoder (ListeningRequest ()) with JsonEncoder [ListeningResponse ] {
167+ implicit val net_listening = new NoParamsMethodDecoder (ListeningRequest ()) with JsonEncoder [ListeningResponse ] {
177168 override def encodeJson (t : ListeningResponse ): JValue = t.value
178169 }
179170
180- implicit val net_peerCount = new NoParamsDecoder (PeerCountRequest ()) with JsonEncoder [PeerCountResponse ] {
171+ implicit val net_peerCount = new NoParamsMethodDecoder (PeerCountRequest ()) with JsonEncoder [PeerCountResponse ] {
181172 override def encodeJson (t : PeerCountResponse ): JValue = encodeAsHex(t.value)
182173 }
183174
184- implicit val personal_importRawKey = new JsonDecoder [ImportRawKeyRequest ] with JsonEncoder [ImportRawKeyResponse ] {
175+ implicit val personal_importRawKey = new JsonMethodDecoder [ImportRawKeyRequest ]
176+ with JsonEncoder [ImportRawKeyResponse ] {
185177 def decodeJson (params : Option [JArray ]): Either [JsonRpcError , ImportRawKeyRequest ] =
186178 params match {
187179 case Some (JArray (JString (key) :: JString (passphrase) :: _)) =>
@@ -194,7 +186,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
194186 JString (t.address.toString)
195187 }
196188
197- implicit val personal_newAccount = new JsonDecoder [NewAccountRequest ] with JsonEncoder [NewAccountResponse ] {
189+ implicit val personal_newAccount = new JsonMethodDecoder [NewAccountRequest ] with JsonEncoder [NewAccountResponse ] {
198190 def decodeJson (params : Option [JArray ]): Either [JsonRpcError , NewAccountRequest ] =
199191 params match {
200192 case Some (JArray (JString (passphrase) :: _)) =>
@@ -207,14 +199,14 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
207199 JString (t.address.toString)
208200 }
209201
210- implicit val personal_listAccounts = new NoParamsDecoder (ListAccountsRequest ())
202+ implicit val personal_listAccounts = new NoParamsMethodDecoder (ListAccountsRequest ())
211203 with JsonEncoder [ListAccountsResponse ] {
212204 def encodeJson (t : ListAccountsResponse ): JValue =
213205 JArray (t.addresses.map(a => JString (a.toString)))
214206 }
215207
216208 implicit val personal_sendTransaction =
217- new Codec [SendTransactionWithPassphraseRequest , SendTransactionWithPassphraseResponse ] {
209+ new JsonMethodCodec [SendTransactionWithPassphraseRequest , SendTransactionWithPassphraseResponse ] {
218210 def decodeJson (params : Option [JArray ]): Either [JsonRpcError , SendTransactionWithPassphraseRequest ] =
219211 params match {
220212 case Some (JArray (JObject (tx) :: JString (passphrase) :: _)) =>
@@ -227,7 +219,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
227219 encodeAsHex(t.txHash)
228220 }
229221
230- implicit val personal_sign = new Codec [SignRequest , SignResponse ] {
222+ implicit val personal_sign = new JsonMethodCodec [SignRequest , SignResponse ] {
231223 override def encodeJson (t : SignResponse ): JValue = {
232224 import t .signature ._
233225 encodeAsHex(ByteString (r.toUnsignedByteArray ++ s.toUnsignedByteArray :+ v))
@@ -245,7 +237,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
245237 }
246238 }
247239
248- implicit val personal_ecRecover = new Codec [EcRecoverRequest , EcRecoverResponse ] {
240+ implicit val personal_ecRecover = new JsonMethodCodec [EcRecoverRequest , EcRecoverResponse ] {
249241
250242 def decodeJson (params : Option [JArray ]): Either [JsonRpcError , EcRecoverRequest ] =
251243 params match {
@@ -274,7 +266,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
274266 encodeAsHex(t.address.bytes)
275267 }
276268
277- implicit val personal_unlockAccount = new Codec [UnlockAccountRequest , UnlockAccountResponse ] {
269+ implicit val personal_unlockAccount = new JsonMethodCodec [UnlockAccountRequest , UnlockAccountResponse ] {
278270 def decodeJson (params : Option [JArray ]): Either [JsonRpcError , UnlockAccountRequest ] = {
279271 params match {
280272 case Some (JArray (JString (addr) :: JString (passphrase) :: JNull :: _)) =>
@@ -295,7 +287,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
295287 JBool (t.result)
296288 }
297289
298- implicit val personal_lockAccount = new Codec [LockAccountRequest , LockAccountResponse ] {
290+ implicit val personal_lockAccount = new JsonMethodCodec [LockAccountRequest , LockAccountResponse ] {
299291 def decodeJson (params : Option [JArray ]): Either [JsonRpcError , LockAccountRequest ] = {
300292 params match {
301293 case Some (JArray (JString (addr) :: _)) =>
0 commit comments