• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python forest.get_attributedelta_type函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.forest.get_attributedelta_type函数的典型用法代码示例。如果您正苦于以下问题:Python get_attributedelta_type函数的具体用法?Python get_attributedelta_type怎么用?Python get_attributedelta_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_attributedelta_type函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, node, my_pubkey_hash, donation_percentage, merged_urls, worker_fee):
     worker_interface.WorkerBridge.__init__(self)
     self.recent_shares_ts_work = []
     
     self.node = node
     self.my_pubkey_hash = my_pubkey_hash
     self.donation_percentage = donation_percentage
     self.worker_fee = worker_fee
     
     self.net = self.node.net.PARENT
     self.running = True
     self.pseudoshare_received = variable.Event()
     self.share_received = variable.Event()
     self.local_rate_monitor = math.RateMonitor(10*60)
     self.local_addr_rate_monitor = math.RateMonitor(10*60)
     
     self.removed_unstales_var = variable.Variable((0, 0, 0))
     self.removed_doa_unstales_var = variable.Variable(0)
     
     
     self.my_share_hashes = set()
     self.my_doa_share_hashes = set()
     
     self.tracker_view = forest.TrackerView(self.node.tracker, forest.get_attributedelta_type(dict(forest.AttributeDelta.attrs,
         my_count=lambda share: 1 if share.hash in self.my_share_hashes else 0,
         my_doa_count=lambda share: 1 if share.hash in self.my_doa_share_hashes else 0,
         my_orphan_announce_count=lambda share: 1 if share.hash in self.my_share_hashes and share.share_data['stale_info'] == 'orphan' else 0,
         my_dead_announce_count=lambda share: 1 if share.hash in self.my_share_hashes and share.share_data['stale_info'] == 'doa' else 0,
     )))
     
     @self.node.tracker.verified.removed.watch
     def _(share):
         if share.hash in self.my_share_hashes and self.node.tracker.is_child_of(share.hash, self.node.best_share_var.value):
             assert share.share_data['stale_info'] in [None, 'orphan', 'doa'] # we made these shares in this instance
             self.removed_unstales_var.set((
                 self.removed_unstales_var.value[0] + 1,
                 self.removed_unstales_var.value[1] + (1 if share.share_data['stale_info'] == 'orphan' else 0),
                 self.removed_unstales_var.value[2] + (1 if share.share_data['stale_info'] == 'doa' else 0),
             ))
         if share.hash in self.my_doa_share_hashes and self.node.tracker.is_child_of(share.hash, self.node.best_share_var.value):
             self.removed_doa_unstales_var.set(self.removed_doa_unstales_var.value + 1)
     
     # MERGED WORK
     
     self.merged_work = variable.Variable({})
     
     @defer.inlineCallbacks
     def set_merged_work(merged_url, merged_userpass):
         merged_proxy = jsonrpc.HTTPProxy(merged_url, dict(Authorization='Basic ' + base64.b64encode(merged_userpass)))
         while self.running:
             auxblock = yield deferral.retry('Error while calling merged getauxblock on %s:' % (merged_url,), 30)(merged_proxy.rpc_getauxblock)()
             self.merged_work.set(math.merge_dicts(self.merged_work.value, {auxblock['chainid']: dict(
                 hash=int(auxblock['hash'], 16),
                 target='p2pool' if auxblock['target'] != 'p2pool' else pack.IntType(256).unpack(auxblock['target'].decode('hex')),
                 merged_proxy=merged_proxy,
             )}))
             yield deferral.sleep(1)
     for merged_url, merged_userpass in merged_urls:
         set_merged_work(merged_url, merged_userpass)
     
     @self.merged_work.changed.watch
     def _(new_merged_work):
         print 'Got new merged mining work!'
     
     # COMBINE WORK
     
     self.current_work = variable.Variable(None)
     def compute_work():
         t = self.node.bitcoind_work.value
         bb = self.node.best_block_header.value
         if bb is not None and bb['previous_block'] == t['previous_block'] and self.node.net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(bb)) <= t['bits'].target:
             print 'Skipping from block %x to block %x!' % (bb['previous_block'],
                 bitcoin_data.hash256(bitcoin_data.block_header_type.pack(bb)))
             t = dict(
                 version=bb['version'],
                 previous_block=bitcoin_data.hash256(bitcoin_data.block_header_type.pack(bb)),
                 bits=bb['bits'], # not always true
                 coinbaseflags='',
                 height=t['height'] + 1,
                 time=bb['timestamp'] + 600, # better way?
                 transactions=[],
                 transaction_fees=[],
                 merkle_link=bitcoin_data.calculate_merkle_link([None], 0),
                 subsidy=self.node.net.PARENT.SUBSIDY_FUNC(self.node.bitcoind_work.value['height']),
                 last_update=self.node.bitcoind_work.value['last_update'],
             )
         
         self.current_work.set(t)
     self.node.bitcoind_work.changed.watch(lambda _: compute_work())
     self.node.best_block_header.changed.watch(lambda _: compute_work())
     compute_work()
     
     self.new_work_event = variable.Event()
     @self.current_work.transitioned.watch
     def _(before, after):
         # trigger LP if version/previous_block/bits changed or transactions changed from nothing
         if any(before[x] != after[x] for x in ['version', 'previous_block', 'bits']) or (not before['transactions'] and after['transactions']):
             self.new_work_event.happened()
     self.merged_work.changed.watch(lambda _: self.new_work_event.happened())
     self.node.best_share_var.changed.watch(lambda _: self.new_work_event.happened())
