官术网_书友最值得收藏!

 Hashing the data

The next method that we are going to look at and add into our blockchain data structure is called hashBlock. What this hashBlock method will do is take in a block from our blockchain and hash its data into a fixed length string. This hashed data will appear randomly.

In essence, what we're going to do is pass some blocks of data into this hash method, and in return we'll get a fixed-length string, which will simply be a hash data that is generated from the data that we passed in or from the block that we passed.  

To add the hashBlock method to our blockchain data structure, type the following line of code after our createNewTransaction method: 

Blockchain.prototype.hashBlock = function(blockdata) {

}

In our hashBlock method, blockdata will be the input data of our block from which we want to generate the hash.  

So, how can we take a block or blocks of data and get a hashed string in return? For generating hash data, we're going to use a hashing function called SHA256

主站蜘蛛池模板: 阿拉尔市| 西藏| 湟中县| 平顶山市| 辰溪县| 宾川县| 特克斯县| 临潭县| 乌审旗| 菏泽市| 甘肃省| 翼城县| 丁青县| 蓬安县| 乐清市| 界首市| 灵山县| 长垣县| 迁西县| 金乡县| 临夏市| 扎鲁特旗| 贵阳市| 麻阳| 清水河县| 沙雅县| 屯门区| 莱芜市| 比如县| 林州市| 开鲁县| 榕江县| 宝鸡市| 沙坪坝区| 潢川县| 十堰市| 怀化市| 桃源县| 磐石市| 汪清县| 大连市|