Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Pull Request #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bitcoin Whitepaper Exercises
# Bitcoin Whitepaper Exercises - This is Vijay's version

In these exercises, you will learn about blockchains from the perspective of the [original Bitcoin Whitepaper](https://bitcoin.org/en/bitcoin-paper).

Expand Down
26 changes: 24 additions & 2 deletions hashing/hashing.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,29 @@ Blockchain.blocks.push({
});

// TODO: insert each line into blockchain
// for (let line of poem) {
// }
for (let line of poem) {
createBlock(line)
}

// Create function createBlock
// `index`
// `prevHash`
// `data`
// `timestamp`
// `hash`

function createBlock(_data) {
let block = {
index: Blockchain.blocks.length,
prevHash: Blockchain.blocks[Blockchain.blocks.length - 1].hash,
data: _data,
timestamp: Date.now()
}
block.hash = blockHash(block)
Blockchain.blocks.push(block)
console.log(block)
return block
}

// console.log(`Blockchain is valid: ${verifyChain(Blockchain)}`);

Expand All @@ -39,5 +60,6 @@ Blockchain.blocks.push({
function blockHash(bl) {
return crypto.createHash("sha256").update(
// TODO: use block data to calculate hash
`${bl.index};${bl.prevHash};${bl.data};${bl.timestamp};`
).digest("hex");
}