Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_fee_update_message( # pylint: disable=too-many-arguments
updating_participant: Address,
chain_id=ChainID(61),
channel_identifier=DEFAULT_CHANNEL_ID,
token_network_address: TokenNetworkAddress = DEFAULT_TOKEN_NETWORK_ADDRESS,
fee_schedule: FeeScheduleState = FeeScheduleState(
cap_fees=True, flat=FeeAmount(1), proportional=ProportionalFeeAmount(1)
),
timestamp: datetime = datetime.utcnow(),
privkey_signer: bytes = PRIVATE_KEY_1,
) -> PFSFeeUpdate:
fee_message = PFSFeeUpdate(
canonical_identifier=CanonicalIdentifier(
chain_identifier=chain_id,
channel_identifier=channel_identifier,
token_network_address=token_network_address,
),
updating_participant=updating_participant,
fee_schedule=fee_schedule,
timestamp=timestamp,
signature=EMPTY_SIGNATURE,
)
fee_message.sign(LocalSigner(privkey_signer))
return fee_message
token_network_address=TokenNetworkAddress(address2),
block_number=BlockNumber(1),
)
event_log = format_to_hex(_logger=logger, _log_method=log_method, event_dict=dict(event=event))
assert ( # pylint: disable=unsubscriptable-object
to_checksum_address(address) == event_log["event"]["token_address"]
)
assert ( # pylint: disable=unsubscriptable-object
to_checksum_address(address2) == event_log["event"]["token_network_address"]
)
assert ( # pylint: disable=unsubscriptable-object
event_log["event"]["type_name"] == "ReceiveTokenNetworkCreatedEvent"
)
message = PFSFeeUpdate(
canonical_identifier=CanonicalIdentifier(
chain_identifier=ChainID(61),
token_network_address=TokenNetworkAddress(address),
channel_identifier=ChannelID(1),
),
updating_participant=PARTICIPANT1,
fee_schedule=FeeScheduleState(),
timestamp=datetime.utcnow(),
signature=EMPTY_SIGNATURE,
)
message_log = format_to_hex(
_logger=logger, _log_method=log_method, event_dict=dict(message=message)
)
assert ( # pylint: disable=unsubscriptable-object
to_checksum_address(address)
== message_log["message"]["canonical_identifier"]["token_network_address"]
)
def contractreceivechannelwithdraw_from_event(
event: DecodedEvent, fee_config: MediationFeeConfig
) -> ContractReceiveChannelWithdraw:
data = event.event_data
args = data["args"]
channel_identifier = args["channel_identifier"]
participant = args["participant"]
total_withdraw = args["total_withdraw"]
return ContractReceiveChannelWithdraw(
canonical_identifier=CanonicalIdentifier(
chain_identifier=event.chain_id,
token_network_address=TokenNetworkAddress(event.originating_contract),
channel_identifier=channel_identifier,
),
total_withdraw=total_withdraw,
participant=participant,
transaction_hash=event.transaction_hash,
block_number=event.block_number,
block_hash=event.block_hash,
fee_config=fee_config,
)
our_state = NettingChannelEndState(new_channel_details.our_address, Balance(0))
partner_state = NettingChannelEndState(new_channel_details.partner_address, Balance(0))
open_transaction = TransactionExecutionStatus(
None, block_number, TransactionExecutionStatus.SUCCESS
)
# If the node was offline for a long period, the channel may have been
# closed already, if that is the case during initialization the node will
# process the other events and update the channel's state
close_transaction: Optional[TransactionExecutionStatus] = None
settle_transaction: Optional[TransactionExecutionStatus] = None
channel_state = NettingChannelState(
canonical_identifier=CanonicalIdentifier(
chain_identifier=new_channel_details.chain_id,
token_network_address=token_network_address,
channel_identifier=identifier,
),
token_address=new_channel_details.token_address,
token_network_registry_address=new_channel_details.token_network_registry_address,
reveal_timeout=channel_config.reveal_timeout,
settle_timeout=settle_timeout,
fee_schedule=channel_config.fee_schedule,
our_state=our_state,
partner_state=partner_state,
open_transaction=open_transaction,
close_transaction=close_transaction,
settle_transaction=settle_transaction,
)
balance_hash = hash_balance_data(
balance_proof.transferred_amount, balance_proof.locked_amount, balance_proof.locksroot
)
# The balance proof must be tied to a single channel instance, through the
# chain_id, token_network_address, and channel_identifier, otherwise the
# on-chain contract would be susceptible to replay attacks across channels.
#
# The balance proof must also authenticate the offchain balance (blinded in
# the balance_hash field), and authenticate the rest of message data
# (blinded in additional_hash).
data_that_was_signed = pack_balance_proof(
nonce=balance_proof.nonce,
balance_hash=balance_hash,
additional_hash=balance_proof.message_hash,
canonical_identifier=CanonicalIdentifier(
chain_identifier=balance_proof.chain_id,
token_network_address=balance_proof.token_network_address,
channel_identifier=balance_proof.channel_identifier,
),
)
return is_valid_signature(
data=data_that_was_signed, signature=balance_proof.signature, sender_address=sender_address
)
token_network = views.get_token_network_by_token_address(
chain_state=chain_state,
token_network_registry_address=token_network_registry_address,
token_address=token_address,
)
if token_network is None:
raise ValueError(
f"The token {token_address} is not registered on "
f"the network {token_network_registry_address}."
)
token_network_address = token_network.address
list_cannonical_ids = [
CanonicalIdentifier(
chain_identifier=chain_state.chain_id,
token_network_address=token_network_address,
channel_identifier=channel_identifier,
)
for channel_identifier in channel_ids
]
log_details = {
"token_network_registry_address": to_checksum_address(token_network_registry_address),
"token_address": to_checksum_address(token_address),
"list_cannonical_ids": list_cannonical_ids,
"target_states": target_states,
}
while list_cannonical_ids:
assert raiden, ALARM_TASK_ERROR_MSG
token_network: Dict[str, Any],
channel: Dict[str, Any],
) -> Tuple[Locksroot, Locksroot]:
channel_new_state_change = _find_channel_new_state_change(
storage=storage,
token_network_address=token_network["address"],
channel_identifier=channel["identifier"],
)
if not channel_new_state_change:
raise RaidenUnrecoverableError(
f'Could not find the state change for channel {channel["identifier"]}, '
f'token network address: {token_network["address"]} being created. '
)
canonical_identifier = CanonicalIdentifier(
chain_identifier=-1,
token_network_address=to_canonical_address(token_network["address"]),
channel_identifier=int(channel["identifier"]),
)
our_locksroot, partner_locksroot = get_onchain_locksroots(
chain=raiden.chain,
canonical_identifier=canonical_identifier,
participant1=to_canonical_address(channel["our_state"]["address"]),
participant2=to_canonical_address(channel["partner_state"]["address"]),
block_identifier="latest",
)
return our_locksroot, partner_locksroot
sender_end_state.pending_locks, EncodedData(bytes(locked_lock.encoded))
)
if not pending_locks:
return None, None
nonce = get_next_nonce(sender_end_state)
locksroot = compute_locksroot(pending_locks)
balance_proof = BalanceProofUnsignedState(
nonce=nonce,
transferred_amount=transferred_amount,
locked_amount=updated_locked_amount,
locksroot=locksroot,
canonical_identifier=CanonicalIdentifier(
chain_identifier=chain_id,
token_network_address=token_network_address,
channel_identifier=channel_identifier,
),
)
send_lock_expired = SendLockExpired(
recipient=recipient,
canonical_identifier=balance_proof.canonical_identifier,
message_identifier=message_identifier_from_prng(pseudo_random_generator),
balance_proof=balance_proof,
secrethash=locked_lock.secrethash,
)
return send_lock_expired, pending_locks
def handle_contract_receive_channel_closed(
chain_state: ChainState, state_change: ContractReceiveChannelClosed
) -> TransitionResult[ChainState]:
# cleanup queue for channel
canonical_identifier = CanonicalIdentifier(
chain_identifier=chain_state.chain_id,
token_network_address=state_change.token_network_address,
channel_identifier=state_change.channel_identifier,
)
channel_state = views.get_channelstate_by_canonical_identifier(
chain_state=chain_state, canonical_identifier=canonical_identifier
)
if channel_state:
queue_id = QueueIdentifier(
recipient=channel_state.partner_state.address,
canonical_identifier=canonical_identifier,
)
if queue_id in chain_state.queueids_to_queues:
chain_state.queueids_to_queues.pop(queue_id)
return handle_token_network_action(chain_state=chain_state, state_change=state_change)
def verify_request_monitoring(
self, partner_address: Address, requesting_address: Address
) -> bool:
""" One should only use this method to verify integrity and signatures of a
RequestMonitoring message. """
if not self.non_closing_signature:
return False
balance_proof_data = pack_balance_proof(
nonce=self.balance_proof.nonce,
balance_hash=self.balance_proof.balance_hash,
additional_hash=self.balance_proof.additional_hash,
canonical_identifier=CanonicalIdentifier(
chain_identifier=self.balance_proof.chain_id,
token_network_address=self.balance_proof.token_network_address,
channel_identifier=self.balance_proof.channel_identifier,
),
)
blinded_data = pack_balance_proof_update(
nonce=self.balance_proof.nonce,
balance_hash=self.balance_proof.balance_hash,
additional_hash=self.balance_proof.additional_hash,
canonical_identifier=CanonicalIdentifier(
chain_identifier=self.balance_proof.chain_id,
token_network_address=self.balance_proof.token_network_address,
channel_identifier=self.balance_proof.channel_identifier,
),
partner_signature=self.balance_proof.signature,
)