比特币如何防止双重支出



有人能帮我创建一个伪代码来展示比特币如何防止双重支出吗?这是我的代码(在的帮助下https://www.sofi.com/):

This program is to prevent double-spending:
Person A and Person B go to a store with only one collective BTC to spend.
Person A buys a TV costing exactly 1 BTC.
Person B buys a motorcycle that also costs exactly 1 BTC.
blockchain = []
pool_of_unconfirmed_transactions = []
Both transactions go into a pool of unconfirmed transactions:
pool_of_unconfirmed_transactions.append(person A buys)
pool_of_unconfirmed_transactions.append(person B buys)
only the first transaction gets confirmations
and is verified by miners in the next block.
If person A buys == first buyer:
person A's transaction == valid
blockchain.append(person A's transaction)
del mem_pool[person B's transaction]
else:
person B's transaction == valid
del mem_pool[person A's transaction]
Whichever transaction gets the maximum number of network confirmations
(typically a minimum of six) will be included in the blockchain,
while others are discarded.
Once confirmations and transactions are put on the blockchain
they are time-stamped, rendering them irreversible and impossible to alter.

可以吗?有什么建议吗?

比特币通过不产生一个区块来防止双重支出,该区块花费了另一个区块先前花费的UTXO。内存池或未经确认的事务与此无关。

包含双倍支出的比特币区块将不是有效区块,因此世界上所有的比特币节点都会拒绝它;公共分类账"-比特币区块链是整个系统所有余额的账簿(账本(。

因此,如果有两个相互竞争的交易,矿工将决定哪些被花费,哪些被拒绝。

相关内容

  • 没有找到相关文章

最新更新