未验证 提交 08ae98e3 编写于 作者: Y Yasser Hassan 提交者: GitHub

add accessList attribute (#1465)

* add eip1559 attributes to block and transaction

* remove test from EthBlockTest

* gradle spotlessJavaApply

* adding accessList attribute

* resolve conflict1

* spotlessJava

* remove exit and desktop.ini files

* update imports

* update imports
上级 f80c64f5
/*
* 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());
}
}
......@@ -579,7 +579,8 @@ public class EthBlock extends Response<EthBlock.Block> {
int v,
String type,
String maxFeePerGas,
String maxPriorityFeePerGas) {
String maxPriorityFeePerGas,
List<AccessListObject> accessList) {
super(
hash,
nonce,
......@@ -600,7 +601,8 @@ public class EthBlock extends Response<EthBlock.Block> {
v,
type,
maxFeePerGas,
maxPriorityFeePerGas);
maxPriorityFeePerGas,
accessList);
}
@Override
......
......@@ -13,6 +13,7 @@
package org.web3j.protocol.core.methods.response;
import java.math.BigInteger;
import java.util.List;
import org.web3j.utils.Numeric;
......@@ -41,6 +42,7 @@ public class Transaction {
private String type;
private String maxFeePerGas;
private String maxPriorityFeePerGas;
private List<AccessListObject> accessList;
public Transaction() {}
......@@ -64,7 +66,8 @@ public class Transaction {
long v,
String type,
String maxFeePerGas,
String maxPriorityFeePerGas) {
String maxPriorityFeePerGas,
List accessList) {
this.hash = hash;
this.nonce = nonce;
this.blockHash = blockHash;
......@@ -85,6 +88,7 @@ public class Transaction {
this.type = type;
this.maxFeePerGas = maxFeePerGas;
this.maxPriorityFeePerGas = maxPriorityFeePerGas;
this.accessList = accessList;
}
public String getHash() {
......@@ -292,6 +296,14 @@ public class Transaction {
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) {
......@@ -382,6 +394,11 @@ public class Transaction {
: 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;
}
......@@ -415,6 +432,7 @@ public class Transaction {
+ (getMaxPriorityFeePerGas() != null
? getMaxPriorityFeePerGas().hashCode()
: 0);
result = 31 * result + (getAccessList() != null ? getAccessList().hashCode() : 0);
return result;
}
}
/*
* 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
......@@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test;
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;
......@@ -723,6 +724,13 @@ public class ResponseTest extends ResponseTester {
+ " \"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"
......@@ -782,7 +790,13 @@ public class ResponseTest extends ResponseTester {
(byte) 0,
"0x0",
"0x7f110",
"0x7f110")),
"0x7f110",
Arrays.asList(
new AccessListObject(
"0x408e41876cccdc0f92210600ef50372656052a38",
Arrays.asList(
"0x18919546fd5421b0ef1b1b8dfce80500e69f2e28ae34c4d6298172949fa77dcc",
"0x4869ff95a61ee1ded0b22e2d0e3f54f3199886a9f361e634132c95164bfc5129"))))),
Arrays.asList(
"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff"),
......@@ -790,6 +804,7 @@ public class ResponseTest extends ResponseTester {
"0x57919c4e72e79ad7705a26e7ecd5a08ff546ac4fa37882e9cc57be87a3dab26b",
"0x39a3eb432fbef1fc"),
"0x7");
assertEquals(ethBlock.getBlock(), (block));
}
......@@ -838,7 +853,14 @@ public class ResponseTest extends ResponseTester {
+ " \"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"
......@@ -895,10 +917,16 @@ public class ResponseTest extends ResponseTester {
"0xf8cd83103a048504a817c800830e57e0945927c5cc723c4486f93bf90bad3be8831139499e80b864140f8dd300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000c03905df347aa6490d5a98fbb8d8e49520000000000000000000000000000000000000000000000000000000057d56ee61ba0f115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dca04a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62",
"0xf115cc4d7516dd430046504e1c888198e0323e8ded016d755f89c226ba3481dc",
"0x4a2ae8ee49f1100b5c0202b37ed8bacf4caeddebde6b7f77e12e7a55893e9f62",
0x9d,
0,
"0x0",
"0x7f110",
"0x7f110")),
"0x7f110",
Arrays.asList(
new AccessListObject(
"0x408e41876cccdc0f92210600ef50372656052a38",
Arrays.asList(
"0x18919546fd5421b0ef1b1b8dfce80500e69f2e28ae34c4d6298172949fa77dcc",
"0x4869ff95a61ee1ded0b22e2d0e3f54f3199886a9f361e634132c95164bfc5129"))))),
Arrays.asList(
"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff"),
......@@ -917,7 +945,7 @@ public class ResponseTest extends ResponseTester {
EthBlock ethBlock = deserialiseResponse(EthBlock.class);
assertNull(ethBlock.getBlock());
}
//
@Test
public void testEthTransaction() {
......@@ -943,6 +971,13 @@ public class ResponseTest extends ResponseTester {
+ " \"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"
......@@ -969,7 +1004,13 @@ public class ResponseTest extends ResponseTester {
(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));
......
......@@ -16,6 +16,10 @@ import java.math.BigInteger;
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 {
......@@ -39,4 +43,23 @@ public class EthBlockTest {
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());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册