初级
在区块中加入Merkle Root字段
未完成
初级参考
完整示例代码供参考,建议自己理解后重新输入
def solve(block, transactions):
import hashlib
import copy
import json
b = copy.deepcopy(block)
if transactions:
while len(transactions) > 1:
if len(transactions) % 2 == 1:
transactions.append(transactions[-1])
transactions = [hashlib.sha256((transactions[i] + transactions[i+1]).encode()).hexdigest() for i in range(0, len(transactions), 2)]
b['merkle_root'] = transactions[0] if transactions else ''
print(b)
示例
输入
solve({"index": 1}, ["tx1", "tx2"])
期望输出
{'index': 1, 'merkle_root': 'b75fa4cca73a24cc129213c6e064b971533e2fa3eb0d118e3f484a7ae4a70fd3'}
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199