Пример #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),
            ))
Пример #2
0
    def populate_token_network(
        token_network: TokenNetwork,
        private_keys: List[str],
        addresses: List[Address],
        web3: Web3,
        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(
                ChannelIdentifier(channel_id),
                addresses[p1_index],
                addresses[p2_index],
                settle_timeout=settle_timeout,
            )

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

            token_network.handle_channel_balance_update_message(
                channel_identifier=ChannelIdentifier(channel_id),
                updating_participant=addresses[p1_index],
                other_participant=addresses[p2_index],
                updating_nonce=1,
                other_nonce=1,
                updating_capacity=p1_capacity,
                other_capacity=p2_capacity,
                reveal_timeout=p1_reveal_timeout,
            )
            token_network.handle_channel_balance_update_message(
                channel_identifier=ChannelIdentifier(channel_id),
                updating_participant=addresses[p2_index],
                other_participant=addresses[p1_index],
                updating_nonce=2,
                other_nonce=1,
                updating_capacity=p2_capacity,
                other_capacity=p1_capacity,
                reveal_timeout=p2_reveal_timeout,
            )
Пример #3
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 = ChannelIdentifier(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, deposit2 = random.sample(range(1000), 2)
        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(
            channel_identifier=channel_id,
            updating_participant=address1,
            other_participant=address2,
            updating_nonce=1,
            other_nonce=1,
            updating_capacity=deposit1,
            other_capacity=deposit2,
            reveal_timeout=2,
        )
        token_network_model.handle_channel_balance_update_message(
            channel_identifier=channel_id,
            updating_participant=address2,
            other_participant=address1,
            updating_nonce=2,
            other_nonce=1,
            updating_capacity=deposit1,
            other_capacity=deposit2,
            reveal_timeout=2,
        )
Пример #4
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(
                channel_identifier=ChannelID(channel_id),
                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),
            )
            token_network.handle_channel_balance_update_message(
                channel_identifier=ChannelID(channel_id),
                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),
            )
Пример #5
0
def token_network_model(add_and_register_token: Callable, ) -> TokenNetwork:
    token = add_and_register_token(
        initial_amount=1000000,
        decimals=18,
        token_name='PFSTestToken',
        token_symbol='PFS',
    )
    return TokenNetwork(token.address, token.address)
Пример #6
0
 def get_token_networks(self) -> Iterator[TokenNetwork]:
     with self._cursor() as cursor:
         for row in cursor.execute(
                 "SELECT address, settle_timeout FROM token_network"):
             yield TokenNetwork(
                 token_network_address=TokenNetworkAddress(
                     to_canonical_address(row[0])),
                 settle_timeout=row[1],
             )
Пример #7
0
    def populate_token_network(
        token_network: TokenNetwork,
        private_keys: List[str],
        addresses: List[Address],
        web3: Web3,
        channel_descriptions: List,
    ):
        for channel_id, (
                p1_index,
                p1_deposit,
                _p1_transferred_amount,
                _p1_fee,
                p2_index,
                p2_deposit,
                _p2_transferred_amount,
                _p2_fee,
        ) in enumerate(channel_descriptions):
            token_network.handle_channel_opened_event(
                ChannelIdentifier(channel_id),
                addresses[p1_index],
                addresses[p2_index],
            )

            token_network.handle_channel_new_deposit_event(
                ChannelIdentifier(channel_id),
                addresses[p1_index],
                p1_deposit,
            )
            token_network.handle_channel_new_deposit_event(
                ChannelIdentifier(channel_id),
                addresses[p2_index],
                p2_deposit,
            )
Пример #8
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 = ChannelIdentifier(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))
        token_network_model.handle_channel_opened_event(
            channel_id,
            address1,
            address2,
        )

        # deposit to channels
        deposit1, deposit2 = random.sample(range(1000), 2)
        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,
        )
