Exemple #1
0
def handle_tokennetwork_new(raiden: "RaidenService", event: Event):
    """ Handles a `TokenNetworkCreated` event. """
    data = event.event_data
    args = data["args"]
    block_number = data["block_number"]
    token_network_address = args["token_network_address"]
    token_address = typing.TokenAddress(args["token_address"])
    block_hash = data["block_hash"]

    token_network_proxy = raiden.chain.token_network(token_network_address)
    raiden.blockchain_events.add_token_network_listener(
        token_network_proxy=token_network_proxy,
        contract_manager=raiden.contract_manager,
        from_block=block_number,
    )

    token_network_state = TokenNetworkState(token_network_address,
                                            token_address)

    transaction_hash = event.event_data["transaction_hash"]

    new_token_network = ContractReceiveNewTokenNetwork(
        transaction_hash=transaction_hash,
        payment_network_identifier=event.originating_contract,
        token_network=token_network_state,
        block_number=block_number,
        block_hash=block_hash,
    )
    raiden.handle_and_track_state_change(new_token_network)
Exemple #2
0
def handle_tokennetwork_new(raiden, event):
    data = event.event_data
    manager_address = data['channel_manager_address']

    registry = raiden.default_registry
    manager_proxy = registry.manager(manager_address)
    netting_channel_proxies = get_channel_proxies(raiden.chain, raiden.address,
                                                  manager_proxy)

    # Install the filters first to avoid missing changes, as a consequence
    # some events might be applied twice.
    raiden.blockchain_events.add_channel_manager_listener(manager_proxy)
    for channel_proxy in netting_channel_proxies:
        raiden.blockchain_events.add_netting_channel_listener(channel_proxy)

    token_network_state = get_token_network_state_from_proxies(
        raiden,
        manager_proxy,
        netting_channel_proxies,
    )

    new_payment_network = ContractReceiveNewTokenNetwork(
        event.originating_contract,
        token_network_state,
    )
    raiden.handle_state_change(new_payment_network)
Exemple #3
0
def handle_tokennetwork_new(raiden, event: Event):
    """ Handles a `TokenNetworkCreated` event. """
    data = event.event_data
    token_network_address = data['token_network_address']

    token_network_proxy = raiden.chain.token_network(token_network_address)
    raiden.blockchain_events.add_token_network_listener(
        token_network_proxy=token_network_proxy,
        contract_manager=raiden.contract_manager,
        from_block=data['blockNumber'],
    )

    token_address = data_decoder(event.event_data['args']['token_address'])

    token_network_state = TokenNetworkState(
        token_network_address,
        token_address,
    )

    transaction_hash = event.event_data['transactionHash']
    assert transaction_hash, 'A mined transaction must have the hash field'

    new_token_network = ContractReceiveNewTokenNetwork(
        transaction_hash=transaction_hash,
        payment_network_identifier=event.originating_contract,
        token_network=token_network_state,
        block_number=data['block_number'],
    )
    raiden.handle_state_change(new_token_network)
Exemple #4
0
def test_handle_new_token_network(chain_state, token_network_address):
    token_address = factories.make_address()
    token_network = TokenNetworkState(
        address=token_network_address,
        token_address=token_address,
        network_graph=TokenNetworkGraphState(token_network_address=token_network_address),
    )
    token_network_registry_address = factories.make_address()
    state_change = ContractReceiveNewTokenNetwork(
        token_network_registry_address=token_network_registry_address,
        token_network=token_network,
        transaction_hash=factories.make_transaction_hash(),
        block_hash=factories.make_block_hash(),
        block_number=factories.make_block_number(),
    )
    transition_result = handle_contract_receive_new_token_network(
        chain_state=chain_state, state_change=state_change
    )
    new_chain_state = transition_result.new_state
    token_network_registry = new_chain_state.identifiers_to_tokennetworkregistries[
        token_network_registry_address
    ]
    assert token_network_registry.address == token_network_registry_address
    assert not transition_result.events
    assert get_networks(
        chain_state=chain_state,
        token_network_registry_address=token_network_registry_address,
        token_address=token_address,
    ) == (token_network_registry, token_network)
def handle_tokennetwork_new(raiden, event, current_block_number):
    """ Handles a `TokenNetworkCreated` event. """
    data = event.event_data
    token_network_address = data['token_network_address']

    token_network_proxy = raiden.chain.token_network(token_network_address)
    raiden.blockchain_events.add_token_network_listener(
        token_network_proxy,
        from_block=data['blockNumber'],
    )

    token_address = data_decoder(event.event_data['args']['token_address'])

    token_network_state = TokenNetworkState(
        token_network_address,
        token_address,
    )

    from_address = raiden.chain.client.get_transaction_from(
        event.event_data['transactionHash'])
    assert from_address, 'A mined transaction must have the from field'

    new_token_network = ContractReceiveNewTokenNetwork(
        from_address,
        event.originating_contract,
        token_network_state,
    )
    raiden.handle_state_change(new_token_network, current_block_number)
Exemple #6
0
def contractreceivenewtokennetwork_from_event(
    event: DecodedEvent
) -> ContractReceiveNewTokenNetwork:
    data = event.event_data
    args = data["args"]
    token_network_address = args["token_network_address"]

    return ContractReceiveNewTokenNetwork(
        token_network_registry_address=TokenNetworkRegistryAddress(event.originating_contract),
        token_network=TokenNetworkState(
            address=token_network_address,
            token_address=args["token_address"],
            network_graph=TokenNetworkGraphState(token_network_address),
        ),
        transaction_hash=event.transaction_hash,
        block_number=event.block_number,
        block_hash=event.block_hash,
    )
def handle_tokennetwork_new2(raiden, event, current_block_number):
    """ Handles a `TokenNetworkCreated` event. """
    data = event.event_data
    token_network_address = data['token_network_address']

    token_network_registry_address = event.originating_contract
    token_network_registry_proxy = raiden.chain.token_network_registry(
        token_network_registry_address, )
    token_network_proxy = token_network_registry_proxy.token_network(
        token_network_address)

    raiden.blockchain_events.add_token_network_listener(token_network_proxy)
    token_network_state = create_new_token_network_state(
        raiden,
        token_network_proxy,
    )

    new_token_network = ContractReceiveNewTokenNetwork(
        event.originating_contract,
        token_network_state,
    )
    raiden.handle_state_change(new_token_network, current_block_number)
def handle_tokennetwork_new(raiden, event, current_block_number):
    """ Handles a `TokenNetworkCreated` event. """
    data = event.event_data
    token_network_address = data['token_network_address']

    token_network_proxy = raiden.chain.token_network(token_network_address)
    raiden.blockchain_events.add_token_network_listener(
        token_network_proxy,
        from_block=data['blockNumber'],
    )

    token_address = data_decoder(event.event_data['args']['token_address'])

    token_network_state = TokenNetworkState(
        token_network_address,
        token_address,
    )

    new_token_network = ContractReceiveNewTokenNetwork(
        event.originating_contract,
        token_network_state,
    )
    raiden.handle_state_change(new_token_network, current_block_number)