def __init__(self, canonical_identifier: CanonicalIdentifier, triggered_by_block_hash: BlockHash, channel_state: NettingChannelState): super().__init__(triggered_by_block_hash) canonical_identifier.validate() self.channel_state = channel_state self.canonical_identifier = canonical_identifier
def __init__( self, transaction_hash: TransactionHash, canonical_identifier: CanonicalIdentifier, participant: Address, partner: Address, locksroot: Locksroot, unlocked_amount: TokenAmount, returned_tokens: TokenAmount, block_number: BlockNumber, block_hash: BlockHash, ) -> None: canonical_identifier.validate() if not isinstance(participant, T_Address): raise ValueError("participant must be of type address") if not isinstance(partner, T_Address): raise ValueError("partner must be of type address") super().__init__(transaction_hash, block_number, block_hash) self.canonical_identifier = canonical_identifier self.participant = participant self.partner = partner self.locksroot = locksroot self.unlocked_amount = unlocked_amount self.returned_tokens = returned_tokens
def handle_channel_closed(raiden: "RaidenService", event: Event): token_network_identifier = event.originating_contract data = event.event_data block_number = data["block_number"] args = data["args"] channel_identifier = args["channel_identifier"] transaction_hash = data["transaction_hash"] block_hash = data["block_hash"] chain_state = views.state_from_raiden(raiden) channel_state = views.get_channelstate_by_canonical_identifier_and_address( chain_state=chain_state, canonical_identifier=CanonicalIdentifier( chain_identifier=chain_state.chain_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ), address=args['closing_participant'], ) channel_closed: StateChange if channel_state: # The from address is included in the ChannelClosed event as the # closing_participant field if raiden.address == channel_state.our_state.address: channel_closed = ContractReceiveChannelClosed( transaction_hash=transaction_hash, transaction_from=args["closing_participant"], canonical_identifier=channel_state.canonical_identifier, block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(channel_closed) else: # Must be a light client latest_non_closing_balance_proof = LightClientMessageHandler.get_latest_light_client_non_closing_balance_proof( channel_state.identifier, raiden.wal.storage) channel_closed = ContractReceiveChannelClosedLight( transaction_hash=transaction_hash, transaction_from=args["closing_participant"], canonical_identifier=channel_state.canonical_identifier, block_number=block_number, block_hash=block_hash, light_client_address=channel_state.our_state.address, latest_update_non_closing_balance_proof_data= latest_non_closing_balance_proof) raiden.handle_and_track_state_change(channel_closed) else: # This is a channel close event of a channel we're not a participant of route_closed = ContractReceiveRouteClosed( transaction_hash=transaction_hash, canonical_identifier=CanonicalIdentifier( chain_identifier=chain_state.chain_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ), block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(route_closed)
def test_waiting_messages(pathfinding_service_mock): participant1_privkey, participant1 = make_privkey_address() token_network_address = TokenNetworkAddress(b"1" * 20) channel_id = ChannelID(1) # register token network internally database = pathfinding_service_mock.database database.conn.execute( "INSERT INTO token_network(address) VALUES (?)", [to_checksum_address(token_network_address)], ) fee_update = PFSFeeUpdate( canonical_identifier=CanonicalIdentifier( chain_identifier=ChainID(1), token_network_address=token_network_address, channel_identifier=channel_id, ), updating_participant=participant1, fee_schedule=FeeScheduleState(), timestamp=datetime.utcnow(), signature=EMPTY_SIGNATURE, ) fee_update.sign(LocalSigner(participant1_privkey)) capacity_update = PFSCapacityUpdate( canonical_identifier=CanonicalIdentifier( chain_identifier=ChainID(1), token_network_address=token_network_address, channel_identifier=channel_id, ), updating_participant=make_address(), other_participant=make_address(), updating_nonce=Nonce(1), other_nonce=Nonce(1), updating_capacity=TokenAmount(100), other_capacity=TokenAmount(111), reveal_timeout=50, signature=EMPTY_SIGNATURE, ) capacity_update.sign(LocalSigner(participant1_privkey)) for message in (fee_update, capacity_update): database.insert_waiting_message(message) recovered_messages = list( database.pop_waiting_messages( token_network_address=token_network_address, channel_id=channel_id ) ) assert len(recovered_messages) == 1 assert message == recovered_messages[0] recovered_messages2 = list( database.pop_waiting_messages( token_network_address=token_network_address, channel_id=channel_id ) ) assert len(recovered_messages2) == 0
def __init__( self, transaction_hash: TransactionHash, canonical_identifier: CanonicalIdentifier, block_number: BlockNumber, block_hash: BlockHash, ) -> None: super().__init__(transaction_hash, block_number, block_hash) canonical_identifier.validate() self.canonical_identifier = canonical_identifier
def _get_onchain_locksroots( raiden: "RaidenService", storage: SQLiteStorage, 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=ChainID(-1), token_network_address=TokenNetworkAddress( to_canonical_address(token_network["address"])), channel_identifier=ChannelID(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
def handle_channel_update_transfer(raiden: "RaidenService", event: Event): token_network_identifier = event.originating_contract data = event.event_data args = data["args"] channel_identifier = args["channel_identifier"] transaction_hash = data["transaction_hash"] block_number = data["block_number"] block_hash = data["block_hash"] chain_state = views.state_from_raiden(raiden) channel_state = views.get_channelstate_by_canonical_identifier_and_address( chain_state=chain_state, canonical_identifier=CanonicalIdentifier( chain_identifier=chain_state.chain_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ), address=args['closing_participant'], ) if channel_state: channel_transfer_updated = ContractReceiveUpdateTransfer( transaction_hash=transaction_hash, canonical_identifier=channel_state.canonical_identifier, nonce=args["nonce"], block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(channel_transfer_updated)
def payment_channel_open_and_deposit( app0: App, app1: App, token_address: TokenAddress, deposit: TokenAmount, settle_timeout: BlockTimeout, ) -> None: """ Open a new channel with app0 and app1 as participants """ assert token_address block_identifier: BlockSpecification if app0.raiden.wal: block_identifier = views.state_from_raiden(app0.raiden).block_hash else: block_identifier = "latest" token_network_address = app0.raiden.default_registry.get_token_network( token_address=token_address, block_identifier=block_identifier ) assert token_network_address, "request a channel for an unregistered token" token_network_proxy = app0.raiden.proxy_manager.token_network(token_network_address) channel_identifier = token_network_proxy.new_netting_channel( partner=app1.raiden.address, settle_timeout=settle_timeout, given_block_identifier=block_identifier, ) assert channel_identifier if deposit != 0: canonical_identifier = CanonicalIdentifier( chain_identifier=state_from_raiden(app0.raiden).chain_id, token_network_address=token_network_proxy.address, channel_identifier=channel_identifier, ) for app in [app0, app1]: # Use each app's own chain because of the private key / local signing token = app.raiden.proxy_manager.token(token_address) payment_channel_proxy = app.raiden.proxy_manager.payment_channel( canonical_identifier=canonical_identifier ) # This check can succeed and the deposit still fail, if channels are # openned in parallel previous_balance = token.balance_of(app.raiden.address) assert previous_balance >= deposit # the payment channel proxy will call approve # token.approve(token_network_proxy.address, deposit) payment_channel_proxy.set_total_deposit( total_deposit=deposit, block_identifier="latest" ) # Balance must decrease by at least but not exactly `deposit` amount, # because channels can be openned in parallel new_balance = token.balance_of(app.raiden.address) assert new_balance <= previous_balance - deposit check_channel( app0, app1, token_network_proxy.address, channel_identifier, settle_timeout, deposit )
def get_updatepfs_message( # pylint: disable=too-many-arguments updating_participant: Address, other_participant: Address, chain_identifier=ChainID(1), channel_identifier=DEFAULT_CHANNEL_ID, token_network_address: TokenNetworkAddress = DEFAULT_TOKEN_NETWORK_ADDRESS, updating_nonce=Nonce(1), other_nonce=Nonce(0), updating_capacity=TokenAmount(90), other_capacity=TokenAmount(110), reveal_timeout: int = 2, mediation_fee: FeeAmount = FeeAmount(0), privkey_signer: bytes = PRIVATE_KEY_1, ) -> UpdatePFS: updatepfs_message = UpdatePFS( canonical_identifier=CanonicalIdentifier( chain_identifier=chain_identifier, channel_identifier=channel_identifier, token_network_address=token_network_address, ), updating_participant=updating_participant, other_participant=other_participant, updating_nonce=updating_nonce, other_nonce=other_nonce, updating_capacity=updating_capacity, other_capacity=other_capacity, reveal_timeout=reveal_timeout, mediation_fee=mediation_fee, signature=EMPTY_SIGNATURE, ) updatepfs_message.sign(LocalSigner(privkey_signer)) return updatepfs_message
def test_update_fee(order, pathfinding_service_mock, token_network_model): pathfinding_service_mock.database.insert( "token_network", dict(address=token_network_model.address)) if order == "normal": setup_channel(pathfinding_service_mock, token_network_model) fee_schedule = FeeScheduleState( flat=FeeAmount(1), proportional=ProportionalFeeAmount(int(0.1e9)), imbalance_penalty=[(TokenAmount(0), FeeAmount(0)), (TokenAmount(10), FeeAmount(10))], ) fee_update = PFSFeeUpdate( canonical_identifier=CanonicalIdentifier( chain_identifier=ChainID(1), token_network_address=token_network_model.address, channel_identifier=ChannelID(1), ), updating_participant=PARTICIPANT1, fee_schedule=fee_schedule, timestamp=datetime.now(timezone.utc), signature=EMPTY_SIGNATURE, ) fee_update.sign(LocalSigner(PARTICIPANT1_PRIVKEY)) pathfinding_service_mock.handle_message(fee_update) if order == "fee_update_before_channel_open": setup_channel(pathfinding_service_mock, token_network_model) cv = token_network_model.G[PARTICIPANT1][PARTICIPANT2]["view"] for key in ("flat", "proportional", "imbalance_penalty"): assert getattr(cv.fee_schedule_sender, key) == getattr(fee_schedule, key)
def handle_contract_send_channelclose( raiden: "RaidenService", chain_state: ChainState, channel_close_event: ContractSendChannelClose, ): balance_proof = channel_close_event.balance_proof if balance_proof: nonce = balance_proof.nonce balance_hash = balance_proof.balance_hash signature = balance_proof.signature message_hash = balance_proof.message_hash else: nonce = Nonce(0) balance_hash = EMPTY_BALANCE_HASH signature = EMPTY_SIGNATURE message_hash = EMPTY_MESSAGE_HASH channel_proxy = raiden.chain.payment_channel( canonical_identifier=CanonicalIdentifier( chain_identifier=chain_state.chain_id, token_network_address=channel_close_event.token_network_identifier, channel_identifier=channel_close_event.channel_identifier, ) ) channel_proxy.close( nonce=nonce, balance_hash=balance_hash, additional_hash=message_hash, signature=signature, block_identifier=channel_close_event.triggered_by_block_hash, )
def test_serialize_contract_send_subclass(chain_state): """Serializing must preserve class Regression test for https://github.com/raiden-network/raiden/issues/6075 """ canonical_identifier = CanonicalIdentifier( chain_identifier=ChainID(1), token_network_address=TokenNetworkAddress(factories.make_address()), channel_identifier=factories.make_channel_identifier(), ) chain_state.pending_transactions = [ ContractSendChannelClose( canonical_identifier=canonical_identifier, triggered_by_block_hash=factories.make_block_hash(), balance_proof=None, ) ] serialized_chain_state = JSONSerializer.serialize(chain_state) deserialized_chain_state = JSONSerializer.deserialize( serialized_chain_state) assert ( chain_state.pending_transactions[0].__class__.__name__ == deserialized_chain_state.pending_transactions[0].__class__.__name__) assert chain_state == deserialized_chain_state
def get_capacity_update_message( # pylint: disable=too-many-arguments updating_participant: Address, other_participant: Address, chain_id=ChainID(61), channel_identifier=DEFAULT_CHANNEL_ID, token_network_address: TokenNetworkAddress = DEFAULT_TOKEN_NETWORK_ADDRESS, updating_nonce=Nonce(1), other_nonce=Nonce(0), updating_capacity=TA(90), other_capacity=TA(110), reveal_timeout: BlockTimeout = BlockTimeout(2), privkey_signer: bytes = PRIVATE_KEY_1, ) -> PFSCapacityUpdate: updatepfs_message = PFSCapacityUpdate( canonical_identifier=CanonicalIdentifier( chain_identifier=chain_id, channel_identifier=channel_identifier, token_network_address=token_network_address, ), updating_participant=updating_participant, other_participant=other_participant, updating_nonce=updating_nonce, other_nonce=other_nonce, updating_capacity=updating_capacity, other_capacity=other_capacity, reveal_timeout=reveal_timeout, signature=EMPTY_SIGNATURE, ) updatepfs_message.sign(LocalSigner(privkey_signer)) return updatepfs_message
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
def from_dict(cls, data: Dict[str, Any]) -> "ContractSendChannelSettle": restored = cls( canonical_identifier=CanonicalIdentifier.from_dict( data["canonical_identifier"]), triggered_by_block_hash=BlockHash( deserialize_bytes(data["triggered_by_block_hash"])), ) return restored
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_signed_balance_proof( msg_type=MessageTypeId.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, ) reward_proof_data = pack_reward_proof( chain_id=self.balance_proof.chain_id, token_network_address=self.balance_proof.token_network_address, reward_amount=self.reward_amount, monitoring_service_contract_address=self. monitoring_service_contract_address, non_closing_participant=requesting_address, non_closing_signature=self.non_closing_signature, ) reward_proof_signature = self.reward_proof_signature or EMPTY_SIGNATURE return (recover(balance_proof_data, self.balance_proof.signature) == partner_address and recover(blinded_data, self.non_closing_signature) == requesting_address and recover(reward_proof_data, reward_proof_signature) == requesting_address)
def from_dict(cls, data: Dict[str, Any]) -> "ContractReceiveRouteClosed": return cls( transaction_hash=deserialize_transactionhash( data["transaction_hash"]), canonical_identifier=CanonicalIdentifier.from_dict( data["canonical_identifier"]), block_number=BlockNumber(int(data["block_number"])), block_hash=BlockHash(deserialize_bytes(data["block_hash"])), )
def wait_for_channel_in_states(raiden: "RaidenService", payment_network_id: PaymentNetworkID, token_address: TokenAddress, channel_ids: List[ChannelID], retry_timeout: float, target_states: Sequence[str], partner_addresses: List[Address]) -> None: """Wait until all channels are in `target_states`. Raises: ValueError: If the token_address is not registered in the payment_network. Note: This does not time out, use gevent.Timeout. """ chain_state = views.state_from_raiden(raiden) token_network = views.get_token_network_by_token_address( chain_state=chain_state, payment_network_id=payment_network_id, token_address=token_address) if token_network is None: raise ValueError( f"The token {token_address} is not registered on the network {payment_network_id}." ) 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 ] while list_cannonical_ids: assert raiden, ALARM_TASK_ERROR_MSG assert raiden.alarm, ALARM_TASK_ERROR_MSG canonical_id = list_cannonical_ids[-1] chain_state = views.state_from_raiden(raiden) channel_state = views.get_channelstate_by_canonical_identifier_and_address( chain_state=chain_state, canonical_identifier=canonical_id, address=partner_addresses[0]) channel_is_settled = (channel_state is None or channel.get_status(channel_state) in target_states) if channel_is_settled: list_cannonical_ids.pop() else: gevent.sleep(retry_timeout)
def handle_channel_closed(raiden: "RaidenService", event: Event): token_network_identifier = event.originating_contract data = event.event_data block_number = data["block_number"] args = data["args"] channel_identifier = args["channel_identifier"] transaction_hash = data["transaction_hash"] block_hash = data["block_hash"] chain_state = views.state_from_raiden(raiden) channel_state = views.get_channelstate_by_canonical_identifier( chain_state=chain_state, canonical_identifier=CanonicalIdentifier( chain_identifier=chain_state.chain_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ), ) channel_closed: StateChange if channel_state: # The from address is included in the ChannelClosed event as the # closing_participant field channel_closed = ContractReceiveChannelClosed( transaction_hash=transaction_hash, transaction_from=args["closing_participant"], canonical_identifier=channel_state.canonical_identifier, block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(channel_closed) else: # This is a channel close event of a channel we're not a participant of route_closed = ContractReceiveRouteClosed( transaction_hash=transaction_hash, canonical_identifier=CanonicalIdentifier( chain_identifier=chain_state.chain_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ), block_number=block_number, block_hash=block_hash, ) raiden.handle_and_track_state_change(route_closed)
def check_channel( app1: App, app2: App, token_network_address: TokenNetworkAddress, channel_identifier: ChannelID, settle_timeout: BlockTimeout, deposit_amount: TokenAmount, ) -> None: canonical_identifier = CanonicalIdentifier( chain_identifier=state_from_raiden(app1.raiden).chain_id, token_network_address=token_network_address, channel_identifier=channel_identifier, ) netcontract1 = app1.raiden.proxy_manager.payment_channel( canonical_identifier=canonical_identifier ) netcontract2 = app2.raiden.proxy_manager.payment_channel( canonical_identifier=canonical_identifier ) # Check a valid settle timeout was used, the netting contract has an # enforced minimum and maximum assert settle_timeout == netcontract1.settle_timeout() assert settle_timeout == netcontract2.settle_timeout() if deposit_amount > 0: assert netcontract1.can_transfer("latest") assert netcontract2.can_transfer("latest") app1_details = netcontract1.detail("latest") app2_details = netcontract2.detail("latest") assert ( app1_details.participants_data.our_details.address == app2_details.participants_data.partner_details.address ) assert ( app1_details.participants_data.partner_details.address == app2_details.participants_data.our_details.address ) assert ( app1_details.participants_data.our_details.deposit == app2_details.participants_data.partner_details.deposit ) assert ( app1_details.participants_data.partner_details.deposit == app2_details.participants_data.our_details.deposit ) assert app1_details.chain_id == app2_details.chain_id assert app1_details.participants_data.our_details.deposit == deposit_amount assert app1_details.participants_data.partner_details.deposit == deposit_amount assert app2_details.participants_data.our_details.deposit == deposit_amount assert app2_details.participants_data.partner_details.deposit == deposit_amount assert app2_details.chain_id == UNIT_CHAIN_ID
def from_dict(cls, data: Dict[str, Any]) -> "ContractSendChannelBatchUnlock": restored = cls( canonical_identifier=CanonicalIdentifier.from_dict( data["canonical_identifier"]), participant=to_canonical_address(data["participant"]), triggered_by_block_hash=BlockHash( deserialize_bytes(data["triggered_by_block_hash"])), ) return restored
def from_dict(cls, data: Dict[str, Any]) -> "ContractReceiveChannelNewBalance": return cls( transaction_hash=deserialize_transactionhash( data["transaction_hash"]), canonical_identifier=CanonicalIdentifier.from_dict( data["canonical_identifier"]), deposit_transaction=data["deposit_transaction"], block_number=BlockNumber(int(data["block_number"])), block_hash=BlockHash(deserialize_bytes(data["block_hash"])), )
def from_dict(cls, data: Dict[str, Any]) -> "ContractReceiveRouteNew": return cls( transaction_hash=deserialize_transactionhash( data["transaction_hash"]), canonical_identifier=CanonicalIdentifier.from_dict( data["canonical_identifier"]), participant1=to_canonical_address(data["participant1"]), participant2=to_canonical_address(data["participant2"]), block_number=BlockNumber(int(data["block_number"])), block_hash=BlockHash(deserialize_bytes(data["block_hash"])), )
def subdispatch_targettask( chain_state: ChainState, state_change: StateChange, token_network_identifier: TokenNetworkID, channel_identifier: ChannelID, secrethash: SecretHash, ) -> TransitionResult[ChainState]: block_number = chain_state.block_number sub_task = chain_state.payment_mapping.secrethashes_to_task.get(secrethash) if not sub_task: is_valid_subtask = True target_state = None elif sub_task and isinstance(sub_task, TargetTask): is_valid_subtask = token_network_identifier == sub_task.token_network_identifier target_state = sub_task.target_state else: is_valid_subtask = False events: List[Event] = list() channel_state = None if is_valid_subtask: channel_state = views.get_channelstate_by_canonical_identifier( chain_state=chain_state, canonical_identifier=CanonicalIdentifier( chain_identifier=chain_state.chain_id, token_network_address=token_network_identifier, channel_identifier=channel_identifier, ), ) if channel_state: pseudo_random_generator = chain_state.pseudo_random_generator iteration = target.state_transition( target_state=target_state, state_change=state_change, channel_state=channel_state, pseudo_random_generator=pseudo_random_generator, block_number=block_number, ) events = iteration.events if iteration.new_state: sub_task = TargetTask(channel_state.canonical_identifier, iteration.new_state) chain_state.payment_mapping.secrethashes_to_task[ secrethash] = sub_task elif secrethash in chain_state.payment_mapping.secrethashes_to_task: del chain_state.payment_mapping.secrethashes_to_task[secrethash] return TransitionResult(chain_state, events)
def from_dict(cls, data: Dict[str, Any]) -> "ContractSendChannelClose": if not "signed_close_tx" in data: data["signed_close_tx"] = "" restored = cls(canonical_identifier=CanonicalIdentifier.from_dict( data["canonical_identifier"]), balance_proof=data["balance_proof"], triggered_by_block_hash=BlockHash( deserialize_bytes(data["triggered_by_block_hash"])), signed_close_tx=data["signed_close_tx"]) return restored
def set_fee(self, node1: int, node2: int, fee_schedule: FeeSchedule): channel_id = self.G[a(node1)][a(node2)]["view"].channel_id self.handle_channel_fee_update( FeeUpdate( CanonicalIdentifier( chain_identifier=ChainID(1), token_network_address=self.address, channel_identifier=channel_id, ), a(node1), a(node2), fee_schedule, ))
def __init__( self, transaction_hash: TransactionHash, canonical_identifier: CanonicalIdentifier, participant1: Address, participant2: Address, block_number: BlockNumber, block_hash: BlockHash, ) -> None: if not isinstance(participant1, T_Address): raise ValueError("participant1 must be of type address") if not isinstance(participant2, T_Address): raise ValueError("participant2 must be of type address") canonical_identifier.validate() super().__init__(transaction_hash, block_number, block_hash) self.canonical_identifier = canonical_identifier self.participant1 = participant1 self.participant2 = participant2
def set_fee(self, node1: int, node2: int, **fee_params): channel_id = self.G[a(node1)][a(node2)]["view"].channel_id self.handle_channel_fee_update( PFSFeeUpdate( canonical_identifier=CanonicalIdentifier( chain_identifier=ChainID(1), token_network_address=self.address, channel_identifier=channel_id, ), updating_participant=a(node1), fee_schedule=RaidenFeeSchedule(**fee_params), signature=EMPTY_SIGNATURE, timestamp=datetime.now(timezone.utc), ))
def _canonical_id_from_string(string: str) -> CanonicalIdentifier: try: chain_id_str, token_network_address_hex, channel_id_str = string.split( "|") return CanonicalIdentifier( chain_identifier=ChainID(int(chain_id_str)), token_network_address=to_bytes( hexstr=token_network_address_hex), channel_identifier=ChannelID(int(channel_id_str)), ) except ValueError: raise ValueError( f"Could not reconstruct canonical identifier from string: {string}" )
def from_dict(cls, data: Dict[str, Any]) -> "ContractReceiveChannelSettled": return cls( transaction_hash=deserialize_transactionhash( data["transaction_hash"]), canonical_identifier=CanonicalIdentifier.from_dict( data["canonical_identifier"]), our_onchain_locksroot=deserialize_locksroot( data["our_onchain_locksroot"]), partner_onchain_locksroot=deserialize_locksroot( data["partner_onchain_locksroot"]), block_number=BlockNumber(int(data["block_number"])), block_hash=BlockHash(deserialize_bytes(data["block_hash"])), )