Пример #9
0
    def populate_token_network(
        token_network: TokenNetwork,
        reachability_state: SimpleReachabilityContainer,
        addresses: List[Address],
        channel_descriptions: List,
    ):
        for (
            channel_id,
            (
                p1_index,
                p1_capacity,
                _p1_fee,
                p1_reveal_timeout,
                p1_reachability,
                p2_index,
                p2_capacity,
                _p2_fee,
                p2_reveal_timeout,
                p2_reachability,
            ),
        ) 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,
            )

            token_network.handle_channel_balance_update_message(
                PFSCapacityUpdate(
                    canonical_identifier=CanonicalIdentifier(
                        chain_identifier=ChainID(61),
                        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,
                    signature=EMPTY_SIGNATURE,
                ),
                updating_capacity_partner=TokenAmount(0),
                other_capacity_partner=TokenAmount(0),
            )
            token_network.handle_channel_balance_update_message(
                PFSCapacityUpdate(
                    canonical_identifier=CanonicalIdentifier(
                        chain_identifier=ChainID(61),
                        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,
                    signature=EMPTY_SIGNATURE,
                ),
                updating_capacity_partner=TokenAmount(p1_capacity),
                other_capacity_partner=TokenAmount(p2_capacity),
            )

            # Update presence state according to scenario
            reachability_state.reachabilities[participant1] = p1_reachability
            reachability_state.reachabilities[participant2] = p2_reachability
Пример #10
0
 def get_token_networks(self) -> Iterator[TokenNetwork]:
     for row in self.conn.execute("SELECT address FROM token_network"):
         yield TokenNetwork(
             token_network_address=TokenNetworkAddress(to_canonical_address(row[0]))
         )
Пример #11
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
Пример #12
0
def token_network_model() -> TokenNetwork:
    return TokenNetwork(TokenNetworkAddress(bytes([1] * 20)),
                        DEFAULT_TOKEN_NETWORK_SETTLE_TIMEOUT)
Пример #13
0
 def get_token_networks(self) -> Iterator[TokenNetwork]:
     for row in self.conn.execute("SELECT address FROM token_network"):
         yield TokenNetwork(token_network_address=decode_hex(row[0]))
Пример #14
0
def token_network_model(token_network) -> TokenNetwork:
    return TokenNetwork(token_network.address, token_network.address)
Пример #15
0
def token_network_model() -> TokenNetwork:
    return TokenNetwork(TokenNetworkAddress('0x' + '1' * 40))
Пример #16
0
def populate_token_network_random(
    token_network_model: TokenNetwork, private_keys: List[str]
) -> None:
    number_of_channels = 300
    # 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 = private_key_to_address(private_key1)
        address2 = private_key_to_address(private_key2)
        token_network_model.handle_channel_opened_event(
            channel_identifier=channel_id,
            participant1=address1,
            participant2=address2,
        )

        # 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_balance_update_message(
            PFSCapacityUpdate(
                canonical_identifier=CanonicalIdentifier(
                    chain_identifier=ChainID(61),
                    channel_identifier=channel_id,
                    token_network_address=TokenNetworkAddress(token_network_model.address),
                ),
                updating_participant=address1,
                other_participant=address2,
                updating_nonce=Nonce(1),
                other_nonce=Nonce(1),
                updating_capacity=deposit1,
                other_capacity=deposit2,
                reveal_timeout=BlockTimeout(2),
                signature=EMPTY_SIGNATURE,
            ),
            updating_capacity_partner=TokenAmount(0),
            other_capacity_partner=TokenAmount(0),
        )
        token_network_model.handle_channel_balance_update_message(
            PFSCapacityUpdate(
                canonical_identifier=CanonicalIdentifier(
                    chain_identifier=ChainID(61),
                    channel_identifier=channel_id,
                    token_network_address=TokenNetworkAddress(token_network_model.address),
                ),
                updating_participant=address2,
                other_participant=address1,
                updating_nonce=Nonce(2),
                other_nonce=Nonce(1),
                updating_capacity=deposit2,
                other_capacity=deposit1,
                reveal_timeout=BlockTimeout(2),
                signature=EMPTY_SIGNATURE,
            ),
            updating_capacity_partner=TokenAmount(deposit1),
            other_capacity_partner=TokenAmount(deposit2),
        )
Пример #17
0
def token_network_model() -> TokenNetwork:
    return TokenNetwork(TokenNetworkAddress("0x" + "1" * 40))
Пример #18
0
def token_network_model() -> TokenNetwork:
    return TokenNetwork(TokenNetworkAddress(bytes([1] * 20)))