forked from hyperledger-web3j/web3j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support admin txpool_content method (hyperledger-web3j#1178)
* Adds support for txpool content * Small fixes
- Loading branch information
1 parent
30297bc
commit c594443
Showing
7 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
core/src/main/java/org/web3j/protocol/admin/methods/response/TxPoolContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2020 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.admin.methods.response; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.web3j.protocol.core.Response; | ||
import org.web3j.protocol.core.methods.response.Transaction; | ||
|
||
/** txpool_content */ | ||
public class TxPoolContent extends Response<TxPoolContent.TxPoolContentResult> { | ||
public static class TxPoolContentResult { | ||
|
||
private Map<String, Map<BigInteger, Transaction>> pending; | ||
private Map<String, Map<BigInteger, Transaction>> queued; | ||
|
||
public TxPoolContentResult() {} | ||
|
||
public TxPoolContentResult( | ||
Map<String, Map<BigInteger, Transaction>> pending, | ||
Map<String, Map<BigInteger, Transaction>> queued) { | ||
this.pending = | ||
Collections.unmodifiableMap( | ||
pending.entrySet().stream() | ||
.collect( | ||
Collectors.toMap( | ||
(Map.Entry<String, Map<BigInteger, Transaction>> | ||
i) -> i.getKey().toLowerCase(), | ||
(Map.Entry<String, Map<BigInteger, Transaction>> | ||
i) -> | ||
Collections.unmodifiableMap( | ||
i.getValue())))); | ||
this.queued = | ||
Collections.unmodifiableMap( | ||
queued.entrySet().stream() | ||
.collect( | ||
Collectors.toMap( | ||
(Map.Entry<String, Map<BigInteger, Transaction>> | ||
i) -> i.getKey().toLowerCase(), | ||
(Map.Entry<String, Map<BigInteger, Transaction>> | ||
i) -> | ||
Collections.unmodifiableMap( | ||
i.getValue())))); | ||
} | ||
|
||
public Map<String, Map<BigInteger, Transaction>> getPending() { | ||
return pending; | ||
} | ||
|
||
public Map<String, Map<BigInteger, Transaction>> getQueued() { | ||
return queued; | ||
} | ||
|
||
public List<Transaction> getPendingTransactions() { | ||
return pending.values().stream() | ||
.flatMap(i -> i.values().stream()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<Transaction> getQueuedTransactions() { | ||
return queued.values().stream() | ||
.flatMap(i -> i.values().stream()) | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
integration-tests/src/test/java/org/web3j/protocol/geth/GethIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2020 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.geth; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.web3j.protocol.admin.methods.response.TxPoolContent; | ||
import org.web3j.protocol.http.HttpService; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class GethIT { | ||
|
||
private Geth web3j; | ||
|
||
public GethIT() {} | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
this.web3j = Geth.build(new HttpService()); | ||
} | ||
|
||
@Test | ||
public void testWeb3ClientVersion() throws Exception { | ||
TxPoolContent content = web3j.txPoolContent().send(); | ||
assertNotNull(content.getResult()); | ||
} | ||
} |