])
class Share(object):
- __slots__ = 'header share_info merkle_branch other_txs timestamp share_data previous_hash target pow_hash header_hash hash time_seen peer net'.split(' ')
+ __slots__ = 'header share_info merkle_branch other_txs timestamp share_data previous_hash target pow_hash header_hash hash time_seen peer net new_script'.split(' ')
@classmethod
def from_share(cls, share, net):
raise ValueError('new_script too long!')
if script.get_sigop_count(self.share_data['new_script']) > 1:
raise ValueError('too many sigops!')
+ self.new_script = self.share_data['new_script']
self.previous_hash = self.share_data['previous_share_hash']
def go(share, tracker, t, d):
#c = color.green if share.peer is None else color.red
- c = get_color(share.share_data['new_script'])
+ c = get_color(share.new_script)
pos = get_pos(share, t, d)
pygame.draw.circle(d, c, pos.rounded, 5)
if share.previous_hash in tracker.shares:
pygame.draw.circle(d, c, pos.rounded, 10, 2)
for child_hash in tracker.reverse_shares.get(share.hash, set()):
go(tracker.shares[child_hash], tracker, t, d)
- d.blit(f.render(bitcoin_data.script2_to_human(share.share_data['new_script'], tracker.net.PARENT), True, (255, 255, 255)), pos)
+ d.blit(f.render(bitcoin_data.script2_to_human(share.new_script, tracker.net.PARENT), True, (255, 255, 255)), pos)
pygame.font.init()
f = pygame.font.SysFont("Monospace", 16)
def _new_share(self, share):
if share.pow_hash <= share.header['bits'].target and share.header_hash not in self.announced_hashes and abs(share.timestamp - time.time()) < 10*60:
self.announced_hashes.add(share.header_hash)
- message = '\x02%s BLOCK FOUND by %s! %s%064x' % (net.NAME.upper(), bitcoin_data.script2_to_address(share.share_data['new_script'], net.PARENT), net.PARENT.BLOCK_EXPLORER_URL_PREFIX, share.header_hash)
+ message = '\x02%s BLOCK FOUND by %s! %s%064x' % (net.NAME.upper(), bitcoin_data.script2_to_address(share.new_script, net.PARENT), net.PARENT.BLOCK_EXPLORER_URL_PREFIX, share.header_hash)
self.delayed_messages[message] = reactor.callLater(random.expovariate(1/5), lambda: (self.say(self.channel, message), self.delayed_messages.pop(message)))
def connectionLost(self, reason):
tracker.verified.added.unwatch(self.watch_id)
from p2pool.bitcoin import data as bitcoin_data
share = self.tracker.shares[element]
att = bitcoin_data.target_to_average_attempts(share.target)
- return 1, {share.share_data['new_script']: att*(65535-share.share_data['donation'])}, att*65535, att*share.share_data['donation']
+ return 1, {share.new_script: att*(65535-share.share_data['donation'])}, att*65535, att*share.share_data['donation']
def combine_deltas(self, (share_count1, weights1, total_weight1, total_donation_weight1), (share_count2, weights2, total_weight2, total_donation_weight2)):
return share_count1 + share_count2, math.add_dicts(weights1, weights2), total_weight1 + total_weight2, total_donation_weight1 + total_donation_weight2
t = forest.Tracker()
d = skiplists.WeightsSkipList(t)
for i in xrange(200):
- t.add(test_forest.FakeShare(hash=i, previous_hash=i - 1 if i > 0 else None, share_data=dict(new_script=i, donation=1234), target=2**249))
+ t.add(test_forest.FakeShare(hash=i, previous_hash=i - 1 if i > 0 else None, new_script=i, share_data=dict(donation=1234), target=2**249))
for i in xrange(200):
a = random.randrange(200)
d(a, random.randrange(a + 1), 1000000*65535)[1]