def test_all(self): data = '76 A9 14 89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC'.replace(' ', '').decode('hex') self.assertEquals( list(script.parse(data)), [('UNK_118', None), ('UNK_169', None), ('PUSH', '\x89\xab\xcd\xef\xab\xba\xab\xba\xab\xba\xab\xba\xab\xba\xab\xba\xab\xba\xab\xba'), ('UNK_136', None), ('CHECKSIG', None)], ) self.assertEquals(script.get_sigop_count(data), 1)
def check(self, tracker): if script.get_sigop_count(self.new_script) > 1: raise ValueError('too many sigops!') share_info, gentx = generate_transaction(tracker, self.share_info['share_data'], self.header['bits'].target, self.share_info['timestamp'], self.net) if share_info != self.share_info: raise ValueError('share difficulty invalid') if bitcoin_data.check_merkle_branch(bitcoin_data.hash256(bitcoin_data.tx_type.pack(gentx)), 0, self.merkle_branch) != self.header['merkle_root']: raise ValueError('''gentx doesn't match header via merkle_branch''')
def test_all(self): data = '76 A9 14 89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC'.replace( ' ', '').decode('hex') self.assertEquals( list(script.parse(data)), [('UNK_118', None), ('UNK_169', None), ('PUSH', '\x89\xab\xcd\xef\xab\xba\xab\xba\xab\xba\xab\xba\xab\xba\xab\xba\xab\xba\xab\xba' ), ('UNK_136', None), ('CHECKSIG', None)], ) self.assertEquals(script.get_sigop_count(data), 1)
def __init__(self, header, share_info, merkle_branch=None, other_txs=None): 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 = 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.other_txs = other_txs self.timestamp = self.header['timestamp'] self.share_data = self.share_info['share_data'] self.new_script = self.share_info['new_script'] self.subsidy = self.share_info['subsidy'] 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.target = self.share_data['target'] self.nonce = self.share_data['nonce'] if len(self.nonce) > 100: raise ValueError('nonce too long!') self.bitcoin_hash = bitcoin_data.block_header_type.hash256(header) self.hash = share1a_type.hash256(self.as_share1a()) if self.bitcoin_hash > self.target: print 'hash', hex(self.bitcoin_hash) print 'targ', hex(self.target) raise ValueError('not enough work!') if script.get_sigop_count(self.new_script) > 1: raise ValueError('too many sigops!') # XXX eww self.time_seen = time.time() self.shared = False 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 check(self, tracker): if script.get_sigop_count(self.new_script) > 1: raise ValueError('too many sigops!') share_info, gentx = generate_transaction(tracker, self.share_info['share_data'], self.header['target'], self.share_info['timestamp'], self.net) if share_info != self.share_info: raise ValueError('share difficulty invalid') if bitcoin_data.check_merkle_branch( gentx, 0, self.merkle_branch) != self.header['merkle_root']: raise ValueError( '''gentx doesn't match header via merkle_branch''')