Skip to content

Commit

Permalink
Merge pull request iotaledger#190 from oskyk/181-security-level-in-ge…
Browse files Browse the repository at this point in the history
…t-account-data

iotaledger#181 security_level into get_account_data
  • Loading branch information
todofixthis authored Jul 1, 2018
2 parents d1d3646 + fbd44a7 commit 8f804e6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
14 changes: 12 additions & 2 deletions iota/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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::
Expand All @@ -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):
Expand Down
12 changes: 7 additions & 5 deletions iota/commands/extended/get_account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 []

Expand Down Expand Up @@ -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'
},
)

Expand Down
6 changes: 5 additions & 1 deletion test/commands/extended/get_account_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_pass_happy_path(self):
'start': 0,
'stop': 10,
'inclusionStates': True,
'security_level': 2
}

filter_ = self._filter(request)
Expand All @@ -58,6 +59,7 @@ def test_pass_compatible_types(self):
'start': 42,
'stop': 86,
'inclusionStates': True,
'security_level': 2
})

self.assertFilterPasses(filter_)
Expand All @@ -69,6 +71,7 @@ def test_pass_compatible_types(self):
'start': 42,
'stop': 86,
'inclusionStates': True,
'security_level': 2
},
)

Expand All @@ -89,6 +92,7 @@ def test_pass_optional_parameters_excluded(self):
'start': 0,
'stop': None,
'inclusionStates': False,
'security_level': 2
}
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f804e6

Please sign in to comment.