From 3f23500f2abeca0946f149af637312ce95386987 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 08:11:39 +0530 Subject: [PATCH 01/20] Create Mirudhulaa S --- Mirudhulaa S | 1 + 1 file changed, 1 insertion(+) create mode 100644 Mirudhulaa S diff --git a/Mirudhulaa S b/Mirudhulaa S new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Mirudhulaa S @@ -0,0 +1 @@ + From a7299770331ffef0a00ae87f020c1988049c3dbe Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 08:12:11 +0530 Subject: [PATCH 02/20] Delete Mirudhulaa S --- Mirudhulaa S | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Mirudhulaa S diff --git a/Mirudhulaa S b/Mirudhulaa S deleted file mode 100644 index 8b13789..0000000 --- a/Mirudhulaa S +++ /dev/null @@ -1 +0,0 @@ - From e65e92eb87f80e0e395647cca4c70c6daa8bf4ca Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 08:31:52 +0530 Subject: [PATCH 03/20] Create Code Implementation code --- assignments/Code Implementation | 106 ++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 assignments/Code Implementation diff --git a/assignments/Code Implementation b/assignments/Code Implementation new file mode 100644 index 0000000..a3090a5 --- /dev/null +++ b/assignments/Code Implementation @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +struct Transaction { + string sender; + string receiver; + double amount; + time_t timestamp; + + Transaction(string _sender, string _receiver, double _amount) : sender(_sender), receiver(_receiver), amount(_amount) { + timestamp = time(nullptr); + } +}; + +struct Block { + int index; + time_t timestamp; + vector transactions; + string previousHash; + string hash; + + Block(int _index, vector _transactions, string _previousHash) : index(_index), transactions(_transactions), previousHash(_previousHash) { + timestamp = time(nullptr); + hash = calculateHash(); + } + + string calculateHash() { + string data = to_string(index) + to_string(timestamp) + previousHash; + for (const auto& transaction : transactions) + data += transaction.sender + transaction.receiver + to_string(transaction.amount) + to_string(transaction.timestamp); + + size_t hashValue = std::hash{}(data); + + stringstream ss; + ss << hex << hashValue; + //cout << ss.str(); + return ss.str(); + } +}; + +class Blockchain { +private: + vector chain; + +public: + Blockchain() { + chain.push_back(createGenesisBlock()); + } + + Block createGenesisBlock() { + vector transactions; + return Block(0, transactions, "0"); + } + + void addBlock(vector transactions) { + Block previousBlock = chain.back(); + int newIndex = previousBlock.index + 1; + string previousHash = previousBlock.hash; + Block newBlock(newIndex, transactions, previousHash); + chain.push_back(newBlock); + } + + bool validateChain() { + for (int i = 1; i < chain.size(); i++) { + Block currentBlock = chain[i]; + Block previousBlock = chain[i - 1]; + + if (currentBlock.hash != currentBlock.calculateHash()) { + return false; + } + + if (currentBlock.previousHash != previousBlock.hash) { + return false; + } + } + return true; + } +}; + +int main() { + + Blockchain blockchain; + //Block1 Transaction + vector block1Transactions; + block1Transactions.push_back(Transaction("Ram", "Sita", 1000)); + block1Transactions.push_back(Transaction("Riya", "Roni", 50000)); + block1Transactions.push_back(Transaction("Naruto", "Hinata", 4500)); + blockchain.addBlock(block1Transactions); + //Block2 Transaction + vector block2Transactions; + block2Transactions.push_back(Transaction("Aryan", "Karthik", 9500)); + block2Transactions.push_back(Transaction("Alya", "Krish", 45000)); + block2Transactions.push_back(Transaction("Chintu", "Kichu", 300000)); + blockchain.addBlock(block2Transactions); + //Validation + bool isValid = blockchain.validateChain(); + cout << "Is blockchain valid? " << (isValid ? "Yes" : "No") << endl; + + return 0; +} From 66885969fb9ebcd1e20259f7909a789ff371754e Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 08:37:12 +0530 Subject: [PATCH 04/20] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a6d23d --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# evaluation + From dbf8420673cb1da8d63e77973d87358a4985adc2 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 08:41:12 +0530 Subject: [PATCH 05/20] README.md --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 7a6d23d..071a652 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,27 @@ # evaluation +# Introduction +In this assignment, you will be using your knowledge of the C++ programming language to implement a simple blockchain. A blockchain is a digital ledger of transactions that is decentralized and secure. Each block in the chain contains a cryptographic hash of the previous block, along with the current transactions. + +# Requirements +Implement a basic blockchain data structure in C++. The blockchain should consist of blocks, each with a unique hash and a pointer to the previous block in the chain. +Each block should contain a list of transactions, represented as a linked list. +Implement a function to add a new block to the chain. This function should take a list of transactions as input, calculate the hash of the previous block, and add the new block to the chain. +Implement a function to validate the blockchain. This function should traverse the chain and verify that each block's hash matches the previous block's hash. +Test your blockchain implementation by adding some transactions and validating the chain. +Research and write a brief report on the security implications of using a blockchain for financial transactions. +Submission Guidelines +Fork this repository and create a new branch for your work. +Create a folder with your name and place all your files inside it. +Write all your code in C++ language. +Include a README.md file explaining how to compile and run your code. +Write a brief report on the security implications of using a blockchain for financial transactions and include it in your folder. +Submit a pull request to the master branch of the original repository. + +# Evaluation +Your assignment will be evaluated based on the following criteria: + +Correctness and completeness of the blockchain implementation +Clarity and readability of the code +Correctness and completeness of the validation function +Quality and completeness of the report on blockchain security From 2b5337263ebe1bfdef5a4d202c508c5f6a66c013 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 10:38:59 +0530 Subject: [PATCH 06/20] README.md --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 071a652..8d4c939 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,27 @@ -# evaluation +# Brief Review + +# Intro:- +Blockchain Technology is a method of recording information under a decentralised system which is impossible to change, manipulate or hacked. Blockchain is a distributed ledger that duplicates and distribute the transactional information to all the connected networks. It is a structure that stores all records of transaction in a single block which is connected to the next block of transaction in a chain manner which is termed as Blockchain. This storage is known as Digital Ledger. It is highly secured, distributed, immutable, decentralised and transparent. + +Every transaction in a ledger is authorised by the digital signature of the owner which authenticates the transaction and safeguards from tampering. Hence, its highly secured. + +# Structure of Blockchain:- + +A Block consists of three major components: +1) Header - contains metadata such as timpestamp and previous block's hash. +2) Data section - contains the actual information such as transactions and smart contracts. +3) Hash - its a unique cryptographic value of the entire block for verification purposes. + +# Process of Transaction:- + +When two people want to perform a transaction using their private and public keys, respectively, the first party would attach the transaction data to the second party's public key. The block includes a timestamp, a digital signature, and other crucial details. It should be emphasised that the block does not contain information on the parties to the transaction's identities. The block is then sent around the entire network, and when the correct user uses his private key to match it with the block, the transaction is successfully completed. + +The Blockchain is able to record financial transactions as well as prperties, cars, and so on which is known as smart contracts. + + + + + # Introduction In this assignment, you will be using your knowledge of the C++ programming language to implement a simple blockchain. A blockchain is a digital ledger of transactions that is decentralized and secure. Each block in the chain contains a cryptographic hash of the previous block, along with the current transactions. From f8ef3f2a614f27da98fcfa4c535ea3dacf1f5717 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 10:40:34 +0530 Subject: [PATCH 07/20] Create Assignment --- assignments/Assignment | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 assignments/Assignment diff --git a/assignments/Assignment b/assignments/Assignment new file mode 100644 index 0000000..c897dcc --- /dev/null +++ b/assignments/Assignment @@ -0,0 +1,26 @@ +# Introduction +In this assignment, you will be using your knowledge of the C++ programming language to implement a simple blockchain. A blockchain is a digital ledger of transactions that is decentralized and secure. Each block in the chain contains a cryptographic hash of the previous block, along with the current transactions. + +# Requirements +Implement a basic blockchain data structure in C++. The blockchain should consist of blocks, each with a unique hash and a pointer to the previous block in the chain. +Each block should contain a list of transactions, represented as a linked list. +Implement a function to add a new block to the chain. This function should take a list of transactions as input, calculate the hash of the previous block, and add the new block to the chain. +Implement a function to validate the blockchain. This function should traverse the chain and verify that each block's hash matches the previous block's hash. +Test your blockchain implementation by adding some transactions and validating the chain. +Research and write a brief report on the security implications of using a blockchain for financial transactions. +Submission Guidelines +Fork this repository and create a new branch for your work. +Create a folder with your name and place all your files inside it. +Write all your code in C++ language. +Include a README.md file explaining how to compile and run your code. +Write a brief report on the security implications of using a blockchain for financial transactions and include it in your folder. +Submit a pull request to the master branch of the original repository. + +# Evaluation +Your assignment will be evaluated based on the following criteria: + +Correctness and completeness of the blockchain implementation +Clarity and readability of the code +Correctness and completeness of the validation function +Quality and completeness of the report on blockchain security + From 91fb793f782c7b6125b301d42e72044c8f735458 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 10:41:10 +0530 Subject: [PATCH 08/20] Assignment --- assignments/Assignment | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/assignments/Assignment b/assignments/Assignment index c897dcc..08e4502 100644 --- a/assignments/Assignment +++ b/assignments/Assignment @@ -1,11 +1,16 @@ # Introduction -In this assignment, you will be using your knowledge of the C++ programming language to implement a simple blockchain. A blockchain is a digital ledger of transactions that is decentralized and secure. Each block in the chain contains a cryptographic hash of the previous block, along with the current transactions. +In this assignment, you will be using your knowledge of the C++ programming language to implement a simple blockchain. +A blockchain is a digital ledger of transactions that is decentralized and secure. Each block in the chain contains a cryptographic +hash of the previous block, along with the current transactions. # Requirements -Implement a basic blockchain data structure in C++. The blockchain should consist of blocks, each with a unique hash and a pointer to the previous block in the chain. +Implement a basic blockchain data structure in C++. The blockchain should consist of blocks, each with a unique hash and a pointer +to the previous block in the chain. Each block should contain a list of transactions, represented as a linked list. -Implement a function to add a new block to the chain. This function should take a list of transactions as input, calculate the hash of the previous block, and add the new block to the chain. -Implement a function to validate the blockchain. This function should traverse the chain and verify that each block's hash matches the previous block's hash. +Implement a function to add a new block to the chain. This function should take a list of transactions as input, calculate the hash +of the previous block, and add the new block to the chain. +Implement a function to validate the blockchain. This function should traverse the chain and verify that each block's hash matches +the previous block's hash. Test your blockchain implementation by adding some transactions and validating the chain. Research and write a brief report on the security implications of using a blockchain for financial transactions. Submission Guidelines From 410df6aeab7beb601675b34ce949cd84095090c6 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 10:43:59 +0530 Subject: [PATCH 09/20] README.md --- README.md | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/README.md b/README.md index 8d4c939..d9dcc7c 100644 --- a/README.md +++ b/README.md @@ -21,30 +21,3 @@ The Blockchain is able to record financial transactions as well as prperties, ca - -# Introduction -In this assignment, you will be using your knowledge of the C++ programming language to implement a simple blockchain. A blockchain is a digital ledger of transactions that is decentralized and secure. Each block in the chain contains a cryptographic hash of the previous block, along with the current transactions. - -# Requirements -Implement a basic blockchain data structure in C++. The blockchain should consist of blocks, each with a unique hash and a pointer to the previous block in the chain. -Each block should contain a list of transactions, represented as a linked list. -Implement a function to add a new block to the chain. This function should take a list of transactions as input, calculate the hash of the previous block, and add the new block to the chain. -Implement a function to validate the blockchain. This function should traverse the chain and verify that each block's hash matches the previous block's hash. -Test your blockchain implementation by adding some transactions and validating the chain. -Research and write a brief report on the security implications of using a blockchain for financial transactions. -Submission Guidelines -Fork this repository and create a new branch for your work. -Create a folder with your name and place all your files inside it. -Write all your code in C++ language. -Include a README.md file explaining how to compile and run your code. -Write a brief report on the security implications of using a blockchain for financial transactions and include it in your folder. -Submit a pull request to the master branch of the original repository. - -# Evaluation -Your assignment will be evaluated based on the following criteria: - -Correctness and completeness of the blockchain implementation -Clarity and readability of the code -Correctness and completeness of the validation function -Quality and completeness of the report on blockchain security - From 8b8882fac2a4aa14dfeb625143f689a4ce598d00 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 11:29:03 +0530 Subject: [PATCH 10/20] README.md --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index d9dcc7c..57e3d00 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ Blockchain Technology is a method of recording information under a decentralised Every transaction in a ledger is authorised by the digital signature of the owner which authenticates the transaction and safeguards from tampering. Hence, its highly secured. +Blockchain network connects all the peer-to-peer network via internet on a blockchain platform like Ethereum and Solana where we can create DApps. Each and every transactional details is visible on all other user's device except their profile. When the user commit a transaction, it attains finality and it can't be changed by anyone. Once if anyone tries to tamper the network or any transaction, it applies to their network alone and all other devices remains unchanged. + # Structure of Blockchain:- A Block consists of three major components: @@ -12,12 +14,21 @@ A Block consists of three major components: 2) Data section - contains the actual information such as transactions and smart contracts. 3) Hash - its a unique cryptographic value of the entire block for verification purposes. +The decentralised structure of a blockchain is a way to record transactions. Every block has a specific number of transactions within it, making it a node. Every transaction has a distinct hash value along with a digital signature, and each block is linked to the next block by the hash values of the previous block. Blocks are treated as linked lists in this instance. + # Process of Transaction:- When two people want to perform a transaction using their private and public keys, respectively, the first party would attach the transaction data to the second party's public key. The block includes a timestamp, a digital signature, and other crucial details. It should be emphasised that the block does not contain information on the parties to the transaction's identities. The block is then sent around the entire network, and when the correct user uses his private key to match it with the block, the transaction is successfully completed. The Blockchain is able to record financial transactions as well as prperties, cars, and so on which is known as smart contracts. +# Implementation of a simple Blockchain:- + +To begin with the code implementation, +1) We have created a blockchain class and created an object for that. +2) Create a vector to store transactions in a block using push_back() also we can add new blocks. +3) Struct Transaction stores information of the sender, receiver, amount, timestamp. + From ed4e69a3316394a41135adbe14f292d85a39c8c5 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 11:38:11 +0530 Subject: [PATCH 11/20] README.md --- README.md | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 57e3d00..07f8765 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Blockchain Technology is a method of recording information under a decentralised Every transaction in a ledger is authorised by the digital signature of the owner which authenticates the transaction and safeguards from tampering. Hence, its highly secured. -Blockchain network connects all the peer-to-peer network via internet on a blockchain platform like Ethereum and Solana where we can create DApps. Each and every transactional details is visible on all other user's device except their profile. When the user commit a transaction, it attains finality and it can't be changed by anyone. Once if anyone tries to tamper the network or any transaction, it applies to their network alone and all other devices remains unchanged. +Blockchain network connects all the peer-to-peer network via internet on a blockchain platform like Ethereum and Solana where we can create DApps. Each and every transactional details is visible on all other user's device except their profile. When the user commit a transaction, it attains finality and it can't be changed by anyone. Once if anyone tries to tamper the network or any transaction, it applies to their network alone and all other devices remains unchanged. This feature ensures the integrity of the data and prevents double spending, providing a high level of security and trust in Blockchain types and sustainability. # Structure of Blockchain:- @@ -24,10 +24,27 @@ The Blockchain is able to record financial transactions as well as prperties, ca # Implementation of a simple Blockchain:- -To begin with the code implementation, -1) We have created a blockchain class and created an object for that. -2) Create a vector to store transactions in a block using push_back() also we can add new blocks. -3) Struct Transaction stores information of the sender, receiver, amount, timestamp. +A simple Blockchain class is defined. + +1.Two essential structures are defined: Transaction and Block. +Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. +Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. + +2. Blockchain contains a private member variable chain, which is a vector of Block objects. The constructor initializes the chain with the genesis block (block with index 0 and empty transactions). + +4. The createGenesisBlock() method creates and returns the genesis block. + +5. The addBlock() method is used to add a new block to the blockchain. It takes a vector of transactions as input and creates a new block with the provided transactions, linking it to the last block in the chain. + +6. The validateChain() method iterates through the entire blockchain and checks if each block's hash matches the calculated hash and if the previous block's hash matches the stored previous hash. If any inconsistency is found, the method returns false, indicating that the blockchain is invalid. Otherwise, it returns true, indicating a valid blockchain. + +7. In the main() function, an instance of the Blockchain class named blockchain is created. + +8. Two blocks with different transactions are added to the blockchain using the addBlock() method. + +9. The validateChain() method is called to check the validity of the blockchain. + +10. The result of the validation is printed on the console. From 84e7af29a0230cb6fb910b7280487c257c652637 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 11:58:07 +0530 Subject: [PATCH 12/20] Code Implementation --- assignments/Code Implementation | 35 +++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/assignments/Code Implementation b/assignments/Code Implementation index a3090a5..30ebcf2 100644 --- a/assignments/Code Implementation +++ b/assignments/Code Implementation @@ -1,4 +1,4 @@ -#include + #include #include #include #include @@ -39,7 +39,6 @@ struct Block { stringstream ss; ss << hex << hashValue; - //cout << ss.str(); return ss.str(); } }; @@ -47,6 +46,7 @@ struct Block { class Blockchain { private: vector chain; + vector transact; public: Blockchain() { @@ -65,6 +65,23 @@ public: Block newBlock(newIndex, transactions, previousHash); chain.push_back(newBlock); } + + void displayChain() { + for (const auto& block : chain) { + cout << "Block #" << block.index << endl; + cout << "Timestamp: " << block.timestamp << endl; + cout << "Previous Hash: " << block.previousHash << endl; + cout << "Hash: " << block.hash << endl; + cout << endl; + } + for (const auto& trans : transact) { + cout << "Sender: " << trans.sender << endl; + cout << "Receiver: " << trans.receiver << endl; + cout << "Amount: " << trans.amount << endl; + cout << endl; + } + + } bool validateChain() { for (int i = 1; i < chain.size(); i++) { @@ -86,18 +103,28 @@ public: int main() { Blockchain blockchain; + //Block1 Transaction vector block1Transactions; block1Transactions.push_back(Transaction("Ram", "Sita", 1000)); - block1Transactions.push_back(Transaction("Riya", "Roni", 50000)); block1Transactions.push_back(Transaction("Naruto", "Hinata", 4500)); blockchain.addBlock(block1Transactions); + //Block2 Transaction vector block2Transactions; block2Transactions.push_back(Transaction("Aryan", "Karthik", 9500)); block2Transactions.push_back(Transaction("Alya", "Krish", 45000)); - block2Transactions.push_back(Transaction("Chintu", "Kichu", 300000)); blockchain.addBlock(block2Transactions); + + //Block3 Transaction + vector block3Transactions; + block3Transactions.push_back(Transaction("Krish", "Karthik", 19500)); + block3Transactions.push_back(Transaction("Ram", "Mrithi", 4000)); + blockchain.addBlock(block3Transactions); + + //Display Blocks + blockchain.displayChain(); + //Validation bool isValid = blockchain.validateChain(); cout << "Is blockchain valid? " << (isValid ? "Yes" : "No") << endl; From 5a4fc3ff864c3be529ac2026b139c8a3f0d6d7ae Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:37:17 +0530 Subject: [PATCH 13/20] Code Implementation --- assignments/Code Implementation | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/assignments/Code Implementation b/assignments/Code Implementation index 30ebcf2..18bc856 100644 --- a/assignments/Code Implementation +++ b/assignments/Code Implementation @@ -24,6 +24,7 @@ struct Block { vector transactions; string previousHash; string hash; + string Data, data; Block(int _index, vector _transactions, string _previousHash) : index(_index), transactions(_transactions), previousHash(_previousHash) { timestamp = time(nullptr); @@ -31,9 +32,12 @@ struct Block { } string calculateHash() { - string data = to_string(index) + to_string(timestamp) + previousHash; - for (const auto& transaction : transactions) + Data = ""; + data = to_string(index) + to_string(timestamp) + previousHash; + for (const auto& transaction : transactions) { + Data += "Sender: " + transaction.sender + "\nReceiver: " + transaction.receiver + "\nAmount: " + to_string(transaction.amount) + "\n\n"; data += transaction.sender + transaction.receiver + to_string(transaction.amount) + to_string(transaction.timestamp); + } size_t hashValue = std::hash{}(data); @@ -46,7 +50,6 @@ struct Block { class Blockchain { private: vector chain; - vector transact; public: Blockchain() { @@ -68,19 +71,15 @@ public: void displayChain() { for (const auto& block : chain) { + cout<<"-------------------------------------------------\n"; cout << "Block #" << block.index << endl; - cout << "Timestamp: " << block.timestamp << endl; + cout<<"-------------------------------------------------\n"; + cout << "Timestamp: " << block.timestamp << endl << endl; + cout << block.Data; cout << "Previous Hash: " << block.previousHash << endl; cout << "Hash: " << block.hash << endl; - cout << endl; - } - for (const auto& trans : transact) { - cout << "Sender: " << trans.sender << endl; - cout << "Receiver: " << trans.receiver << endl; - cout << "Amount: " << trans.amount << endl; - cout << endl; + cout << endl << endl; } - } bool validateChain() { @@ -126,6 +125,7 @@ int main() { blockchain.displayChain(); //Validation + cout<<"-------------------------------------------------\n"; bool isValid = blockchain.validateChain(); cout << "Is blockchain valid? " << (isValid ? "Yes" : "No") << endl; From f355db5efcf789f1dccca64a191500328ef70a5f Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:37:36 +0530 Subject: [PATCH 14/20] Code Implementation --- assignments/Code Implementation | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/Code Implementation b/assignments/Code Implementation index 18bc856..080384e 100644 --- a/assignments/Code Implementation +++ b/assignments/Code Implementation @@ -1,4 +1,4 @@ - #include +#include #include #include #include From 83633e57003fab70712fb9b18ae76b40b42833de Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:39:19 +0530 Subject: [PATCH 15/20] Code Implementation --- assignments/Code Implementation | 74 +++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/assignments/Code Implementation b/assignments/Code Implementation index 080384e..f08187f 100644 --- a/assignments/Code Implementation +++ b/assignments/Code Implementation @@ -131,3 +131,77 @@ int main() { return 0; } + + +/* + +OUTPUT: + +------------------------------------------------- +Block #0 +------------------------------------------------- +Timestamp: 1689491193 + +Previous Hash: 0 +Hash: 572d4f397483c4bd + + +------------------------------------------------- +Block #1 +------------------------------------------------- +Timestamp: 1689491193 + +Sender: Ram +Receiver: Sita +Amount: 1000.000000 + +Sender: Naruto +Receiver: Hinata +Amount: 4500.000000 + +Previous Hash: 572d4f397483c4bd +Hash: 659fae22fb1b4c98 + + +------------------------------------------------- +Block #2 +------------------------------------------------- +Timestamp: 1689491193 + +Sender: Aryan +Receiver: Karthik +Amount: 9500.000000 + +Sender: Alya +Receiver: Krish +Amount: 45000.000000 + +Previous Hash: 659fae22fb1b4c98 +Hash: e910d5c1c8669065 + + +------------------------------------------------- +Block #3 +------------------------------------------------- +Timestamp: 1689491193 + +Sender: Krish +Receiver: Karthik +Amount: 19500.000000 + +Sender: Ram +Receiver: Mrithi +Amount: 4000.000000 + +Sender: Ram +Receiver: Mrithi +Amount: 4000.000000 + +Previous Hash: e910d5c1c8669065 +Hash: 37bdce5c4b4b6a4c + + +------------------------------------------------- +Is blockchain valid? Yes + +*/ From 330a64cd3f67e9a79754e38b6c800ec05de185c4 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:48:43 +0530 Subject: [PATCH 16/20] README.md --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 07f8765..82b2076 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,16 @@ The Blockchain is able to record financial transactions as well as prperties, ca A simple Blockchain class is defined. -1.Two essential structures are defined: Transaction and Block. -Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. -Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. +- index: An integer to keep track of the block's position in the chain. +- data: A string representing the data to be stored in the block. +- timestamp: A string representing the time when the block is created. +- previous_hash: A string representing the hash of the previous block in the chain. +- hash: A string representing the hash of the current block. The hash is calculated based on the block's data and other properties. + +1. Two essential structures are defined: Transaction and Block. + + Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. + Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. 2. Blockchain contains a private member variable chain, which is a vector of Block objects. The constructor initializes the chain with the genesis block (block with index 0 and empty transactions). From b0898188df11e108e0f8178fabae2966f3450859 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:49:15 +0530 Subject: [PATCH 17/20] README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 82b2076..17ee660 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ A simple Blockchain class is defined. 1. Two essential structures are defined: Transaction and Block. Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. + Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. 2. Blockchain contains a private member variable chain, which is a vector of Block objects. The constructor initializes the chain with the genesis block (block with index 0 and empty transactions). From b4d63c278788e94d5458a87aea670ef8f68953d2 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:49:42 +0530 Subject: [PATCH 18/20] README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 17ee660..67c6caa 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ A simple Blockchain class is defined. 1. Two essential structures are defined: Transaction and Block. - Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. + Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. - Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. + Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. 2. Blockchain contains a private member variable chain, which is a vector of Block objects. The constructor initializes the chain with the genesis block (block with index 0 and empty transactions). From d093f2ce9d812ac3d4b2185320a509161ee1bb45 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:50:46 +0530 Subject: [PATCH 19/20] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67c6caa..ee41d1a 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ A simple Blockchain class is defined. 1. Two essential structures are defined: Transaction and Block. - Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. + Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. - Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. + Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. 2. Blockchain contains a private member variable chain, which is a vector of Block objects. The constructor initializes the chain with the genesis block (block with index 0 and empty transactions). From 9a71122fdad225c4daf2a1759fdb8cf5c7674ab7 Mon Sep 17 00:00:00 2001 From: MirudhulaaS <132981563+MirudhulaaS@users.noreply.github.com> Date: Sun, 16 Jul 2023 12:55:14 +0530 Subject: [PATCH 20/20] README.md --- README.md | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index ee41d1a..3730174 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,56 @@ # Brief Review -# Intro:- +## Intro:- Blockchain Technology is a method of recording information under a decentralised system which is impossible to change, manipulate or hacked. Blockchain is a distributed ledger that duplicates and distribute the transactional information to all the connected networks. It is a structure that stores all records of transaction in a single block which is connected to the next block of transaction in a chain manner which is termed as Blockchain. This storage is known as Digital Ledger. It is highly secured, distributed, immutable, decentralised and transparent. Every transaction in a ledger is authorised by the digital signature of the owner which authenticates the transaction and safeguards from tampering. Hence, its highly secured. Blockchain network connects all the peer-to-peer network via internet on a blockchain platform like Ethereum and Solana where we can create DApps. Each and every transactional details is visible on all other user's device except their profile. When the user commit a transaction, it attains finality and it can't be changed by anyone. Once if anyone tries to tamper the network or any transaction, it applies to their network alone and all other devices remains unchanged. This feature ensures the integrity of the data and prevents double spending, providing a high level of security and trust in Blockchain types and sustainability. -# Structure of Blockchain:- +## Structure of Blockchain:- -A Block consists of three major components: -1) Header - contains metadata such as timpestamp and previous block's hash. -2) Data section - contains the actual information such as transactions and smart contracts. -3) Hash - its a unique cryptographic value of the entire block for verification purposes. +### A Block consists of three major components: +1) **Header** - contains metadata such as timpestamp and previous block's hash. +2) **Data section** - contains the actual information such as transactions and smart contracts. +3) **Hash** - its a unique cryptographic value of the entire block for verification purposes. The decentralised structure of a blockchain is a way to record transactions. Every block has a specific number of transactions within it, making it a node. Every transaction has a distinct hash value along with a digital signature, and each block is linked to the next block by the hash values of the previous block. Blocks are treated as linked lists in this instance. -# Process of Transaction:- +## Process of Transaction:- When two people want to perform a transaction using their private and public keys, respectively, the first party would attach the transaction data to the second party's public key. The block includes a timestamp, a digital signature, and other crucial details. It should be emphasised that the block does not contain information on the parties to the transaction's identities. The block is then sent around the entire network, and when the correct user uses his private key to match it with the block, the transaction is successfully completed. The Blockchain is able to record financial transactions as well as prperties, cars, and so on which is known as smart contracts. -# Implementation of a simple Blockchain:- +## Implementation of a simple Blockchain:- -A simple Blockchain class is defined. +### A simple Blockchain class is defined. -- index: An integer to keep track of the block's position in the chain. -- data: A string representing the data to be stored in the block. -- timestamp: A string representing the time when the block is created. -- previous_hash: A string representing the hash of the previous block in the chain. -- hash: A string representing the hash of the current block. The hash is calculated based on the block's data and other properties. +- **index:** An integer to keep track of the block's position in the chain. +- **data:** A string representing the data to be stored in the block. +- **timestamp:** A string representing the time when the block is created. +- **previous_hash:** A string representing the hash of the previous block in the chain. +- **hash:** A string representing the hash of the current block. The hash is calculated based on the block's data and other properties. 1. Two essential structures are defined: Transaction and Block. - Transaction: Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. + **Transaction:** Represents a single transaction in the blockchain, with attributes for the sender, receiver, amount, and timestamp when the transaction occurred. - Block: Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. + **Block:** Represents a block in the blockchain, containing an index, timestamp, a vector of Transaction objects, a previous block's hash, and its own hash. 2. Blockchain contains a private member variable chain, which is a vector of Block objects. The constructor initializes the chain with the genesis block (block with index 0 and empty transactions). -4. The createGenesisBlock() method creates and returns the genesis block. +4. The ***createGenesisBlock()*** method creates and returns the genesis block. -5. The addBlock() method is used to add a new block to the blockchain. It takes a vector of transactions as input and creates a new block with the provided transactions, linking it to the last block in the chain. +5. The ***addBlock()*** method is used to add a new block to the blockchain. It takes a vector of transactions as input and creates a new block with the provided transactions, linking it to the last block in the chain. -6. The validateChain() method iterates through the entire blockchain and checks if each block's hash matches the calculated hash and if the previous block's hash matches the stored previous hash. If any inconsistency is found, the method returns false, indicating that the blockchain is invalid. Otherwise, it returns true, indicating a valid blockchain. +6. The ***validateChain()*** method iterates through the entire blockchain and checks if each block's hash matches the calculated hash and if the previous block's hash matches the stored previous hash. If any inconsistency is found, the method returns false, indicating that the blockchain is invalid. Otherwise, it returns true, indicating a valid blockchain. -7. In the main() function, an instance of the Blockchain class named blockchain is created. +7. In the ***main()*** function, an instance of the Blockchain class named blockchain is created. -8. Two blocks with different transactions are added to the blockchain using the addBlock() method. +8. Two blocks with different transactions are added to the blockchain using the ***addBlock()*** method. -9. The validateChain() method is called to check the validity of the blockchain. +9. The ***validateChain()*** method is called to check the validity of the blockchain. 10. The result of the validation is printed on the console.