Skip to content

Commit

Permalink
[iotaledger#145] Reformat multisig commands for PEP-8.
Browse files Browse the repository at this point in the history
  • Loading branch information
todofixthis committed Jun 15, 2018
1 parent 07886c1 commit e2922b6
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 249 deletions.
3 changes: 1 addition & 2 deletions iota/multisig/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding=utf-8
from __future__ import absolute_import, division, print_function, \
unicode_literals

unicode_literals

from .create_multisig_address import *
from .get_digests import *
Expand Down
54 changes: 28 additions & 26 deletions iota/multisig/commands/create_multisig_address.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
# coding=utf-8
from __future__ import absolute_import, division, print_function, \
unicode_literals
unicode_literals

from typing import List

import filters as f

from iota.commands import FilterCommand, RequestFilter
from iota.crypto.types import Digest
from iota.filters import Trytes
from iota.multisig.crypto.addresses import MultisigAddressBuilder

__all__ = [
'CreateMultisigAddressCommand',
'CreateMultisigAddressCommand',
]


class CreateMultisigAddressCommand(FilterCommand):
"""
Implements `create_multisig_address` multisig command.
"""
Implements `create_multisig_address` multisig command.
References:
References:
- :py:meth:`iota.multisig.api.MultisigIota.create_multisig_address`
"""
command = 'createMultisigAddress'
"""
command = 'createMultisigAddress'

def get_request_filter(self):
return CreateMultisigAddressRequestFilter()
def get_request_filter(self):
return CreateMultisigAddressRequestFilter()

def get_response_filter(self):
pass
def get_response_filter(self):
pass

def _execute(self, request):
digests = request['digests'] # type: List[Digest]
def _execute(self, request):
digests = request['digests'] # type: List[Digest]

builder = MultisigAddressBuilder()
builder = MultisigAddressBuilder()

for d in digests:
builder.add_digest(d)
for d in digests:
builder.add_digest(d)

return {
'address': builder.get_address(),
}
return {
'address': builder.get_address(),
}


class CreateMultisigAddressRequestFilter(RequestFilter):
def __init__(self):
super(CreateMultisigAddressRequestFilter, self).__init__({
'digests':
f.Required
| f.Array
| f.FilterRepeater(f.Required | Trytes(result_type=Digest)),
})
def __init__(self):
super(CreateMultisigAddressRequestFilter, self).__init__({
'digests':
f.Required | f.Array | f.FilterRepeater(
f.Required | Trytes(Digest),
),
})
99 changes: 45 additions & 54 deletions iota/multisig/commands/get_digests.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,71 @@
# coding=utf-8
from __future__ import absolute_import, division, print_function, \
unicode_literals
unicode_literals

from typing import Optional

import filters as f

from iota.commands import FilterCommand, RequestFilter
from iota.crypto.addresses import AddressGenerator
from iota.crypto.types import Seed
from iota.filters import Trytes
from iota.filters import SecurityLevel, Trytes
from iota.multisig.commands.get_private_keys import GetPrivateKeysCommand

__all__ = [
'GetDigestsCommand',
'GetDigestsCommand',
]


class GetDigestsCommand(FilterCommand):
"""
Implements `getDigests` multisig API command.
"""
Implements `getDigests` multisig API command.
References:
References:
- :py:meth:`iota.multisig.api.MultisigIota.get_digests`
"""
command = 'getDigests'
"""
command = 'getDigests'

def get_request_filter(self):
return GetDigestsRequestFilter()
def get_request_filter(self):
return GetDigestsRequestFilter()

def get_response_filter(self):
pass
def get_response_filter(self):
pass

def _execute(self, request):
count = request['count'] # type: Optional[int]
index = request['index'] # type: int
seed = request['seed'] # type: Seed
security_level = request['securityLevel'] # type: int
def _execute(self, request):
count = request['count'] # type: Optional[int]
index = request['index'] # type: int
seed = request['seed'] # type: Seed
security_level = request['securityLevel'] # type: int

gpk_result =\
GetPrivateKeysCommand(self.adapter)(
seed = seed,
count = count,
index = index,
securityLevel = security_level,
)
gpk_result = GetPrivateKeysCommand(self.adapter)(
seed=seed,
count=count,
index=index,
securityLevel=security_level,
)

return {
'digests': [key.get_digest() for key in gpk_result['keys']],
}
return {
'digests': [key.get_digest() for key in gpk_result['keys']],
}


class GetDigestsRequestFilter(RequestFilter):
def __init__(self):
super(GetDigestsRequestFilter, self).__init__(
{
# Optional Parameters
'count':
f.Type(int) | f.Min(1) | f.Optional(default=1),

'index':
f.Type(int) | f.Min(0) | f.Optional(default=0),

'securityLevel':
f.Type(int)
| f.Min(1)
| f.Optional(default=AddressGenerator.DEFAULT_SECURITY_LEVEL),

# Required Parameters
'seed':
f.Required | Trytes(result_type=Seed),
},

allow_missing_keys = {
'count',
'index',
'securityLevel',
},
)
def __init__(self):
super(GetDigestsRequestFilter, self).__init__(
{
# Optional Parameters
'count': f.Type(int) | f.Min(1) | f.Optional(default=1),
'index': f.Type(int) | f.Min(0) | f.Optional(default=0),
'securityLevel': SecurityLevel,

# Required Parameters
'seed': f.Required | Trytes(Seed),
},

allow_missing_keys={
'count',
'index',
'securityLevel',
},
)
97 changes: 46 additions & 51 deletions iota/multisig/commands/get_private_keys.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,71 @@
# coding=utf-8
from __future__ import absolute_import, division, print_function, \
unicode_literals
unicode_literals

from typing import Optional

import filters as f

from iota.commands import FilterCommand, RequestFilter
from iota.crypto.addresses import AddressGenerator
from iota.crypto.signing import KeyGenerator
from iota.crypto.types import Seed
from iota.filters import Trytes
from iota.filters import SecurityLevel, Trytes

__all__ = [
'GetPrivateKeysCommand',
'GetPrivateKeysCommand',
]


class GetPrivateKeysCommand(FilterCommand):
"""
Implements `get_private_keys` multisig API command.
"""
Implements `get_private_keys` multisig API command.
References:
- :py:meth:`iota.multisig.MultisigIota.get_private_key`
- https://github.com/iotaledger/wiki/blob/master/multisigs.md
"""
command = 'getPrivateKeys'
References:
def get_request_filter(self):
return GetPrivateKeysRequestFilter()
- :py:meth:`iota.multisig.MultisigIota.get_private_key`
- https://github.com/iotaledger/wiki/blob/master/multisigs.md
"""
command = 'getPrivateKeys'

def get_response_filter(self):
pass
def get_request_filter(self):
return GetPrivateKeysRequestFilter()

def _execute(self, request):
count = request['count'] # type: Optional[int]
index = request['index'] # type: int
seed = request['seed'] # type: Seed
security_level = request['securityLevel'] # type: int
def get_response_filter(self):
pass

generator = KeyGenerator(seed)
def _execute(self, request):
count = request['count'] # type: Optional[int]
index = request['index'] # type: int
seed = request['seed'] # type: Seed
security_level = request['securityLevel'] # type: int

return {
'keys':
generator.get_keys(start=index, count=count, iterations=security_level),
}
generator = KeyGenerator(seed)

return {
'keys': generator.get_keys(
start=index,
count=count,
iterations=security_level,
),
}


class GetPrivateKeysRequestFilter(RequestFilter):
def __init__(self):
super(GetPrivateKeysRequestFilter, self).__init__(
{
# Optional Parameters
'count':
f.Type(int) | f.Min(1) | f.Optional(default=1),

'index':
f.Type(int) | f.Min(0) | f.Optional(default=0),

'securityLevel':
f.Type(int)
| f.Min(1)
| f.Optional(default=AddressGenerator.DEFAULT_SECURITY_LEVEL),

# Required Parameters
'seed':
f.Required | Trytes(result_type=Seed),
},

allow_missing_keys = {
'count',
'index',
'securityLevel',
},
)
def __init__(self):
super(GetPrivateKeysRequestFilter, self).__init__(
{
# Optional Parameters
'count': f.Type(int) | f.Min(1) | f.Optional(default=1),
'index': f.Type(int) | f.Min(0) | f.Optional(default=0),
'securityLevel': SecurityLevel,

# Required Parameters
'seed': f.Required | Trytes(Seed),
},

allow_missing_keys={
'count',
'index',
'securityLevel',
},
)
Loading

0 comments on commit e2922b6

Please sign in to comment.