Question

implement the block chain coding based on the following video. Submit the code, and a separate...

implement the block chain coding based on the following video. Submit the code, and a separate explanation how the code works.

https://youtu.be/zVqczFZr124

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Block{

//Structure of the block what information a block should coantain

constructor(index,timestamp,data,previousHash=' ')

this.index=index;;

this.timestamp=timestamp;

this.data=data;

this.previousHash=previousHash;

this.hash=this.calculate();

calculateHash(){

return SHA256( this.index+this.timestamp+this.previousHash+JSON.stringfy(this.data)).toString();

}

class Blockchain{

constructor(){

this.chain=[this.createGenesisBlock()];

}

// the first block in block chain is called genesis block

createGenesisBlock(){

new Block(0,"16/11/2018","Genesis Block","0");

}

getLatestBlock{

return this.chain[this.chain.lenght-1];

}

addBlock{

newBlock.previousHash=this.getLatestBlock().hash;

newBlock.hash=newBlock.calculateHash();

this.chain.push(newBlock);

}

//Checking if the chain in valid or not (previous hash value in current block ) should be equal to (hash value in previous // // // block) . If not then that block is referring to some other block chain.

isChainValid(){

for(i=1;i<this.chain.length; i++)

const currentBlock = this.chain[i];

const previousBlock = this.chain[i-1];

if(currentBlock.hash != currentBlock.calculatehash()){

return false;

}

if(currentBlock.previousHash != previousBlock.hash()){

return false;

}

return true;

}

let coin=new Blockchain();

coin.addBlock(new Block(1, "17/11/2017", {amount:4} ));

coin.addBlock(new Block(1, "18/11/2017", {amount: 5 } ));

console.log(JSON.stringify(coin, null , 4));

Notes:

Run the above script as node chain.js

See, Every block in block chain has a hash function and hash function for the previous block . So a newly created block is attached to the previous block and thus chain keeps on growing.

First Block has no previous block so : That is called genesis block

Also if a new block is created you cannot delete that block.

Add a comment
Know the answer?
Add Answer to:
implement the block chain coding based on the following video. Submit the code, and a separate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q2 : Assume we are having a linear block coding, use Hamming code to do the...

    Q2 : Assume we are having a linear block coding, use Hamming code to do the following A. Encode the dataword 10011010 ? B. Examine the codeword 10100110001000 to see if it is correct or not? If you think is incorrect, then show the position of the bit causing the error and correct as appropriate?

  • a, b, and c find a means to watch the following YouTube video sound is not...

    a, b, and c find a means to watch the following YouTube video sound is not necessary: https://youtu.be/ICp6tkyThe The video demonstrates the behavior of three liquids: water, glycerin, and alcohol Answer the following questions about the video Batween the time of 0:20 - 2820 of the video, write down your observations about the relative ih of the surface tension of these three liquids. Based on this evidence alone, rank these three strength of the e from strongest to weakest in...

  • 1. Channel Coding We would like to add linear block code (3,6) using the generator matrix:...

    1. Channel Coding We would like to add linear block code (3,6) using the generator matrix: 1 001 01 G-0 1 0 0 1 1 (a) (5 points) Determine the parity check matrix H (b) (20 points) What is the minimum distance of this code? How many error can this code correct? (c) (5 points) What is the code word for the data sequence 011000101111? (d) (20 points) If you receive the codeword 010001000010101010, what is the transmitted sequence?

  • 7. View the first seven minutes of the following video: “Part 1: Genes that Control Aging”...

    7. View the first seven minutes of the following video: “Part 1: Genes that Control Aging” by Dr. Cynthia Kenyon (iBioSeminars). If you would like to learn more about Dr. Kenyon’s research, please feel free to view the entire video! Note: You may copy and paste the link for the video directly into the address bar of your browser: https://youtu.be/DT4PWu43e9U Then answer the following questions. What critical observations did Dr. Kenyon’s initial hypothesis explain? What was Dr. Kenyon’s initial hypothesis?...

  • VIVA QUESTIONS: 1. Implement the following function using VHDL coding. (Try to minimize if you can)....

    VIVA QUESTIONS: 1. Implement the following function using VHDL coding. (Try to minimize if you can). F(A,B,C,D)=(A'+B+C). (A+B'+D'). (B+C'+D') . (A+B+C+D) 2. What will be the no. of rows in the truth table of N variables? 3. What are the advantages of VHDL? 4. Design Ex-OR gate using behavioral model? 5. Implement the following function using VHDL code f=AB+CD. 6. What are the differences between half adder and full adder? 7. What are the advantages of minimizing the logical expressions?...

  • Write code in python for following Use queue to implement it Implement a decryption method String...

    Write code in python for following Use queue to implement it Implement a decryption method String decrpt(String s) to decrypt a number sequence (stored in a string s). The decryption algorithm works as follows: Delete the first element of the sequence Move the first element of the sequence to the end Delete the first element of the sequence Move the first element of the sequence to the end …. This process keeps running until all element in the sequence has...

  • Write code to implement the following function: /* * Generate mask indicating leftmost 1 in x....

    Write code to implement the following function: /* * Generate mask indicating leftmost 1 in x. Assume w=32. * For example 0xFF00 -> 0x8000, and 0x6600 --> 0x4000. * If x = 0,then return 0. */ int leftmost_one(unsigned x); Your function should follow the above bit-level integer coding rules, except that you may assume that data type int has w=32 bits. Your code should contain a total of at most 15 arithmetic, bit-wise, and logical operations. In C++ and has...

  • For the following activity, you will submit your entire program to the code runner, from your...

    For the following activity, you will submit your entire program to the code runner, from your first import statement to your last curly bracket. Please download the Lesson 35 Activity template (Links to an external site.) and use it to write your code. Additionally, you can download the Lesson 35 Coding Activity (PDF) (Links to an external site.) to print or use as an offline reference. If you need a refresher on how to use this Code Runner, watch the...

  • Implement the array-based stack class. Use it in the client code to convert and compute post-fix...

    Implement the array-based stack class. Use it in the client code to convert and compute post-fix expressions. The postfix expressions are saved in a file named "postfix.txt", one expression each line. For simplicity, you may assume all numbers in the expressions are single digit numbers. Submit: 1. Source code: the stack class and the client code; 2. Output screen capture: show the results for the following expressions (The errors in some expressions are intentional. Your code must detect it and...

  • Review the following lecture: Coding for Medical Necessity Introduction: In order to properly code a bill for medic...

    Review the following lecture: Coding for Medical Necessity Introduction: In order to properly code a bill for medical necessity, it is important to understand the electronic medical record. This record contains information about the patient's health both before and after the treatment and has the data needed to assure a payer that the treatment was necessary. Tasks: Explain the contents of the medical record. Describe SOAP notes-subjective, objective, assessment, and plan. Explain operative reports function in medical necessity coding. Explain...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT