From 2e6ae0d869820d362c5405a1f0b180c3b2af1a6d Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Wed, 30 Aug 2023 23:06:56 -0400 Subject: [PATCH] problem: error-prone approach with manual serialization, a field can easily be missed in one of the places solution: use Jackson annotations --- .../emeraldpay/etherjar/domain/ChainId.java | 4 +- .../etherjar/domain/TransactionSignature.java | 11 +-- .../etherjar/domain/ChainIdSpec.groovy | 16 ++-- .../rpc/json/HexDataDeserializer.java | 6 +- .../etherjar/rpc/json/HexIntDeserializer.java | 40 ++++++++ .../etherjar/rpc/json/HexIntSerializer.java | 27 ++++++ .../rpc/json/HexLongDeserializer.java | 2 +- .../etherjar/rpc/json/TransactionJson.java | 53 ++++++++-- .../rpc/json/TransactionJsonDeserializer.java | 2 +- .../rpc/json/TransactionJsonSerializer.java | 2 +- .../etherjar/rpc/EtherjarModuleSpec.groovy | 2 +- .../etherjar/rpc/JacksonEthEncodeSpec.groovy | 12 ++- .../json/ResponseJsonSerializerSpec.groovy | 3 +- .../TransactionJsonDeserializeSpec.groovy | 39 +++++++- .../json/TransactionJsonSerializeSpec.groovy | 11 +++ .../src/test/resources/tx/0x408dc2.json | 96 +++++++++++++++++++ .../test/resources/tx/0x5c7851-result.json | 21 ++++ 17 files changed, 307 insertions(+), 40 deletions(-) create mode 100644 etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexIntDeserializer.java create mode 100644 etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexIntSerializer.java create mode 100644 etherjar-rpc-json/src/test/resources/tx/0x408dc2.json create mode 100644 etherjar-rpc-json/src/test/resources/tx/0x5c7851-result.json diff --git a/etherjar-domain/src/main/java/io/emeraldpay/etherjar/domain/ChainId.java b/etherjar-domain/src/main/java/io/emeraldpay/etherjar/domain/ChainId.java index 1695d22d..c11dfe39 100644 --- a/etherjar-domain/src/main/java/io/emeraldpay/etherjar/domain/ChainId.java +++ b/etherjar-domain/src/main/java/io/emeraldpay/etherjar/domain/ChainId.java @@ -30,7 +30,7 @@ public class ChainId { public static final ChainId RINKEBY_TESTNET = new ChainId(4); public static final ChainId KOVAN_TESTNET = new ChainId(42); - private int value; + private final int value; public ChainId(int value) { if (!ChainId.isValid(value)) { @@ -40,7 +40,7 @@ public ChainId(int value) { } public static boolean isValid(int value) { - return value >= 0 && value <= 255; + return value >= 0; } public int getValue() { diff --git a/etherjar-domain/src/main/java/io/emeraldpay/etherjar/domain/TransactionSignature.java b/etherjar-domain/src/main/java/io/emeraldpay/etherjar/domain/TransactionSignature.java index f043cad8..c8e48ac9 100644 --- a/etherjar-domain/src/main/java/io/emeraldpay/etherjar/domain/TransactionSignature.java +++ b/etherjar-domain/src/main/java/io/emeraldpay/etherjar/domain/TransactionSignature.java @@ -28,7 +28,6 @@ public class TransactionSignature { private ChainId chainId; - private HexData publicKey; private HexData r; private HexData s; private Integer v; @@ -44,14 +43,6 @@ public void setChainId(ChainId chainId) { this.chainId = chainId; } - public HexData getPublicKey() { - return publicKey; - } - - public void setPublicKey(HexData publicKey) { - this.publicKey = publicKey; - } - public HexData getR() { return r; } @@ -105,7 +96,7 @@ public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TransactionSignature)) return false; TransactionSignature that = (TransactionSignature) o; - return Objects.equals(chainId, that.chainId) && Objects.equals(publicKey, that.publicKey) && Objects.equals(r, that.r) && Objects.equals(s, that.s) && Objects.equals(v, that.v); + return Objects.equals(chainId, that.chainId) && Objects.equals(r, that.r) && Objects.equals(s, that.s) && Objects.equals(v, that.v); } @Override diff --git a/etherjar-domain/src/test/groovy/io/emeraldpay/etherjar/domain/ChainIdSpec.groovy b/etherjar-domain/src/test/groovy/io/emeraldpay/etherjar/domain/ChainIdSpec.groovy index 9e2cea99..59eec26b 100644 --- a/etherjar-domain/src/test/groovy/io/emeraldpay/etherjar/domain/ChainIdSpec.groovy +++ b/etherjar-domain/src/test/groovy/io/emeraldpay/etherjar/domain/ChainIdSpec.groovy @@ -60,17 +60,19 @@ class ChainIdSpec extends Specification { x << (0..255) } - def "Decline non-byte numbers"() { + def "Decline negative numbers"() { expect: !ChainId.isValid(x) where: - x << [-1, -100, -250, 256, 1024, 6161, 6819571, Integer.MAX_VALUE, Integer.MIN_VALUE] + x << [-1, -100, -250] } - def "Doesn't allow to create invalid id"() { - when: - new ChainId(1024) - then: - thrown(IllegalArgumentException) + def "Accept standard chains"() { + // see https://chainlist.org/ + expect: + ChainId.isValid(x) + where: + x << [1, 56, 42161, 137, 10, 43114, 25, 2222, 8453, 8217, 32659, 369, 66, 42220, 30, 250, 100] } + } diff --git a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexDataDeserializer.java b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexDataDeserializer.java index 66a8a0b4..61543ad7 100644 --- a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexDataDeserializer.java +++ b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexDataDeserializer.java @@ -20,8 +20,12 @@ public HexDataDeserializer() { public HexData deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken token = p.currentToken(); if (token == JsonToken.VALUE_STRING) { + String value = p.getValueAsString(); + if ("0x".equals(value)) { + return null; + } try { - return HexData.from(p.getValueAsString()); + return HexData.from(value); } catch (Throwable t) { throw JsonMappingException.from(p,"Invalid HexData value: " + p.getValueAsString(), t); } diff --git a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexIntDeserializer.java b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexIntDeserializer.java new file mode 100644 index 00000000..b822513d --- /dev/null +++ b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexIntDeserializer.java @@ -0,0 +1,40 @@ +package io.emeraldpay.etherjar.rpc.json; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import io.emeraldpay.etherjar.hex.HexQuantity; + +import java.io.IOException; + +/** + * Deserialize Long from Hex Quantity + */ +public class HexIntDeserializer extends StdDeserializer { + + public HexIntDeserializer() { + super(Integer.class); + } + + @Override + public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { + JsonToken token = p.currentToken(); + if (token == JsonToken.VALUE_STRING) { + try { + return HexQuantity.from(p.getValueAsString()).getValue().intValueExact(); + } catch (Throwable t) { + throw JsonMappingException.from(p,"Invalid HexQuantity value: " + p.getValueAsString(), t); + } + } + if (token == JsonToken.VALUE_NUMBER_INT) { + return p.getValueAsInt(); + } + if (token == JsonToken.VALUE_NULL) { + return null; + } + throw JsonMappingException.from(p,"Invalid HexQuantity type: " + token); + } +} diff --git a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexIntSerializer.java b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexIntSerializer.java new file mode 100644 index 00000000..34e0c85c --- /dev/null +++ b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexIntSerializer.java @@ -0,0 +1,27 @@ +package io.emeraldpay.etherjar.rpc.json; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import io.emeraldpay.etherjar.hex.HexQuantity; + +import java.io.IOException; + +/** + * Serialize Long as Hex Quantity + */ +public class HexIntSerializer extends StdSerializer { + + public HexIntSerializer() { + super(Integer.class); + } + + @Override + public void serialize(Integer value, JsonGenerator gen, SerializerProvider provider) throws IOException { + if (value == null) { + gen.writeNull(); + } else { + gen.writeString(HexQuantity.from(value.longValue()).toHex()); + } + } +} diff --git a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexLongDeserializer.java b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexLongDeserializer.java index fb5e9d92..e53e2316 100644 --- a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexLongDeserializer.java +++ b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/HexLongDeserializer.java @@ -24,7 +24,7 @@ public Long deserialize(JsonParser p, DeserializationContext ctxt) throws IOExce JsonToken token = p.currentToken(); if (token == JsonToken.VALUE_STRING) { try { - return HexQuantity.from(p.getValueAsString()).getValue().longValue(); + return HexQuantity.from(p.getValueAsString()).getValue().longValueExact(); } catch (Throwable t) { throw JsonMappingException.from(p,"Invalid HexQuantity value: " + p.getValueAsString(), t); } diff --git a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJson.java b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJson.java index ab71bb64..d067ca36 100644 --- a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJson.java +++ b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJson.java @@ -17,6 +17,9 @@ package io.emeraldpay.etherjar.rpc.json; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.emeraldpay.etherjar.domain.*; @@ -29,13 +32,15 @@ import java.util.List; import java.util.Objects; -@JsonDeserialize(using = TransactionJsonDeserializer.class) -@JsonSerialize(using = TransactionJsonSerializer.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public class TransactionJson extends TransactionRefJson implements TransactionRef, Serializable { /** * the number of transactions made by the sender prior to this one. */ + @JsonDeserialize(using = HexLongDeserializer.class) + @JsonSerialize(using = HexLongSerializer.class) private Long nonce; /** @@ -46,11 +51,15 @@ public class TransactionJson extends TransactionRefJson implements TransactionRe /** * block number where this transaction was in. null when its pending. */ + @JsonDeserialize(using = HexLongDeserializer.class) + @JsonSerialize(using = HexLongSerializer.class) private Long blockNumber; /** - * position in the block. null when its pending. + * position in the block. null when it's pending. */ + @JsonDeserialize(using = HexLongDeserializer.class) + @JsonSerialize(using = HexLongSerializer.class) private Long transactionIndex; /** @@ -61,6 +70,7 @@ public class TransactionJson extends TransactionRefJson implements TransactionRe /** * address of the receiver. null when its a contract creation transaction. */ + @JsonInclude(JsonInclude.Include.ALWAYS) private Address to; /** @@ -83,6 +93,8 @@ public class TransactionJson extends TransactionRefJson implements TransactionRe /** * gas provided by the sender. */ + @JsonDeserialize(using = HexLongDeserializer.class) + @JsonSerialize(using = HexLongSerializer.class) private Long gas; /** @@ -90,17 +102,34 @@ public class TransactionJson extends TransactionRefJson implements TransactionRe */ private HexData input; - private TransactionSignature signature; - /** * Transaction type * * @see EIP-2718: Typed Transaction Envelope */ + @JsonDeserialize(using = HexIntDeserializer.class) + @JsonSerialize(using = HexIntSerializer.class) private int type = 0; + @JsonDeserialize(using = HexIntDeserializer.class) + @JsonSerialize(using = HexIntSerializer.class) private Integer chainId; + @JsonDeserialize(using = HexIntDeserializer.class) + @JsonSerialize(using = HexIntSerializer.class) + private Integer v; + + @JsonDeserialize + @JsonSerialize + private HexData r; + + @JsonDeserialize + @JsonSerialize + private HexData s; + + @JsonIgnore + private transient TransactionSignature signature; + private List accessList; public Long getNonce() { @@ -208,7 +237,19 @@ public void setInput(HexData input) { } public TransactionSignature getSignature() { - return signature; + if (signature != null) { + return signature; + } + if (v == null || r == null || s == null) { + return null; + } + TransactionSignature created = new TransactionSignature(); + created.setV(v); + created.setR(r); + created.setS(s); + created.setChainId(chainId != null ? new ChainId(chainId) : null); + this.signature = created; + return created; } public void setSignature(TransactionSignature signature) { diff --git a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJsonDeserializer.java b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJsonDeserializer.java index cd944128..7c134741 100644 --- a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJsonDeserializer.java +++ b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJsonDeserializer.java @@ -78,7 +78,7 @@ public TransactionJson deserialize(JsonNode node) { signature.setR(getData(node, "r")); signature.setS(getData(node, "s")); signature.setV(getLong(node, "v").intValue()); - signature.setPublicKey(getData(node, "publicKey")); +// signature.setPublicKey(getData(node, "publicKey")); tx.setSignature(signature); } diff --git a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJsonSerializer.java b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJsonSerializer.java index 9e15d1d0..bf9fb9fe 100644 --- a/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJsonSerializer.java +++ b/etherjar-rpc-json/src/main/java/io/emeraldpay/etherjar/rpc/json/TransactionJsonSerializer.java @@ -62,7 +62,7 @@ public void serialize(TransactionJson value, JsonGenerator gen, SerializerProvid if (signature.getV() != null) { writeField(gen, "v", signature.getV().longValue()); } - writeField(gen, "publicKey", signature.getPublicKey()); +// writeField(gen, "publicKey", signature.getPublicKey()); } List accessList = value.getAccessList(); if (accessList != null) { diff --git a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/EtherjarModuleSpec.groovy b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/EtherjarModuleSpec.groovy index 093035cc..18519431 100644 --- a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/EtherjarModuleSpec.groovy +++ b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/EtherjarModuleSpec.groovy @@ -97,7 +97,7 @@ class EtherjarModuleSpec extends Specification { when: def obj = objectMapper.readValue(json, TestObject.class) then: - obj.hexData == HexData.empty() + obj.hexData == null } def "Fails to decode HexData invalid string value"() { diff --git a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/JacksonEthEncodeSpec.groovy b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/JacksonEthEncodeSpec.groovy index c547b17b..3607ee30 100644 --- a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/JacksonEthEncodeSpec.groovy +++ b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/JacksonEthEncodeSpec.groovy @@ -205,7 +205,8 @@ class JacksonEthEncodeSpec extends Specification { ' "value" : "0x0",\n' + ' "gasPrice" : "0x59b9b95f0",\n' + ' "gas" : "0x3d090",\n' + - ' "input" : "0x667a2f58"\n' + + ' "input" : "0x667a2f58",\n' + + ' "type" : "0x0"\n' + ' } ]\n' + '}' } @@ -239,7 +240,8 @@ class JacksonEthEncodeSpec extends Specification { ' "value" : "0x0",\n' + ' "gasPrice" : "0x59b9b95f0",\n' + ' "gas" : "0x3d090",\n' + - ' "input" : "0x667a2f58"\n' + + ' "input" : "0x667a2f58",\n' + + ' "type" : "0x0"\n' + '}' } @@ -266,7 +268,8 @@ class JacksonEthEncodeSpec extends Specification { ' "value" : "0x0",\n' + ' "gasPrice" : "0x59b9b95f0",\n' + ' "gas" : "0x3d090",\n' + - ' "input" : "0x667a2f58"\n' + + ' "input" : "0x667a2f58",\n' + + ' "type" : "0x0"\n' + '}' } @@ -300,7 +303,8 @@ class JacksonEthEncodeSpec extends Specification { ' "value" : "0x0",\n' + ' "gasPrice" : "0x4a817c800",\n' + ' "gas" : "0x2dc6c0",\n' + - ' "input" : "0x6060604052600261010860005055604051611b51380380611b51833981016040528080518201919060200180519060200190919080519060200190919050505b805b83835b600060018351016001600050819055503373ffffffffffffffffffffffffffffffffffffffff16600260005060016101008110156100025790900160005b5081905550600161010260005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005081905550600090505b825181101561016e5782818151811015610002579060200190602002015173ffffffffffffffffffffffffffffffffffffffff166002600050826002016101008110156100025790900160005b508190555080600201610102600050600085848151811015610002579060200190602002015173ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055505b80600101905080506100c2565b816000600050819055505b505050806101056000508190555061018f6101ad565b610107600050819055505b505b505050611992806101bf6000396000f35b600062015180420490506101bc565b9056606060405236156100f8576000357c010000000000000000000000000000000000000000000000000000000090048063173825d9146101605780632f54bf6e146101785780634123cb6b146101a457806352375093146101c757806354fd4d50146101ea5780635c52c2f51461020d578063659010e71461021c5780637065cb481461023f578063746c917114610257578063797af6271461027a578063b20d30a9146102a6578063b61d27f6146102be578063b75c7dc614610307578063ba51a6df1461031f578063c2cf732614610337578063cbf0b0c01461036c578063f00d4b5d14610384578063f1736d86146103a5576100f8565b61015e5b600034111561015b577fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c3334604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b5b565b005b61017660048080359060200190919050506107c4565b005b61018e60048080359060200190919050506109a5565b6040518082815260200191505060405180910390f35b6101b16004805050610a91565b6040518082815260200191505060405180910390f35b6101d46004805050610b38565b6040518082815260200191505060405180910390f35b6101f76004805050610b42565b6040518082815260200191505060405180910390f35b61021a6004805050610adf565b005b6102296004805050610b2e565b6040518082815260200191505060405180910390f35b610255600480803590602001909190505061066e565b005b6102646004805050610a88565b6040518082815260200191505060405180910390f35b6102906004808035906020019091905050610f0e565b6040518082815260200191505060405180910390f35b6102bc6004808035906020019091905050610a9a565b005b6102f160048080359060200190919080359060200190919080359060200190820180359060200191909192905050610b9e565b6040518082815260200191505060405180910390f35b61031d60048080359060200190919050506103c8565b005b610335600480803590602001909190505061090f565b005b61035660048080359060200190919080359060200190919050506109e7565b6040518082815260200191505060405180910390f35b6103826004808035906020019091905050610b4c565b005b6103a360048080359060200190919080359060200190919050506104ca565b005b6103b26004805050610b24565b6040518082815260200191505060405180910390f35b60006000600061010260005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050549250600083141561040f576104c4565b8260020a91506101036000506000858152602001908152602001600020600050905060008282600101600050541611156104c3578060000160008181505480929190600101919050555081816001016000828282505403925050819055507fc7fb647e59b18047309aa15aad418e5d7ca96d173ad704f1031a2c3d7591734b3385604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b5b50505050565b600060003643604051808484808284378201915050828152602001935050505060405180910390206104fb816112db565b1561066757610509836109a5565b156105145750610669565b61010260005060008573ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005054915060008214156105565750610669565b61055e611777565b8273ffffffffffffffffffffffffffffffffffffffff166002600050836101008110156100025790900160005b5081905550600061010260005060008673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055508161010260005060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055507fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c8484604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a15b505b505050565b600036436040518084848082843782019150508281526020019350505050604051809103902061069d816112db565b156107bf576106ab826109a5565b156106b657506107c1565b6106be611777565b60fa6001600050541015156106d7576106d561153d565b505b60fa6001600050541015156106ec57506107c1565b60016000818150548092919060010191905055508173ffffffffffffffffffffffffffffffffffffffff1660026000506001600050546101008110156100025790900160005b508190555060016000505461010260005060008473ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055507f994a936646fe87ffe4f1e469d3d6aa417d6b855598397f323de5b449f765f0c382604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a15b505b50565b600060003643604051808484808284378201915050828152602001935050505060405180910390206107f5816112db565b156109095761010260005060008473ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050549150600082141561083c575061090b565b6001600160005054036000600050541115610857575061090b565b60006002600050836101008110156100025790900160005b5081905550600061010260005060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055506108b2611777565b6108ba61153d565b507f58619076adf5bb0943d100ef88d52d7c3fd691b19d3a9071b555b651fbf418da83604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a15b505b5050565b600036436040518084848082843782019150508281526020019350505050604051809103902061093e816112db565b156109a05760016000505482111561095657506109a2565b81600060005081905550610968611777565b7facbdb084c721332ac59f9b8e392196c9eb0e4932862da8eb9beaf0dad4f550da826040518082815260200191505060405180910390a15b505b50565b6000600061010260005060008473ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541190506109e2565b919050565b60006000600060006101036000506000878152602001908152602001600020600050925061010260005060008673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505491506000821415610a505760009350610a7f565b8160020a90506000818460010160005054161415610a755760009350610a7f56610a7e565b60019350610a7f565b5b50505092915050565b60006000505481565b60016000505481565b6000364360405180848480828437820191505082815260200193505050506040518091039020610ac9816112db565b15610ada5781610105600050819055505b505b50565b6000364360405180848480828437820191505082815260200193505050506040518091039020610b0e816112db565b15610b20576000610106600050819055505b505b565b6101056000505481565b6101066000505481565b6101076000505481565b6101086000505481565b6000364360405180848480828437820191505082815260200193505050506040518091039020610b7b816112db565b15610b99578173ffffffffffffffffffffffffffffffffffffffff16ff5b505b50565b6000610ba9336109a5565b15610f0557610bb7846116d7565b15610ca0577f92ca3a80853e6663fa31fa10b99225f18d4902939b4c53a9caae9043f6efd0043385878686604051808673ffffffffffffffffffffffffffffffffffffffff1681526020018581526020018473ffffffffffffffffffffffffffffffffffffffff1681526020018060200182810382528484828181526020019250808284378201915050965050505050505060405180910390a18473ffffffffffffffffffffffffffffffffffffffff168484846040518083838082843782019150509250505060006040518083038185876185025a03f1925050505060006001029050610f06565b600036436040518084848082843782019150508281526020019350505050604051809103902090508050610cd381610f0e565b158015610d3357506000610109600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b15610f045784610109600050600083815260200190815260200160002060005060000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555083610109600050600083815260200190815260200160002060005060010160005081905550828261010960005060008481526020019081526020016000206000506002016000509190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610e0857803560ff1916838001178555610e39565b82800160010185558215610e39579182015b82811115610e38578235826000505591602001919060010190610e1a565b5b509050610e649190610e46565b80821115610e605760008181506000905550600101610e46565b5090565b50507f1733cbb53659d713b79580f79f3f9ff215f78a7c7aa45890f3b89fc5cddfbf32813386888787604051808781526020018673ffffffffffffffffffffffffffffffffffffffff1681526020018581526020018473ffffffffffffffffffffffffffffffffffffffff168152602001806020018281038252848482818152602001925080828437820191505097505050505050505060405180910390a15b5b5b949350505050565b600081610f1a816112db565b156112d4576000610109600050600085815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415156112d357610109600050600084815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610109600050600085815260200190815260200160002060005060010160005054610109600050600086815260200190815260200160002060005060020160005060405180828054600181600116156101000203166002900480156110765780601f1061104b57610100808354040283529160200191611076565b820191906000526020600020905b81548152906001019060200180831161105957829003601f168201915b505091505060006040518083038185876185025a03f192505050507fe7c957c06e9a662c1a6c77366179f5b702b97651dc28eee7d5bf1dff6e40bb4a3384610109600050600087815260200190815260200160002060005060010160005054610109600050600088815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166101096000506000898152602001908152602001600020600050600201600050604051808673ffffffffffffffffffffffffffffffffffffffff1681526020018581526020018481526020018373ffffffffffffffffffffffffffffffffffffffff168152602001806020018281038252838181546001816001161561010002031660029004815260200191508054600181600116156101000203166002900480156112005780601f106111d557610100808354040283529160200191611200565b820191906000526020600020905b8154815290600101906020018083116111e357829003601f168201915b5050965050505050505060405180910390a1610109600050600084815260200190815260200160002060006000820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000506000905560028201600050805460018160011615610100020316600290046000825580601f1061128957506112c6565b601f0160209004906000526020600020908101906112c591906112a7565b808211156112c157600081815060009055506001016112a7565b5090565b5b50505060019150506112d6565b5b505b919050565b600060006000600061010260005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050549250600083141561132457611535565b610103600050600086815260200190815260200160002060005091506000826000016000505414156113fd57600060005054826000016000508190555060008260010160005081905550610104600050805480919060010190908154818355818115116113c3578183600052602060002091820191016113c291906113a4565b808211156113be57600081815060009055506001016113a4565b5090565b5b5050508260020160005081905550846101046000508360020160005054815481101561000257906000526020600020900160005b50819055505b8260020a90506000818360010160005054161415611534577fe1c52dc63b719ade82e8bea94cc41a0d5d28e4aaf536adb5e9cccc9ff8c1aeda3386604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001826000016000505411151561150757610104600050610103600050600087815260200190815260200160002060005060020160005054815481101561000257906000526020600020900160005b50600090556101036000506000868152602001908152602001600020600060008201600050600090556001820160005060009055600282016000506000905550506001935061153556611533565b816000016000818150548092919060019003919050555080826001016000828282505417925050819055505b5b5b505050919050565b60006000600190505b6001600050548110156116d2575b60016000505481108015611580575060006002600050826101008110156100025790900160005b505414155b15611592578080600101915050611554565b5b60016001600050541180156115c45750600060026000506001600050546101008110156100025790900160005b5054145b156115e357600160008181505480929190600190039190505550611593565b600160005054811080156116145750600060026000506001600050546101008110156100025790900160005b505414155b8015611637575060006002600050826101008110156100025790900160005b5054145b156116cd5760026000506001600050546101008110156100025790900160005b50546002600050826101008110156100025790900160005b50819055508061010260005060006002600050846101008110156100025790900160005b5054815260200190815260200160002060005081905550600060026000506001600050546101008110156100025790900160005b50819055505b611546565b5b5090565b60006116e2336109a5565b1561177157610107600050546116f6611980565b111561171b57600061010660005081905550611710611980565b610107600050819055505b610106600050548261010660005054011015801561174757506101056000505482610106600050540111155b15611768578161010660008282825054019250508190555060019050611772565b60009050611772565b5b919050565b60006000610104600050805490509150600090505b8181101561187857610109600050600061010460005083815481101561000257906000526020600020900160005b5054815260200190815260200160002060006000820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000506000905560028201600050805460018160011615610100020316600290046000825580601f1061182a5750611867565b601f0160209004906000526020600020908101906118669190611848565b808211156118625760008181506000905550600101611848565b5090565b5b5050505b806001019050805061178c565b611880611885565b5b5050565b60006000610104600050805490509150600090505b8181101561193857600060010261010460005082815481101561000257906000526020600020900160005b505414151561192a57610103600050600061010460005083815481101561000257906000526020600020900160005b50548152602001908152602001600020600060008201600050600090556001820160005060009055600282016000506000905550505b5b806001019050805061189a565b61010460005080546000825590600052602060002090810190611979919061195b565b80821115611975576000818150600090555060010161195b565b5090565b5b505b5050565b6000620151804204905061198f565b90560000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000052b7d2dcc80cd2e4000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000072d61152f6c0c0e57c1fe2b0343a5eac055ff56e"\n' + + ' "input" : "0x6060604052600261010860005055604051611b51380380611b51833981016040528080518201919060200180519060200190919080519060200190919050505b805b83835b600060018351016001600050819055503373ffffffffffffffffffffffffffffffffffffffff16600260005060016101008110156100025790900160005b5081905550600161010260005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005081905550600090505b825181101561016e5782818151811015610002579060200190602002015173ffffffffffffffffffffffffffffffffffffffff166002600050826002016101008110156100025790900160005b508190555080600201610102600050600085848151811015610002579060200190602002015173ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055505b80600101905080506100c2565b816000600050819055505b505050806101056000508190555061018f6101ad565b610107600050819055505b505b505050611992806101bf6000396000f35b600062015180420490506101bc565b9056606060405236156100f8576000357c010000000000000000000000000000000000000000000000000000000090048063173825d9146101605780632f54bf6e146101785780634123cb6b146101a457806352375093146101c757806354fd4d50146101ea5780635c52c2f51461020d578063659010e71461021c5780637065cb481461023f578063746c917114610257578063797af6271461027a578063b20d30a9146102a6578063b61d27f6146102be578063b75c7dc614610307578063ba51a6df1461031f578063c2cf732614610337578063cbf0b0c01461036c578063f00d4b5d14610384578063f1736d86146103a5576100f8565b61015e5b600034111561015b577fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c3334604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b5b565b005b61017660048080359060200190919050506107c4565b005b61018e60048080359060200190919050506109a5565b6040518082815260200191505060405180910390f35b6101b16004805050610a91565b6040518082815260200191505060405180910390f35b6101d46004805050610b38565b6040518082815260200191505060405180910390f35b6101f76004805050610b42565b6040518082815260200191505060405180910390f35b61021a6004805050610adf565b005b6102296004805050610b2e565b6040518082815260200191505060405180910390f35b610255600480803590602001909190505061066e565b005b6102646004805050610a88565b6040518082815260200191505060405180910390f35b6102906004808035906020019091905050610f0e565b6040518082815260200191505060405180910390f35b6102bc6004808035906020019091905050610a9a565b005b6102f160048080359060200190919080359060200190919080359060200190820180359060200191909192905050610b9e565b6040518082815260200191505060405180910390f35b61031d60048080359060200190919050506103c8565b005b610335600480803590602001909190505061090f565b005b61035660048080359060200190919080359060200190919050506109e7565b6040518082815260200191505060405180910390f35b6103826004808035906020019091905050610b4c565b005b6103a360048080359060200190919080359060200190919050506104ca565b005b6103b26004805050610b24565b6040518082815260200191505060405180910390f35b60006000600061010260005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050549250600083141561040f576104c4565b8260020a91506101036000506000858152602001908152602001600020600050905060008282600101600050541611156104c3578060000160008181505480929190600101919050555081816001016000828282505403925050819055507fc7fb647e59b18047309aa15aad418e5d7ca96d173ad704f1031a2c3d7591734b3385604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a15b5b50505050565b600060003643604051808484808284378201915050828152602001935050505060405180910390206104fb816112db565b1561066757610509836109a5565b156105145750610669565b61010260005060008573ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005054915060008214156105565750610669565b61055e611777565b8273ffffffffffffffffffffffffffffffffffffffff166002600050836101008110156100025790900160005b5081905550600061010260005060008673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055508161010260005060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055507fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c8484604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a15b505b505050565b600036436040518084848082843782019150508281526020019350505050604051809103902061069d816112db565b156107bf576106ab826109a5565b156106b657506107c1565b6106be611777565b60fa6001600050541015156106d7576106d561153d565b505b60fa6001600050541015156106ec57506107c1565b60016000818150548092919060010191905055508173ffffffffffffffffffffffffffffffffffffffff1660026000506001600050546101008110156100025790900160005b508190555060016000505461010260005060008473ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055507f994a936646fe87ffe4f1e469d3d6aa417d6b855598397f323de5b449f765f0c382604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a15b505b50565b600060003643604051808484808284378201915050828152602001935050505060405180910390206107f5816112db565b156109095761010260005060008473ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050549150600082141561083c575061090b565b6001600160005054036000600050541115610857575061090b565b60006002600050836101008110156100025790900160005b5081905550600061010260005060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055506108b2611777565b6108ba61153d565b507f58619076adf5bb0943d100ef88d52d7c3fd691b19d3a9071b555b651fbf418da83604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a15b505b5050565b600036436040518084848082843782019150508281526020019350505050604051809103902061093e816112db565b156109a05760016000505482111561095657506109a2565b81600060005081905550610968611777565b7facbdb084c721332ac59f9b8e392196c9eb0e4932862da8eb9beaf0dad4f550da826040518082815260200191505060405180910390a15b505b50565b6000600061010260005060008473ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050541190506109e2565b919050565b60006000600060006101036000506000878152602001908152602001600020600050925061010260005060008673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505491506000821415610a505760009350610a7f565b8160020a90506000818460010160005054161415610a755760009350610a7f56610a7e565b60019350610a7f565b5b50505092915050565b60006000505481565b60016000505481565b6000364360405180848480828437820191505082815260200193505050506040518091039020610ac9816112db565b15610ada5781610105600050819055505b505b50565b6000364360405180848480828437820191505082815260200193505050506040518091039020610b0e816112db565b15610b20576000610106600050819055505b505b565b6101056000505481565b6101066000505481565b6101076000505481565b6101086000505481565b6000364360405180848480828437820191505082815260200193505050506040518091039020610b7b816112db565b15610b99578173ffffffffffffffffffffffffffffffffffffffff16ff5b505b50565b6000610ba9336109a5565b15610f0557610bb7846116d7565b15610ca0577f92ca3a80853e6663fa31fa10b99225f18d4902939b4c53a9caae9043f6efd0043385878686604051808673ffffffffffffffffffffffffffffffffffffffff1681526020018581526020018473ffffffffffffffffffffffffffffffffffffffff1681526020018060200182810382528484828181526020019250808284378201915050965050505050505060405180910390a18473ffffffffffffffffffffffffffffffffffffffff168484846040518083838082843782019150509250505060006040518083038185876185025a03f1925050505060006001029050610f06565b600036436040518084848082843782019150508281526020019350505050604051809103902090508050610cd381610f0e565b158015610d3357506000610109600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16145b15610f045784610109600050600083815260200190815260200160002060005060000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083021790555083610109600050600083815260200190815260200160002060005060010160005081905550828261010960005060008481526020019081526020016000206000506002016000509190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610e0857803560ff1916838001178555610e39565b82800160010185558215610e39579182015b82811115610e38578235826000505591602001919060010190610e1a565b5b509050610e649190610e46565b80821115610e605760008181506000905550600101610e46565b5090565b50507f1733cbb53659d713b79580f79f3f9ff215f78a7c7aa45890f3b89fc5cddfbf32813386888787604051808781526020018673ffffffffffffffffffffffffffffffffffffffff1681526020018581526020018473ffffffffffffffffffffffffffffffffffffffff168152602001806020018281038252848482818152602001925080828437820191505097505050505050505060405180910390a15b5b5b949350505050565b600081610f1a816112db565b156112d4576000610109600050600085815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415156112d357610109600050600084815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16610109600050600085815260200190815260200160002060005060010160005054610109600050600086815260200190815260200160002060005060020160005060405180828054600181600116156101000203166002900480156110765780601f1061104b57610100808354040283529160200191611076565b820191906000526020600020905b81548152906001019060200180831161105957829003601f168201915b505091505060006040518083038185876185025a03f192505050507fe7c957c06e9a662c1a6c77366179f5b702b97651dc28eee7d5bf1dff6e40bb4a3384610109600050600087815260200190815260200160002060005060010160005054610109600050600088815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166101096000506000898152602001908152602001600020600050600201600050604051808673ffffffffffffffffffffffffffffffffffffffff1681526020018581526020018481526020018373ffffffffffffffffffffffffffffffffffffffff168152602001806020018281038252838181546001816001161561010002031660029004815260200191508054600181600116156101000203166002900480156112005780601f106111d557610100808354040283529160200191611200565b820191906000526020600020905b8154815290600101906020018083116111e357829003601f168201915b5050965050505050505060405180910390a1610109600050600084815260200190815260200160002060006000820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000506000905560028201600050805460018160011615610100020316600290046000825580601f1061128957506112c6565b601f0160209004906000526020600020908101906112c591906112a7565b808211156112c157600081815060009055506001016112a7565b5090565b5b50505060019150506112d6565b5b505b919050565b600060006000600061010260005060003373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050549250600083141561132457611535565b610103600050600086815260200190815260200160002060005091506000826000016000505414156113fd57600060005054826000016000508190555060008260010160005081905550610104600050805480919060010190908154818355818115116113c3578183600052602060002091820191016113c291906113a4565b808211156113be57600081815060009055506001016113a4565b5090565b5b5050508260020160005081905550846101046000508360020160005054815481101561000257906000526020600020900160005b50819055505b8260020a90506000818360010160005054161415611534577fe1c52dc63b719ade82e8bea94cc41a0d5d28e4aaf536adb5e9cccc9ff8c1aeda3386604051808373ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a16001826000016000505411151561150757610104600050610103600050600087815260200190815260200160002060005060020160005054815481101561000257906000526020600020900160005b50600090556101036000506000868152602001908152602001600020600060008201600050600090556001820160005060009055600282016000506000905550506001935061153556611533565b816000016000818150548092919060019003919050555080826001016000828282505417925050819055505b5b5b505050919050565b60006000600190505b6001600050548110156116d2575b60016000505481108015611580575060006002600050826101008110156100025790900160005b505414155b15611592578080600101915050611554565b5b60016001600050541180156115c45750600060026000506001600050546101008110156100025790900160005b5054145b156115e357600160008181505480929190600190039190505550611593565b600160005054811080156116145750600060026000506001600050546101008110156100025790900160005b505414155b8015611637575060006002600050826101008110156100025790900160005b5054145b156116cd5760026000506001600050546101008110156100025790900160005b50546002600050826101008110156100025790900160005b50819055508061010260005060006002600050846101008110156100025790900160005b5054815260200190815260200160002060005081905550600060026000506001600050546101008110156100025790900160005b50819055505b611546565b5b5090565b60006116e2336109a5565b1561177157610107600050546116f6611980565b111561171b57600061010660005081905550611710611980565b610107600050819055505b610106600050548261010660005054011015801561174757506101056000505482610106600050540111155b15611768578161010660008282825054019250508190555060019050611772565b60009050611772565b5b919050565b60006000610104600050805490509150600090505b8181101561187857610109600050600061010460005083815481101561000257906000526020600020900160005b5054815260200190815260200160002060006000820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000506000905560028201600050805460018160011615610100020316600290046000825580601f1061182a5750611867565b601f0160209004906000526020600020908101906118669190611848565b808211156118625760008181506000905550600101611848565b5090565b5b5050505b806001019050805061178c565b611880611885565b5b5050565b60006000610104600050805490509150600090505b8181101561193857600060010261010460005082815481101561000257906000526020600020900160005b505414151561192a57610103600050600061010460005083815481101561000257906000526020600020900160005b50548152602001908152602001600020600060008201600050600090556001820160005060009055600282016000506000905550505b5b806001019050805061189a565b61010460005080546000825590600052602060002090810190611979919061195b565b80821115611975576000818150600090555060010161195b565b5090565b5b505b5050565b6000620151804204905061198f565b90560000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000052b7d2dcc80cd2e4000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000072d61152f6c0c0e57c1fe2b0343a5eac055ff56e",\n' + + ' "type" : "0x0"\n' + '}' } } diff --git a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/ResponseJsonSerializerSpec.groovy b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/ResponseJsonSerializerSpec.groovy index b71e6fd3..c614dcff 100644 --- a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/ResponseJsonSerializerSpec.groovy +++ b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/ResponseJsonSerializerSpec.groovy @@ -136,7 +136,8 @@ class ResponseJsonSerializerSpec extends Specification { '"to":"0x4d3c2271bb98e41d29896318d29f9e017b1c1669",' + '"value":"0xd8b72d434c800000",' + '"gasPrice":"0x5af3107a4000",' + - '"gas":"0x5208"}}' + '"gas":"0x5208",' + + '"type":"0x0"}}' } diff --git a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/TransactionJsonDeserializeSpec.groovy b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/TransactionJsonDeserializeSpec.groovy index 4637b5ab..5c2c6013 100644 --- a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/TransactionJsonDeserializeSpec.groovy +++ b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/TransactionJsonDeserializeSpec.groovy @@ -1,12 +1,17 @@ package io.emeraldpay.etherjar.rpc.json +import com.fasterxml.jackson.databind.ObjectMapper import io.emeraldpay.etherjar.domain.Wei +import io.emeraldpay.etherjar.rpc.EtherjarModule import io.emeraldpay.etherjar.rpc.JacksonRpcConverter import spock.lang.Specification class TransactionJsonDeserializeSpec extends Specification { JacksonRpcConverter jacksonRpcConverter = new JacksonRpcConverter() + ObjectMapper objectMapper = new ObjectMapper().tap { + it.registerModule(new EtherjarModule()) + } def "Parse unprotected tx 0x5c7851"() { InputStream json = TransactionJsonDeserializeSpec.classLoader.getResourceAsStream("tx/0x5c7851.json") @@ -15,13 +20,29 @@ class TransactionJsonDeserializeSpec extends Specification { def act = jacksonRpcConverter.fromJson(json, TransactionJson) then: + act.hash.toString() == "0x5c7851f4b2dc93860ed5a6624a422d4f17975d41c68667b64453de3ffaa8af49" + act.signature != null + act.signature.chainId == null + !act.signature.protected + act.signature.r.toHex() == '0xe28800dc73a56b5c687ad6b38789f5a485a5ead8236b3d1fc04143fbc1b12c40' + act.signature.s.toHex() == '0x690014487d34d1881461f89edf6662e2efb833f08c5d6913bace4289f2f7736e' + act.signature.v == 27 + } + + def "Parse unprotected tx 0x5c7851 as resulting json"() { + InputStream json = TransactionJsonDeserializeSpec.classLoader.getResourceAsStream("tx/0x5c7851-result.json") + + when: + def act = objectMapper.readValue(json, TransactionJson) + + then: + act.hash.toString() == "0x5c7851f4b2dc93860ed5a6624a422d4f17975d41c68667b64453de3ffaa8af49" act.signature != null act.signature.chainId == null !act.signature.protected act.signature.r.toHex() == '0xe28800dc73a56b5c687ad6b38789f5a485a5ead8236b3d1fc04143fbc1b12c40' act.signature.s.toHex() == '0x690014487d34d1881461f89edf6662e2efb833f08c5d6913bace4289f2f7736e' act.signature.v == 27 - act.signature.publicKey.toHex() == '0x2d4fa87b8e395b5e3f9ff674e0ec109e32d9db99b2b20387cf2f2079c9c041aa2199a67390b8696457020e0aae324cfd1b5e21f86a17683b8afd3660c3ed8c01' } def "Parse protected tx 0xb35804"() { @@ -32,12 +53,10 @@ class TransactionJsonDeserializeSpec extends Specification { then: act.signature != null - act.signature.chainId.value == 61 act.signature.protected act.signature.r.toHex() == '0x9873696b852c34c3da10dda993f02eb800892e30cb5acacd335d47109e73e51b' act.signature.s.toHex() == '0x45adb2148a0f37d30d0a2b4ac3bf4ec0f4d8b938181b45635f02e054ae750759' act.signature.v == 157 - act.signature.publicKey.toHex() == '0x7ac35ec4a59a772186573ed9d26787889cde2042110572ddf79a1f9ef2c7bc28b55b35d4fc5497c50e90cdf53b5a6be6174c456d98ba479a86ff4753d652fba3' } def "Parse tx 0x1e694e"() { @@ -78,7 +97,7 @@ class TransactionJsonDeserializeSpec extends Specification { act.nonce == 259 } - def "Parse tx 0x19442f"() { + def "Parse tx 0x19442f without v"() { InputStream json = this.class.classLoader.getResourceAsStream("tx/0x19442f.json") when: @@ -138,7 +157,7 @@ class TransactionJsonDeserializeSpec extends Specification { act.chainId == 1 } - def "Reads access list"() { + def "Parse tx 0xb8e7e1 with access list"() { setup: InputStream json = this.class.classLoader.getResourceAsStream("tx/0xb8e7e1.json") when: @@ -186,6 +205,16 @@ class TransactionJsonDeserializeSpec extends Specification { ] } } + def "Parse tx 0x408dc2 with access list"() { + setup: + InputStream json = this.class.classLoader.getResourceAsStream("tx/0x408dc2.json") + when: + def act = jacksonRpcConverter.fromJson(json, TransactionJson) + + then: + act.accessList != null + act.accessList.size() == 5 + } def "Reads tx with v=0"() { setup: diff --git a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/TransactionJsonSerializeSpec.groovy b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/TransactionJsonSerializeSpec.groovy index d06b6cbc..b45453c4 100644 --- a/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/TransactionJsonSerializeSpec.groovy +++ b/etherjar-rpc-json/src/test/groovy/io/emeraldpay/etherjar/rpc/json/TransactionJsonSerializeSpec.groovy @@ -19,4 +19,15 @@ class TransactionJsonSerializeSpec extends Specification { then: act == base } + + def "Write 0xb8e7e1"() { + setup: + InputStream json = this.class.classLoader.getResourceAsStream("tx/0xb8e7e1.json") + when: + def base = jacksonRpcConverter.fromJson(json, TransactionJson) + def serialized = objectMapper.writeValueAsString(base) + + then: + serialized.contains("\"hash\":\"0xb8e7e1e41e0b11ed6524a869a89c5dc471371f6a79982a95293caa6705331c8c\"") + } } diff --git a/etherjar-rpc-json/src/test/resources/tx/0x408dc2.json b/etherjar-rpc-json/src/test/resources/tx/0x408dc2.json new file mode 100644 index 00000000..b373ef77 --- /dev/null +++ b/etherjar-rpc-json/src/test/resources/tx/0x408dc2.json @@ -0,0 +1,96 @@ +{ + "jsonrpc": "2.0", + "id": "1111", + "result": { + "blockHash": "0x4ae0e31fe275e5664329884f530b17f0c4b0ebad3860fcc2f72cfc158a26a2ec", + "blockNumber": "0x113033e", + "from": "0xae2fc483527b8ef99eb5d9b44875f005ba1fae13", + "gas": "0x84e7a", + "gasPrice": "0x5a895467a", + "maxFeePerGas": "0x5a895467a", + "maxPriorityFeePerGas": "0x0", + "hash": "0x408dc24db58d7cd18aff4bbc018c04fd227f80864c47418aa1d3071c6a747294", + "input": "0x3e341b3f15979f8b80e307c78e3caf0413cfa923e88e90042e7eb9e8757a197b3b17b207d6de3840de09bcf2dfb75b72c4e8b8c0c0b01bf12500be042e9d09cb588331ff911c2b46fd833a3e5bd6c02aaa39b223fe8d0a0e5c4f27ead9083c756cc22710f2fe34a0fe3568a816bace1cb01bf1ffffb829cbffff2d", + "nonce": "0x126af5", + "to": "0x6b75d8af000000e20b7a7ddf000ba900b4009a80", + "transactionIndex": "0x17", + "value": "0x4641f5", + "type": "0x2", + "accessList": [ + { + "address": "0x3f15979f8b80e307c78e3caf0413cfa923e88e90", + "storageKeys": [ + "0x000000000000000000000000000000000000000000000000000000000000000c", + "0x0000000000000000000000000000000000000000000000000000000000000008", + "0x0000000000000000000000000000000000000000000000000000000000000006", + "0x0000000000000000000000000000000000000000000000000000000000000007", + "0x0000000000000000000000000000000000000000000000000000000000000009", + "0x000000000000000000000000000000000000000000000000000000000000000a" + ] + }, + { + "address": "0x2e19067cbeb38d6554d31a1a83aefc4018a1688a", + "storageKeys": [ + "0x0000000000000000000000000000000000000000000000000000000000000005", + "0x0000000000000000000000000000000000000000000000000000000000000006", + "0xfece53a7d6e347d1ef029381c7322403b8151ef56d4fc376d04f236e22510284", + "0xd5585c5298bf20950f07a6fd107cf76d026485721035f105d896ea0839a6e8d6", + "0xb39e9ba92c3c47c76d4f70e3bc9c3270ab78d2592718d377c8f5433a34d3470a", + "0x49310d23f1265a367377963544cd74272bd31fb3c0bab2d79e5ff92028bc5884" + ] + }, + { + "address": "0x757a197b3b17b207d6de3840de09bcf2dfb75b72", + "storageKeys": [ + "0xed38a10ceeb8f9c8e3e56a4bc055958c5815994c6f79bbf68f525907868ca884", + "0xed38a10ceeb8f9c8e3e56a4bc055958c5815994c6f79bbf68f525907868ca885", + "0x2816f87fc6edf37cf530711b08881066a4ad276fd95d5cacce08b9adc285c178", + "0x0000000000000000000000000000000000000000000000000000000000000001", + "0xe677ffd4263f891b03f61092d0e297939c25389dba44c5913cc109ffaad24cb7", + "0xe677ffd4263f891b03f61092d0e297939c25389dba44c5913cc109ffaad24cba", + "0x0000000000000000000000000000000000000000000000000000000000000004", + "0x0000000000000000000000000000000000000000000000000000000000000002", + "0xc0d1c00078410fd0164580b0bad93d8a579580d06cf45fc2696a823498097b8a", + "0x0000000000000000000000000000000000000000000000000000000000000008", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0xed38a10ceeb8f9c8e3e56a4bc055958c5815994c6f79bbf68f525907868ca883", + "0xe677ffd4263f891b03f61092d0e297939c25389dba44c5913cc109ffaad24cb9", + "0xed38a10ceeb8f9c8e3e56a4bc055958c5815994c6f79bbf68f525907868ca886", + "0x2816f87fc6edf37cf530711b08881066a4ad276fd95d5cacce08b9adc285c177", + "0x2816f87fc6edf37cf530711b08881066a4ad276fd95d5cacce08b9adc285c179", + "0xe677ffd4263f891b03f61092d0e297939c25389dba44c5913cc109ffaad24cb8" + ] + }, + { + "address": "0xbe042e9d09cb588331ff911c2b46fd833a3e5bd6", + "storageKeys": [ + "0xe3f9f9b97b537de593db31a72e038b4b187aa300785fc9f1fa8d7569cd6ffeef", + "0xc7d07bc7b4b06c606d8bd09d68b5b57a8ae0ff2e1ce65b1f30b9a2e225f724fe", + "0x746997d64020d8550105c7442c1ccec5f3a941de97d171182d68cc87c5b6164c", + "0x1eb7d80269e4b80437501ded06d9812be62c30f7a80fcba5a707be4729e49bfc", + "0xab761c2430b0498e679102ac10a4b47c01761a1a4b4743b91f561613623f3400", + "0x0000000000000000000000000000000000000000000000000000000000000023", + "0x0000000000000000000000000000000000000000000000000000000000000009", + "0x0000000000000000000000000000000000000000000000000000000000000005", + "0xb39e9ba92c3c47c76d4f70e3bc9c3270ab78d2592718d377c8f5433a34d3470a", + "0x6ae0b329c9ee8a4f57a216001bad290ce9fbca67159b959bfe82c1d0c08ab0bd", + "0x0000000000000000000000000000000000000000000000000000000000000011", + "0x1452bec7c5a6b3b18899526ff060d769988f8a08d53556d16d83520944659dd5", + "0xac5a0d3f79300e89b6c5577e31fa69b23677c1acb41e1d8af9a2b5a208b0565a" + ] + }, + { + "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", + "storageKeys": [ + "0x38a547390e4c48347325a1aa7e93658c68b3052a51adcd64bb2852a2933d56da", + "0x12231cd4c753cb5530a43a74c45106c24765e6f81dc8927d4f4be7e53315d5a8", + "0xe5323e9ae9378c846cd8751f5f4ffd31faebe66e25ec9fe51f367a75701b0fbd" + ] + } + ], + "chainId": "0x1", + "v": "0x1", + "r": "0xe885e2d6947d0010e1936891d60faf0cf10073248cf1abd5f773ad72ab73b501", + "s": "0x4385cdf910537c8e1723ddf3d0a4be1da8743f9f3cc3288c1c633e9f42d62cf1" + } +} diff --git a/etherjar-rpc-json/src/test/resources/tx/0x5c7851-result.json b/etherjar-rpc-json/src/test/resources/tx/0x5c7851-result.json new file mode 100644 index 00000000..8944f36a --- /dev/null +++ b/etherjar-rpc-json/src/test/resources/tx/0x5c7851-result.json @@ -0,0 +1,21 @@ +{ + "blockHash": "0xa270c7663f9fffa93fd631768c57ad62f2c614d3dc472b3c4494826a1a5c3d8a", + "blockNumber": "0x2e1ae2", + "creates": null, + "from": "0xb7819ff807d9d52a9ce5d713dc7053e8871e077b", + "gas": "0xdbba0", + "gasPrice": "0x4a817c800", + "hash": "0x5c7851f4b2dc93860ed5a6624a422d4f17975d41c68667b64453de3ffaa8af49", + "input": "0xa9059cbb00000000000000000000000014dd45d07d1d700579a9b7cfb3a4536890aafdc20000000000000000000000000000000000000000000000000000000001ca3c98", + "networkId": null, + "nonce": "0xe", + "publicKey": "0x2d4fa87b8e395b5e3f9ff674e0ec109e32d9db99b2b20387cf2f2079c9c041aa2199a67390b8696457020e0aae324cfd1b5e21f86a17683b8afd3660c3ed8c01", + "r": "0xe28800dc73a56b5c687ad6b38789f5a485a5ead8236b3d1fc04143fbc1b12c40", + "raw": "0xf8aa0e8504a817c800830dbba09457d90b64a1a57749b0f932f1a3395792e12e705501b844a9059cbb00000000000000000000000014dd45d07d1d700579a9b7cfb3a4536890aafdc20000000000000000000000000000000000000000000000000000000001ca3c981ba0e28800dc73a56b5c687ad6b38789f5a485a5ead8236b3d1fc04143fbc1b12c40a0690014487d34d1881461f89edf6662e2efb833f08c5d6913bace4289f2f7736e", + "s": "0x690014487d34d1881461f89edf6662e2efb833f08c5d6913bace4289f2f7736e", + "standardV": "0x0", + "to": "0x57d90b64a1a57749b0f932f1a3395792e12e7055", + "transactionIndex": "0x0", + "v": "0x1b", + "value": "0x1" +}