@@ -6,30 +6,21 @@ import akka.util.ByteString
6
6
import io .iohk .ethereum .crypto .ECDSASignature
7
7
import io .iohk .ethereum .domain .Address
8
8
import 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 }
11
9
import io .iohk .ethereum .jsonrpc .JsonRpcError .InvalidParams
12
- import io .iohk .ethereum .jsonrpc .JsonSerializers .{
13
- AddressJsonSerializer ,
14
- OptionNoneToJNullSerializer ,
15
- QuantitiesSerializer ,
16
- UnformattedDataJsonSerializer
17
- }
18
10
import io .iohk .ethereum .jsonrpc .NetService ._
19
11
import io .iohk .ethereum .jsonrpc .PersonalService ._
20
12
import 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 }
21
15
import io .iohk .ethereum .utils .BigIntExtensionMethods .BigIntAsUnsigned
16
+ import org .bouncycastle .util .encoders .Hex
22
17
import org .json4s .JsonAST ._
23
18
import org .json4s .JsonDSL ._
24
- import org .json4s .{DefaultFormats , Formats }
25
- import org .bouncycastle .util .encoders .Hex
26
19
27
20
import scala .util .Try
28
21
29
22
trait JsonMethodsImplicits {
30
-
31
- implicit val formats : Formats = DefaultFormats .preservingEmptyValues + OptionNoneToJNullSerializer +
32
- QuantitiesSerializer + UnformattedDataJsonSerializer + AddressJsonSerializer
23
+ implicit val formats = JsonSerializers .formats
33
24
34
25
protected def encodeAsHex (input : ByteString ): JString =
35
26
JString (s " 0x ${Hex .toHexString(input.toArray[Byte ])}" )
@@ -154,7 +145,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
154
145
155
146
import JsonRpcError ._
156
147
157
- implicit val web3_sha3 = new JsonDecoder [Sha3Request ] with JsonEncoder [Sha3Response ] {
148
+ implicit val web3_sha3 = new JsonMethodDecoder [Sha3Request ] with JsonEncoder [Sha3Response ] {
158
149
override def decodeJson (params : Option [JArray ]): Either [JsonRpcError , Sha3Request ] =
159
150
params match {
160
151
case Some (JArray ((input : JString ) :: Nil )) => extractBytes(input).map(Sha3Request )
@@ -164,24 +155,25 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
164
155
override def encodeJson (t : Sha3Response ): JValue = encodeAsHex(t.data)
165
156
}
166
157
167
- implicit val web3_clientVersion = new NoParamsDecoder (ClientVersionRequest ())
158
+ implicit val web3_clientVersion = new NoParamsMethodDecoder (ClientVersionRequest ())
168
159
with JsonEncoder [ClientVersionResponse ] {
169
160
override def encodeJson (t : ClientVersionResponse ): JValue = t.value
170
161
}
171
162
172
- implicit val net_version = new NoParamsDecoder (VersionRequest ()) with JsonEncoder [VersionResponse ] {
163
+ implicit val net_version = new NoParamsMethodDecoder (VersionRequest ()) with JsonEncoder [VersionResponse ] {
173
164
override def encodeJson (t : VersionResponse ): JValue = t.value
174
165
}
175
166
176
- implicit val net_listening = new NoParamsDecoder (ListeningRequest ()) with JsonEncoder [ListeningResponse ] {
167
+ implicit val net_listening = new NoParamsMethodDecoder (ListeningRequest ()) with JsonEncoder [ListeningResponse ] {
177
168
override def encodeJson (t : ListeningResponse ): JValue = t.value
178
169
}
179
170
180
- implicit val net_peerCount = new NoParamsDecoder (PeerCountRequest ()) with JsonEncoder [PeerCountResponse ] {
171
+ implicit val net_peerCount = new NoParamsMethodDecoder (PeerCountRequest ()) with JsonEncoder [PeerCountResponse ] {
181
172
override def encodeJson (t : PeerCountResponse ): JValue = encodeAsHex(t.value)
182
173
}
183
174
184
- implicit val personal_importRawKey = new JsonDecoder [ImportRawKeyRequest ] with JsonEncoder [ImportRawKeyResponse ] {
175
+ implicit val personal_importRawKey = new JsonMethodDecoder [ImportRawKeyRequest ]
176
+ with JsonEncoder [ImportRawKeyResponse ] {
185
177
def decodeJson (params : Option [JArray ]): Either [JsonRpcError , ImportRawKeyRequest ] =
186
178
params match {
187
179
case Some (JArray (JString (key) :: JString (passphrase) :: _)) =>
@@ -194,7 +186,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
194
186
JString (t.address.toString)
195
187
}
196
188
197
- implicit val personal_newAccount = new JsonDecoder [NewAccountRequest ] with JsonEncoder [NewAccountResponse ] {
189
+ implicit val personal_newAccount = new JsonMethodDecoder [NewAccountRequest ] with JsonEncoder [NewAccountResponse ] {
198
190
def decodeJson (params : Option [JArray ]): Either [JsonRpcError , NewAccountRequest ] =
199
191
params match {
200
192
case Some (JArray (JString (passphrase) :: _)) =>
@@ -207,14 +199,14 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
207
199
JString (t.address.toString)
208
200
}
209
201
210
- implicit val personal_listAccounts = new NoParamsDecoder (ListAccountsRequest ())
202
+ implicit val personal_listAccounts = new NoParamsMethodDecoder (ListAccountsRequest ())
211
203
with JsonEncoder [ListAccountsResponse ] {
212
204
def encodeJson (t : ListAccountsResponse ): JValue =
213
205
JArray (t.addresses.map(a => JString (a.toString)))
214
206
}
215
207
216
208
implicit val personal_sendTransaction =
217
- new Codec [SendTransactionWithPassphraseRequest , SendTransactionWithPassphraseResponse ] {
209
+ new JsonMethodCodec [SendTransactionWithPassphraseRequest , SendTransactionWithPassphraseResponse ] {
218
210
def decodeJson (params : Option [JArray ]): Either [JsonRpcError , SendTransactionWithPassphraseRequest ] =
219
211
params match {
220
212
case Some (JArray (JObject (tx) :: JString (passphrase) :: _)) =>
@@ -227,7 +219,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
227
219
encodeAsHex(t.txHash)
228
220
}
229
221
230
- implicit val personal_sign = new Codec [SignRequest , SignResponse ] {
222
+ implicit val personal_sign = new JsonMethodCodec [SignRequest , SignResponse ] {
231
223
override def encodeJson (t : SignResponse ): JValue = {
232
224
import t .signature ._
233
225
encodeAsHex(ByteString (r.toUnsignedByteArray ++ s.toUnsignedByteArray :+ v))
@@ -245,7 +237,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
245
237
}
246
238
}
247
239
248
- implicit val personal_ecRecover = new Codec [EcRecoverRequest , EcRecoverResponse ] {
240
+ implicit val personal_ecRecover = new JsonMethodCodec [EcRecoverRequest , EcRecoverResponse ] {
249
241
250
242
def decodeJson (params : Option [JArray ]): Either [JsonRpcError , EcRecoverRequest ] =
251
243
params match {
@@ -274,7 +266,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
274
266
encodeAsHex(t.address.bytes)
275
267
}
276
268
277
- implicit val personal_unlockAccount = new Codec [UnlockAccountRequest , UnlockAccountResponse ] {
269
+ implicit val personal_unlockAccount = new JsonMethodCodec [UnlockAccountRequest , UnlockAccountResponse ] {
278
270
def decodeJson (params : Option [JArray ]): Either [JsonRpcError , UnlockAccountRequest ] = {
279
271
params match {
280
272
case Some (JArray (JString (addr) :: JString (passphrase) :: JNull :: _)) =>
@@ -295,7 +287,7 @@ object JsonMethodsImplicits extends JsonMethodsImplicits {
295
287
JBool (t.result)
296
288
}
297
289
298
- implicit val personal_lockAccount = new Codec [LockAccountRequest , LockAccountResponse ] {
290
+ implicit val personal_lockAccount = new JsonMethodCodec [LockAccountRequest , LockAccountResponse ] {
299
291
def decodeJson (params : Option [JArray ]): Either [JsonRpcError , LockAccountRequest ] = {
300
292
params match {
301
293
case Some (JArray (JString (addr) :: _)) =>
0 commit comments