iepngs
2019-12-17 17:49
// run performs a proof-of-work func (pow *ProofOfWork) Run() (int, []byte) { var hashInt big.Int var hash [32]byte nonce := 0 fmt.Printf("mining the block containing \"%s\"\n", pow.block.Data) for nonce < maxNonce { data := pow.prepareData(nonce) hash = sha256.Sum256(data) fmt.Printf("\r%x", hash) hashInt.SetBytes(hash[:]) if hashInt.Cmp(pow.target) == -1 { break } else { nonce++ } } fmt.Print("\n\n") return nonce, hash[:] }
这里的run方法,for循环里面的fmt.Printf的输出为什么是覆盖滚动显示的而不是逐句输出全部显示?
fmt.Printf("\r%x", hash)
\r 代表回车,每行打印完后,下一次光标会移至改行的行首,重新覆盖打印;\n 是换行,这里换成\n就是全部显示
私有区块链,我们一起GO
24081 学习 · 48 问题
相似问题