Skip to content

Commit

Permalink
Changes based on PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
lsebrie committed Feb 14, 2018
1 parent bcd8896 commit 12df226
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 46 deletions.
5 changes: 0 additions & 5 deletions rskj-core/src/main/java/co/rsk/core/RskFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,6 @@ public PersonalModule getPersonalModuleWallet(RskSystemProperties config, Rsk rs
return new PersonalModuleWalletEnabled(config, rsk, wallet, pendingState);
}

@Bean
public TxPoolModule getTxPoolModule(RskSystemProperties config, Rsk rsk, PendingState pendingState) {
return new TxPoolModuleImpl(rsk, pendingState);
}

@Bean
public EthModuleWallet getEthModuleWallet(RskSystemProperties config, Rsk rsk, Wallet wallet, PendingState pendingState) {
if (wallet == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package co.rsk.rpc.modules.txpool;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.ethereum.core.PendingState;
import org.ethereum.facade.Ethereum;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

public class TxPoolModuleImpl implements TxPoolModule{
@Component
public class TxPoolModuleImpl implements TxPoolModule {

private Ethereum eth;
private PendingState pendingState;
private ObjectMapper mapper;
private final JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
private final PendingState pendingState;

public TxPoolModuleImpl(Ethereum eth, PendingState pendingState) {
this.eth = eth;
public TxPoolModuleImpl(PendingState pendingState) {
this.pendingState = pendingState;
this.mapper = new ObjectMapper();
}

/**
* This method should return 2 dictionaries containing pending and queued transactions
* Each entry is an origin-address to a batch of scheduled transactions
* These batches themselves are maps associating nonces with actual transactions.
* When there are no transactions the answer would be
* "{"pending": {}, "queued": {}}"
*/
@Override
public String content() {
// return "{"pending": {}, queued: {}}";
Expand All @@ -32,23 +35,35 @@ public String content() {
return node.toString();
}

/**
* This method should return 2 dictionaries containing pending and queued transactions
* Each entry is an origin-address to a batch of scheduled transactions
* These batches themselves are maps associating nonces with transactions summary strings.
* When there are no transactions the answer would be
* "{"pending": {}, "queued": {}}"
*/
@Override
public String inspect() {
// return "{"pending": {}, "queued": {}}";
Map<String, JsonNode> txProps = new HashMap<>();
txProps.put("pending", jsonNodeFactory.objectNode());
txProps.put("queued", jsonNodeFactory.objectNode());
JsonNode node = jsonNodeFactory.objectNode().setAll(txProps);
return node.toString();
}

/**
* This method should return 2 integers for pending and queued transactions
* These value represents
* the number of transactions currently pending for inclusion in the next block(s),
* as well as the ones that are being scheduled for future execution only.
* "{"pending": 0, "queued": 0}"
*/
@Override
public String status() {
// return "{pending: 0, queued: 0}";
Map<String, JsonNode> txProps = new HashMap<>();
txProps.put("pending", jsonNodeFactory.numberNode(0));
txProps.put("queued", jsonNodeFactory.numberNode(0));
JsonNode node = jsonNodeFactory.objectNode().setAll(txProps);
return node.toString();
}
}
}
4 changes: 0 additions & 4 deletions rskj-core/src/main/java/org/ethereum/rpc/Web3.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ public String toString() {
boolean personal_lockAccount(String key);
String personal_dumpRawKey(String address) throws Exception;

String txpool_content();
String txpool_inspect();
String txpool_status();

String eth_netHashrate();
String[] net_peerList();
Map<String, Object> eth_bridgeState() throws Exception;
Expand Down
16 changes: 3 additions & 13 deletions rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import static java.lang.Math.max;
import static org.ethereum.rpc.TypeConverter.*;

public class Web3Impl implements Web3 {
public class Web3Impl implements Web3, Web3TxPoolModule {
private static final Logger logger = LoggerFactory.getLogger("web3");

private final SnapshotManager snapshotManager = new SnapshotManager();
Expand Down Expand Up @@ -1161,18 +1161,8 @@ public boolean personal_lockAccount(String address) {
}

@Override
public String txpool_content() {
return txPoolModule.content();
}

@Override
public String txpool_inspect() {
return txPoolModule.inspect();
}

@Override
public String txpool_status() {
return txPoolModule.status();
public TxPoolModule getTxPoolModule() {
return txPoolModule;
}

@Override
Expand Down
20 changes: 20 additions & 0 deletions rskj-core/src/main/java/org/ethereum/rpc/Web3TxPoolModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.ethereum.rpc;

import co.rsk.rpc.modules.txpool.TxPoolModule;

public interface Web3TxPoolModule {

default String txpool_content() {
return getTxPoolModule().content();
}

default String txpool_inspect() {
return getTxPoolModule().inspect();
}

default String txpool_status() {
return getTxPoolModule().status();
}

TxPoolModule getTxPoolModule();
}
4 changes: 2 additions & 2 deletions rskj-core/src/test/java/co/rsk/rpc/Web3RskImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public void web3_ext_dumpState() throws Exception {
RskSystemProperties config = new RskSystemProperties();
PersonalModule pm = new PersonalModuleWalletEnabled(config, rsk, wallet, null);
EthModule em = new EthModule(config, rsk, new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, rsk, wallet, null));
TxPoolModule txm = new TxPoolModuleImpl(rsk, null);
Web3RskImpl web3 = new Web3RskImpl(rsk, blockchain, Web3Mocks.getMockPendingState(), config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, txm,
TxPoolModule tpm = new TxPoolModuleImpl(null);
Web3RskImpl web3 = new Web3RskImpl(rsk, blockchain, Web3Mocks.getMockPendingState(), config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, tpm,
Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, networkStateExporter, blockStore, null, null, null, null);
web3.ext_dumpState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ private Web3Impl createWeb3(Blockchain blockchain, PendingState pendingState) {
private Web3Impl createWeb3(Ethereum eth, Blockchain blockchain, PendingState pendingState, Wallet wallet) {
PersonalModule personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, null);
EthModule ethModule = new EthModule(config, eth, new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, eth, wallet, null));
TxPoolModule txPoolModule = new TxPoolModuleImpl(eth, null);
TxPoolModule txPoolModule = new TxPoolModuleImpl(null);

return new Web3RskImpl(eth, blockchain, pendingState, config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(),
personalModule, ethModule, txPoolModule, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, blockchain.getBlockStore(), null, null, null, new SimpleConfigCapabilities());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ private static Web3Impl createWeb3(PeerScoringManager peerScoringManager) {
RskSystemProperties config = new RskSystemProperties();
PersonalModule pm = new PersonalModuleWalletEnabled(config, rsk, wallet, null);
EthModule em = new EthModule(config, rsk, new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, rsk, wallet, null));
TxPoolModule txm = new TxPoolModuleImpl(rsk, null);
return new Web3RskImpl(rsk, world.getBlockChain(), null, config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, txm, Web3Mocks.getMockChannelManager(), rsk.getRepository(), peerScoringManager, null, null, null, null, null, null);
TxPoolModule tpm = new TxPoolModuleImpl(null);
return new Web3RskImpl(rsk, world.getBlockChain(), null, config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, tpm, Web3Mocks.getMockChannelManager(), rsk.getRepository(), peerScoringManager, null, null, null, null, null, null);
}

private static NodeID generateNodeID() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ public void increaseTimeTwice() {
private static Web3Impl createWeb3(World world, SimpleEthereum ethereum, MinerServer minerServer) {
MinerClientImpl minerClient = new MinerClientImpl(null, minerServer, config);
PersonalModule pm = new PersonalModuleWalletDisabled();
TxPoolModule txm = new TxPoolModuleImpl(null, null);
TxPoolModule tpm = new TxPoolModuleImpl(null);

ethereum.repository = world.getRepository();
ethereum.blockchain = world.getBlockChain();

return new Web3Impl(ethereum, world.getBlockChain(), null, world.getBlockChain().getBlockStore(), Web3Mocks.getMockProperties(), minerClient, minerServer, pm, null, txm, Web3Mocks.getMockChannelManager(), ethereum.repository, null, null, null, null, null);
return new Web3Impl(ethereum, world.getBlockChain(), null, world.getBlockChain().getBlockStore(), Web3Mocks.getMockProperties(), minerClient, minerServer, pm, null, tpm, Web3Mocks.getMockChannelManager(), ethereum.repository, null, null, null, null, null);
}

private static Web3Impl createWeb3(World world) {
Expand Down
10 changes: 5 additions & 5 deletions rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void eth_mining() {
RskSystemProperties mockProperties = Web3Mocks.getMockProperties();
MinerClient minerClient = new SimpleMinerClient();
PersonalModule personalModule = new PersonalModuleWalletDisabled();
TxPoolModule txPoolModule = new TxPoolModuleImpl(null, null);
TxPoolModule txPoolModule = new TxPoolModuleImpl(null);
Web3 web3 = new Web3Impl(ethMock, blockchain, pendingState, blockStore, mockProperties, minerClient, null, personalModule, null, txPoolModule,
Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null);

Expand Down Expand Up @@ -1253,7 +1253,7 @@ private Web3Impl createWeb3(SimpleEthereum eth, PeerServer peerServer) {
PendingState pendingState = Web3Mocks.getMockPendingState();
PersonalModuleWalletEnabled personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, null);
EthModule ethModule = new EthModule(config, eth, new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, eth, wallet, null));
TxPoolModule txPoolModule = new TxPoolModuleImpl(eth, pendingState);
TxPoolModule txPoolModule = new TxPoolModuleImpl(pendingState);
MinerClient minerClient = new SimpleMinerClient();
ChannelManager channelManager = new SimpleChannelManager();
return new Web3RskImpl(eth, blockchain, pendingState, config, minerClient, Web3Mocks.getMockMinerServer(), personalModule, ethModule, txPoolModule,
Expand All @@ -1280,7 +1280,7 @@ private Web3Impl createWeb3(Ethereum eth, Blockchain blockchain, PendingState pe
wallet = WalletFactory.createWallet();
PersonalModuleWalletEnabled personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, pendingState);
EthModule ethModule = new EthModule(config, eth, new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, eth, wallet, pendingState));
TxPoolModule txPoolModule = new TxPoolModuleImpl(eth, pendingState);
TxPoolModule txPoolModule = new TxPoolModuleImpl(pendingState);
MinerClient minerClient = new SimpleMinerClient();
ChannelManager channelManager = new SimpleChannelManager();
return new Web3RskImpl(eth, blockchain, pendingState, config, minerClient, Web3Mocks.getMockMinerServer(), personalModule, ethModule, txPoolModule,
Expand All @@ -1299,7 +1299,7 @@ public void eth_compileSolidity() throws Exception {
Ethereum eth = Mockito.mock(Ethereum.class);
EthModule ethModule = new EthModule(config, eth, new EthModuleSolidityEnabled(new SolidityCompiler(systemProperties)), null);
PersonalModule personalModule = new PersonalModuleWalletDisabled();
TxPoolModule txPoolModule = new TxPoolModuleImpl(eth, null);
TxPoolModule txPoolModule = new TxPoolModuleImpl(null);
Web3Impl web3 = new Web3RskImpl(eth, null, null, systemProperties, null, null, personalModule, ethModule, txPoolModule, Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null, null, null);
String contract = "pragma solidity ^0.4.1; contract rsk { function multiply(uint a) returns(uint d) { return a * 7; } }";

Expand Down Expand Up @@ -1329,7 +1329,7 @@ public void eth_compileSolidityWithoutSolidity() throws Exception {
Blockchain blockchain = Web3Mocks.getMockBlockchain();
PendingState pendingState = Web3Mocks.getMockPendingState();
EthModule ethModule = new EthModule(config, eth, new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, eth, wallet, null));
TxPoolModule txPoolModule = new TxPoolModuleImpl(eth, pendingState);
TxPoolModule txPoolModule = new TxPoolModuleImpl(pendingState);
Web3Impl web3 = new Web3RskImpl(eth, blockchain, pendingState, config, null, null, new PersonalModuleWalletDisabled(), ethModule, txPoolModule,
Web3Mocks.getMockChannelManager(), Web3Mocks.getMockRepository(), null, null, null, null, null, null, null);

Expand Down

0 comments on commit 12df226

Please sign in to comment.