區(qū)塊鏈hello world 思路:
根據(jù)學(xué)習(xí)筆記一知道绘雁,一個區(qū)塊鏈需要包含如下信息
1:交易數(shù)據(jù)
2:區(qū)塊信息(hash值 工作量等)
基礎(chǔ)方法:
交易功能 functon(從A,給B位隶,100元)
addTransactions(A,B,100)
"message": [
"這筆交易會被增加到區(qū)塊4"
]
}
以上數(shù)據(jù)是在我請求接口時候截取贡未,之所以放在第4個塊熊榛,是因為我寫筆記的時候已經(jīng)挖到了4個塊锚国,前3個塊已經(jīng)打包。
挖出新塊functon(最近的交易打包成區(qū)塊后玄坦,新增一個區(qū)塊)
做了以下三件事
計算工作量證明PoW
通過新增一個交易授予礦工(自己)一個幣
構(gòu)造新區(qū)塊并將其添加到鏈中
addNewBlock(新交易數(shù)據(jù)血筑,上一個區(qū)塊hash值)
{
"index": 5,
"proof": 146502,
"message": "New Block Forged",
"transactions": [
{
"amount": 1,
"sender": "0",
"recipient": "a9b92e8a11d447639a1f1cdb1954fc48"
}
],
"previous_hash": "40d003f3f756200731c4d2109be15fa718056d95bf57fe0ccaa18f8195a6e841"
}
查詢當前區(qū)塊所有信息functon(當前所有區(qū)塊绘沉,所有的交易)
{
"chain": [
{
"index": 1,
"proof": 100,
"transactions": [],
"timestamp": 1523528930232,
"previous_hash": "0"
},
{
"index": 2,
"proof": 35293,
"transactions": [
{
"amount": 126,
"sender": "程小凡",
"recipient": "張小"
},
{
"amount": 1,
"sender": "0",
"recipient": "a9b92e8a11d447639a1f1cdb1954fc48"
}
],
"timestamp": 1523528945659,
"previous_hash": "77f2390ba87ce4f8427a7f3f2427cc463e9d0a9086e104ea2f99ed2070c08656"
},
{
"index": 3,
"proof": 35089,
"transactions": [
{
"amount": 1260,
"sender": "程二凡",
"recipient": "張小二"
},
{
"amount": 1,
"sender": "0",
"recipient": "a9b92e8a11d447639a1f1cdb1954fc48"
}
],
"timestamp": 1523528972115,
"previous_hash": "4c1799601a670d28a1ce508c3c89de94c4f87ad59f5d89b73a1288d9f234b17e"
},
{
"index": 4,
"proof": 119678,
"transactions": [
{
"amount": 1260,
"sender": "李浩",
"recipient": "金正"
},
{
"amount": 1260,
"sender": "李浩",
"recipient": "金正"
},
{
"amount": 1260,
"sender": "李浩",
"recipient": "金正"
},
{
"amount": 1260,
"sender": "李浩",
"recipient": "金正"
},
{
"amount": 1,
"sender": "0",
"recipient": "a9b92e8a11d447639a1f1cdb1954fc48"
}
],
"timestamp": 1523529024979,
"previous_hash": "9e4c840d8f01fa8decea1eac4fcbb8e15357fb7ddea7bd64d8a99c222ef6f147"
},
{
"index": 5,
"proof": 146502,
"transactions": [
{
"amount": 1,
"sender": "0",
"recipient": "a9b92e8a11d447639a1f1cdb1954fc48"
}
],
"timestamp": 1523585237009,
"previous_hash": "40d003f3f756200731c4d2109be15fa718056d95bf57fe0ccaa18f8195a6e841"
}
],
"length": 5
}
區(qū)塊的結(jié)構(gòu)
首先需要說明一下區(qū)塊的結(jié)構(gòu),每個區(qū)塊包含屬性:索引(index)豺总,時間戳(timestamp)车伞,交易列表(transactions),工作量證明喻喳,以及前一個區(qū)塊的Hash值另玖。
創(chuàng)世區(qū)塊是沒有前一個區(qū)塊的,類比Java的 List
區(qū)塊的結(jié)構(gòu)基礎(chǔ)信息:
block = {
'index': 1,
'timestamp': 1506057125.900785,
'transactions': [
{
'sender': "發(fā)送者的銀行卡號",
'recipient': "接受者的銀行卡號",
'amount': 5,
} 沸枯,{
"amount": 1260,
"sender": "李浩",
"recipient": "金正"
},
{
"amount": 1260,
"sender": "李浩",
"recipient": "金正"
}
],
'proof': 愿意給的轉(zhuǎn)賬手續(xù)費日矫,可以自定義,
'previous_hash': "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
}
學(xué)習(xí)筆記只在學(xué)習(xí)區(qū)塊鏈,了解區(qū)塊鏈绑榴,屬于helloworld程序哪轿,
和真實的場景,類比接口翔怎,復(fù)雜度等都不一樣窃诉,僅在學(xué)習(xí)其原理,術(shù)語
甚至因為我自己可能有誤解~赤套,僅在為測試區(qū)塊鏈做一些準備飘痛。
新手入門資料:
3cshool
http://www.runoob.com/w3cnote/blockchain-intro.html
高手進階 以太坊
http://xc.hubwiz.com/course/5a952991adb3847553d205d1?affid=51cto