简体   繁体   English

区块链如何验证交易金额有效

[英]How blockchain verifies transaction amount is valid

I'm new to blockchain. 我是区块链新手。 I understand that blockchain keeps records of all transactions and each transaction is signed with private key. 我了解区块链会保留所有交易的记录,并且每个交易都使用私钥签名。 However, why cannot anyone enter an arbitrary amount of Bitcoin transaction? 但是,为什么没有人可以输入任意数量的比特币交易? Say, address a only has 1 Bitcoin, but its owner can create a transaction of 100 Bitcoins and still sign it. 假设一个地址只有1个比特币,但是​​它的所有者可以创建100个比特币的交易并仍然对其进行签名。 What is Bitcoin's mechanism to verify the outgoing and incoming amounts of a transaction? 比特币用于验证交易的出入金额的机制是什么?

Bitcoin's blockchain contains a historical record of all transactions which have ever occured on it. 比特币的区块链包含曾经发生过的所有交易的历史记录。 Clients can certainly choose to store less, and the blockchain can be pruned by not storing transactions which have already been spent long-ago. 客户当然可以选择减少存储量,并且可以通过不存储已经花费很长时间的交易来修剪区块链。

Bitcoin addresses don't technically have a "balance" in the sense of a traditional bank ledger. 从传统的银行总账的意义上讲,比特币地址在技术上没有“余额”。 Instead, an address has the ability to spend transactions which were sent to it. 相反,地址可以处理发送给它的交易。

To delve into technical details, let's look at the address 1PkCAVKjPz1YK7iJwT8xTLxBXR1av8dL98 (which I own). 为了深入研究技术细节,让我们看一下地址1PkCAVKjPz1YK7iJwT8xTLxBXR1av8dL98 (我拥有)。

I received a very small transaction of 0.004 BTC recently, in the transaction with the TxID 432794be2e056275cafb0eeb7ab59a24444dd4c9e00cd9702a49c2a655a3e705 . 最近,我在TxID 432794be2e056275cafb0eeb7ab59a24444dd4c9e00cd9702a49c2a655a3e705的交易中收到了一笔很小的0.004 BTC交易。

The (hex-encoded) raw data of this transaction is: 0100000001e9a24c1d1b8d10b13482cdcbbb90d894577292c4d0c0c1427411fb9d82ea710c010000006b483045022100d9a5433c1381b39b7e02b0b0f042990e7c16cfea252b05ccfef2e85c2dab2a6f022057c7def782fe3b0d7e5e0eae277d2a5890844da7d72309817a2dac22a6307c6001210390d78cb0c1d34d4417db7e0a9a9f125a689dc29dc2197a01a5f827a20f870f62ffffffff01801a0600000000001976a914f97df8f593e0056d337c274fd81a163f47a17d3788ac00000000 的(十六进制编码)该事务的原始数据是: 0100000001e9a24c1d1b8d10b13482cdcbbb90d894577292c4d0c0c1427411fb9d82ea710c010000006b483045022100d9a5433c1381b39b7e02b0b0f042990e7c16cfea252b05ccfef2e85c2dab2a6f022057c7def782fe3b0d7e5e0eae277d2a5890844da7d72309817a2dac22a6307c6001210390d78cb0c1d34d4417db7e0a9a9f125a689dc29dc2197a01a5f827a20f870f62ffffffff01801a0600000000001976a914f97df8f593e0056d337c274fd81a163f47a17d3788ac00000000

Which in its human-readable form is: 以其人类可读的形式是:

{
  "txid": "432794be2e056275cafb0eeb7ab59a24444dd4c9e00cd9702a49c2a655a3e705",
  "size": 192,
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "0c71ea829dfb117442c1c0d0c492725794d890bbcbcd8234b1108d1b1d4ca2e9",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100d9a5433c1381b39b7e02b0b0f042990e7c16cfea252b05ccfef2e85c2dab2a6f022057c7def782fe3b0d7e5e0eae277d2a5890844da7d72309817a2dac22a6307c60[ALL] 0390d78cb0c1d34d4417db7e0a9a9f125a689dc29dc2197a01a5f827a20f870f62",
        "hex": "483045022100d9a5433c1381b39b7e02b0b0f042990e7c16cfea252b05ccfef2e85c2dab2a6f022057c7def782fe3b0d7e5e0eae277d2a5890844da7d72309817a2dac22a6307c6001210390d78cb0c1d34d4417db7e0a9a9f125a689dc29dc2197a01a5f827a20f870f62"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00400000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 f97df8f593e0056d337c274fd81a163f47a17d37 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914f97df8f593e0056d337c274fd81a163f47a17d3788ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1PkCAVKjPz1YK7iJwT8xTLxBXR1av8dL98"
        ]
      }
    }
  ]
}

