Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
55 changes: 55 additions & 0 deletions examples/sandbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# coding=utf-8
from __future__ import absolute_import, division, print_function, \
unicode_literals

from iota import *
from iota.adapter.sandbox import SandboxAdapter


# Create the API object.
iota =\
Iota(
# To use sandbox mode, inject a ``SandboxAdapter``.
adapter = SandboxAdapter(
# URI of the sandbox node.
uri = 'https://sandbox.iotatoken.com/api/v1/',

# Access token used to authenticate requests.
# Contact the node maintainer to get an access token.
auth_token = 'auth token goes here',
),

# Seed used for cryptographic functions.
# If null, a random seed will be generated.
seed = b'SEED9GOES9HERE',
)

# Example of sending a transfer using the sandbox.
# For more information, see :py:meth:`Iota.send_transfer`.
# noinspection SpellCheckingInspection
iota.send_transfer(
depth = 100,

# One or more :py:class:`ProposedTransaction` objects to add to the
# bundle.
transfers = [
ProposedTransaction(
# Recipient of the transfer.
address =
Address(
b'TESTVALUE9DONTUSEINPRODUCTION99999FBFFTG'
b'QFWEHEL9KCAFXBJBXGE9HID9XCOHFIDABHDG9AHDR'
),

# Amount of IOTA to transfer.
# This value may be zero.
value = 42,

# Optional tag to attach to the transfer.
tag = Tag(b'EXAMPLE'),

# Optional message to include with the transfer.
message = TryteString.from_string('Hello, Tangle!'),
),
],
)
41 changes: 14 additions & 27 deletions examples/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from argparse import ArgumentParser
from getpass import getpass as secure_input
from logging import INFO, basicConfig, getLogger
from logging import DEBUG, basicConfig, getLogger
from sys import argv, stderr

from six import text_type
Expand All @@ -18,10 +18,10 @@

from iota import __version__
from iota.adapter import resolve_adapter
from iota.adapter.wrappers import LogWrapper, RoutingWrapper
from iota.adapter.wrappers import RoutingWrapper


basicConfig(level=INFO, stream=stderr)
basicConfig(level=DEBUG, stream=stderr)


def main(uri, testnet, pow_uri, debug_requests):
Expand All @@ -34,16 +34,23 @@ def main(uri, testnet, pow_uri, debug_requests):
if isinstance(seed, text_type):
seed = seed.encode('ascii')

adapter_ = resolve_adapter(uri)

# If ``pow_uri`` is specified, route POW requests to a separate node.
adapter_ = create_adapter(uri, debug_requests)
if pow_uri:
pow_adapter = create_adapter(pow_uri, debug_requests)
pow_adapter = resolve_adapter(pow_uri)

adapter_ =\
RoutingWrapper(adapter_)\
.add_route('attachToTangle', pow_adapter)\
.add_route('interruptAttachingToTangle', pow_adapter)

# If ``debug_requests`` is specified, log HTTP requests/responses.
if debug_requests:
logger = getLogger(__name__)
logger.setLevel(DEBUG)
adapter_.set_logger(logger)

iota = Iota(adapter_, seed=seed, testnet=testnet)

_banner = (
Expand All @@ -57,26 +64,6 @@ def main(uri, testnet, pow_uri, debug_requests):
start_shell(iota, _banner)


def create_adapter(uri, debug):
# type: (Text, bool) -> BaseAdapter
"""
Creates an adapter with the specified settings.

:param uri:
Node URI.

:param debug:
Whether to attach a LogWrapper to the adapter.
"""
adapter_ = resolve_adapter(uri)

return (
LogWrapper(adapter_, getLogger(__name__), INFO)
if debug
else adapter_
)


def start_shell(iota, _banner):
"""
Starts the shell with limited scope.
Expand All @@ -102,11 +89,11 @@ def start_shell(iota, _banner):
parser.add_argument(
'--uri',
type = text_type,
default = 'udp://localhost:14265/',
default = 'http://localhost:14265/',

help =
'URI of the node to connect to '
'(defaults to udp://localhost:14265/).',
'(defaults to http://localhost:14265/).',
)

parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
name = 'PyOTA',
description = 'IOTA API library for Python',
url = 'https://github.com/iotaledger/iota.lib.py',
version = '1.0.0',
version = '1.1.0',

packages = find_packages('src'),
include_package_data = True,
Expand All @@ -37,7 +37,7 @@

install_requires = [
'filters',
'requests',
'requests[security]',
'six',
'typing',
],
Expand Down
Loading