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

Commit 97cdd1e

Browse files
authored
Merge pull request #208 from iotaledger/release/2.0.7
PyOTA v2.0.7
2 parents 3f452a6 + 6c44d4f commit 97cdd1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+7935
-7443
lines changed

examples/address_generator.py

+105-100
Original file line numberDiff line numberDiff line change
@@ -4,128 +4,133 @@
44
"""
55

66
from __future__ import absolute_import, division, print_function, \
7-
unicode_literals
7+
unicode_literals
88

99
from argparse import ArgumentParser
1010
from getpass import getpass as secure_input
1111
from sys import argv
1212
from typing import Optional, Text
1313

14-
from iota import __version__, Iota
14+
from six import binary_type, moves as compat, text_type
15+
16+
from iota import Iota, __version__
1517
from iota.crypto.addresses import AddressGenerator
1618
from iota.crypto.types import Seed
17-
from six import binary_type, moves as compat, text_type
1819

1920

2021
def main(uri, index, count, security, checksum):
21-
# type: (Text, int, Optional[int], Optional[int], bool) -> None
22-
seed = get_seed()
22+
# type: (Text, int, Optional[int], Optional[int], bool) -> None
23+
seed = get_seed()
2324

24-
# Create the API instance.
25-
# Note: If ``seed`` is null, a random seed will be generated.
26-
api = Iota(uri, seed)
25+
# Create the API instance.
26+
# Note: If ``seed`` is null, a random seed will be generated.
27+
api = Iota(uri, seed)
2728

28-
# If we generated a random seed, then we need to display it to the
29-
# user, or else they won't be able to use their new addresses!
30-
if not seed:
31-
print('A random seed has been generated. Press return to see it.')
32-
output_seed(api.seed)
29+
# If we generated a random seed, then we need to display it to the
30+
# user, or else they won't be able to use their new addresses!
31+
if not seed:
32+
print('A random seed has been generated. Press return to see it.')
33+
output_seed(api.seed)
3334

34-
print('Generating addresses. This may take a few minutes...')
35-
print('')
35+
print('Generating addresses. This may take a few minutes...')
36+
print('')
3637

37-
# Here's where all the magic happens!
38-
api_response = api.get_new_addresses(index, count, security, checksum)
39-
for addy in api_response['addresses']:
40-
print(binary_type(addy).decode('ascii'))
38+
# Here's where all the magic happens!
39+
api_response = api.get_new_addresses(index, count, security, checksum)
40+
for addy in api_response['addresses']:
41+
print(binary_type(addy).decode('ascii'))
4142

42-
print('')
43+
print('')
4344

4445

4546
def get_seed():
46-
# type: () -> binary_type
47-
"""
48-
Prompts the user securely for their seed.
49-
"""
50-
print(
51-
'Enter seed and press return (typing will not be shown). '
52-
'If empty, a random seed will be generated and displayed on the screen.'
53-
)
54-
seed = secure_input('') # type: Text
55-
return seed.encode('ascii')
47+
# type: () -> binary_type
48+
"""
49+
Prompts the user securely for their seed.
50+
"""
51+
print(
52+
'Enter seed and press return (typing will not be shown). '
53+
'If empty, a random seed will be generated and displayed on the screen.'
54+
)
55+
seed = secure_input('') # type: Text
56+
return seed.encode('ascii')
5657

5758

5859
def output_seed(seed):
59-
# type: (Seed) -> None
60-
"""
61-
Outputs the user's seed to stdout, along with lots of warnings
62-
about security.
63-
"""
64-
print(
65-
'WARNING: Anyone who has your seed can spend your IOTAs! '
66-
'Clear the screen after recording your seed!'
67-
)
68-
compat.input('')
69-
print('Your seed is:')
70-
print('')
71-
print(binary_type(seed).decode('ascii'))
72-
print('')
73-
74-
print(
75-
'Clear the screen to prevent shoulder surfing, '
76-
'and press return to continue.'
77-
)
78-
print('https://en.wikipedia.org/wiki/Shoulder_surfing_(computer_security)')
79-
compat.input('')
60+
# type: (Seed) -> None
61+
"""
62+
Outputs the user's seed to stdout, along with lots of warnings
63+
about security.
64+
"""
65+
print(
66+
'WARNING: Anyone who has your seed can spend your IOTAs! '
67+
'Clear the screen after recording your seed!'
68+
)
69+
compat.input('')
70+
print('Your seed is:')
71+
print('')
72+
print(binary_type(seed).decode('ascii'))
73+
print('')
74+
75+
print(
76+
'Clear the screen to prevent shoulder surfing, '
77+
'and press return to continue.'
78+
)
79+
print('https://en.wikipedia.org/wiki/Shoulder_surfing_(computer_security)')
80+
compat.input('')
8081

8182

8283
if __name__ == '__main__':
83-
parser = ArgumentParser(
84-
description = __doc__,
85-
epilog = 'PyOTA v{version}'.format(version=__version__),
86-
)
87-
88-
parser.add_argument(
89-
'--uri',
90-
type = text_type,
91-
default = 'http://localhost:14265/',
92-
93-
help =
94-
'URI of the node to connect to '
95-
'(defaults to http://localhost:14265/).',
96-
)
97-
98-
parser.add_argument(
99-
'--index',
100-
type = int,
101-
default = 0,
102-
help = 'Index of the key to generate.',
103-
)
104-
105-
parser.add_argument(
106-
'--count',
107-
type = int,
108-
default = None,
109-
110-
help =
111-
'Number of addresses to generate. '
112-
'If not specified, the first unused address will be returned.'
113-
)
114-
115-
parser.add_argument(
116-
'--security',
117-
type = int,
118-
default = AddressGenerator.DEFAULT_SECURITY_LEVEL,
119-
help = 'Security level to be used for the private key / address. '
120-
'Can be 1, 2 or 3',
121-
)
122-
123-
parser.add_argument(
124-
'--with-checksum',
125-
action = 'store_true',
126-
default = False,
127-
dest = 'checksum',
128-
help = 'List the address with the checksum.',
129-
)
130-
131-
main(**vars(parser.parse_args(argv[1:])))
84+
parser = ArgumentParser(
85+
description=__doc__,
86+
epilog='PyOTA v{version}'.format(version=__version__),
87+
)
88+
89+
parser.add_argument(
90+
'--uri',
91+
type=text_type,
92+
default='http://localhost:14265/',
93+
94+
help=(
95+
'URI of the node to connect to '
96+
'(defaults to http://localhost:14265/).'
97+
),
98+
)
99+
100+
parser.add_argument(
101+
'--index',
102+
type=int,
103+
default=0,
104+
help='Index of the key to generate.',
105+
)
106+
107+
parser.add_argument(
108+
'--count',
109+
type=int,
110+
default=None,
111+
112+
help=(
113+
'Number of addresses to generate. '
114+
'If not specified, the first unused address will be returned.'
115+
),
116+
)
117+
118+
parser.add_argument(
119+
'--security',
120+
type=int,
121+
default=AddressGenerator.DEFAULT_SECURITY_LEVEL,
122+
help=(
123+
'Security level to be used for the private key / address. '
124+
'Can be 1, 2 or 3'
125+
),
126+
)
127+
128+
parser.add_argument(
129+
'--with-checksum',
130+
action='store_true',
131+
default=False,
132+
dest='checksum',
133+
help='List the address with the checksum.',
134+
)
135+
136+
main(**vars(parser.parse_args(argv[1:])))

examples/hello_world.py

+34-31
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from __future__ import absolute_import, division, print_function, \
8-
unicode_literals
8+
unicode_literals
99

1010
from argparse import ArgumentParser
1111
from pprint import pprint
@@ -19,36 +19,39 @@
1919

2020

2121
def main(uri):
22-
# type: (Text) -> None
23-
api = StrictIota(uri)
24-
25-
try:
26-
node_info = api.get_node_info()
27-
except ConnectionError as e:
28-
print("Hm. {uri} isn't responding. Is the node running?".format(uri=uri))
29-
print(e)
30-
except BadApiResponse as e:
31-
print("Looks like {uri} isn't very talkative today ):".format(uri=uri))
32-
print(e)
33-
else:
34-
print('Hello {uri}!'.format(uri=uri))
35-
pprint(node_info)
22+
# type: (Text) -> None
23+
api = StrictIota(uri)
24+
25+
try:
26+
node_info = api.get_node_info()
27+
except ConnectionError as e:
28+
print(
29+
"Hm. {uri} isn't responding; is the node running?".format(uri=uri)
30+
)
31+
print(e)
32+
except BadApiResponse as e:
33+
print("Looks like {uri} isn't very talkative today ):".format(uri=uri))
34+
print(e)
35+
else:
36+
print('Hello {uri}!'.format(uri=uri))
37+
pprint(node_info)
3638

3739

3840
if __name__ == '__main__':
39-
parser = ArgumentParser(
40-
description = __doc__,
41-
epilog = 'PyOTA v{version}'.format(version=__version__),
42-
)
43-
44-
parser.add_argument(
45-
'--uri',
46-
type = text_type,
47-
default = 'http://localhost:14265/',
48-
49-
help =
50-
'URI of the node to connect to '
51-
'(defaults to http://localhost:14265/).',
52-
)
53-
54-
main(**vars(parser.parse_args(argv[1:])))
41+
parser = ArgumentParser(
42+
description=__doc__,
43+
epilog='PyOTA v{version}'.format(version=__version__),
44+
)
45+
46+
parser.add_argument(
47+
'--uri',
48+
type=text_type,
49+
default='http://localhost:14265/',
50+
51+
help=(
52+
'URI of the node to connect to '
53+
'(defaults to http://localhost:14265/).'
54+
),
55+
)
56+
57+
main(**vars(parser.parse_args(argv[1:])))

0 commit comments

Comments
 (0)