【问题标题】:how does bitcoin prevent double-spending?比特币如何防止双花?
【发布时间】:2022-01-15 09:03:35
【问题描述】:

有人可以帮我创建一个伪代码来显示比特币如何防止双花吗? 这是我的代码(在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.

没事吧? 有什么建议吗?

【问题讨论】:

    标签: python security pseudocode bitcoin


    【解决方案1】:

    比特币通过不产生一个花费另一个块之前已经花费的 UTXO 的块来防止双重花费。内存池或未确认的事务与它无关。

    包含双花的比特币区块不是有效区块,因此世界上所有比特币节点都会拒绝它。这也是它被称为“公共账本”的原因——比特币区块链是整个系统所有余额的账本(账本)。

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

    【讨论】:

    • 你能写成伪代码吗?请❤
    • 最好自己阅读和研究比特币源代码。
    猜你喜欢
    • 1970-01-01
    • 2020-10-14
    • 1970-01-01
    • 2019-05-16
    • 2013-11-29
    • 2012-06-01
    • 2022-01-21
    • 2012-04-24
    • 2015-12-21
    相关资源
    最近更新 更多