Skip to content

Commit 23d5c05

Browse files
committed
Fixes iotaledger#288 Remove tips from get_inclusion_states
- `tips` parameter is no longer in use from IRI 1.9.0. - GetInclusionStates API endpoint returns if tx is confirmed since the last milestone. - `get_latest_iclusion_states` extended API becomes irrelevant, remove in this commit. - Modify components using it, rely on `get_inclusion_states`. - Update tests. - Update documentation.
1 parent 1eef60b commit 23d5c05

10 files changed

+43
-456
lines changed

docs/extended_api.rst

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ tasks such as sending and receiving transfers.
3030
--------------
3131
.. automethod:: Iota.get_inputs
3232

33-
``get_latest_inclusion``
34-
------------------------
35-
.. automethod:: Iota.get_latest_inclusion
36-
3733
``get_new_addresses``
3834
---------------------
3935
.. automethod:: Iota.get_new_addresses

iota/api.py

+3-33
Original file line numberDiff line numberDiff line change
@@ -384,22 +384,17 @@ def get_balances(
384384
tips=tips,
385385
)
386386

387-
def get_inclusion_states(self, transactions, tips):
388-
# type: (Iterable[TransactionHash], Iterable[TransactionHash]) -> dict
387+
def get_inclusion_states(self, transactions):
388+
# type: (Iterable[TransactionHash]) -> dict
389389
"""
390390
Get the inclusion states of a set of transactions. This is for
391391
determining if a transaction was accepted and confirmed by the
392-
network or not. You can search for multiple tips (and thus,
393-
milestones) to get past inclusion states of transactions.
392+
network or not.
394393
395394
:param Iterable[TransactionHash] transactions:
396395
List of transactions you want to get the inclusion state
397396
for.
398397
399-
:param Iterable[TransactionHash] tips:
400-
List of tips (including milestones) you want to search for
401-
the inclusion state.
402-
403398
:return:
404399
``dict`` with the following structure::
405400
@@ -418,7 +413,6 @@ def get_inclusion_states(self, transactions, tips):
418413
"""
419414
return core.GetInclusionStatesCommand(self.adapter)(
420415
transactions=transactions,
421-
tips=tips,
422416
)
423417

424418
def get_missing_transactions(self):
@@ -1123,30 +1117,6 @@ def get_inputs(
11231117
securityLevel=security_level
11241118
)
11251119

1126-
def get_latest_inclusion(self, hashes):
1127-
# type: (Iterable[TransactionHash]) -> Dict[TransactionHash, bool]
1128-
"""
1129-
Fetches the inclusion state for the specified transaction
1130-
hashes, as of the latest milestone that the node has processed.
1131-
1132-
Effectively, this is :py:meth:`get_node_info` +
1133-
:py:meth:`get_inclusion_states`.
1134-
1135-
:param Iterable[TransactionHash] hashes:
1136-
List of transaction hashes.
1137-
1138-
:return:
1139-
``dict`` with the following structure::
1140-
1141-
{
1142-
"states": Dict[TransactionHash, bool]
1143-
``dict`` with one boolean per transaction hash in
1144-
``hashes``.
1145-
}
1146-
1147-
"""
1148-
return extended.GetLatestInclusionCommand(self.adapter)(hashes=hashes)
1149-
11501120
def get_new_addresses(
11511121
self,
11521122
index=0,

iota/commands/core/get_inclusion_states.py

-9
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,5 @@ def __init__(self):
3535
# Required parameters.
3636
'transactions':
3737
StringifiedTrytesArray(TransactionHash) | f.Required,
38-
39-
# Optional parameters.
40-
'tips':
41-
StringifiedTrytesArray(TransactionHash) |
42-
f.Optional(default=[]),
43-
},
44-
45-
allow_missing_keys={
46-
'tips',
4738
},
4839
)

iota/commands/extended/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from .get_account_data import *
1818
from .get_bundles import *
1919
from .get_inputs import *
20-
from .get_latest_inclusion import *
2120
from .get_new_addresses import *
2221
from .get_transaction_objects import *
2322
from .get_transfers import *

