比特币使用的是区块链技术,所以它的所有产生的区块(一个区块里面包含很多条交易)都是透明可查的,可进这个网站:https://btc.com/stats/pool/BTC.com 进行查询。
Bitcoin uses block chain technology, so all the blocks it produces (a block contains many transactions) are transparent and can be consulted on the website: .
binfun选取BTC历史区块里面的一条transaction:
https://btc.com/0627052b6f28912f2703066a912ea577f2ce4da4caa5a5fbd8a57286c345c2f2
Binfun selects one in the BTC historical block:
该条transaction的编号为:0627052b6f28912f2703066a912ea577f2ce4da4caa5a5fbd8a57286c345c2f2
This provision is numbered 0627052b6f28912f2703066a 912ea577f2ce4da4caa5a5fbd8a57286c345c2f2
该交易的内容如截图:
The contents of the transaction are transcribed:
从上图我们可以看到“输入”中的账户1Cdid9KFAaatwczBwBttQcwXYCpvK8h7FK把0.1个BTC分别转给了“输出”中的账户1GdK9UzpHBzqzX2A9JFP3Di4weBwqgmoQA(该账户收到了0.01500000个BTC)
和1Cdid9KFAaatwczBwBttQcwXYCpvK8h7FK(该账户也就是原账户发送给了自己0.08450000个BTC)。
From the above figure we can see the account in the "Input" transferred 0.1 BTC accounts in the "output" ) 所以这交易就是账户1Cdid9KFAaatwczBwBttQcwXYCpvK8h7FK转了0.015个BTC给1GdK9UzpHBzqzX2A9JFP3Di4weBwqgmoQA。 So the transaction is the account 1Cdid9KFAaatwczBwBtbtQcwXYCpvK8FK transferred 0.015 BTCs to . 但是输出中的0.0845 + 0.015=0.0995,并不等于0.1啊,这是因为去掉的0.0005就是矿工费。 However, 0.0845 + 0.015 = 0.0995 in the output is not equal to 0.1 because the 0.0005 removed is the miner's fee. 上面的那张图片实际上把这条交易可视化了,这条交易的真实样子是长这样的: The picture above actually visualizes this transaction. The true face of the deal is as follows: 是不是一脸懵逼,懵逼就对了。这条交易主要由vin和vout两大块组成。看不懂我们就从似曾相识的数字看起:vout里面有个"value": 0.01500000和"value": 0.08450000,这两个数字我懂,这就是转账数字啊。 The deal is made up of two major pieces: 就是刚才的比特币地址1Cdid9KFAaatwczBwBttQcwXYCpvK8h7FK发送给另一个比特币地址1GdK9UzpHBzqzX2A9JFP3Di4weBwqgmoQA的钱嘛。 The money just sent from Bitcoin address 1Cdid9KFAatwczBwBttQcwxYCpvK8h7FK to another Bitcoin address 1GdK9UzpHBzqzX2A9JFP3Di4weBwqgmoQA. 听说比特币地址是由Base58编码的,Base58编码是啥咱也不知道,咱也不敢问,反正估计和Base64大差不差。 I heard that the Bitcoin address was coded by Base58, and we don't know what the Base58 code is, and we're afraid to ask, it's not so different from Base64 anyway. 于是binfun毫不知情地从https://github.com/grondilu/bitcoin-bash-tools上下载了一个脚本bitcoin.sh,一顿猛操作对地址进行Base58解码: As a result, binfun downloaded a script bitcoin.sh from https://github.com/grondulu/bitcoin-bash-tools without knowing it: 得到了: Got it: 这串16进制数有点眼熟啊,这不就和上面看到的 It's kind of familiar, isn't it? 的 It's... it's... it's... it's... it's... it's... it's... it's... it's... it's... it's... it's... it's... it's... it's... 非常接近了,就是多出了头上的"00"和尾巴上的"01974ac6" It's very close. It's "00" and "01974ac6" on the tail. 其中头上的"00"代表了主网版本号,而"01974ac6"代表了校验和,这个校验和可以由以下python命令生成: The "00" on its head represents the main web version number, while "01974ac6" represents the checksum, which can be generated by the python command as follows: 可以看到该校验和由连续两次的sha256后的结果,取该结果的前四个字节,也就是01974ac6 You can see the check and the results of two consecutive shaw256s, the first four bytes of which are 01974 ac6. 以上过程就是类似比特币地址和比特币公钥的转换过程。 The process described above is a process of conversion similar to the Bitcoin address and the Bitcoin public key. 为了便于理解,我们可以认为在vout中,以上所述的两个比特币地址中分别获得了0.015和0.0845个BTC。 For ease of understanding, we can assume that in vout, 0.015 and 0.0845 BTCs were obtained in the two bitcoins referred to above. 换句话说vout就是把比特币“锁定”在上述两个比特币地址中,上面出现的scriptPubKey就是所谓的“锁定脚本”。 In other words, vout “locks” Bitcoin in the above two bitcoin addresses where the appearance of ScriptPubKey is the so-called “lock script”. 那么vin是干啥的,就是解锁呀,让我们再看一眼vin: So what's a strong vin / strong? Unlock it. Let's take another look at strong vin / strong : 以上的txid是transaction id的缩写,我们当前的txid是0627052b6f28912f2703066a912ea577f2ce4da4caa5a5fbd8a57286c345c2f2 The above txid is the acronym of the transposition id, and our current txid is 0627052b6f28912f273066a912ea577fce4da4caa5a5fbd8a57286c345c2f2 但是vin中却引用了 But it's quoted in vin /strang > (下图中用txid7957a35f简写) (Txid7957a35f in the figure below) 这显得有点绕,具体意思如下图所示: This appears to be somewhat intriguing, in the following figure: 所以scriptSig就是“解锁脚本”的意思,其中内容就是用户A使用他的私钥进行了一项签名,证明我是地址A的私钥拥有者,我有权对锁定到地址A内的余额进行使用。 So the scriptSig is the meaning of a “lacing script”, in which user A makes a signature using his private key to prove that I am the owner of the private key at address A and that I have the right to use the balance locked in address A. 那么问题又来了,用户A的钱又是哪里来的???实际上不断追溯源头的话,最终大家的比特币都来自于一种叫做币基交易(coinbase)的特殊交易,币基交易是没有vin的,币基交易是由挖到矿的矿工生成的,所以挖矿挖到的都是“新币”,平时用户转账的币追溯到最上面的话,都是矿工挖出来的。 So the question arises again, where does user A's money come from? In fact, in the end, everyone's bitcoin comes from a special transaction called coinbase, which does not have vin, which is made by miners who dig up the mines, so the digs are all “new coins” and the coins transferred by the users usually go back to the top. 现在我们知道,有用来解锁资金的解锁脚本,以及锁定资金的锁定脚本,解锁脚本是在"vin"中,锁定脚本是在"vout"中。 Now we know that there are unlocked scripts for unlocking funds, and locked scripts for locking funds in vin, and locked scripts in vout. 那么这些脚本长什么样呢?比特币交易脚本语言是一种逆波兰表达式的基于堆栈的执行语言。 So what do these scripts look like? Bitcoin-trading script language is a stack-based enforcement language that is anti-Polish expression. 在介绍解锁、锁定脚本之前,先介绍一下比特币的私钥、公钥、比特币地址之间的关系。 Before introducing unlocking and locking scripts, describe the relationship between Bitcoin's private key, public key, and Bitcoin address. 关于比特币公钥私钥的特性,只需要知道这两点: With regard to the characteristics of the Bitcoin private key, just two things are needed: 私钥经过椭圆算法之后生成公钥,公钥经过哈希算法之后生成比特币地址(也就是公钥哈希)。这个过程是不可逆的,也就是说通过公钥不能倒推出私钥,但是私钥却可以生成公钥。 The private key is generated by an elliptical algorithm, and the public key by a Hashi algorithm generates a bitcoin address (i.e. a public key by a public key). This process is irreversible, that is, a private key cannot be rolled out backwards through a public key, but a private key can generate a public key. 一段文本经过私钥加密之后只能由公钥进行解密,而由公钥加密之后的文本只能由私钥解密,这就是非对称加密算法。 A text that is private key encrypted can only be decrypted by a public key, while a text that is subsequently encrypted by a public key can only be decrypted by a private key, which is the asymmetric encryption algorithm. vout中的一种典型的锁定脚本如下: A typical lock-in script in 其中需要注意的是, Among other things, it should be noted that vin中的一种典型的的解锁脚本如下: A typical unlocked script in 解锁脚本提供了 Unlocking scripts provide the signature The sigScript in the following graph is a unlocked script, and pkScript is a locked script. 参考资料:
(下图中用txid0627052b简写)
. (Summary of txid0627052b in the figure below)
https://github.com/tianmingyun/MasterBitcoin2CN/blob/master/ch06.md
http://www.infoq.com/cn/articles/deep-understanding-of-bitcoin-transaction-script
https://www.cnblogs.com/zhaoweiwei/p/address.html
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论