Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
offchain_secret_reveal = events_for_secretreveal(
state.transfers_pair, secret, pseudo_random_generator
)
balance_proof = events_for_balanceproof(
channelidentifiers_to_channels,
state.transfers_pair,
pseudo_random_generator,
block_number,
secret,
secrethash,
)
events = secret_reveal_events + offchain_secret_reveal + balance_proof + onchain_secret_reveal
iteration = TransitionResult(state, events)
return iteration
)
events: List[Event] = list()
if token_network_state:
iteration = token_network.state_transition(
token_network_state=token_network_state,
state_change=state_change,
block_number=chain_state.block_number,
block_hash=chain_state.block_hash,
pseudo_random_generator=chain_state.pseudo_random_generator,
)
assert iteration.new_state, "No token network state transition can lead to None"
events = iteration.events
return TransitionResult(chain_state, events)
)
unlock_success = EventUnlockClaimSuccess(
transfer.payment_identifier, transfer.lock.secrethash
)
send_processed = SendProcessed(
recipient=balance_proof_sender,
message_identifier=state_change.message_identifier,
canonical_identifier=CANONICAL_IDENTIFIER_GLOBAL_QUEUE,
)
events.extend([payment_received_success, unlock_success, send_processed])
next_target_state = None
return TransitionResult(next_target_state, events)
)
else:
transfer_pair = None
mediated_events = list()
if transfer_pair is None:
assert not mediated_events
mediated_events = list()
state.waiting_transfer = WaitingTransferState(payer_transfer)
else:
# the list must be ordered from high to low expiration, expiration
# handling depends on it
state.transfers_pair.append(transfer_pair)
return TransitionResult(state, mediated_events)
total_withdraw=withdraw_request.total_withdraw,
participant=channel_state.partner_state.address,
nonce=channel_state.our_state.nonce,
expiration=withdraw_state.expiration,
)
events: List[Event] = [send_withdraw]
else:
error_msg = is_valid.as_error_message
assert error_msg, "is_valid_withdraw_request should return error msg if not valid"
invalid_withdraw_request = EventInvalidReceivedWithdrawRequest(
attempted_withdraw=withdraw_request.total_withdraw, reason=error_msg
)
events = [invalid_withdraw_request]
return TransitionResult(channel_state, events)
state_change=state_change,
channelidentifiers_to_channels=token_network_state.channelidentifiers_to_channels,
nodeaddresses_to_networkstates=chain_state.nodeaddresses_to_networkstates,
pseudo_random_generator=chain_state.pseudo_random_generator,
block_number=chain_state.block_number,
)
events: List[Event] = iteration.events
if iteration.new_state:
chain_state.payment_mapping.secrethashes_to_task[secrethash] = InitiatorTask(
token_network_address, iteration.new_state
)
elif secrethash in chain_state.payment_mapping.secrethashes_to_task:
del chain_state.payment_mapping.secrethashes_to_task[secrethash]
return TransitionResult(chain_state, events)
if payer_channel and channel.is_lock_pending(payer_channel.partner_state, secrethash):
return iteration
payee_channel = get_payee_channel(channelidentifiers_to_channels, pair)
if payee_channel and channel.is_lock_pending(payee_channel.our_state, secrethash):
return iteration
if state.waiting_transfer:
waiting_transfer = state.waiting_transfer.transfer
waiting_channel_identifier = waiting_transfer.balance_proof.channel_identifier
waiting_channel = channelidentifiers_to_channels.get(waiting_channel_identifier)
if waiting_channel and channel.is_lock_pending(waiting_channel.partner_state, secrethash):
return iteration
return TransitionResult(None, iteration.events)
def handle_onchain_secretreveal(
payment_state: InitiatorPaymentState,
state_change: ContractReceiveSecretReveal,
channelidentifiers_to_channels: ChannelMap,
pseudo_random_generator: random.Random,
) -> TransitionResult[InitiatorPaymentState]:
initiator_state = payment_state.initiator_transfers.get(state_change.secrethash)
if not initiator_state:
return TransitionResult(payment_state, list())
assert initiator_state.transfer_state != "transfer_cancelled"
sub_iteration = subdispatch_to_initiatortransfer(
payment_state=payment_state,
initiator_state=initiator_state,
state_change=state_change,
channelidentifiers_to_channels=channelidentifiers_to_channels,
pseudo_random_generator=pseudo_random_generator,
)
# The current secretreveal unlocked the transfer
if not transfer_exists(payment_state, state_change.secrethash):
cancel_other_transfers(payment_state)
return TransitionResult(payment_state, sub_iteration.events)
channel_state: NettingChannelState,
withdraw_expired: ReceiveWithdrawExpired,
block_number: BlockNumber,
) -> TransitionResult:
events: List[Event] = list()
withdraw_state = channel_state.partner_state.withdraws_pending.get(
withdraw_expired.total_withdraw
)
if not withdraw_state:
invalid_withdraw_expired_msg = (
f"Withdraw expired of {withdraw_expired.total_withdraw} "
f"did not correspond to previous withdraw request"
)
return TransitionResult(
channel_state,
[
EventInvalidReceivedWithdrawExpired(
attempted_withdraw=withdraw_expired.total_withdraw,
reason=invalid_withdraw_expired_msg,
)
],
)
is_valid = is_valid_withdraw_expired(
channel_state=channel_state,
state_change=withdraw_expired,
withdraw_state=withdraw_state,
block_number=block_number,
)
if is_valid: