主页 > imtoken苹果下载官网 > 首页 > 下载imtoken > 了解比特币原理的程序

首页 > 下载imtoken > 了解比特币原理的程序

imtoken苹果下载官网 2023-08-18 05:12:02

自比特币走红以来,网络上对比特币的解读可以说是纷繁复杂。 但是对于程序员来说,比特币的原理是什么,最直接的方法就是直接看程序代码。 比特币代码再复杂也没关系,我找到了简洁的代码,也能更好地理解比特币。

比特币到底是什么原理

以下节目改编自吴昊在知乎上的回答。

比特币到底是什么原理

  1. function mine()  
  2. {  
  3.     while(true)  
  4.     {  
  5.         longestChain = getLongestValidChain()  
  6.  
  7.         -- A number that changes every time, so that you don't waste   
  8.         -- time trying to calculate a valid blockHash with the same  
  9.         -- input.  
  10.         nonce = getNewNonce()  
  11.  
  12.         currentTXs = getUnconfirmedTransactionsFromNetwork()  
  13.  
  14.         newBlock = getNewBlock(longestChain, currentTXs, nonce)  
  15.  
  16.         -- http://en.wikipedia.org/wiki/SHA-2  
  17.         -- and this is what all the "mining machines" are doing.  
  18.         blockHash = sha256(newBlock)  
  19.  
  20.         if (meetReqirements(blockHash))  
  21.         {  
  22.             broadcast(newBlock)  
  23.             -- Now the height the block chain is incremented by 1 
  24.             -- (if the new block is accepted by other peers),  
  25.             -- and all the TXs in the new block are "confirmed" 
  26.         }  
  27.     }  
  28. }  
  29. ////////////////////////////////////////////////////////////////  
  30. function sendBTC(amount)  
  31. {  
  32.     sourceTXs = pickConfirmedTransactionsToBeSpent(amount)  
  33.     tx = generateTX(sourceTXs, targetAddrs, amount, fee)  
  34.     signedTx = sign(tx, privateKeysOfAllInputAddress)  
  35.     broadcast(signedTx)  
  36. }  
  37. //////////////////////////////////////////////////////////////// 

比特币到底是什么原理

这是我的解释:

比特币到底是什么原理

挖矿过程是不断从比特币网络中获取所有未确认的交易getUnconfirmedTransactionsFromNetwork(),打包成一个区块挂载到最长的区块链getNewBlock(longestChain, currentTXs, nonce),然后计算哈希值sha256(newBlock)比特币 原理,如果哈希值刚好满足挖矿难度meetReqirements(blockHash),则挖矿成功。 所谓挖矿难度是指所需二进制哈希值末尾零的个数比特币 原理,是偶然产生的。 别无他法,只能让自己精疲力竭地研究比特币到底是什么。 需要的零越多,挖矿就越难。 大。

比特币到底是什么原理

支付过程是取出一些已确认的交易余额作为发送地址pickConfirmedTransactionsToBeSpent(amount),然后根据目标地址支付一定的交易手续费生成新的交易generateTX(sourceTXs, targetAddrs, amount, fee ),并使用钱包私传密钥对交易签名sign(tx, privateKeysOfAllInputAddress),然后广播。

原文链接: