{"id":2239,"date":"2023-11-10T18:01:49","date_gmt":"2023-11-10T10:01:49","guid":{"rendered":"https:\/\/bianchenghao6.com\/2239.html"},"modified":"2023-11-10T18:02:11","modified_gmt":"2023-11-10T10:02:11","slug":"%e5%88%9b%e5%bb%ba%e5%8c%ba%e5%9d%97%e9%93%be","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/2239.html","title":{"rendered":"\u521b\u5efa\u533a\u5757\u94fe"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

\u521b\u5efa\u533a\u5757\u94fe<\/h1>\n

Python\u533a\u5757\u94fe\u521b\u5efa\u533a\u5757\u94fe\u8be6\u7ec6\u64cd\u4f5c\u6559\u7a0b<\/span>\n <\/div>\n

\n \u533a\u5757\u94fe\u5305\u542b\u76f8\u4e92\u94fe\u63a5\u7684\u533a\u5757\u5217\u8868\u3002\u4e3a\u4e86\u5b58\u50a8\u6574\u4e2a\u5217\u8868\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aTPCoins\u7684\u5217\u8868\u53d8\u91cf-\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
TPCoins = []
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6211\u4eec\u8fd8\u5c06\u7f16\u5199\u4e00\u4e2a\u540d\u4e3a
\n dump_blockchain <\/b>\u7684\u5b9e\u7528\u7a0b\u5e8f\u65b9\u6cd5\uff0c\u7528\u4e8e\u8f6c\u50a8\u6574\u4e2a\u533a\u5757\u94fe\u7684\u5185\u5bb9\u3002\u6211\u4eec\u9996\u5148\u6253\u5370\u533a\u5757\u94fe\u7684\u957f\u5ea6\uff0c\u4ee5\u4fbf\u77e5\u9053\u533a\u5757\u94fe\u4e2d\u5f53\u524d\u5b58\u5728\u591a\u5c11\u4e2a\u533a\u5757\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
def <\/span>dump_blockchain <\/span>(self):
   print <\/span>(\"Number of blocks in <\/span>the chain: \"<\/span> + str(len (self)))
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8bf7\u6ce8\u610f\uff0c\u968f\u7740\u65f6\u95f4\u7684\u6d41\u901d\uff0c\u7528\u4e8e\u6253\u5370\u7684\u533a\u5757\u94fe\u4e2d\u7684\u533a\u5757\u6570\u91cf\u5c06\u975e\u5e38\u591a\u3002\u56e0\u6b64\uff0c\u5f53\u60a8\u6253\u5370\u533a\u5757\u94fe\u7684\u5185\u5bb9\u65f6\uff0c\u60a8\u53ef\u80fd\u5fc5\u987b\u51b3\u5b9a\u8981\u68c0\u67e5\u7684\u8303\u56f4\u3002\u5728\u4e0b\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u6253\u5370\u4e86\u6574\u4e2a\u533a\u5757\u94fe\uff0c\u56e0\u4e3a\u5728\u5f53\u524d\u6f14\u793a\u4e2d\u4e0d\u4f1a\u6dfb\u52a0\u592a\u591a\u5757\u3002\n <\/div>\n
\n \u8981\u904d\u5386\u6574\u4e2a\u94fe\uff0c\u6211\u4eec\u5982\u4e0b\u8bbe\u7f6e
\n for <\/b>\u5faa\u73af-\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
for <\/span><\/span>x in <\/span>range (len(TPCoins)):
   block_temp = TPCoins[x]
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6bcf\u4e2a\u5f15\u7528\u7684\u5757\u90fd\u590d\u5236\u5230\u4e00\u4e2a\u540d\u4e3a
\n block_temp <\/b>\u7684\u4e34\u65f6\u53d8\u91cf\u4e2d\u3002\n <\/div>\n
\n \u6211\u4eec\u5c06\u5757\u53f7\u6253\u5370\u4e3a\u6bcf\u4e2a\u5757\u7684\u6807\u9898\u3002\u8bf7\u6ce8\u610f\uff0c\u6570\u5b57\u5c06\u4ece\u96f6\u5f00\u59cb\uff0c\u7b2c\u4e00\u4e2a\u5757\u662f\u7f16\u53f7\u4e3a\u96f6\u7684\u521b\u4e16\u5757\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
print <\/span>(\"block # \"<\/span> + str(x))
<\/span> <\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5728\u6bcf\u4e2a\u533a\u5757\u4e2d\uff0c\u6211\u4eec\u5df2\u5c06\u4e09\u4e2a\u4ea4\u6613\u7684\u5217\u8868\uff08\u9664\u4e86\u521b\u4e16\u533a\u5757\uff09\u5b58\u50a8\u5728\u540d\u4e3a
\n verified_transactions <\/b>\u7684\u53d8\u91cf\u4e2d\u3002\u6211\u4eec\u5728
\n for <\/b>\u5faa\u73af\u4e2d\u8fed\u4ee3\u6b64\u5217\u8868\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u68c0\u7d22\u5230\u7684\u9879\u76ee\uff0c\u6211\u4eec\u8c03\u7528
\n display_transaction <\/b>\u51fd\u6570\u4ee5\u663e\u793a\u4ea4\u6613\u660e\u7ec6\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
for <\/span><\/span>transaction in <\/span>block_temp.verified_transactions:
   display_transaction (transaction)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6574\u4e2a\u529f\u80fd\u5b9a\u4e49\u5982\u4e0b\u6240\u793a-\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Bianchenghao6<\/span>
# Author by : bianchenghao6.com<\/span>
# Date : 2020-08-28<\/span>
def <\/span>dump_blockchain <\/span>(self):
   print <\/span>(\"Number of blocks in <\/span>the chain: \"<\/span> + str(len (self)))
   for <\/span><\/span>x in <\/span>range (len(TPCoins)):
      block_temp = TPCoins[x]
      print <\/span>(\"block # \"<\/span> + str(x))
<\/span>       for <\/span><\/span>transaction in <\/span>block_temp.verified_transactions:
         display_transaction (transaction)
         print <\/span>('--------------'<\/span>)
      print <\/span>('====================================='<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u6211\u4eec\u5728\u4ee3\u7801\u7684\u9002\u5f53\u4f4d\u7f6e\u63d2\u5165\u4e86\u5206\u9694\u7b26\uff0c\u4ee5\u5728\u5176\u4e2d\u5212\u5206\u5757\u548c\u4e8b\u52a1\u3002\n <\/div>\n
\n \u7531\u4e8e\u6211\u4eec\u73b0\u5728\u5df2\u7ecf\u521b\u5efa\u4e86\u7528\u4e8e\u5b58\u50a8\u5757\u7684\u533a\u5757\u94fe\uff0c\u6240\u4ee5\u6211\u4eec\u7684\u4e0b\u4e00\u4e2a\u4efb\u52a1\u662f\u521b\u5efa\u5757\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u533a\u5757\u94fe\u4e2d\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5c06\u6dfb\u52a0\u60a8\u5728\u5148\u524d\u6b65\u9aa4\u4e2d\u5df2\u7ecf\u521b\u5efa\u7684\u521b\u4e16\u7eaa\u5757\u3002\n <\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[],"class_list":["post-2239","post","type-post","status-publish","format-standard","hentry","category-python_qkl"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2239"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=2239"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/2239\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=2239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=2239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=2239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}