def from_dict( cls, data: typing.Dict[str, typing.Any]) -> 'ContractReceiveRouteClosed': return cls( transaction_hash=deserialize_bytes(data['transaction_hash']), token_network_identifier=to_canonical_address( data['token_network_identifier']), channel_identifier=int(data['channel_identifier']), block_number=typing.BlockNumber(int(data['block_number'])), )
def from_dict( cls, data: typing.Dict[str, typing.Any]) -> 'ContractReceiveNewTokenNetwork': return cls( transaction_hash=deserialize_bytes(data['transaction_hash']), payment_network_identifier=to_canonical_address( data['payment_network_identifier']), token_network=data['token_network'], block_number=typing.BlockNumber(int(data['block_number'])), )
def from_dict( cls, data: typing.Dict[str, typing.Any]) -> 'ContractReceiveSecretReveal': return cls( transaction_hash=deserialize_bytes(data['transaction_hash']), secret_registry_address=to_canonical_address( data['secret_registry_address']), secrethash=deserialize_bytes(data['secrethash']), secret=deserialize_bytes(data['secret']), block_number=typing.BlockNumber(int(data['block_number'])), )
def from_dict( cls, data: typing.Dict[str, typing.Any]) -> 'ContractReceiveChannelNewBalance': return cls( transaction_hash=deserialize_bytes(data['transaction_hash']), token_network_identifier=to_canonical_address( data['token_network_identifier']), channel_identifier=typing.ChannelID(int( data['channel_identifier'])), deposit_transaction=data['deposit_transaction'], block_number=typing.BlockNumber(int(data['block_number'])), )
def handle_block( initiator_state: InitiatorTransferState, state_change: Block, channel_state: NettingChannelState, pseudo_random_generator: random.Random, ) -> TransitionResult: secrethash = initiator_state.transfer.lock.secrethash locked_lock = channel_state.our_state.secrethashes_to_lockedlocks.get( secrethash) if not locked_lock: return TransitionResult(initiator_state, list()) lock_expiration_threshold = typing.BlockNumber( locked_lock.expiration + DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS * 2, ) lock_has_expired, _ = channel.is_lock_expired( end_state=channel_state.our_state, lock=locked_lock, block_number=state_change.block_number, lock_expiration_threshold=lock_expiration_threshold, ) if lock_has_expired: expired_lock_events = channel.events_for_expired_lock( channel_state=channel_state, locked_lock=locked_lock, pseudo_random_generator=pseudo_random_generator, ) transfer_description = initiator_state.transfer_description # TODO: When we introduce multiple transfers per payment this needs to be # reconsidered. As we would want to try other routes once a route # has failed, and a transfer failing does not mean the entire payment # would have to fail. # Related issue: https://github.com/raiden-network/raiden/issues/2329 transfer_failed = EventPaymentSentFailed( payment_network_identifier=transfer_description. payment_network_identifier, token_network_identifier=transfer_description. token_network_identifier, identifier=transfer_description.payment_identifier, target=transfer_description.target, reason="transfer's lock has expired", ) expired_lock_events.append(transfer_failed) return TransitionResult( None, typing.cast(typing.List[Event], expired_lock_events), ) else: return TransitionResult(initiator_state, list())
def from_dict( cls, data: typing.Dict[str, typing.Any]) -> 'ContractReceiveChannelBatchUnlock': return cls( transaction_hash=deserialize_bytes(data['transaction_hash']), token_network_identifier=to_canonical_address( data['token_network_identifier']), participant=to_canonical_address(data['participant']), partner=to_canonical_address(data['partner']), locksroot=deserialize_bytes(data['locksroot']), unlocked_amount=int(data['unlocked_amount']), returned_tokens=int(data['returned_tokens']), block_number=typing.BlockNumber(int(data['block_number'])), )
def handle_block( target_state: TargetTransferState, channel_state: NettingChannelState, block_number: typing.BlockNumber, ): """ After Raiden learns about a new block this function must be called to handle expiration of the hash time lock. """ transfer = target_state.transfer events = list() lock = transfer.lock secret_known = channel.is_secret_known( channel_state.partner_state, lock.secrethash, ) lock_has_expired, _ = channel.is_lock_expired( end_state=channel_state.our_state, lock=lock, block_number=block_number, lock_expiration_threshold=typing.BlockNumber( lock.expiration + DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS, ), ) if lock_has_expired and target_state.state != 'expired': failed = EventUnlockClaimFailed( identifier=transfer.payment_identifier, secrethash=transfer.lock.secrethash, reason=f'lock expired', ) target_state.state = 'expired' events = [failed] elif secret_known: events = events_for_onchain_secretreveal( target_state, channel_state, block_number, ) return TransitionResult(target_state, events)
def make_block_number() -> typing.BlockNumber: return typing.BlockNumber(random.randint(0, UINT256_MAX))
def from_dict(cls, data: typing.Dict[str, typing.Any]) -> 'Block': return cls( block_number=typing.BlockNumber(int(data['block_number'])), gas_limit=data['gas_limit'], block_hash=deserialize_bytes(data['block_hash']), )