Beispiel #1
0
def populate_token_network_random(token_network_model: TokenNetwork,
                                  private_keys: List[str]) -> None:
    # seed for pseudo-randomness from config constant, that changes from time to time
    random.seed(NUMBER_OF_CHANNELS)

    for channel_id_int in range(NUMBER_OF_CHANNELS):
        channel_id = ChannelID(channel_id_int)

        private_key1, private_key2 = random.sample(private_keys, 2)
        address1 = Address(private_key_to_address(private_key1))
        address2 = Address(private_key_to_address(private_key2))
        settle_timeout = 15
        token_network_model.handle_channel_opened_event(
            channel_id, address1, address2, settle_timeout)

        # deposit to channels
        deposit1 = TokenAmount(random.randint(0, 1000))
        deposit2 = TokenAmount(random.randint(0, 1000))
        address1, address2 = token_network_model.channel_id_to_addresses[
            channel_id]
        token_network_model.handle_channel_new_deposit_event(
            channel_id, address1, deposit1)
        token_network_model.handle_channel_new_deposit_event(
            channel_id, address2, deposit2)
        token_network_model.handle_channel_balance_update_message(
            UpdatePFS(
                canonical_identifier=CanonicalIdentifier(
                    chain_identifier=ChainID(1),
                    channel_identifier=channel_id,
                    token_network_address=TokenNetworkAddressBytes(
                        decode_hex(token_network_model.address)),
                ),
                updating_participant=decode_hex(address1),
                other_participant=decode_hex(address2),
                updating_nonce=Nonce(1),
                other_nonce=Nonce(1),
                updating_capacity=deposit1,
                other_capacity=deposit2,
                reveal_timeout=2,
                mediation_fee=FeeAmount(0),
            ))
        token_network_model.handle_channel_balance_update_message(
            UpdatePFS(
                canonical_identifier=CanonicalIdentifier(
                    chain_identifier=ChainID(1),
                    channel_identifier=channel_id,
                    token_network_address=TokenNetworkAddressBytes(
                        decode_hex(token_network_model.address)),
                ),
                updating_participant=decode_hex(address2),
                other_participant=decode_hex(address1),
                updating_nonce=Nonce(2),
                other_nonce=Nonce(1),
                updating_capacity=deposit2,
                other_capacity=deposit1,
                reveal_timeout=2,
                mediation_fee=FeeAmount(0),
            ))
Beispiel #2
0
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
Beispiel #3
0
def get_updatepfs_message(
    chain_identifier: ChainID = 1,
    channel_identifier: ChannelID = 0,
    token_network_address:
    TokenNetworkAddress = DEFAULT_TOKEN_NETWORK_ADDRESS_BYTES,
    updating_participant: Address = None,
    other_participant: Address = None,
    updating_nonce: Nonce = 1,
    other_nonce: Nonce = 0,
    updating_capacity: TokenAmount = 90,
    other_capacity: TokenAmount = 110,
    reveal_timeout: int = 2,
    signature: Signature = '',
) -> UpdatePFS:
    return 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,
        signature=signature,
    )
