Skip to content
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
4 changes: 2 additions & 2 deletions blockchain.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"hash": "0",
"previousHash": null
"previousHash": null,
"hash": "0"
}
]
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: 11 additions & 3 deletions src/add-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ const addBlock = () => {
const transactions = getTransactions();

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

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

module.exports = { addBlock };
module.exports = { addBlock };
10 changes: 7 additions & 3 deletions src/add-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ const addTransaction = () => {

// Xreate 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 };
5 changes: 5 additions & 0 deletions src/init-blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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"
};
const blockchain = [genesisBlock];

// Create a blockchain constant containing genesisBlock
// Refer writeBlockchain function from blockchain-helpers
Expand Down
8 changes: 7 additions & 1 deletion transactions.json
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
[]
[
{
"fromAddress": "123",
"toAddress": "456",
"amount": 789
}
]