Question: implement the findProof method. The method should 1) Add one extra coin to the miner's account in the ledger 2) Convert the new ledger to

implement the findProof method. The method should

1) Add one extra coin to the miner's account in the ledger 2) Convert the new ledger to a String (ledgeStr) 3) Search for a "proof" where the result of hash(ledgerStr + proof) has NUM_ZEROES leading zeroes,

import static java.lang.System.out; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Map; public class Miner { public static int NUM_ZEROES = 22; private String name; public Miner(String name) { this.name = name; } public String findProof(Map ledger) throws Exception { return null; } public static String hash(String s) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(s.getBytes()); byte[] data = md.digest(); StringBuffer sb = new StringBuffer(); for (int i=0; i ledger = new HashMap(); ledger.put("Alice", 42); ledger.put("Bob", 316); ledger.put("Charlie", 19); Miner alice = new Miner("Alice"); out.println(alice.findProof(ledger)); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!