Skip to content

Commit

Permalink
Trivial: Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
orogvany committed May 23, 2018
1 parent e6fdee2 commit 3d75620
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 400 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/semuxpool/pool/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

/**
*/
public class Constants
{
public class Constants {
public static final long SEM = 1_000_000_000;

public static String getInSEM(long amount)
{
public static String getInSEM(long amount) {
return String.format("%.8f", amount / (float) Constants.SEM);
}
}
25 changes: 8 additions & 17 deletions src/main/java/com/semuxpool/pool/PoolChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@
/**
* Small util to verify payments
*/
public class PoolChecker
{
public static void main(String[] args) throws IOException, SemuxException
{
public class PoolChecker {
public static void main(String[] args) throws IOException, SemuxException {
Properties properties = new Properties();
if (args.length > 0)
{
if (args.length > 0) {
properties.load(new FileInputStream(new File("./config/" + args[0])));
}
else
{
} else {
properties.load(new FileInputStream(new File("./config/semuxpool.properties")));
}

Expand All @@ -48,21 +43,17 @@ public static void main(String[] args) throws IOException, SemuxException
JsonPersistence persistence = new JsonPersistence(payoutsDirectory);
List<Payout> payouts = persistence.getAllPayouts();
Set<Long> blocksForged = new HashSet<>();
for(Payout payout : payouts)
{
for (Payout payout : payouts) {
TreeMap<Long, String> forged = payout.getBlocksForged();
blocksForged.addAll(forged.keySet());
}

//let's scan all blocks since beginning of time and see what's missing
Long totalBlocks = (long) client.getInfo().getLatestBlockNumber();
for(long i =0; i<= totalBlocks;i++)
{
for (long i = 0; i <= totalBlocks; i++) {
Block block = client.getBlock(i);
if(block.getCoinbase().equals(delegateAddress))
{
if(!blocksForged.contains(block.getNumber()))
{
if (block.getCoinbase().equals(delegateAddress)) {
if (!blocksForged.contains(block.getNumber())) {
System.out.println("Missed block " + block.getNumber());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
* todo - work in progress.
* need to figure out ssl certs issue
*/
public class AggregationSiteSubmitter
{
public class AggregationSiteSubmitter {
private static final Logger logger = LoggerFactory.getLogger(AggregationSiteSubmitter.class);

public void registerValidator(String validatorAddress, float donationPercent, SemuxClient client)
{
public void registerValidator(String validatorAddress, float donationPercent, SemuxClient client) {
/**
* The software is free/open without restriction, but semuxpool.com advertising for pool
* It costs money to run, and my web dev guy likes to be paid for his work :D
Expand All @@ -43,14 +41,11 @@ public void registerValidator(String validatorAddress, float donationPercent, Se
*/
// don't register with semuxpool.com if not supporting site operation.
// advertising is not free.
if (donationPercent >= 0.05f)
{
if (donationPercent >= 0.05f) {
HttpPost post = new HttpPost("https://semuxpool.com/api/delegates");
try
{
try {
Delegate delegate = client.getDelegate(validatorAddress);
if (delegate == null)
{
if (delegate == null) {
logger.error("Unable to find delegate with address " + validatorAddress);
return;
}
Expand All @@ -63,50 +58,40 @@ public void registerValidator(String validatorAddress, float donationPercent, Se
post.setHeader("Content-type", "application/json");

CloseableHttpResponse response = httpClient.execute(post);
if (response.getStatusLine().getStatusCode() != 200)
{
if (response.getStatusLine().getStatusCode() != 200) {
logger.error("Unable to register delegate with semuxpool.com");
}
httpClient.close();
}
catch (IOException | SemuxException | NoSuchAlgorithmException | KeyManagementException e)
{
} catch (IOException | SemuxException | NoSuchAlgorithmException | KeyManagementException e) {
logger.error(e.getMessage(), e);
}
}
else
{
} else {
logger.warn("Not registering with semuxpool.com, donation amount too low.");
}
}

private CloseableHttpClient getClient() throws KeyManagementException, NoSuchAlgorithmException
{
private CloseableHttpClient getClient() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext sslContext = SSLContext.getInstance("SSL");

// set up a TrustManager that trusts everything temporarily
sslContext.init(
null, new TrustManager[] {
new X509TrustManager()
{
public X509Certificate[] getAcceptedIssuers()
{
System.out.println("getAcceptedIssuers =============");
return null;
}
null, new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
System.out.println("getAcceptedIssuers =============");
return null;
}

public void checkClientTrusted(X509Certificate[] certs,
String authType)
{
System.out.println("checkClientTrusted =============");
}
public void checkClientTrusted(X509Certificate[] certs,
String authType) {
System.out.println("checkClientTrusted =============");
}

public void checkServerTrusted(X509Certificate[] certs,
String authType)
{
System.out.println("checkServerTrusted =============");
}
} }, new SecureRandom());
public void checkServerTrusted(X509Certificate[] certs,
String authType) {
System.out.println("checkServerTrusted =============");
}
}}, new SecureRandom());

SSLSocketFactory sf = new SSLSocketFactory(sslContext);
Scheme httpsScheme = new Scheme("https", 443, sf);
Expand Down
45 changes: 15 additions & 30 deletions src/main/java/com/semuxpool/pool/api/BlockResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,41 @@
/**
* Payout results for a single given forged block.
*/
public class BlockResult
{
public class BlockResult {
private Long blockId;
private Long totalVotes;
private Map<String, Long> votes;
private Long blockReward;
private String delegate;

public Long getTotalVotes()
{
public Long getTotalVotes() {
return totalVotes;
}

public void setTotalVotes(Long totalVotes)
{
public void setTotalVotes(Long totalVotes) {
this.totalVotes = totalVotes;
}

public Map<String, Long> getVotes()
{
public Map<String, Long> getVotes() {
return votes;
}

public void setVotes(Map<String, Long> votes)
{
public void setVotes(Map<String, Long> votes) {
this.votes = votes;
}

public Long getBlockReward()
{
public Long getBlockReward() {
return blockReward;
}

public void setBlockReward(Long blockReward)
{
public void setBlockReward(Long blockReward) {
this.blockReward = blockReward;
}

@JsonIgnore
public Map<String, Long> getPayouts()
{
public Map<String, Long> getPayouts() {
Map<String, Long> payout = new HashMap<>();
for (Map.Entry<String, Long> voter : votes.entrySet())
{
for (Map.Entry<String, Long> voter : votes.entrySet()) {
payout.put(voter.getKey(), getPartialReward(voter.getValue()));
}
return payout;
Expand All @@ -64,33 +55,27 @@ public Map<String, Long> getPayouts()
* @param value value
* @return partial reward
*/
private Long getPartialReward(Long value)
{
if(totalVotes == 0)
{
private Long getPartialReward(Long value) {
if (totalVotes == 0) {
return 0l;
}
BigInteger results = BigInteger.valueOf(getBlockReward()).multiply(BigInteger.valueOf(value)).divide(BigInteger.valueOf(totalVotes));
return results.longValue();
}

public void setDelegate(String delegate)
{
public void setDelegate(String delegate) {
this.delegate = delegate;
}

public String getDelegate()
{
public String getDelegate() {
return delegate;
}

public Long getBlockId()
{
public Long getBlockId() {
return blockId;
}

public void setBlockId(Long blockId)
{
public void setBlockId(Long blockId) {
this.blockId = blockId;
}
}
27 changes: 9 additions & 18 deletions src/main/java/com/semuxpool/pool/api/DelegateInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,41 @@
/**
* Information about a delegate
*/
public class DelegateInfo
{
public class DelegateInfo {
private String name;
private String address;
private Long blocksForged;
private Float votesSem;

public String getName()
{
public String getName() {
return name;
}

public void setName(String name)
{
public void setName(String name) {
this.name = name;
}

public String getAddress()
{
public String getAddress() {
return address;
}

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

public Long getBlocksForged()
{
public Long getBlocksForged() {
return blocksForged;
}

public void setBlocksForged(Long blocksForged)
{
public void setBlocksForged(Long blocksForged) {
this.blocksForged = blocksForged;
}

public Float getVotesSem()
{
public Float getVotesSem() {
return votesSem;
}

public void setVotesSem(Float votesSem)
{
public void setVotesSem(Float votesSem) {
this.votesSem = votesSem;
}
}
Loading

0 comments on commit 3d75620

Please sign in to comment.