Beispiel #4
0
def get_updatepfs_message(
    updating_participant: Address,
    other_participant: Address,
    chain_identifier=ChainID(1),
    channel_identifier=ChannelID(0),
    token_network_address:
    TokenNetworkAddressBytes = DEFAULT_TOKEN_NETWORK_ADDRESS_BYTES,
    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 = PRIVAT_KEY_EXAMPLE_1,
) -> UpdatePFS:
    updatepfs_message = UpdatePFS(
        canonical_identifier=CanonicalIdentifier(
            chain_identifier=chain_identifier,
            channel_identifier=channel_identifier,
            token_network_address=token_network_address,
        ),
        updating_participant=decode_hex(updating_participant),
        other_participant=decode_hex(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,
    )

    updatepfs_message.sign(LocalSigner(privkey_signer))

    return updatepfs_message
Beispiel #5
0
    def populate_token_network(
        token_network: TokenNetwork,
        address_to_reachability: Dict[Address, AddressReachability],
        addresses: List[Address],
        channel_descriptions: List,
    ):
        for (
                channel_id,
            (
                p1_index,
                p1_deposit,
                p1_capacity,
                _p1_fee,
                p1_reveal_timeout,
                p1_reachability,
                p2_index,
                p2_deposit,
                p2_capacity,
                _p2_fee,
                p2_reveal_timeout,
                p2_reachability,
                settle_timeout,
            ),
        ) in enumerate(channel_descriptions):
            participant1 = addresses[p1_index]
            participant2 = addresses[p2_index]
            token_network.handle_channel_opened_event(
                channel_identifier=ChannelID(channel_id),
                participant1=participant1,
                participant2=participant2,
                settle_timeout=settle_timeout,
            )

            token_network.handle_channel_new_deposit_event(
                channel_identifier=ChannelID(channel_id),
                receiver=participant1,
                total_deposit=p1_deposit,
            )
            token_network.handle_channel_new_deposit_event(
                channel_identifier=ChannelID(channel_id),
                receiver=participant2,
                total_deposit=p2_deposit,
            )

            token_network.handle_channel_balance_update_message(
                UpdatePFS(
                    canonical_identifier=CanonicalIdentifier(
                        chain_identifier=ChainID(1),
                        channel_identifier=ChannelID(channel_id),
                        token_network_address=TokenNetworkAddress(
                            token_network.address),
                    ),
                    updating_participant=addresses[p1_index],
                    other_participant=addresses[p2_index],
                    updating_nonce=Nonce(1),
                    other_nonce=Nonce(1),
                    updating_capacity=p1_capacity,
                    other_capacity=p2_capacity,
                    reveal_timeout=p1_reveal_timeout,
                    mediation_fee=FeeAmount(0),
                    signature=EMPTY_SIGNATURE,
                ),
                updating_capacity_partner=TokenAmount(0),
                other_capacity_partner=TokenAmount(0),
            )
            token_network.handle_channel_balance_update_message(
                UpdatePFS(
                    canonical_identifier=CanonicalIdentifier(
                        chain_identifier=ChainID(1),
                        channel_identifier=ChannelID(channel_id),
                        token_network_address=TokenNetworkAddress(
                            token_network.address),
                    ),
                    updating_participant=addresses[p2_index],
                    other_participant=addresses[p1_index],
                    updating_nonce=Nonce(2),
                    other_nonce=Nonce(1),
                    updating_capacity=p2_capacity,
                    other_capacity=p1_capacity,
                    reveal_timeout=p2_reveal_timeout,
                    mediation_fee=FeeAmount(0),
                    signature=EMPTY_SIGNATURE,
                ),
                updating_capacity_partner=TokenAmount(p1_capacity),
                other_capacity_partner=TokenAmount(p2_capacity),
            )

            # Update presence state according to scenario
            address_to_reachability[participant1] = p1_reachability
            address_to_reachability[participant2] = p2_reachability
Beispiel #6
0
    def populate_token_network(token_network: TokenNetwork,
                               addresses: List[Address],
                               channel_descriptions: List):
        for (
                channel_id,
            (
                p1_index,
                p1_deposit,
                p1_capacity,
                _p1_fee,
                p1_reveal_timeout,
                p2_index,
                p2_deposit,
                p2_capacity,
                _p2_fee,
                p2_reveal_timeout,
                settle_timeout,
            ),
        ) in enumerate(channel_descriptions):
            token_network.handle_channel_opened_event(
                ChannelID(channel_id),
                addresses[p1_index],
                addresses[p2_index],
                settle_timeout=settle_timeout,
            )

            token_network.handle_channel_new_deposit_event(
                ChannelID(channel_id), addresses[p1_index], p1_deposit)
            token_network.handle_channel_new_deposit_event(
                ChannelID(channel_id), addresses[p2_index], p2_deposit)

            token_network.handle_channel_balance_update_message(
                UpdatePFS(
                    canonical_identifier=CanonicalIdentifier(
                        chain_identifier=ChainID(1),
                        channel_identifier=ChannelID(channel_id),
                        token_network_address=TokenNetworkAddressBytes(
                            decode_hex(token_network.address)),
                    ),
                    updating_participant=decode_hex(addresses[p1_index]),
                    other_participant=decode_hex(addresses[p2_index]),
                    updating_nonce=Nonce(1),
                    other_nonce=Nonce(1),
                    updating_capacity=p1_capacity,
                    other_capacity=p2_capacity,
                    reveal_timeout=p1_reveal_timeout,
                    mediation_fee=FeeAmount(0),
                ))
            token_network.handle_channel_balance_update_message(
                UpdatePFS(
                    canonical_identifier=CanonicalIdentifier(
                        chain_identifier=ChainID(1),
                        channel_identifier=ChannelID(channel_id),
                        token_network_address=TokenNetworkAddressBytes(
                            decode_hex(token_network.address)),
                    ),
                    updating_participant=decode_hex(addresses[p2_index]),
                    other_participant=decode_hex(addresses[p1_index]),
                    updating_nonce=Nonce(2),
                    other_nonce=Nonce(1),
                    updating_capacity=p2_capacity,
                    other_capacity=p1_capacity,
                    reveal_timeout=p2_reveal_timeout,
                    mediation_fee=FeeAmount(0),
                ))