forked from iotaledger/iota.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iotaledger#145] Reformat multisig commands for PEP-8.
- Loading branch information
1 parent
07886c1
commit e2922b6
Showing
5 changed files
with
233 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
) |
Oops, something went wrong.