Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit d4662f5

Browse files
committed
[#145][#184] Reformat for PEP-8, remove dead code.
1 parent 0d57510 commit d4662f5

14 files changed

+1095
-1053
lines changed
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
# coding=utf-8
22
from __future__ import absolute_import, division, print_function, \
3-
unicode_literals
3+
unicode_literals
44

55
from iota.commands import FilterCommand
66
from iota.commands.core.broadcast_transactions import \
7-
BroadcastTransactionsCommand
7+
BroadcastTransactionsCommand
88
from iota.commands.core.store_transactions import StoreTransactionsCommand
99

1010
__all__ = [
11-
'BroadcastAndStoreCommand',
11+
'BroadcastAndStoreCommand',
1212
]
1313

1414

1515
class BroadcastAndStoreCommand(FilterCommand):
16-
"""
17-
Executes ``broadcastAndStore`` extended API command.
16+
"""
17+
Executes ``broadcastAndStore`` extended API command.
1818
19-
See :py:meth:`iota.api.Iota.broadcast_and_store` for more info.
20-
"""
21-
command = 'broadcastAndStore'
19+
See :py:meth:`iota.api.Iota.broadcast_and_store` for more info.
20+
"""
21+
command = 'broadcastAndStore'
2222

23-
def get_request_filter(self):
24-
pass
23+
def get_request_filter(self):
24+
pass
2525

26-
def get_response_filter(self):
27-
pass
26+
def get_response_filter(self):
27+
pass
2828

29-
def _execute(self, request):
30-
BroadcastTransactionsCommand(self.adapter)(**request)
31-
StoreTransactionsCommand(self.adapter)(**request)
32-
return {
33-
'trytes': request['trytes'],
34-
}
29+
def _execute(self, request):
30+
BroadcastTransactionsCommand(self.adapter)(**request)
31+
StoreTransactionsCommand(self.adapter)(**request)
32+
return {
33+
'trytes': request['trytes'],
34+
}
Lines changed: 127 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,153 @@
11
# coding=utf-8
22
from __future__ import absolute_import, division, print_function, \
3-
unicode_literals
3+
unicode_literals
44

55
from operator import attrgetter
66
from typing import List, Optional
77

88
import filters as f
9+
910
from iota import Address, TransactionHash
1011
from iota.commands import FilterCommand, RequestFilter
1112
from iota.commands.core.find_transactions import FindTransactionsCommand
1213
from iota.commands.core.get_balances import GetBalancesCommand
1314
from iota.commands.extended.utils import get_bundles_from_transaction_hashes, \
14-
iter_used_addresses
15+
iter_used_addresses
1516
from iota.crypto.addresses import AddressGenerator
1617
from iota.crypto.types import Seed
1718
from iota.filters import Trytes
1819

1920
__all__ = [
20-
'GetAccountDataCommand',
21+
'GetAccountDataCommand',
2122
]
2223

2324

2425
class GetAccountDataCommand(FilterCommand):
25-
"""
26-
Executes ``getAccountData`` extended API command.
27-
28-
See :py:meth:`iota.api.Iota.get_account_data` for more info.
29-
"""
30-
command = 'getAccountData'
31-
32-
def get_request_filter(self):
33-
return GetAccountDataRequestFilter()
34-
35-
def get_response_filter(self):
36-
pass
37-
38-
def _execute(self, request):
39-
inclusion_states = request['inclusionStates'] # type: bool
40-
seed = request['seed'] # type: Seed
41-
start = request['start'] # type: int
42-
stop = request['stop'] # type: Optional[int]
43-
44-
if stop is None:
45-
my_addresses = [] # type: List[Address]
46-
my_hashes = [] # type: List[TransactionHash]
47-
48-
for addy, hashes in iter_used_addresses(self.adapter, seed, start):
49-
my_addresses.append(addy)
50-
my_hashes.extend(hashes)
51-
else:
52-
ft_command = FindTransactionsCommand(self.adapter)
53-
54-
my_addresses = AddressGenerator(seed).get_addresses(start, stop - start)
55-
my_hashes = ft_command(addresses=my_addresses).get('hashes') or []
56-
57-
account_balance = 0
58-
if my_hashes:
59-
# Load balances for the addresses that we generated.
60-
gb_response = GetBalancesCommand(self.adapter)(addresses=my_addresses)
61-
62-
for i, balance in enumerate(gb_response['balances']):
63-
my_addresses[i].balance = balance
64-
account_balance += balance
65-
66-
return {
67-
'addresses': list(sorted(my_addresses, key=attrgetter('key_index'))),
68-
'balance': account_balance,
69-
70-
'bundles':
71-
get_bundles_from_transaction_hashes(
72-
adapter = self.adapter,
73-
transaction_hashes = my_hashes,
74-
inclusion_states = inclusion_states,
75-
),
76-
}
26+
"""
27+
Executes ``getAccountData`` extended API command.
28+
29+
See :py:meth:`iota.api.Iota.get_account_data` for more info.
30+
"""
31+
command = 'getAccountData'
32+
33+
def get_request_filter(self):
34+
return GetAccountDataRequestFilter()
35+
36+
def get_response_filter(self):
37+
pass
38+
39+
def _execute(self, request):
40+
inclusion_states = request['inclusionStates'] # type: bool
41+
seed = request['seed'] # type: Seed
42+
start = request['start'] # type: int
43+
stop = request['stop'] # type: Optional[int]
44+
45+
if stop is None:
46+
my_addresses = [] # type: List[Address]
47+
my_hashes = [] # type: List[TransactionHash]
48+
49+
for addy, hashes in iter_used_addresses(self.adapter, seed, start):
50+
my_addresses.append(addy)
51+
my_hashes.extend(hashes)
52+
else:
53+
ft_command = FindTransactionsCommand(self.adapter)
54+
55+
my_addresses = (
56+
AddressGenerator(seed).get_addresses(start, stop - start)
57+
)
58+
my_hashes = ft_command(addresses=my_addresses).get('hashes') or []
59+
60+
account_balance = 0
61+
if my_hashes:
62+
# Load balances for the addresses that we generated.
63+
gb_response = (
64+
GetBalancesCommand(self.adapter)(addresses=my_addresses)
65+
)
66+
67+
for i, balance in enumerate(gb_response['balances']):
68+
my_addresses[i].balance = balance
69+
account_balance += balance
70+
71+
return {
72+
'addresses':
73+
list(sorted(my_addresses, key=attrgetter('key_index'))),
74+
75+
'balance': account_balance,
76+
77+
'bundles':
78+
get_bundles_from_transaction_hashes(
79+
adapter=self.adapter,
80+
transaction_hashes=my_hashes,
81+
inclusion_states=inclusion_states,
82+
),
83+
}
7784

7885

7986
class GetAccountDataRequestFilter(RequestFilter):
80-
MAX_INTERVAL = 500
81-
82-
CODE_INTERVAL_INVALID = 'interval_invalid'
83-
CODE_INTERVAL_TOO_BIG = 'interval_too_big'
84-
85-
templates = {
86-
CODE_INTERVAL_INVALID: '``start`` must be <= ``stop``',
87-
CODE_INTERVAL_TOO_BIG: '``stop`` - ``start`` must be <= {max_interval}',
88-
}
89-
90-
def __init__(self):
91-
super(GetAccountDataRequestFilter, self).__init__(
92-
{
93-
# Required parameters.
94-
'seed': f.Required | Trytes(result_type=Seed),
95-
96-
# Optional parameters.
97-
'stop': f.Type(int) | f.Min(0),
98-
'start': f.Type(int) | f.Min(0) | f.Optional(0),
99-
100-
'inclusionStates': f.Type(bool) | f.Optional(False),
101-
},
102-
103-
allow_missing_keys = {
104-
'stop',
105-
'inclusionStates',
106-
'start',
107-
},
108-
)
109-
110-
def _apply(self, value):
111-
# noinspection PyProtectedMember
112-
filtered = super(GetAccountDataRequestFilter, self)._apply(value)
113-
114-
if self._has_errors:
115-
return filtered
116-
117-
if filtered['stop'] is not None:
118-
if filtered['start'] > filtered['stop']:
119-
filtered['start'] = self._invalid_value(
120-
value = filtered['start'],
121-
reason = self.CODE_INTERVAL_INVALID,
122-
sub_key = 'start',
123-
124-
context = {
125-
'start': filtered['start'],
126-
'stop': filtered['stop'],
127-
},
128-
)
129-
elif (filtered['stop'] - filtered['start']) > self.MAX_INTERVAL:
130-
filtered['stop'] = self._invalid_value(
131-
value = filtered['stop'],
132-
reason = self.CODE_INTERVAL_TOO_BIG,
133-
sub_key = 'stop',
134-
135-
context = {
136-
'start': filtered['start'],
137-
'stop': filtered['stop'],
138-
},
139-
140-
template_vars = {
141-
'max_interval': self.MAX_INTERVAL,
142-
},
87+
MAX_INTERVAL = 500
88+
89+
CODE_INTERVAL_INVALID = 'interval_invalid'
90+
CODE_INTERVAL_TOO_BIG = 'interval_too_big'
91+
92+
templates = {
93+
CODE_INTERVAL_INVALID: '``start`` must be <= ``stop``',
94+
CODE_INTERVAL_TOO_BIG: '``stop`` - ``start`` must be <= {max_interval}',
95+
}
96+
97+
def __init__(self):
98+
super(GetAccountDataRequestFilter, self).__init__(
99+
{
100+
# Required parameters.
101+
'seed': f.Required | Trytes(Seed),
102+
103+
# Optional parameters.
104+
'stop': f.Type(int) | f.Min(0),
105+
'start': f.Type(int) | f.Min(0) | f.Optional(0),
106+
107+
'inclusionStates': f.Type(bool) | f.Optional(False),
108+
},
109+
110+
allow_missing_keys={
111+
'stop',
112+
'inclusionStates',
113+
'start',
114+
},
143115
)
144116

145-
return filtered
117+
def _apply(self, value):
118+
# noinspection PyProtectedMember
119+
filtered = super(GetAccountDataRequestFilter, self)._apply(value)
120+
121+
if self._has_errors:
122+
return filtered
123+
124+
if filtered['stop'] is not None:
125+
if filtered['start'] > filtered['stop']:
126+
filtered['start'] = self._invalid_value(
127+
value=filtered['start'],
128+
reason=self.CODE_INTERVAL_INVALID,
129+
sub_key='start',
130+
131+
context={
132+
'start': filtered['start'],
133+
'stop': filtered['stop'],
134+
},
135+
)
136+
137+
elif (filtered['stop'] - filtered['start']) > self.MAX_INTERVAL:
138+
filtered['stop'] = self._invalid_value(
139+
value=filtered['stop'],
140+
reason=self.CODE_INTERVAL_TOO_BIG,
141+
sub_key='stop',
142+
143+
context={
144+
'start': filtered['start'],
145+
'stop': filtered['stop'],
146+
},
147+
148+
template_vars={
149+
'max_interval': self.MAX_INTERVAL,
150+
},
151+
)
152+
153+
return filtered

0 commit comments

Comments
 (0)