Esempio n. 1
0
    def __init__(
            self,
            amount: typing.TokenAmount,
            expiration: typing.BlockNumber,
            secrethash: typing.Keccak256):

        if not isinstance(amount, typing.T_TokenAmount):
            raise ValueError('amount must be a token_amount instance')

        if not isinstance(expiration, typing.T_BlockNumber):
            raise ValueError('expiration must be a block_number instance')

        if not isinstance(secrethash, typing.T_Keccak256):
            raise ValueError('secrethash must be a keccak256 instance')

        packed = messages.Lock(buffer_for(messages.Lock))
        packed.amount = amount
        packed.expiration = expiration
        packed.secrethash = secrethash
        encoded = bytes(packed.data)

        self.amount = amount
        self.expiration = expiration
        self.secrethash = secrethash
        self.encoded = encoded
        self.lockhash: typing.LockHash = typing.LockHash(sha3(encoded))
Esempio n. 2
0
    def __init__(
            self,
            amount: typing.TokenAmount,
            expiration: typing.BlockNumber,
            hashlock: typing.Keccak256):

        if not isinstance(amount, typing.TokenAmount):
            raise ValueError('amount must be a token_amount instance')

        if not isinstance(expiration, typing.BlockNumber):
            raise ValueError('expiration must be a block_number instance')

        if not isinstance(hashlock, typing.Keccak256):
            raise ValueError('hashlock must be a keccak256 instance')

        packed = messages.Lock(buffer_for(messages.Lock))
        packed.amount = amount
        packed.expiration = expiration
        packed.hashlock = hashlock
        encoded = bytes(packed.data)

        self.amount = amount
        self.expiration = expiration
        self.hashlock = hashlock
        self.encoded = encoded
        self.lockhash = sha3(encoded)
Esempio n. 3
0
    def from_bytes(cls, serialized):
        packed = messages.Lock(serialized)

        return cls(
            packed.amount,
            packed.expiration,
            packed.secrethash,
        )
Esempio n. 4
0
    def as_bytes(self):
        packed = messages.Lock(buffer_for(messages.Lock))
        packed.amount = self.amount
        packed.expiration = self.expiration
        packed.secrethash = self.secrethash

        # convert bytearray to bytes
        return bytes(packed.data)
Esempio n. 5
0
    def as_bytes(self):
        if self._asbytes is None:
            packed = messages.Lock(buffer_for(messages.Lock))
            packed.amount = self.amount
            packed.expiration = self.expiration
            packed.hashlock = self.hashlock

            self._asbytes = packed.data

        return self._asbytes
Esempio n. 6
0
    def as_bytes(self):
        if self._asbytes is None:
            packed = messages.Lock(buffer_for(messages.Lock))
            packed.amount = self.amount
            packed.expiration = self.expiration
            packed.secrethash = self.secrethash

            self._asbytes = packed.data

        # convert bytearray to bytes
        return bytes(self._asbytes)