Last active
November 29, 2017 06:04
-
-
Save aludwiko/bd380f8b131fec1d9bf105c34e52d842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val infiniteTransactionsStream = | |
Stream.continually(s"$randomUser() sent $randomValue() BTC to $randomUser()") | |
Source(infiniteTransactionsStream) | |
.grouped(5) //group transactions into 5 element blocks | |
.scan(0.hashCode.toString) { (previousBlockHash, transactions) => | |
//hash for block is defined as hash of transactions hash and previous block hash | |
(transactions.hashCode(), previousBlockHash).hashCode.toString | |
} | |
.mapAsync(1)(saveHashAndReturnIt) | |
.runForeach(savedHash => println(s"saved block with hash:$savedHash")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment