Creating Blockchain with Python #5 - Validating Proof
Creating Blockchain with Python #5
Validating Proof
in this tutorial we will learn how to validate the proof, so we can add a new transaction in the blockchain.
we will use two functions to do validation: valid_proof() function and pow() function.
steps:
1. watch previous video
Creating Blockchain with Python #1 - Create a Chain with List
https://youtu.be/3QRwQ4VLdvw
Creating Blockchain with Python #2 - Adding New Transaction
https://youtu.be/cwPaN2N6nYo
Creating Blockchain with Python #3 - Genesis Block
https://youtu.be/IbnO2QLouY8
Creating Blockchain with Python #4 - Hash Function
https://youtu.be/78M86NFy-2s
2. download the code here
https://github.com/cryptocodecg/blockchain-cg/blob/master/blockchain-5.py
3. let’s take a look at the code
4. run the code
valid_proof() function has three arguments:
* Transactions: the transactions inside the block
* Last hash: the hash of the last block
* Nonce
pow() function:
* extracting the last block from the blockchain and putting it into last_block
* hashing the last_block and putting them into the last_hash
* while loops keeps running until the valid_proof function returns TRUE. (The not convert will convert the TRUE into FALSE and hence break out of the loop)
* The nonce is then returned
we are specifically looking for a hash which started with “00”. This is why, the computer ran through multiple hashes by changing the nonce until it finally stumbled upon a hash which fulfilled the given difficulty criteria.
now let’s test the code
look that we only have the genesis block
and LOTS of hashing trials until we get what we are looking for
001f946e8c2172affa830ef27761270aab2de515ffac8ae90e5de95b48dc366c (the hash with 00 in the beginning)
and the nonce we get is 93 (also means that the code tries 93 times to finally get the expected hash)
we can use different way to validate proof, for example adding difficulties by searching or hash with ‘00000’ in the beginning :) the point is that once the hash is found, then it is valid to add a new block :)
ok this is it for now, until the next tutorial, we will learning about mining ;)
please click subscribe and like and share and don’t forget to leave some comments ;)
thanks for watching :)
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Creating Blockchain with Python #5 - Validating Proof», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.