async def address_status(self, hashX): '''Returns an address status. Status is a hex string, but must be None if there is no history. ''' # Note history is ordered and mempool unordered in electrum-server # For mempool, height is -1 if unconfirmed txins, otherwise 0 history = await self.controller.get_history(hashX) mempool = await self.controller.mempool_transactions(hashX) status = ''.join('{}:{:d}:'.format(hash_to_str(tx_hash), height) for tx_hash, height in history) status += ''.join('{}:{:d}:'.format(hex_hash, -unconfirmed) for hex_hash, tx_fee, unconfirmed in mempool) if status: status = sha256(status.encode()).hex() else: status = None if mempool: self.mempool_statuses[hashX] = status else: self.mempool_statuses.pop(hashX, None) return status
async def hash160_contract_status(self, hash160, contract_addr, topic): eventlogs = await self.controller.contract_event_get_history( hash160, contract_addr, topic) status = ':'.join('{}:{:d}:{:d}'.format(dic.get( 'tx_hash'), int(dic.get('height')), int(dic.get('log_index'))) for dic in eventlogs) if status: status = sha256(status.encode('ascii')).hex() else: status = None return status
async def hash160_contract_status(self, hash160, contract_addr): eventlogs = await self.controller.hash160_contract_get_eventlogs( hash160, contract_addr) status = ''.join( '{}:{:d}:'.format(dic.get('tx_hash'), int(dic.get('height'))) for dic in eventlogs) if status: status = sha256(status.encode()).hex() else: status = None return status
async def address_status(self, hashX): '''Returns status as 32 bytes.''' # Note history is ordered and mempool unordered in electrum-server # For mempool, height is -1 if unconfirmed txins, otherwise 0 history = await self.get_history(hashX) mempool = await self.mempool_transactions(hashX) status = ''.join('{}:{:d}:'.format(hash_to_str(tx_hash), height) for tx_hash, height in history) status += ''.join('{}:{:d}:'.format(hex_hash, -unconfirmed) for hex_hash, tx_fee, unconfirmed in mempool) if status: return sha256(status.encode()).hex() return None
def read_tx_and_hash(self): from lib.hash import sha256 start = self.cursor return self.read_tx(), sha256(self.binary[start:self.cursor])
def test_sha256(): assert lib_hash.sha256( b'sha256' ) == b'][\t\xf6\xdc\xb2\xd5:_\xff\xc6\x0cJ\xc0\xd5_\xab\xdfU`i\xd6c\x15E\xf4*\xa6\xe3P\x0f.' with pytest.raises(TypeError): lib_hash.sha256('sha256')