分享
golang[45]-区块链-挖矿困难度
jonson_jackson · · 1530 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
##比特币挖矿困难度
比特币的挖矿困难度 = 目标hash / 创世hash
比特币挖矿的计算
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
*计算挖矿difficulty
*/
func CalculateDifficulty(strTargetHash string) string {
strGeniusBlockHash := "00000000ffff0000000000000000000000000000000000000000000000000000" // 创世块编号
var biGeniusHash big.Int
var biTargetHash big.Int
biGeniusHash.SetString(strGeniusBlockHash, 16)
biTargetHash.SetString(strTargetHash, 16)
difficulty := big.NewInt(0)
difficulty.Div(&biGeniusHash, &biTargetHash)
//fmt.Printf("%T \n" , difficulty)
return fmt.Sprintf("%s", difficulty)
}
本文链接: https://dreamerjonson.com/2018/12/12/golang-45-blockchain-difficulty/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议 许可协议。转载请注明出处!
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信1530 次点击
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
##比特币挖矿困难度
比特币的挖矿困难度 = 目标hash / 创世hash
比特币挖矿的计算
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
*计算挖矿difficulty
*/
func CalculateDifficulty(strTargetHash string) string {
strGeniusBlockHash := "00000000ffff0000000000000000000000000000000000000000000000000000" // 创世块编号
var biGeniusHash big.Int
var biTargetHash big.Int
biGeniusHash.SetString(strGeniusBlockHash, 16)
biTargetHash.SetString(strTargetHash, 16)
difficulty := big.NewInt(0)
difficulty.Div(&biGeniusHash, &biTargetHash)
//fmt.Printf("%T \n" , difficulty)
return fmt.Sprintf("%s", difficulty)
}
本文链接: https://dreamerjonson.com/2018/12/12/golang-45-blockchain-difficulty/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议 许可协议。转载请注明出处!