diff --git a/iota/api.py b/iota/api.py index d17eee0..a932ab1 100644 --- a/iota/api.py +++ b/iota/api.py @@ -511,8 +511,8 @@ def broadcast_and_store(self, trytes): """ return extended.BroadcastAndStoreCommand(self.adapter)(trytes=trytes) - def get_account_data(self, start=0, stop=None, inclusion_states=False): - # type: (int, Optional[int], bool) -> dict + def get_account_data(self, start=0, stop=None, inclusion_states=False, security_level=None): + # type: (int, Optional[int], bool, Optional[int]) -> dict """ More comprehensive version of :py:meth:`get_transfers` that returns addresses and account balance in addition to bundles. @@ -539,6 +539,15 @@ def get_account_data(self, start=0, stop=None, inclusion_states=False): This requires an additional API call to the node, so it is disabled by default. + :param security_level: + Number of iterations to use when generating new addresses + (see :py:meth:`get_new_addresses`). + + This value must be between 1 and 3, inclusive. + + If not set, defaults to + :py:attr:`AddressGenerator.DEFAULT_SECURITY_LEVEL`. + :return: Dict with the following structure:: @@ -562,6 +571,7 @@ def get_account_data(self, start=0, stop=None, inclusion_states=False): start=start, stop=stop, inclusionStates=inclusion_states, + security_level=security_level ) def get_bundles(self, transaction): diff --git a/iota/commands/extended/get_account_data.py b/iota/commands/extended/get_account_data.py index 12ef466..7235d10 100644 --- a/iota/commands/extended/get_account_data.py +++ b/iota/commands/extended/get_account_data.py @@ -15,7 +15,7 @@ iter_used_addresses from iota.crypto.addresses import AddressGenerator from iota.crypto.types import Seed -from iota.filters import Trytes +from iota.filters import Trytes, SecurityLevel __all__ = [ 'GetAccountDataCommand', @@ -41,19 +41,20 @@ def _execute(self, request): seed = request['seed'] # type: Seed start = request['start'] # type: int stop = request['stop'] # type: Optional[int] + security_level = request['security_level'] # 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): + 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).get_addresses(start, stop - start) + AddressGenerator(seed, security_level).get_addresses(start, stop - start) ) my_hashes = ft_command(addresses=my_addresses).get('hashes') or [] @@ -103,14 +104,15 @@ def __init__(self): # Optional parameters. 'stop': f.Type(int) | f.Min(0), 'start': f.Type(int) | f.Min(0) | f.Optional(0), - 'inclusionStates': f.Type(bool) | f.Optional(False), + 'security_level': SecurityLevel }, allow_missing_keys={ 'stop', - 'inclusionStates', 'start', + 'inclusionStates', + 'security_level' }, ) diff --git a/test/commands/extended/get_account_data_test.py b/test/commands/extended/get_account_data_test.py index f48a039..fd743f7 100644 --- a/test/commands/extended/get_account_data_test.py +++ b/test/commands/extended/get_account_data_test.py @@ -37,6 +37,7 @@ def test_pass_happy_path(self): 'start': 0, 'stop': 10, 'inclusionStates': True, + 'security_level': 2 } filter_ = self._filter(request) @@ -58,6 +59,7 @@ def test_pass_compatible_types(self): 'start': 42, 'stop': 86, 'inclusionStates': True, + 'security_level': 2 }) self.assertFilterPasses(filter_) @@ -69,6 +71,7 @@ def test_pass_compatible_types(self): 'start': 42, 'stop': 86, 'inclusionStates': True, + 'security_level': 2 }, ) @@ -89,6 +92,7 @@ def test_pass_optional_parameters_excluded(self): 'start': 0, 'stop': None, 'inclusionStates': False, + 'security_level': 2 } ) @@ -369,7 +373,7 @@ def test_happy_path(self): Loading account data for an account. """ # noinspection PyUnusedLocal - def mock_iter_used_addresses(adapter, seed, start): + def mock_iter_used_addresses(adapter, seed, start, security_level): """ Mocks the ``iter_used_addresses`` function, so that we can simulate its functionality without actually connecting to the