示例#1
0
 def __init__(self, msg_or_echo, *args):
     if isinstance(msg_or_echo, SignedMessage):
         self.echo = msg_or_echo.hash
     else:
         assert ishash(msg_or_echo)
         self.echo = msg_or_echo
     super(BaseError, self).__init__(*args)
示例#2
0
 def __init__(self, msg_or_echo, *args):
     if isinstance(msg_or_echo, SignedMessage):
         self.echo = msg_or_echo.hash
     else:
         assert ishash(msg_or_echo)
         self.echo = msg_or_echo
     super(BaseError, self).__init__(*args)
示例#3
0
    def __init__(self, amount, expiration, hashlock):
        if amount < 0:
            raise ValueError('amount {} needs to be positive'.format(amount))

        if amount > 2**256:
            raise ValueError('amount {} is too large'.format(amount))

        assert ishash(hashlock)
        self.amount = amount
        self.expiration = expiration
        self.hashlock = hashlock
        self._asstring = None
示例#4
0
    def __init__(self, amount, expiration, hashlock):
        if amount < 0:
            raise ValueError('amount {} needs to be positive'.format(amount))

        if amount > 2 ** 256:
            raise ValueError('amount {} is too large'.format(amount))

        assert ishash(hashlock)
        self.amount = amount
        self.expiration = expiration
        self.hashlock = hashlock
        self._asstring = None
示例#5
0
    def __init__(self, amount, expiration, hashlock):
        # guarantee that `amount` can be serialized using the available bytes
        # in the fixed length format
        if amount < 0:
            raise ValueError('amount {} needs to be positive'.format(amount))

        if amount > 2**256:
            raise ValueError('amount {} is too large'.format(amount))

        assert ishash(hashlock)
        self.amount = amount
        self.expiration = expiration
        self.hashlock = hashlock
        self._asbytes = None
示例#6
0
    def __init__(self, amount, expiration, hashlock):
        # guarantee that `amount` can be serialized using the available bytes
        # in the fixed length format
        if amount < 0:
            raise ValueError('amount {} needs to be positive'.format(amount))

        if amount > 2 ** 256:
            raise ValueError('amount {} is too large'.format(amount))

        assert ishash(hashlock)
        self.amount = amount
        self.expiration = expiration
        self.hashlock = hashlock
        self._asbytes = None
示例#7
0
    def __post_init__(self):
        # guarantee that `amount` can be serialized using the available bytes
        # in the fixed length format
        if self.amount < 0:
            raise ValueError(f"amount {self.amount} needs to be positive")

        if self.amount > UINT256_MAX:
            raise ValueError(f"amount {self.amount} is too large")

        if self.expiration < 0:
            raise ValueError(f"expiration {self.expiration} needs to be positive")

        if self.expiration > UINT256_MAX:
            raise ValueError(f"expiration {self.expiration} is too large")

        if not ishash(self.secrethash):
            raise ValueError("secrethash {self.secrethash} is not a valid hash")
示例#8
0
    def __init__(self, amount: TokenAmount, expiration: BlockExpiration, secrethash: SecretHash):
        # guarantee that `amount` can be serialized using the available bytes
        # in the fixed length format
        if amount < 0:
            raise ValueError('amount {} needs to be positive'.format(amount))

        if amount >= 2 ** 256:
            raise ValueError('amount {} is too large'.format(amount))

        if expiration < 0:
            raise ValueError('expiration {} needs to be positive'.format(amount))

        if expiration >= 2 ** 256:
            raise ValueError('expiration {} is too large'.format(amount))

        assert ishash(secrethash)
        self.amount = amount
        self.expiration = expiration
        self.secrethash = secrethash
示例#9
0
    def __init__(self, amount: TokenAmount, expiration: BlockExpiration, secrethash: SecretHash):
        # guarantee that `amount` can be serialized using the available bytes
        # in the fixed length format
        if amount < 0:
            raise ValueError('amount {} needs to be positive'.format(amount))

        if amount >= 2 ** 256:
            raise ValueError('amount {} is too large'.format(amount))

        if expiration < 0:
            raise ValueError('expiration {} needs to be positive'.format(amount))

        if expiration >= 2 ** 256:
            raise ValueError('expiration {} is too large'.format(amount))

        assert ishash(secrethash)
        self.amount = amount
        self.expiration = expiration
        self.secrethash = secrethash
示例#10
0
    def payment_channel(
            self,
            token_network_address: Address,
            channel_id: ChannelID,
    ) -> PaymentChannel:

        if not is_binary_address(token_network_address):
            raise ValueError('address must be a valid address')
        if not ishash(channel_id):
            raise ValueError('identifier must be a hash')

        dict_key = (token_network_address, channel_id)

        if dict_key not in self.identifier_to_payment_channel:
            token_network = self.token_network(token_network_address)

            self.identifier_to_payment_channel[dict_key] = PaymentChannel(
                token_network=token_network,
                channel_identifier=channel_id,
            )

        return self.identifier_to_payment_channel[dict_key]
示例#11
0
    def payment_channel(
        self,
        token_network_address: Address,
        channel_id: ChannelID,
    ) -> PaymentChannel:

        if not is_binary_address(token_network_address):
            raise ValueError('address must be a valid address')
        if not ishash(channel_id):
            raise ValueError('identifier must be a hash')

        dict_key = (token_network_address, channel_id)

        if dict_key not in self.identifier_to_payment_channel:
            token_network = self.token_network(token_network_address)

            self.identifier_to_payment_channel[dict_key] = PaymentChannel(
                token_network=token_network,
                channel_identifier=channel_id,
            )

        return self.identifier_to_payment_channel[dict_key]