Skip to content

Instantly share code, notes, and snippets.

@felixklauke
Last active June 22, 2018 11:05
Show Gist options
  • Save felixklauke/879c17c528f632ce7691f01074fde915 to your computer and use it in GitHub Desktop.
Save felixklauke/879c17c528f632ce7691f01074fde915 to your computer and use it in GitHub Desktop.
Simple block chains service layer implementation.
@Service
public class BlockChainService {
private BlockChain blockChain = new BlockChain();
public BlockChainService() {
blockChain.addBlock(new Block(0, "", new ArrayList<>(), 0));
}
public void addTransaction(Transaction transaction) {
blockChain.addTransaction(transaction);
}
public List<Block> getBlockChainContent() {
return new ArrayList<>(blockChain.getBlocks());
}
public Block startMining() {
Block block = blockChain.mineBlock();
blockChain.addBlock(block);
return block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment