Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2021 Web3 Labs Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.web3j.protocol.core.methods.response;

import java.util.List;
import java.util.Objects;

public class AccessListObject {
private String address;
private List<String> storageKeys;

public AccessListObject() {}

public AccessListObject(String address, List<String> storageKeys) {
this.address = address;
this.storageKeys = storageKeys;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public List<String> getStorageKeys() {
return storageKeys;
}

public void setStorageKeys(List<String> storageKeys) {
this.storageKeys = storageKeys;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AccessListObject that = (AccessListObject) o;
return Objects.equals(getAddress(), that.getAddress())
&& Objects.equals(getStorageKeys(), that.getStorageKeys());
}

@Override
public int hashCode() {
return Objects.hash(getAddress(), getStorageKeys());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ public TransactionObject(
int v,
String type,
String maxFeePerGas,
String maxPriorityFeePerGas) {
String maxPriorityFeePerGas,
List<AccessListObject> accessList) {
super(
hash,
nonce,
Expand All @@ -600,7 +601,8 @@ public TransactionObject(
v,
type,
maxFeePerGas,
maxPriorityFeePerGas);
maxPriorityFeePerGas,
accessList);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.web3j.protocol.core.methods.response;

import java.math.BigInteger;
import java.util.List;

import org.web3j.utils.Numeric;

Expand Down Expand Up @@ -41,6 +42,7 @@ public class Transaction {
private String type;
private String maxFeePerGas;
private String maxPriorityFeePerGas;
private List<AccessListObject> accessList;

public Transaction() {}

Expand All @@ -64,7 +66,8 @@ public Transaction(
long v,
String type,
String maxFeePerGas,
String maxPriorityFeePerGas) {
String maxPriorityFeePerGas,
List accessList) {
this.hash = hash;
this.nonce = nonce;
this.blockHash = blockHash;
Expand All @@ -85,6 +88,7 @@ public Transaction(
this.type = type;
this.maxFeePerGas = maxFeePerGas;
this.maxPriorityFeePerGas = maxPriorityFeePerGas;
this.accessList = accessList;
}

public String getHash() {
Expand Down Expand Up @@ -292,6 +296,14 @@ public void setMaxPriorityFeePerGas(String maxPriorityFeePerGas) {
this.maxPriorityFeePerGas = maxPriorityFeePerGas;
}

public List<AccessListObject> getAccessList() {
return accessList;
}

public void setAccessList(List<AccessListObject> accessList) {
this.accessList = accessList;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -382,6 +394,11 @@ public boolean equals(Object o) {
: that.getMaxPriorityFeePerGas() != null) {
return false;
}
if (getAccessList() != null
? !getAccessList().equals(that.getAccessList())
: that.getAccessList() != null) {
return false;
}
return getS() != null ? getS().equals(that.getS()) : that.getS() == null;
}

Expand Down Expand Up @@ -415,6 +432,7 @@ public int hashCode() {
+ (getMaxPriorityFeePerGas() != null
? getMaxPriorityFeePerGas().hashCode()
: 0);
result = 31 * result + (getAccessList() != null ? getAccessList().hashCode() : 0);
return result;
}
}
55 changes: 48 additions & 7 deletions core/src/test/java/org/web3j/protocol/core/ResponseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Web3 Labs Ltd.
* Copyright 2021 Web3 Labs Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Expand All @@ -25,6 +25,7 @@

import org.web3j.protocol.ResponseTester;
import org.web3j.protocol.core.methods.response.AbiDefinition;
import org.web3j.protocol.core.methods.response.AccessListObject;
import org.web3j.protocol.core.methods.response.BooleanResponse;
import org.web3j.protocol.core.methods.response.DbGetHex;
import org.web3j.protocol.core.methods.response.DbGetString;
Expand Down Expand Up @@ -723,6 +724,13 @@ public void testEthBlockFullTransactionsParity() {
+ " \"r\":\"0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc\",\n"
+ " \"s\":\"0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62\",\n"
+ " \"v\":\"0\",\n"
+ " \"accessList\": [{"
+ " \"address\":\"0x408e41876cccdc0f92210600ef50372656052a38\",\n"
+ " \"storageKeys\": ["
+ " \"0x18919546fd5421b0ef1b1b8dfce80500e69f2e28ae34c4d6298172949fa77dcc\",\n"
+ " \"0x4869ff95a61ee1ded0b22e2d0e3f54f3199886a9f361e634132c95164bfc5129\"\n"
+ " ] \n"
+ " }], \n"
+ " \"type\":\"0x0\",\n"
+ " \"maxFeePerGas\": \"0x7f110\",\n"
+ " \"maxPriorityFeePerGas\": \"0x7f110\"\n"
Expand Down Expand Up @@ -782,14 +790,21 @@ public void testEthBlockFullTransactionsParity() {
(byte) 0,
"0x0",
"0x7f110",
"0x7f110")),
"0x7f110",
Arrays.asList(
new AccessListObject(
"0x408e41876cccdc0f92210600ef50372656052a38",
Arrays.asList(
"0x18919546fd5421b0ef1b1b8dfce80500e69f2e28ae34c4d6298172949fa77dcc",
"0x4869ff95a61ee1ded0b22e2d0e3f54f3199886a9f361e634132c95164bfc5129"))))),
Arrays.asList(
"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff"),
Arrays.asList(
"0x57919c4e72e79ad7705a26e7ecd5a08ff546ac4fa37882e9cc57be87a3dab26b",
"0x39a3eb432fbef1fc"),
"0x7");

assertEquals(ethBlock.getBlock(), (block));
}

Expand Down Expand Up @@ -838,7 +853,14 @@ public void testEthBlockFullTransactionsGeth() {
+ " \"raw\":\"0xf8cd83103a048504a817c800830e57e0945927c5cc723c4486f93bf90bad3be8831139499e80b864140f8dd300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000c03905df347aa6490d5a98fbb8d8e49520000000000000000000000000000000000000000000000000000000057d56ee61ba0f115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dca04a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62\",\n"
+ " \"r\":\"0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc\",\n"
+ " \"s\":\"0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62\",\n"
+ " \"v\":\"0x9d\",\n"
+ " \"v\":\"0\",\n"
+ " \"accessList\": [{"
+ " \"address\":\"0x408e41876cccdc0f92210600ef50372656052a38\",\n"
+ " \"storageKeys\": ["
+ " \"0x18919546fd5421b0ef1b1b8dfce80500e69f2e28ae34c4d6298172949fa77dcc\",\n"
+ " \"0x4869ff95a61ee1ded0b22e2d0e3f54f3199886a9f361e634132c95164bfc5129\"\n"
+ " ] \n"
+ " }], \n"
+ " \"type\":\"0x0\",\n"
+ " \"maxFeePerGas\": \"0x7f110\",\n"
+ " \"maxPriorityFeePerGas\": \"0x7f110\"\n"
Expand Down Expand Up @@ -895,10 +917,16 @@ public void testEthBlockFullTransactionsGeth() {
"0xf8cd83103a048504a817c800830e57e0945927c5cc723c4486f93bf90bad3be8831139499e80b864140f8dd300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000c03905df347aa6490d5a98fbb8d8e49520000000000000000000000000000000000000000000000000000000057d56ee61ba0f115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dca04a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62",
"0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc",
"0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62",
0x9d,
0,
"0x0",
"0x7f110",
"0x7f110")),
"0x7f110",
Arrays.asList(
new AccessListObject(
"0x408e41876cccdc0f92210600ef50372656052a38",
Arrays.asList(
"0x18919546fd5421b0ef1b1b8dfce80500e69f2e28ae34c4d6298172949fa77dcc",
"0x4869ff95a61ee1ded0b22e2d0e3f54f3199886a9f361e634132c95164bfc5129"))))),
Arrays.asList(
"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff"),
Expand All @@ -917,7 +945,7 @@ public void testEthBlockNull() {
EthBlock ethBlock = deserialiseResponse(EthBlock.class);
assertNull(ethBlock.getBlock());
}

