Pages

Saturday, April 14, 2018

Understanding BlockChain through C++ Code


Bitcoin became famous in 2017 when herds of people bought it and multiple exchanges were started across India to trade in Bitcoin however it has been losing steam since last few months. RBI in it first policy for FY19 has banned Bitcoins which has stranded many Indian Investors however most of them are tech savvy and will find out a way to get their money back.

In Today's article, we will discuss the underlying technology which has vast applications. Block Chain technology works on distributed ledger and Proof-of-Work which makes it difficult to centralize the system epsecially in the case of Bitcoin by increasing the computational cost.

Bitcoin Block Generation

As per BlockChain technology, the information (transanctions) are stored in the block and are then encrypted(hashed) & stored as Merkel tree which can be again used to verify the authentiivty of the data.

All the pending transactions to be created in the block are advertized on the network which various miners* across the netwrok picks up and start solving PoW.

The difficulty for PoW is set in such a way that only one block can be createad in 10 mins. Once the block is created, then winner is announced and new block is published on the network. Miners will then start working on the pending transanctions and any new trsansaction released in the last 10 mins.

Implementation in Other Areas

BlockChain technology used for Bitcoin uses high level of dificulty to slow the process however the difficulty can be reduced depending upon the criticality of the data and the speed at which transactions are done.

We should see this more as a decentralized ledger where information can be published across the netwrok and can be decrypted by the recipient as required. One quick application is money transfer across countries where the money can be quickly transfered than otherwise conducted trsansation using Banks/FX Platforms.

By keepng the infomraton visible to entire network, it reduces the risk of data getting corrupted as well.


Linked List example - 

Below is the C++ code for linked list which implements the linked list, we can add the encryption function is make it more suitable to store any confidential data

#include<iostream>
#include<string>
struct node{
  
  int count;
  std::string t_text;
  node *prev;
  node *next;
   
};


using namespace std;

int main() {

node *first = new node;
//node *Prev = new node;
int i = 1;

first->t_text = "first node";
//cout << first->t_text;
first->count = i++;
first->prev = NULL;
first->next = NULL;
//Prev = first;



while (i <10) {

node *temp = new node;

temp->t_text = "Added text";
temp->count = i++;
temp->next = NULL;
temp->prev = first;

first->next = temp;
first = temp;

//cout << first->t_text;
}


do 
{
cout << first->count <<endl;
first = first->prev;
i--;
} while (first-> prev != NULL)


return 0;
}