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

Update the core commands to match the latest IRI 1.8.1 release #236

Merged
merged 3 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ These methods are "low level" and generally do not need to be called
directly.

For the full documentation of all the Core API calls, please refer
to the `official documentation <https://iota.readme.io/>`__.
to the `official documentation <https://docs.iota.org/docs/node-software/0.1/
iri/references/api-reference>`__.

Extended API
============
Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Installation
============
PyOTA is compatible with Python 3.6, 3.5 and 2.7.
PyOTA is compatible with Python 3.7, 3.6, 3.5 and 2.7.

Install PyOTA using `pip`:

Expand Down Expand Up @@ -76,7 +76,7 @@ your API requests so that they contain the necessary authentication metadata.
)

.. _forum: https://forum.iota.org/
.. _official api: https://iota.readme.io/
.. _official api: https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference
.. _pyota-ccurl extension: https://pypi.python.org/pypi/PyOTA-CCurl
.. _run your own node.: http://iotasupport.com/headlessnode.shtml
.. _slack: http://slack.iota.org/
Expand Down
94 changes: 69 additions & 25 deletions iota/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class StrictIota(object):

References:

- https://iota.readme.io/docs/getting-started
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference
"""
commands = discover_commands('iota.commands.core')

Expand Down Expand Up @@ -100,7 +100,7 @@ def __getattr__(self, command):

References:

- https://iota.readme.io/docs/making-requests
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference
"""
# Fix an error when invoking :py:func:`help`.
# https://github.com/iotaledger/iota.lib.py/issues/41
Expand Down Expand Up @@ -165,7 +165,7 @@ def add_neighbors(self, uris):

References:

- https://iota.readme.io/docs/addneighors
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#addneighbors
"""
return core.AddNeighborsCommand(self.adapter)(uris=uris)

Expand All @@ -190,7 +190,7 @@ def attach_to_tangle(

References:

- https://iota.readme.io/docs/attachtotangle
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#attachtotangle
"""
if min_weight_magnitude is None:
min_weight_magnitude = self.default_min_weight_magnitude
Expand All @@ -212,7 +212,7 @@ def broadcast_transactions(self, trytes):

References:

