Skip to content

Commit 270ea99

Browse files
committed
solution: annotation-based json mapping for Tx Receipt
1 parent 67d50c8 commit 270ea99

File tree

9 files changed

+183
-250
lines changed

9 files changed

+183
-250
lines changed

etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionLogJson.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import java.util.List;
3131
import java.util.Objects;
3232

33-
@JsonDeserialize(using = TransactionLogJsonDeserializer.class)
34-
@JsonSerialize(using = TransactionLogJsonSerializer.class)
3533
public class TransactionLogJson implements TransactionRef, Serializable {
3634

3735
/**
@@ -42,11 +40,15 @@ public class TransactionLogJson implements TransactionRef, Serializable {
4240
/**
4341
* log index position in the block. null when its pending log.
4442
*/
43+
@JsonDeserialize(using = HexLongDeserializer.class)
44+
@JsonSerialize(using = HexLongSerializer.class)
4545
private Long logIndex;
4646

4747
/**
4848
* transactions index position log was created from. null when its pending log.
4949
*/
50+
@JsonDeserialize(using = HexLongDeserializer.class)
51+
@JsonSerialize(using = HexLongSerializer.class)
5052
private Long transactionIndex;
5153

5254
/**
@@ -62,6 +64,8 @@ public class TransactionLogJson implements TransactionRef, Serializable {
6264
/**
6365
* the block number where this log was in. null when its pending. null when its pending log.
6466
*/
67+
@JsonDeserialize(using = HexLongDeserializer.class)
68+
@JsonSerialize(using = HexLongSerializer.class)
6569
private Long blockNumber;
6670

6771
/**

etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionLogJsonDeserializer.java

-58
This file was deleted.

etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionLogJsonSerializer.java

-50
This file was deleted.

etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionReceiptJson.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import java.util.List;
2626
import java.util.Objects;
2727

28-
@JsonDeserialize(using = TransactionReceiptJsonDeserializer.class)
29-
@JsonSerialize(using = TransactionReceiptJsonSerializer.class)
3028
public class TransactionReceiptJson implements TransactionRef, Serializable {
3129

3230
/**
@@ -37,6 +35,8 @@ public class TransactionReceiptJson implements TransactionRef, Serializable {
3735
/**
3836
* position in the block
3937
*/
38+
@JsonDeserialize(using = HexLongDeserializer.class)
39+
@JsonSerialize(using = HexLongSerializer.class)
4040
private Long transactionIndex;
4141

4242
/**
@@ -47,11 +47,15 @@ public class TransactionReceiptJson implements TransactionRef, Serializable {
4747
/**
4848
* block number where this transaction was in
4949
*/
50+
@JsonDeserialize(using = HexLongDeserializer.class)
51+
@JsonSerialize(using = HexLongSerializer.class)
5052
private Long blockNumber;
5153

5254
/**
5355
* total amount of gas used when this transaction was executed in the block.
5456
*/
57+
@JsonDeserialize(using = HexLongDeserializer.class)
58+
@JsonSerialize(using = HexLongSerializer.class)
5559
private Long cumulativeGasUsed;
5660

5761
/**
@@ -67,6 +71,8 @@ public class TransactionReceiptJson implements TransactionRef, Serializable {
6771
/**
6872
* amount of gas used by this specific transaction alone.
6973
*/
74+
@JsonDeserialize(using = HexLongDeserializer.class)
75+
@JsonSerialize(using = HexLongSerializer.class)
7076
private Long gasUsed;
7177

7278
/**
@@ -82,8 +88,10 @@ public class TransactionReceiptJson implements TransactionRef, Serializable {
8288
private Bloom logsBloom;
8389

8490
/**
85-
* Optinal tx status. 0 if failed, 1 if successfull
91+
* Optional tx status. 0 if failed, 1 if successfull
8692
*/
93+
@JsonDeserialize(using = HexIntDeserializer.class)
94+
@JsonSerialize(using = HexIntSerializer.class)
8795
private Integer status;
8896

8997
private Wei effectiveGasPrice;
@@ -93,7 +101,9 @@ public class TransactionReceiptJson implements TransactionRef, Serializable {
93101
*
94102
* @see <a href="https://eips.ethereum.org/EIPS/eip-2718">EIP-2718: Typed Transaction Envelope</a>
95103
*/
96-
private int type = 0;
104+
@JsonDeserialize(using = HexIntDeserializer.class)
105+
@JsonSerialize(using = HexIntSerializer.class)
106+
private Integer type = 0;
97107

98108
public TransactionId getTransactionHash() {
99109
return transactionHash;
@@ -200,6 +210,9 @@ public void setEffectiveGasPrice(Wei effectiveGasPrice) {
200210
}
201211

202212
public int getType() {
213+
if (type == null) {
214+
return 0;
215+
}
203216
return type;
204217
}
205218

etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionReceiptJsonDeserializer.java

-75
This file was deleted.

etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionReceiptJsonSerializer.java

-60
This file was deleted.

0 commit comments

Comments
 (0)