//
@Test
public void testEthTransaction() {

Expand All @@ -943,6 +971,13 @@ public void testEthTransaction() {
+ " \"r\":\"0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc\",\n"
+ " \"s\":\"0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62\",\n"
+ " \"v\":\"0\",\n"
+ " \"accessList\": [{"
+ " \"address\":\"0x408e41876cccdc0f92210600ef50372656052a38\",\n"
+ " \"storageKeys\": ["
+ " \"0x18919546fd5421b0ef1b1b8dfce80500e69f2e28ae34c4d6298172949fa77dcc\",\n"
+ " \"0x4869ff95a61ee1ded0b22e2d0e3f54f3199886a9f361e634132c95164bfc5129\"\n"
+ " ] \n"
+ " }], \n"
+ " \"type\":\"0x0\",\n"
+ " \"maxFeePerGas\": \"0x7f110\",\n"
+ " \"maxPriorityFeePerGas\": \"0x7f110\"\n"
Expand All @@ -969,7 +1004,13 @@ public void testEthTransaction() {
(byte) 0,
"0x0",
"0x7f110",
"0x7f110");
"0x7f110",
Arrays.asList(
new AccessListObject(
"0x408e41876cccdc0f92210600ef50372656052a38",
Arrays.asList(
"0x18919546fd5421b0ef1b1b8dfce80500e69f2e28ae34c4d6298172949fa77dcc",
"0x4869ff95a61ee1ded0b22e2d0e3f54f3199886a9f361e634132c95164bfc5129"))));

EthTransaction ethTransaction = deserialiseResponse(EthTransaction.class);
assertEquals(ethTransaction.getTransaction().get(), (transaction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

import org.junit.jupiter.api.Test;

import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class EthBlockTest {
Expand All @@ -39,4 +43,23 @@ public void testEthBlockNotNullSize() {

assertEquals(ethBlock.getSize(), BigInteger.valueOf(1000));
}

@Test
public void testGetTransactionByHash() throws Exception {
String nodeUrl =
System.getenv()
.getOrDefault(
"WEB3J_NODE_URL",
"https://ropsten.infura.io/v3/5501769a6f86457faadb55a129f5cbae");
Credentials credentials =
Credentials.create(
"8bf15e7802fe7ab126ee5dea38f3c13fa40cf09d02a233448a7601850e6ef060");
Web3j web3j = Web3j.build(new HttpService(nodeUrl));
EthTransaction transaction =
web3j.ethGetTransactionByHash(
"0xcd48e1dea9c9a17b66e938120348eeb8fa53e18100543a49fa7553ed20bd55b2")
.send();
System.out.println(transaction.getTransaction().get().getChainId());
System.out.println(transaction.getTransaction().get().getAccessList().size());
}
}