iota/commands/extended/get_latest_inclusion.py

-56
This file was deleted.

iota/commands/extended/is_reattachable.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
from iota import Address
1010
from iota.commands import FilterCommand, RequestFilter, ResponseFilter
11-
from iota.commands.extended import FindTransactionObjectsCommand, \
12-
GetLatestInclusionCommand
11+
from iota.commands.extended import FindTransactionObjectsCommand
12+
from iota.commands.core import GetInclusionStatesCommand
1313
from iota.filters import Trytes, StringifiedTrytesArray
1414

1515
__all__ = [
@@ -52,14 +52,15 @@ def _execute(self, request):
5252
}
5353

5454
# Fetch inclusion states.
55-
inclusion_states = GetLatestInclusionCommand(adapter=self.adapter)(
56-
hashes=list(transaction_map.values()),
55+
inclusion_states = GetInclusionStatesCommand(adapter=self.adapter)(
56+
transactions=list(transaction_map.values()),
5757
)
58-
inclusion_states = inclusion_states['states']
58+
inclusion_states_map = dict(zip(
59+
list(transaction_map.keys()), inclusion_states['states']))
5960

6061
return {
6162
'reattachable': [
62-
not inclusion_states[transaction_map[address]]
63+
not inclusion_states_map[address]
6364
for address in addresses
6465
],
6566
}

iota/commands/extended/utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
WereAddressesSpentFromCommand
1414
from iota.commands.extended import FindTransactionObjectsCommand
1515
from iota.commands.extended.get_bundles import GetBundlesCommand
16-
from iota.commands.extended.get_latest_inclusion import \
17-
GetLatestInclusionCommand
16+
from iota.commands.core.get_inclusion_states import \
17+
GetInclusionStatesCommand
1818
from iota.crypto.addresses import AddressGenerator
1919
from iota.crypto.types import Seed
2020

@@ -109,12 +109,12 @@ def get_bundles_from_transaction_hashes(
109109

110110
# Attach inclusion states, if requested.
111111
if inclusion_states:
112-
gli_response = GetLatestInclusionCommand(adapter)(
113-
hashes=list(tail_transaction_hashes),
112+
gli_response = GetInclusionStatesCommand(adapter)(
113+
transactions=list(tail_transaction_hashes),
114114
)
115115

116-
for txn in tail_transactions:
117-
txn.is_confirmed = gli_response['states'].get(txn.hash)
116+
for txn, state in zip(tail_transactions, gli_response['states']):
117+
txn.is_confirmed = state
118118

119119
# Find the bundles for each transaction.
120120
for txn in tail_transactions:

test/commands/core/get_inclusion_states_test.py

+23-82
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,13 @@ def test_pass_happy_path(self):
3939
request = {
4040
# Raw trytes are extracted to match the IRI's JSON protocol.
4141
'transactions': [self.trytes1, self.trytes2],
42-
43-
# These values would normally be different from
44-
# ``transactions``, but for purposes of this unit test, we just
45-
# need to make sure the format is correct.
46-
'tips': [self.trytes1, self.trytes2],
4742
}
4843

4944
filter_ = self._filter(request)
5045

5146
self.assertFilterPasses(filter_)
5247
self.assertDictEqual(filter_.cleaned_data, request)
5348

54-
def test_pass_optional_parameters_omitted(self):
55-
"""
56-
The request omits optional parameters.
57-
"""
58-
filter_ = self._filter({
59-
'transactions': [self.trytes1, self.trytes2],
60-
})
61-
62-
self.assertFilterPasses(filter_)
63-
self.assertDictEqual(
64-
filter_.cleaned_data,
65-
66-
{
67-
'tips': [],
68-
'transactions': [self.trytes1, self.trytes2],
69-
},
70-
)
71-
7249
def test_pass_compatible_types(self):
7350
"""
7451
The request contains values that can be converted to expected
@@ -79,19 +56,13 @@ def test_pass_compatible_types(self):
7956
TransactionHash(self.trytes1),
8057
bytearray(self.trytes2.encode('ascii')),
8158
],
82-
83-
'tips': [
84-
TransactionHash(self.trytes1),
85-
bytearray(self.trytes2.encode('ascii')),
86-
],
8759
})
8860

8961
self.assertFilterPasses(filter_)
9062
self.assertDictEqual(
9163
filter_.cleaned_data,
9264

9365
{
94-
'tips': [self.trytes1, self.trytes2],
9566
'transactions': [self.trytes1, self.trytes2],
9667
},
9768
)
@@ -116,12 +87,12 @@ def test_fail_unexpected_parameters(self):
11687
{
11788
'transactions': [TransactionHash(self.trytes1)],
11889

119-
# I bring scientists, you bring a rock star.
120-
'foo': 'bar',
90+
# 'tips' deprecated in IRI 1.9.0
91+
'tips': [self.trytes1]
12192
},
12293

12394
{
124-
'foo': [f.FilterMapper.CODE_EXTRA_KEY],
95+
'tips': [f.FilterMapper.CODE_EXTRA_KEY],
12596
},
12697
)
12798

@@ -201,62 +172,18 @@ def test_fail_transactions_contents_invalid(self):
201172
},
202173
)
203174

204-
def test_fail_tips_wrong_type(self):
205-
"""
206-
``tips`` is not an array.
207-
"""
208-
self.assertFilterErrors(
209-
{
210-
'tips': TransactionHash(self.trytes2),
211-
212-
'transactions': [TransactionHash(self.trytes1)],
213-
},
214-
215-
{
216-
'tips': [f.Type.CODE_WRONG_TYPE],
217-
},
218-
)
219-
220-
def test_fail_tips_contents_invalid(self):
221-
"""
222-
``tips`` contains invalid values.
223-
"""
224-
self.assertFilterErrors(
225-
{
226-
'tips': [
227-
b'',
228-
True,
229-
None,
230-
b'not valid trytes',
231-
232-
# This is actually valid; I just added it to make sure the
233-
# filter isn't cheating!
234-
TryteString(self.trytes1),
235-
236-
2130706433,
237-
b'9' * 82,
238-
],
239-
240-
'transactions': [TransactionHash(self.trytes1)],
241-
},
242-
243-
{
244-
'tips.0': [f.Required.CODE_EMPTY],
245-
'tips.1': [f.Type.CODE_WRONG_TYPE],
246-
'tips.2': [f.Required.CODE_EMPTY],
247-
'tips.3': [Trytes.CODE_NOT_TRYTES],
248-
'tips.5': [f.Type.CODE_WRONG_TYPE],
249-
'tips.6': [Trytes.CODE_WRONG_FORMAT],
250-
},
251-
)
252-
253175

254176
class GetInclusionStatesCommandTestCase(TestCase):
255177
def setUp(self):
256178
super(GetInclusionStatesCommandTestCase, self).setUp()
257179

258180
self.adapter = MockAdapter()
259181

182+
self.trytes1 = (
183+
'TESTVALUE9DONTUSEINPRODUCTION99999GCXWZZ'
184+
'ZKNRIZENRRXGPAGJOSSWQQOJDD9VGQRMEFCOIFLQB'
185+
)
186+
260187
def test_wireup(self):
261188
"""
262189
Verify that the command is wired up correctly.
@@ -270,11 +197,25 @@ def test_wireup(self):
270197
api = Iota(self.adapter)
271198

272199
# Don't need to call with proper args here.
273-
response = api.get_inclusion_states('transactions', 'tips')
200+
response = api.get_inclusion_states('transactions')
274201

275202
self.assertTrue(mocked_command.called)
276203

277204
self.assertEqual(
278205
response,
279206
'You found me!'
280207
)
208+
209+
def test_fail_on_tips(self):
210+
"""
211+
Fail on provided 'tips' parameter.
212+
213+
Dperecated in IRI 1.9.0
214+
"""
215+
api = Iota(self.adapter)
216+
217+
with self.assertRaises(TypeError):
218+
response = api.get_inclusion_states(
219+
transactions=[self.trytes1],
220+
tips=[self.trytes1]
221+
)

0 commit comments

Comments
 (0)