golang[45]-区块链-挖矿困难度

##比特币挖矿困难度

比特币的挖矿困难度 = 目标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)
}

猜你喜欢

转载自blog.51cto.com/13784902/2330174