So the address 1PkCAVKjPz1YK7iJwT8xTLxBXR1av8dL98 is able to "spend" the transaction 432794be2e056275cafb0eeb7ab59a24444dd4c9e00cd9702a49c2a655a3e705 . 因此,地址1PkCAVKjPz1YK7iJwT8xTLxBXR1av8dL98能够“花费”交易432794be2e056275cafb0eeb7ab59a24444dd4c9e00cd9702a49c2a655a3e705 The output value of that transaction is 0.004 BTC, so I can't make a Bitcoin transaction which attempts to spend more. 该交易的输出值为0.004 BTC,因此我无法进行尝试花费更多的比特币交易。 However, let's try to do it anyway. 但是,无论如何,我们都尝试这样做。

I'll create a raw transaction which attempts to output 0.01 BTC to 1MgLu9L7ftmGQM84xhKYKw8pTXiSANwggs from the transaction with an output balance of 0.004 BTC: 我将创建一个原始交易,尝试从交易中输出0.01 BTC到1MgLu9L7ftmGQM84xhKYKw8pTXiSANwggs ,输出余额为0.004 BTC:

bitcoin-rpc createrawtransaction '[{"txid":"432794be2e056275cafb0eeb7ab59a24444dd4c9e00cd9702a49c2a655a3e705","vout":0}]' '{"1MgLu9L7ftmGQM84xhKYKw8pTXiSANwggs":0.01}'

Returns the raw transaction: 返回原始交易:

010000000105e7a355a6c2492a70d90ce0c9d44d44249ab57aeb0efbca7562052ebe9427430000000000ffffffff0140420f00000000001976a914e2d3595bd0a55c16f4b19f5cd996568dd7e811f688ac00000000

I can then sign the transaction: 然后,我可以签署交易:

bitcoin-rpc signrawtransaction 010000000105e7a355a6c2492a70d90ce0c9d44d44249ab57aeb0efbca7562052ebe9427430000000000ffffffff0140420f00000000001976a914e2d3595bd0a55c16f4b19f5cd996568dd7e811f688ac00000000

which returns: 返回:

{
      "hex": "010000000105e7a355a6c2492a70d90ce0c9d44d44249ab57aeb0efbca7562052ebe942743000000006b483045022100ce3fad8ccdee48f1fe9060ef81624d3bbe721293feb8ee06a96751e65b9c423e0220106a3e80d5fdf93df5dbf037d8cfd32af70a405586e12294c937308a3c57b10e012102f2acb810346866908108dd86462ee5400b15786739f5e908711d2d15d9dd2238ffffffff0140420f00000000001976a914e2d3595bd0a55c16f4b19f5cd996568dd7e811f688ac00000000",
      "complete": true
}

And I can take that returned hex, which is a validly-formatted transaction, and submit it to the network: 然后,我可以将返回的十六进制(格式正确的交易)提交给网络:

bitcoin-rpc sendrawtransaction 010000000105e7a355a6c2492a70d90ce0c9d44d44249ab57aeb0efbca7562052ebe942743000000006b483045022100ce3fad8ccdee48f1fe9060ef81624d3bbe721293feb8ee06a96751e65b9c423e0220106a3e80d5fdf93df5dbf037d8cfd32af70a405586e12294c937308a3c57b10e012102f2acb810346866908108dd86462ee5400b15786739f5e908711d2d15d9dd2238ffffffff0140420f00000000001976a914e2d3595bd0a55c16f4b19f5cd996568dd7e811f688ac00000000

Which gives me the error: 这给了我错误:

66: insufficient priority (code -26)

This is a client-side error, but if I were to successfully broadcast the raw transaction to the network, other peers would simply look up the referenced (or "spent") transaction 432794be2e056275cafb0eeb7ab59a24444dd4c9e00cd9702a49c2a655a3e705 and see that the output total of my new transaction is greater than the output total of the transaction I'm attempting to spend. 这是一个客户端错误,但是如果我要成功地将原始事务广播到网络,其他对等方将简单地查找引用(或“花掉”的)事务432794be2e056275cafb0eeb7ab59a24444dd4c9e00cd9702a49c2a655a3e705比我尝试花费的交易的总输出金额高。

There is one exception to this rule: coinbase transactions generate Bitcoins for miners, and thus are allowed to output the correct block subsidy (originally 50 BTC, but currently 12.5 BTC after the halving about a month and a half ago) plus the transaction fees of all of the transactions contained within the block. 此规则有一个例外:币库交易为矿工生成比特币,因此被允许输出正确的大宗补贴(最初为50 BTC,但目前在大约一个半月前减半后为12.5 BTC)加上交易费用为该区块中包含的所有交易。

I know this post is already old but there is a complete list for validating a bitcoin transcation: 我知道这篇文章已经很老了,但是有一个完整的列表来验证比特币交易:

https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages

Maybe this link on how bitcoin transactions work will help you. 也许有关比特币交易如何工作的链接将为您提供帮助。 Look at the section called "What if the input and output amounts don't match?" 查看“输入和输出量不匹配怎么办?”一节。

Also, since Blockchain uses a distributed ledger, all nodes will validate a transaction before it is accepted. 此外,由于区块链使用分布式分类帐,因此所有节点都将在接受交易之前验证交易。 Furthermore there should be auditors on the chain that make sure fraudulent activities don't happen. 此外,应在链上配备审核员,以确保不会发生欺诈活动。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM