I hereby claim:
- I am FelixKlauke on github.
- I am felixklauke (https://keybase.io/felixklauke) on keybase.
- I have a public key whose fingerprint is 9B6C 45FA 099B 076C 7BED 00A1 7181 F401 CE7C 0A8E
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
private static final String VALIDATION_PREFIX = "00"; | |
public int proofOfWork() { | |
return proofOfWork(getLastBlock().getProofOfWork()); | |
} | |
private int proofOfWork(int lastProof) { | |
int proof = 0; | |
while (!validate(lastProof, proof)) { |
public String getHash() { | |
return DigestUtils.sha256Hex(timestamp + HASH_DELIMITER + transactions.toString() + HASH_DELIMITER + previousBlockHash + HASH_DELIMITER + proofOfWork); | |
} |
import org.apache.commons.codec.digest.DigestUtils; | |
import java.util.Collections; | |
import java.util.List; | |
/** | |
* Represents one block in the chain. | |
* | |
* @author Felix Klauke <info@felix-klauke.de> | |
*/ |
/** | |
* Start mining a new block. | |
* | |
* @return The block instance. | |
*/ | |
public Block mineBlock() { | |
int proofOfWork = proofOfWork(); | |
Block lastBlock = blocks.getLast(); | |
Block block = new Block(lastBlock.getIndex() + 1, lastBlock.getHas(), transactions, proofOfWork); |
@Service | |
public class BlockChainService { | |
private BlockChain blockChain = new BlockChain(); | |
public BlockChainService() { | |
blockChain.addBlock(new Block(0, "", new ArrayList<>(), 0)); | |
} | |
public void addTransaction(Transaction transaction) { |
@RestController | |
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | |
public class BlockChainController { | |
private final BlockChainService blockChainService; | |
@RequestMapping(method = RequestMethod.GET, path = "/chain") | |
public List<Block> requestChainContent() { | |
return blockChainService.getBlockChainContent(); | |
} |
@SpringBootApplication | |
public class SageNodeApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(SageNodeApplication.class, args); | |
} | |
} |
/** | |
* Providing options for low level file access using an input and an output stream. | |
*/ | |
class FileSystemAccessor { | |
public: | |
/** | |
* Create a new file system accessor by passing the file we want to access under the hood. | |
* |