开发者ID:cqtenq,项目名称:p2pool-neoscrypt,代码行数:100,代码来源:work.py


示例2: __init__

    def __init__(self, node, my_pubkey_hash, donation_percentage, merged_urls, worker_fee, diff_policy):
        worker_interface.WorkerBridge.__init__(self)
        self.recent_shares_ts_work = []

        self.node = node
        self.my_pubkey_hash = my_pubkey_hash
        self.donation_percentage = donation_percentage
        self.worker_fee = worker_fee
        self.diff_policy = diff_policy if diff_policy in ["A", "F"] else "D"

        self.net = self.node.net.PARENT
        self.running = True
        self.pseudoshare_received = variable.Event()
        self.share_received = variable.Event()
        self.local_rate_monitor = math.RateMonitor(10 * 60)

        self.removed_unstales_var = variable.Variable((0, 0, 0))
        self.removed_doa_unstales_var = variable.Variable(0)

        self.my_share_hashes = set()
        self.my_doa_share_hashes = set()

        self.tracker_view = forest.TrackerView(
            self.node.tracker,
            forest.get_attributedelta_type(
                dict(
                    forest.AttributeDelta.attrs,
                    my_count=lambda share: 1 if share.hash in self.my_share_hashes else 0,
                    my_doa_count=lambda share: 1 if share.hash in self.my_doa_share_hashes else 0,
                    my_orphan_announce_count=lambda share: 1
                    if share.hash in self.my_share_hashes and share.share_data["stale_info"] == "orphan"
                    else 0,
                    my_dead_announce_count=lambda share: 1
                    if share.hash in self.my_share_hashes and share.share_data["stale_info"] == "doa"
                    else 0,
                )
            ),
        )

        @self.node.tracker.verified.removed.watch
        def _(share):
            if share.hash in self.my_share_hashes and self.node.tracker.is_child_of(
                share.hash, self.node.best_share_var.value
            ):
                assert share.share_data["stale_info"] in [
                    None,
                    "orphan",
                    "doa",
                ]  # we made these shares in this instance
                self.removed_unstales_var.set(
                    (
                        self.removed_unstales_var.value[0] + 1,
                        self.removed_unstales_var.value[1] + (1 if share.share_data["stale_info"] == "orphan" else 0),
                        self.removed_unstales_var.value[2] + (1 if share.share_data["stale_info"] == "doa" else 0),
                    )
                )
            if share.hash in self.my_doa_share_hashes and self.node.tracker.is_child_of(
                share.hash, self.node.best_share_var.value
            ):
                self.removed_doa_unstales_var.set(self.removed_doa_unstales_var.value + 1)

        # MERGED WORK

        self.merged_work = variable.Variable({})

        @defer.inlineCallbacks
        def set_merged_work(merged_url, merged_userpass):
            merged_proxy = jsonrpc.HTTPProxy(
                merged_url, dict(Authorization="Basic " + base64.b64encode(merged_userpass))
            )
            while self.running:
                auxblock = yield deferral.retry("Error while calling merged getauxblock:", 30)(
                    merged_proxy.rpc_getauxblock
                )()
                self.merged_work.set(
                    dict(
                        self.merged_work.value,
                        **{
                            auxblock["chainid"]: dict(
                                hash=int(auxblock["hash"], 16),
                                target="p2pool"
                                if auxblock["target"] == "p2pool"
                                else pack.IntType(256).unpack(auxblock["target"].decode("hex")),
                                merged_proxy=merged_proxy,
                            )
                        }
                    )
                )
                yield deferral.sleep(1)

        for merged_url, merged_userpass in merged_urls:
            set_merged_work(merged_url, merged_userpass)

        @self.merged_work.changed.watch
        def _(new_merged_work):
            print "Got new merged mining work!"

        # COMBINE WORK

        self.current_work = variable.Variable(None)
#.........这里部分代码省略.........
开发者ID:baloo-kiev,项目名称:p2pool-adaptive,代码行数:101,代码来源:work.py



注:本文中的util.forest.get_attributedelta_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python full.matrix函数代码示例发布时间:2022-05-26
下一篇:
Python file.mkstempfname函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap