def __init__(self, net, header, share_info, merkle_branch=None, other_txs=None): self.net = net if merkle_branch is None and other_txs is None: raise ValueError('need either merkle_branch or other_txs') if other_txs is not None: new_merkle_branch = bitcoin_data.calculate_merkle_branch([dict(version=0, tx_ins=[], tx_outs=[], lock_time=0)] + other_txs, 0) if merkle_branch is not None: if merke_branch != new_merkle_branch: raise ValueError('invalid merkle_branch and other_txs') merkle_branch = new_merkle_branch if len(merkle_branch) > 16: raise ValueError('merkle_branch too long!') self.header = header self.previous_block = header['previous_block'] self.share_info = share_info self.merkle_branch = merkle_branch self.share_data = self.share_info['share_data'] self.target = self.share_info['target'] self.timestamp = self.share_info['timestamp'] self.new_script = self.share_data['new_script'] self.subsidy = self.share_data['subsidy'] self.donation = self.share_data['donation'] if len(self.new_script) > 100: raise ValueError('new_script too long!') self.previous_hash = self.previous_share_hash = self.share_data['previous_share_hash'] self.nonce = self.share_data['nonce'] if len(self.nonce) > 100: raise ValueError('nonce too long!') if len(self.share_data['coinbase']) > 100: raise ValueError('''coinbase too large! %i bytes''' % (len(self.share_data['coinbase']),)) self.pow_hash = net.BITCOIN_POW_FUNC(header) self.header_hash = bitcoin_data.block_header_type.hash256(header) self.hash = share1a_type.hash256(self.as_share1a()) if self.pow_hash > self.target: print 'hash %x' % self.pow_hash print 'targ %x' % self.target raise ValueError('not enough work!') self.stale_frac = self.share_data['stale_frac']/254 if self.share_data['stale_frac'] != 255 else None self.other_txs = other_txs if self.pow_hash <= self.header['target'] else None # XXX eww self.time_seen = time.time() self.peer = None
def __init__(self, net, header, share_info, merkle_branch=None, other_txs=None): self.net = net if merkle_branch is None and other_txs is None: raise ValueError('need either merkle_branch or other_txs') if other_txs is not None: new_merkle_branch = bitcoin_data.calculate_merkle_branch([0] + [bitcoin_data.hash256(bitcoin_data.tx_type.pack(x)) for x in other_txs], 0) if merkle_branch is not None: if merke_branch != new_merkle_branch: raise ValueError('invalid merkle_branch and other_txs') merkle_branch = new_merkle_branch if len(merkle_branch) > 16: raise ValueError('merkle_branch too long!') self.header = header self.previous_block = header['previous_block'] self.share_info = share_info self.merkle_branch = merkle_branch self.share_data = self.share_info['share_data'] self.target = self.share_info['bits'].target self.timestamp = self.share_info['timestamp'] self.new_script = self.share_data['new_script'] self.subsidy = self.share_data['subsidy'] self.donation = self.share_data['donation'] if len(self.new_script) > 100: raise ValueError('new_script too long!') self.previous_hash = self.previous_share_hash = self.share_data['previous_share_hash'] self.nonce = self.share_data['nonce'] if len(self.nonce) > 100: raise ValueError('nonce too long!') if len(self.share_data['coinbase']) > 100: raise ValueError('''coinbase too large! %i bytes''' % (len(self.share_data['coinbase']),)) self.pow_hash = net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(header)) self.header_hash = bitcoin_data.hash256(bitcoin_data.block_header_type.pack(header)) self.hash = bitcoin_data.hash256(share1a_type.pack(self.as_share1a())) if self.pow_hash > self.target: print 'hash %x' % self.pow_hash print 'targ %x' % self.target raise ValueError('not enough work!') self.other_txs = other_txs if self.pow_hash <= self.header['bits'].target else None # XXX eww self.time_seen = time.time() self.peer = None
def __init__(self, net, header, share_info, merkle_branch, other_txs=None): self.net = net if p2pool.DEBUG and other_txs is not None and bitcoin_data.calculate_merkle_branch([0] + [bitcoin_data.hash256(bitcoin_data.tx_type.pack(x)) for x in other_txs], 0) != merkle_branch: raise ValueError('merkle_branch and other_txs do not match') if len(merkle_branch) > 16: raise ValueError('merkle_branch too long!') self.header = header self.share_info = share_info self.merkle_branch = merkle_branch self.share_data = self.share_info['share_data'] self.target = self.share_info['bits'].target self.timestamp = self.share_info['timestamp'] if len(self.share_data['new_script']) > 100: raise ValueError('new_script too long!') if script.get_sigop_count(self.share_data['new_script']) > 1: raise ValueError('too many sigops!') self.previous_hash = self.share_data['previous_share_hash'] if len(self.share_data['nonce']) > 100: raise ValueError('nonce too long!') if len(self.share_data['coinbase']) > 100: raise ValueError('''coinbase too large! %i bytes''' % (len(self.share_data['coinbase']),)) self.pow_hash = net.PARENT.POW_FUNC(bitcoin_data.block_header_type.pack(header)) self.header_hash = bitcoin_data.hash256(bitcoin_data.block_header_type.pack(header)) self.hash = bitcoin_data.hash256(share1a_type.pack(self.as_share1a())) if self.pow_hash > self.target: print 'hash %x' % self.pow_hash print 'targ %x' % self.target raise ValueError('not enough work!') if other_txs is not None and not self.pow_hash <= self.header['bits'].target: raise ValueError('other_txs provided when not a block solution') if other_txs is None and self.pow_hash <= self.header['bits'].target: raise ValueError('other_txs not provided when a block solution') self.other_txs = other_txs # XXX eww self.time_seen = time.time() self.peer = None
def from_share1b(cls, share1b, net): return cls(net, merkle_branch=bitcoin_data.calculate_merkle_branch([0] + [bitcoin_data.hash256(bitcoin_data.tx_type.pack(x)) for x in share1b['other_txs']], 0), **share1b)
def __init__(self, net, header, share_info, merkle_branch=None, other_txs=None): self.net = net if merkle_branch is None and other_txs is None: raise ValueError('need either merkle_branch or other_txs') if other_txs is not None: new_merkle_branch = bitcoin_data.calculate_merkle_branch( [dict(version=0, tx_ins=[], tx_outs=[], lock_time=0)] + other_txs, 0) if merkle_branch is not None: if merke_branch != new_merkle_branch: raise ValueError('invalid merkle_branch and other_txs') merkle_branch = new_merkle_branch if len(merkle_branch) > 16: raise ValueError('merkle_branch too long!') self.header = header self.previous_block = header['previous_block'] self.share_info = share_info self.merkle_branch = merkle_branch self.share_data = self.share_info['share_data'] self.target = self.share_info['target'] self.timestamp = self.share_info['timestamp'] self.new_script = self.share_data['new_script'] self.subsidy = self.share_data['subsidy'] self.donation = self.share_data['donation'] if len(self.new_script) > 100: raise ValueError('new_script too long!') self.previous_hash = self.previous_share_hash = self.share_data[ 'previous_share_hash'] self.nonce = self.share_data['nonce'] if len(self.nonce) > 100: raise ValueError('nonce too long!') if len(self.share_data['coinbase']) > 100: raise ValueError('''coinbase too large! %i bytes''' % (len(self.share_data['coinbase']), )) self.pow_hash = net.BITCOIN_POW_FUNC(header) self.header_hash = bitcoin_data.block_header_type.hash256(header) self.hash = share1a_type.hash256(self.as_share1a()) if self.pow_hash > self.target: print 'hash %x' % self.pow_hash print 'targ %x' % self.target raise ValueError('not enough work!') self.stale_frac = self.share_data[ 'stale_frac'] / 254 if self.share_data[ 'stale_frac'] != 255 else None self.other_txs = other_txs if self.pow_hash <= self.header[ 'target'] else None # XXX eww self.time_seen = time.time() self.peer = None