Created
August 16, 2017 03:14
-
-
Save hackervera/e4335299dd4a135e0757ed9a277af823 to your computer and use it in GitHub Desktop.
This file contains 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
require "sequel" | |
require "merkle-hash-tree" | |
require "rbnacl" | |
require "digest" | |
DB = Sequel.connect('postgres://[email protected]/merk') | |
def build_chain(head) | |
chain = DB.from(:chains)[head: head] | |
if chain[:previous_head] == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" | |
[chain[:body]] | |
else | |
build_chain(chain[:previous_head]) << chain[:body] | |
end | |
end | |
head = "529da179869b61355f106f22074b7be466d2f2335ebb464f7e71b360cd62fc40" | |
mht_head = RbNaCl::Util.bin2hex(MerkleHashTree.new(build_chain(head), Digest::SHA256).head) | |
p head == mht_head |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment