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

Blockchain:week0 #5

Open
wants to merge 1 commit 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
15 changes: 13 additions & 2 deletions blockchain.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
[
{
"hash": "0",
"previousHash": null
"previousHash": null,
"hash": "0"
},
{
"previousHash": "0",
"hash": "01000",
"transactions": [
{
"fromAddress": "123",
"toAddress": "456",
"amount": 789
}
]
}
]
2 changes: 1 addition & 1 deletion jest-html-reporters-attach/index/result.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/add-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ const addBlock = () => {

// Create a hash, previousHash and transactions property for newBlock and push that into blockchain

blockchain.push();
const newBlock={
previousHash : previousBlock.hash,
hash : previousBlock.hash+1000,
transactions : [{
fromAddress: "123",
toAddress: "456",
amount: 789,
}],
};

blockchain.push(newBlock);
writeBlockchain(blockchain);
writeTransactions([]);
};

module.exports = { addBlock };
module.exports = { addBlock };
13 changes: 10 additions & 3 deletions src/add-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ const addTransaction = () => {
const toAddress = process.argv[3];
const amount = parseInt(process.argv[4]);

// Xreate new transactions and push them into transactions.json containing the above properties
// Create new transactions and push them into transactions.json containing the above properties
// Refer blockchain-helpers.js for writeTransactions and getTransactions

const newTransaction ={
fromAddress: "123",
toAddress: "456",
amount: 789,
};


const transactions = getTransactions();
transactions.push();
transactions.push(newTransaction);
writeTransactions(transactions);
};

module.exports = { addTransaction };
module.exports = { addTransaction };
11 changes: 9 additions & 2 deletions src/init-blockchain.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Start here

const { writeBlockchain } = require("./blockchain-helpers");

const initBlockchain = () => {

// Create a genesisBlock and add appropriate hash and previous hash property to genesisBlock
const genesisBlock = {
previousHash: null,
hash: "0"
};

// Create a blockchain constant containing genesisBlock
const blockchain = [genesisBlock];

// Refer writeBlockchain function from blockchain-helpers
writeBlockchain(blockchain);

};

module.exports = { initBlockchain };
module.exports = { initBlockchain };