我需要用没有ethereum.conf文件的ethereumj连接到私有的ethereum节点。我需要使用从代码中配置connect。
发布于 2017-07-26 11:56:37
对我来说很管用。也许它会对某些人有帮助。
public class EthereumAppConfig implements BeanPostProcessor {
private static final List<String> ipList = new ArrayList<>();
private static ConfigValue value(Object value) {
return ConfigValueFactory.fromAnyRef(value);
}
@Override
public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
if (o instanceof SystemProperties)
((SystemProperties) o).overrideParams(getConfig());
return o;
}
@Override
public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
return o;
}
private static Config getConfig() {
ipList.add("0.0.0.0:00000");
List<Map<String, String>> peerActives = new ArrayList<>();
Map<String, String> urls = new HashMap<>();
urls.put("url", "enode://0");
urls.put("url", "enode://1");
urls.put("url", "enode://2");
urls.put("url", "enode://4");
peerActives.add(
urls
);
return ConfigFactory.empty()
.withValue("peer.discovery.enabled", value(true))
.withValue("peer.discovery.external.ip", value("0.0.0.0"))
.withValue("peer.discovery.bind.ip", value("0.0.0.0"))
.withValue("peer.discovery.persist", value("false"))
.withValue("peer.listen.port", value(00000))
.withValue("peer.privateKey", value(Hex.toHexString(ECKey.fromPrivate(("0").getBytes()).getPrivKeyBytes())))
.withValue("peer.networkId", value(76543))
.withValue("sync.enabled", value(true))
.withValue("genesis", value("genesis.json"))
.withValue("database.dir", value("database"))
.withValue("peer.discovery.ip.list", value(ipList))
.withValue("peer.active", value(peerActives))
.withValue("mine.start", value(true));
}
}发布于 2017-11-08 00:09:10
请查看我已经上传到Github的代码,它正是这样做的:)它在.conf文件中包含了所有相关的配置。
https://ethereum.stackexchange.com/questions/21642
复制相似问题