- https://iota.readme.io/docs/broadcasttransactions
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#broadcasttransactions
"""
return core.BroadcastTransactionsCommand(self.adapter)(trytes=trytes)

Expand Down Expand Up @@ -242,6 +242,10 @@ def check_consistency(self, tails):
This field will only exist set if ``state`` is
``False``.
}

References:

- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#checkconsistency
"""
return core.CheckConsistencyCommand(self.adapter)(
tails=tails,
Expand Down Expand Up @@ -280,7 +284,7 @@ def find_transactions(

References:

- https://iota.readme.io/docs/findtransactions
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#findtransactions
"""
return core.FindTransactionsCommand(self.adapter)(
bundles=bundles,
Expand All @@ -289,8 +293,13 @@ def find_transactions(
approvees=approvees,
)

def get_balances(self, addresses, threshold=100):
# type: (Iterable[Address], int) -> dict
def get_balances(
self,
addresses, # type: Iterable[Address]
threshold=100, # type: int
tips=None, # type: Optional[Iterable[TransactionHash]]
):
# type: (...) -> dict
"""
Similar to :py:meth:`get_inclusion_states`. Returns the
confirmed balance which a list of addresses have at the latest
Expand All @@ -305,15 +314,19 @@ def get_balances(self, addresses, threshold=100):
List of addresses to get the confirmed balance for.

:param threshold:
Confirmation threshold.
Confirmation threshold between 0 and 100.

:param tips:
Tips whose history of transactions to traverse to find the balance.

References:

- https://iota.readme.io/docs/getbalances
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#getbalances
"""
return core.GetBalancesCommand(self.adapter)(
addresses=addresses,
threshold=threshold,
tips=tips,
)

def get_inclusion_states(self, transactions, tips):
Expand All @@ -334,13 +347,25 @@ def get_inclusion_states(self, transactions, tips):

References:

- https://iota.readme.io/docs/getinclusionstates
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#getinclusionstates
"""
return core.GetInclusionStatesCommand(self.adapter)(
transactions=transactions,
tips=tips,
)

def get_missing_transactions(self):
# type: () -> dict
"""
Returns all transaction hashes that a node is currently requesting
from its neighbors.

References:

- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#getmissingtransactions
"""
return core.GetMissingTransactionsCommand(self.adapter)()

def get_neighbors(self):
# type: () -> dict
"""
Expand All @@ -351,18 +376,29 @@ def get_neighbors(self):

References:

- https://iota.readme.io/docs/getneighborsactivity
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#getneighbors
"""
return core.GetNeighborsCommand(self.adapter)()

def get_node_api_configuration(self):
# type: () -> dict
"""
Returns a node's API configuration settings.

References:

- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#getnodeapiconfiguration
"""
return core.GetNodeAPIConfigurationCommand(self.adapter)()

def get_node_info(self):
# type: () -> dict
"""
Returns information about the node.

References:

- https://iota.readme.io/docs/getnodeinfo
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#getnodeinfo
"""
return core.GetNodeInfoCommand(self.adapter)()

Expand All @@ -374,13 +410,13 @@ def get_tips(self):

References:

- https://iota.readme.io/docs/gettips
- https://iota.readme.io/docs/glossary#iota-terms
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#gettips
- https://docs.iota.org/docs/dev-essentials/0.1/references/glossary
"""
return core.GetTipsCommand(self.adapter)()

def get_transactions_to_approve(self, depth):
# type: (int) -> dict
def get_transactions_to_approve(self, depth, reference=None):
# type: (int, Optional[TransactionHash]) -> dict
"""
Tip selection which returns ``trunkTransaction`` and
``branchTransaction``.
Expand All @@ -393,11 +429,19 @@ def get_transactions_to_approve(self, depth):
will perform for the network (as it will confirm more
transactions that way).

:param reference:
Transaction hash from which to start the weighted random walk.
Use this parameter to make sure the returned tip transaction hashes
approve a given reference transaction.

References:

- https://iota.readme.io/docs/gettransactionstoapprove
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#gettransactionstoapprove
"""
return core.GetTransactionsToApproveCommand(self.adapter)(depth=depth)
return core.GetTransactionsToApproveCommand(self.adapter)(
depth=depth,
reference=reference,
)

def get_trytes(self, hashes):
# type: (Iterable[TransactionHash]) -> dict
Expand All @@ -407,7 +451,7 @@ def get_trytes(self, hashes):

References:

- https://iota.readme.io/docs/gettrytes
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#gettrytes
"""
return core.GetTrytesCommand(self.adapter)(hashes=hashes)

Expand All @@ -419,7 +463,7 @@ def interrupt_attaching_to_tangle(self):

References:

- https://iota.readme.io/docs/interruptattachingtotangle
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#interruptattachingtotangle
"""
return core.InterruptAttachingToTangleCommand(self.adapter)()

Expand All @@ -435,7 +479,7 @@ def remove_neighbors(self, uris):

References:

- https://iota.readme.io/docs/removeneighors
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#removeneighbors
"""
return core.RemoveNeighborsCommand(self.adapter)(uris=uris)

Expand All @@ -449,7 +493,7 @@ def store_transactions(self, trytes):

References:

- https://iota.readme.io/docs/storetransactions
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#storetransactions
"""
return core.StoreTransactionsCommand(self.adapter)(trytes=trytes)

Expand All @@ -464,7 +508,7 @@ def were_addresses_spent_from(self, addresses):

References:

- https://iota.readme.io/docs/wereaddressesspentfrom
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference#wereaddressesspentfrom
"""
return core.WereAddressesSpentFromCommand(self.adapter)(
addresses=addresses,
Expand All @@ -478,7 +522,7 @@ class Iota(StrictIota):

References:

- https://iota.readme.io/docs/getting-started
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference
- https://github.com/iotaledger/wiki/blob/master/api-proposal.md
"""
commands = discover_commands('iota.commands.extended')
Expand Down
4 changes: 3 additions & 1 deletion iota/commands/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

References:

- https://iota.readme.io/docs/getting-started
- https://docs.iota.org/docs/node-software/0.1/iri/references/api-reference
"""

from __future__ import absolute_import, division, print_function, \
Expand All @@ -17,7 +17,9 @@
from .find_transactions import *
from .get_balances import *
from .get_inclusion_states import *
from .get_missing_transactions import *
from .get_neighbors import *
from .get_node_api_configuration import *
from .get_node_info import *
from .get_tips import *
from .get_transactions_to_approve import *
Expand Down
11 changes: 9 additions & 2 deletions iota/commands/core/check_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import filters as f

from iota import TransactionHash
from iota.commands import FilterCommand, RequestFilter
from iota.commands import FilterCommand, RequestFilter, ResponseFilter
from iota.filters import Trytes

__all__ = [
Expand All @@ -25,7 +25,7 @@ def get_request_filter(self):
return CheckConsistencyRequestFilter()

def get_response_filter(self):
pass
return CheckConsistencyResponseFilter()


class CheckConsistencyRequestFilter(RequestFilter):
Expand All @@ -36,3 +36,10 @@ def __init__(self):
f.Array |
f.FilterRepeater(f.Required | Trytes(TransactionHash)),
})


class CheckConsistencyResponseFilter(ResponseFilter):
def __init__(self):
super(CheckConsistencyResponseFilter, self).__init__({
'state': f.Required | f.Type(bool),
})
pdecol marked this conversation as resolved.
Show resolved Hide resolved
40 changes: 36 additions & 4 deletions iota/commands/core/get_balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
unicode_literals

import filters as f
from six import iteritems

from iota import Address
from iota import TransactionHash
from iota.commands import FilterCommand, RequestFilter, ResponseFilter
from iota.filters import AddressNoChecksum, Trytes

Expand Down Expand Up @@ -44,19 +45,50 @@ def __init__(self):
f.Min(0) |
f.Max(100) |
f.Optional(default=100),

'tips':
f.Array | f.FilterRepeater(
f.Required |
Trytes(TransactionHash) |
f.Unicode(encoding='ascii', normalize=False),
)
},

allow_missing_keys={
'threshold',
'threshold', 'tips',
},
)

def _apply(self, value):
value = super(GetBalancesRequestFilter, self)._apply(
value
) # type: dict

if self._has_errors:
return value

# Remove null search terms.
# Note: We will assume that empty lists are intentional.
search_terms = {
term: query
for term, query in iteritems(value)
if query is not None
}

return search_terms


class GetBalancesResponseFilter(ResponseFilter):
def __init__(self):
super(GetBalancesResponseFilter, self).__init__({
'balances': f.Array | f.FilterRepeater(f.Int),

'milestone':
f.ByteString(encoding='ascii') | Trytes(Address),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is a potential backwards incompatible change. milestone was removed in IRI version 1.4.1.6 (https://github.com/iotaledger/iri/blob/v1.4.1.6/src/main/java/com/iota/iri/service/dto/GetBalancesResponse.java) which was released on the 6th of January 2018. Since this was more than one and a half years ago I think it is justified to remove it here too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 Sounds good to me.

'milestoneIndex': f.Int,

'references':
f.Array | f.FilterRepeater(
f.Required |
Trytes(TransactionHash) |
f.Unicode(encoding='ascii', normalize=False),
),
pdecol marked this conversation as resolved.
Show resolved Hide resolved
})
Loading