Commit 348350ab authored by Michel Schudel's avatar Michel Schudel

more changes

parent f9901e15
This diff is collapsed.
......@@ -72,6 +72,7 @@ bootRun {
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-devtools")
compile 'commons-codec:commons-codec:1.10'
testCompile('org.springframework.boot:spring-boot-starter-test')
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.4'
......
#Tue Jan 16 10:35:15 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
......@@ -82,7 +82,7 @@ public class BlockChain {
if (!chain.get(i).getPreviousHash().equals(HashUtil.hash(chain.get(i - 1)))) {
return false;
}
if (!HashUtil.validProof(chain.get(i - 1).getProof(), chain.get(i).getProof())) {
if (!validProof(chain.get(i - 1).getProof(), chain.get(i).getProof())) {
return false;
}
}
......@@ -95,7 +95,7 @@ public class BlockChain {
if (!newBlock.getPreviousHash().equals(HashUtil.hash(lastBlock))) {
return false;
}
if (!HashUtil.validProof(lastBlock.getProof(), newBlock.getProof())) {
if (!validProof(lastBlock.getProof(), newBlock.getProof())) {
return false;
}
......@@ -109,9 +109,15 @@ public class BlockChain {
- Find a number p' such that hash(pp') contains leading 4 zeroes, where p is the previous p'
- p is the previous proof, and p' is the new proof*/
long currentProof = 0;
while (!HashUtil.validProof(lastProof, currentProof)) {
while (!validProof(lastProof, currentProof)) {
currentProof++;
}
return currentProof;
}
private boolean validProof( long previousProof, long currentProof) {
String hash = HashUtil.createHash(previousProof + "" + currentProof);
return hash.startsWith("0000");
}
}
......@@ -18,7 +18,7 @@ public class BlockchainManager {
private static final Logger LOGGER = LoggerFactory.getLogger(BlockchainManager.class);
private static final BigDecimal CRAFTSCOIN_MINING_REWARD = BigDecimal.ONE;
private static final BigDecimal CRAFTSCOIN_MINING_REWARD = BigDecimal.TEN;
private BlockChain blockChain;
private Network network;
......@@ -109,7 +109,7 @@ public class BlockchainManager {
this.blockChain.addBlock(block);
this.network.notifyPeersOfNewBlock(block, sourcePeer);
blockChainRepository.saveBlockChain(blockChain);
clearConfirmedTransactions();
clearConfirmedTransactions();
} else {
LOGGER.info("block is not valid with respect to my blockchain, discarding.");
......
......@@ -20,12 +20,8 @@ public class HashUtil {
}
public static boolean validProof( long previousProof, long currentProof) {
String hash = HashUtil.createHash(previousProof + "" + currentProof);
return hash.startsWith("0000");
}
private static String createHash(String aString) {
public static String createHash(String aString) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(aString.getBytes());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment