def _execute(self, request): inclusion_states = request['inclusionStates'] # type: bool seed = request['seed'] # type: Seed start = request['start'] # type: int stop = request['stop'] # type: Optional[int] # Determine the addresses we will be scanning, and pull their # transaction hashes. if stop is None: my_hashes = list( chain(*(hashes for _, hashes in iter_used_addresses( self.adapter, seed, start)))) else: ft_response = \ FindTransactionsCommand(self.adapter)( addresses= AddressGenerator(seed).get_addresses(start, stop - start), ) my_hashes = ft_response['hashes'] return { 'bundles': get_bundles_from_transaction_hashes( adapter=self.adapter, transaction_hashes=my_hashes, inclusion_states=inclusion_states, ), }
def _execute(self, request): inclusion_states = request['inclusionStates'] # type: bool seed = request['seed'] # type: Seed start = request['start'] # type: int stop = request['stop'] # type: Optional[int] # Determine the addresses we will be scanning, and pull their # transaction hashes. if stop is None: my_hashes = list(chain(*( hashes for _, hashes in iter_used_addresses(self.adapter, seed, start) ))) else: ft_response =\ FindTransactionsCommand(self.adapter)( addresses = AddressGenerator(seed).get_addresses(start, stop - start), ) my_hashes = ft_response['hashes'] return { 'bundles': get_bundles_from_transaction_hashes( adapter = self.adapter, transaction_hashes = my_hashes, inclusion_states = inclusion_states, ), }
async def _execute(self, request: dict) -> dict: inclusion_states: bool = request['inclusionStates'] seed: Seed = request['seed'] start: int = request['start'] stop: Optional[int] = request['stop'] # Determine the addresses we will be scanning, and pull their # transaction hashes. if stop is None: my_hashes = list( chain(*([ hashes async for _, hashes in iter_used_addresses( self.adapter, seed, start) ]))) else: ft_response = \ await FindTransactionsCommand(self.adapter)( addresses= AddressGenerator(seed).get_addresses(start, stop - start), ) my_hashes = ft_response['hashes'] return { 'bundles': await get_bundles_from_transaction_hashes( adapter=self.adapter, transaction_hashes=my_hashes, inclusion_states=inclusion_states, ), }
def _execute(self, request): stop = request['stop'] # type: Optional[int] seed = request['seed'] # type: Seed start = request['start'] # type: int threshold = request['threshold'] # type: Optional[int] security_level = request['securityLevel'] # int # Determine the addresses we will be scanning. if stop is None: addresses =\ [addy for addy, _ in iter_used_addresses(self.adapter, seed, start, security_level=security_level)] else: addresses = AddressGenerator(seed, security_level).get_addresses( start, stop - start) if addresses: # Load balances for the addresses that we generated. gb_response = GetBalancesCommand(self.adapter)(addresses=addresses) else: gb_response = {'balances': []} result = { 'inputs': [], 'totalBalance': 0, } threshold_met = threshold is None for i, balance in enumerate(gb_response['balances']): addresses[i].balance = balance if balance: result['inputs'].append(addresses[i]) result['totalBalance'] += balance if (threshold is not None) and (result['totalBalance'] >= threshold): threshold_met = True break if threshold_met: return result else: # This is an exception case, but note that we attach the result # to the exception context so that it can be used for # troubleshooting. raise with_context( exc=BadApiResponse( 'Accumulated balance {balance} is less than threshold {threshold} ' '(``exc.context`` contains more information).'.format( threshold=threshold, balance=result['totalBalance'], ), ), context={ 'inputs': result['inputs'], 'request': request, 'total_balance': result['totalBalance'], }, )
def _execute(self, request): stop = request['stop'] # type: Optional[int] seed = request['seed'] # type: Seed start = request['start'] # type: int threshold = request['threshold'] # type: Optional[int] # Determine the addresses we will be scanning. if stop is None: addresses =\ [addy for addy, _ in iter_used_addresses(self.adapter, seed, start)] else: addresses = AddressGenerator(seed).get_addresses(start, stop) if addresses: # Load balances for the addresses that we generated. gb_response = GetBalancesCommand(self.adapter)(addresses=addresses) else: gb_response = {'balances': []} result = { 'inputs': [], 'totalBalance': 0, } threshold_met = threshold is None for i, balance in enumerate(gb_response['balances']): addresses[i].balance = balance if balance: result['inputs'].append(addresses[i]) result['totalBalance'] += balance if (threshold is not None) and (result['totalBalance'] >= threshold): threshold_met = True break if threshold_met: return result else: # This is an exception case, but note that we attach the result # to the exception context so that it can be used for # troubleshooting. raise with_context( exc = BadApiResponse( 'Accumulated balance {balance} is less than threshold {threshold} ' '(``exc.context`` contains more information).'.format( threshold = threshold, balance = result['totalBalance'], ), ), context = { 'inputs': result['inputs'], 'request': request, 'total_balance': result['totalBalance'], }, )
async def _execute(self, request: dict) -> dict: inclusion_states: bool = request['inclusionStates'] seed: Seed = request['seed'] start: int = request['start'] stop: Optional[int] = request['stop'] security_level: Optional[int] = request['security_level'] if stop is None: my_addresses: List[Address] = [] my_hashes: List[TransactionHash] = [] async for addy, hashes in iter_used_addresses( self.adapter, seed, start, security_level): my_addresses.append(addy) my_hashes.extend(hashes) else: ft_command = FindTransactionsCommand(self.adapter) my_addresses = (AddressGenerator(seed, security_level).get_addresses( start, stop - start)) my_hashes = (await ft_command(addresses=my_addresses )).get('hashes') or [] account_balance = 0 if my_addresses: # Load balances for the addresses that we generated. gb_response = (await GetBalancesCommand(self.adapter) (addresses=my_addresses)) for i, balance in enumerate(gb_response['balances']): my_addresses[i].balance = balance account_balance += balance return { 'addresses': list(sorted(my_addresses, key=attrgetter('key_index'))), 'balance': account_balance, 'bundles': await get_bundles_from_transaction_hashes( adapter=self.adapter, transaction_hashes=my_hashes, inclusion_states=inclusion_states, ), }
def _execute(self, request): inclusion_states = request['inclusionStates'] # type: bool seed = request['seed'] # type: Seed start = request['start'] # type: int stop = request['stop'] # type: Optional[int] if stop is None: my_addresses = [] # type: List[Address] my_hashes = [] # type: List[TransactionHash] for addy, hashes in iter_used_addresses(self.adapter, seed, start): my_addresses.append(addy) my_hashes.extend(hashes) else: ft_command = FindTransactionsCommand(self.adapter) my_addresses = AddressGenerator(seed).get_addresses( start, stop - start) my_hashes = ft_command(addresses=my_addresses).get('hashes') or [] account_balance = 0 if my_hashes: # Load balances for the addresses that we generated. gb_response = GetBalancesCommand( self.adapter)(addresses=my_addresses) for i, balance in enumerate(gb_response['balances']): my_addresses[i].balance = balance account_balance += balance return { 'addresses': list(sorted(my_addresses, key=attrgetter('key_index'))), 'balance': account_balance, 'bundles': get_bundles_from_transaction_hashes( adapter=self.adapter, transaction_hashes=my_hashes, inclusion_states=inclusion_states, ), }
def _execute(self, request): inclusion_states = request['inclusionStates'] # type: bool seed = request['seed'] # type: Seed start = request['start'] # type: int stop = request['stop'] # type: Optional[int] if stop is None: my_addresses = [] # type: List[Address] my_hashes = [] # type: List[TransactionHash] for addy, hashes in iter_used_addresses(self.adapter, seed, start): my_addresses.append(addy) my_hashes.extend(hashes) else: ft_command = FindTransactionsCommand(self.adapter) my_addresses = AddressGenerator(seed).get_addresses(start, stop - start) my_hashes = ft_command(addresses=my_addresses).get('hashes') or [] account_balance = 0 if my_hashes: # Load balances for the addresses that we generated. gb_response = GetBalancesCommand(self.adapter)(addresses=my_addresses) for i, balance in enumerate(gb_response['balances']): my_addresses[i].balance = balance account_balance += balance return { 'addresses': list(sorted(my_addresses, key=attrgetter('key_index'))), 'balance': account_balance, 'bundles': get_bundles_from_transaction_hashes( adapter = self.adapter, transaction_hashes = my_hashes, inclusion_states = inclusion_states, ), }
async def get_all_used_addresses(self, start=0): # `iter_used_addresses` is an async generator, so we have to use `async for` return [ address async for address, _ in iter_used_addresses( self.adapter, self.seed, start) ]