From 3ce90c05bf702291edf1e34c0bdb2425be87f72f Mon Sep 17 00:00:00 2001 From: Phoenix Zerin Date: Sat, 16 Jun 2018 09:55:00 +1200 Subject: [PATCH] [#145] Reformat multisig crypto for PEP-8. --- iota/multisig/crypto/__init__.py | 2 +- iota/multisig/crypto/addresses.py | 119 ++++++++++++++++-------------- 2 files changed, 64 insertions(+), 57 deletions(-) diff --git a/iota/multisig/crypto/__init__.py b/iota/multisig/crypto/__init__.py index 3f3d02d..725c9ff 100644 --- a/iota/multisig/crypto/__init__.py +++ b/iota/multisig/crypto/__init__.py @@ -1,3 +1,3 @@ # coding=utf-8 from __future__ import absolute_import, division, print_function, \ - unicode_literals + unicode_literals diff --git a/iota/multisig/crypto/addresses.py b/iota/multisig/crypto/addresses.py index d19a7e2..a12e861 100644 --- a/iota/multisig/crypto/addresses.py +++ b/iota/multisig/crypto/addresses.py @@ -1,6 +1,6 @@ # coding=utf-8 from __future__ import absolute_import, division, print_function, \ - unicode_literals + unicode_literals from typing import List, Optional @@ -10,76 +10,83 @@ from iota.multisig.types import MultisigAddress __all__ = [ - 'MultisigAddressBuilder', + 'MultisigAddressBuilder', ] class MultisigAddressBuilder(object): - """ - Creates multisig addresses. - - Note that this class generates a single address from multiple inputs, - (digests) unlike :py:class:`iota.crypto.addresses.AddressGenerator` - which generates multiple addresses from a single input (seed). - """ - def __init__(self): - super(MultisigAddressBuilder, self).__init__() - - self._digests = [] # type: List[Digest] - """ - Keeps track of digests that were added, so that we can attach them - to the final :py:class:`MultisigAddress` object. """ + Creates multisig addresses. - self._address = None # type: Optional[MultisigAddress] + Note that this class generates a single address from multiple + inputs (digests), unlike + :py:class:`iota.crypto.addresses.AddressGenerator` which generates + multiple addresses from a single input (seed). """ - Caches the generated address. - Generating the address modifies the internal state of the curl - sponge, so each :py:class:`MultisigAddressBuilder` instance can - only generate a single address. - """ + def __init__(self): + super(MultisigAddressBuilder, self).__init__() - self._sponge = Kerl() + self._digests = [] # type: List[Digest] + """ + Keeps track of digests that were added, so that we can attach + them to the final :py:class:`MultisigAddress` object. + """ - def add_digest(self, digest): - # type: (Digest) -> None - """ - Absorbs a digest into the sponge. + self._address = None # type: Optional[MultisigAddress] + """ + Caches the generated address. - IMPORTANT: Keep track of the order that digests are added! - To spend inputs from a multisig address, you must provide the - private keys in the same order! + Generating the address modifies the internal state of the curl + sponge, so each :py:class:`MultisigAddressBuilder` instance can + only generate a single address. + """ - References: - - https://github.com/iotaledger/wiki/blob/master/multisigs.md#spending-inputs - """ - if self._address: - raise ValueError('Cannot add digests once an address is extracted.') + self._sponge = Kerl() - self._sponge.absorb(digest.as_trits()) - self._digests.append(digest) + def add_digest(self, digest): + # type: (Digest) -> None + """ + Absorbs a digest into the sponge. - def get_address(self): - # type: () -> MultisigAddress - """ - Returns the new multisig address. + .. important:: + Keep track of the order that digests are added! - Note that you can continue to add digests after extracting an - address; the next address will use *all* of the digests that have - been added so far. - """ - if not self._digests: - raise ValueError( - 'Must call ``add_digest`` at least once ' - 'before calling ``get_address``.', - ) + To spend inputs from a multisig address, you must provide + the private keys in the same order! + + References: + + - https://github.com/iotaledger/wiki/blob/master/multisigs.md#spending-inputs + """ + if self._address: + raise ValueError('Cannot add digests once an address is extracted.') + + self._sponge.absorb(digest.as_trits()) + self._digests.append(digest) + + def get_address(self): + # type: () -> MultisigAddress + """ + Returns the new multisig address. + + Note that you can continue to add digests after extracting an + address; the next address will use *all* of the digests that + have been added so far. + """ + if not self._digests: + raise ValueError( + 'Must call ``add_digest`` at least once ' + 'before calling ``get_address``.', + ) - if not self._address: - address_trits = [0] * HASH_LENGTH - self._sponge.squeeze(address_trits) + if not self._address: + address_trits = [0] * HASH_LENGTH + self._sponge.squeeze(address_trits) - self._address =\ - MultisigAddress.from_trits(address_trits, digests=self._digests[:]) + self._address = MultisigAddress.from_trits( + address_trits, + digests=self._digests[:], + ) - return self._address + return self._address