ProjectOpenSea / operator-filter-registry

MIT License
312 stars 89 forks source link

How does function subscribe work? #34

Closed tdergouzi closed 1 year ago

tdergouzi commented 1 year ago

First, i want to thank to OpenSea about enforce creator fees. I have some problems with the function subscribe:

    /**
     * @notice Subscribe an address to another registrant's filtered operators and codeHashes. Will remove previous
     *         subscription if present.
     *         Note that accounts with subscriptions may go on to subscribe to other accounts - in this case,
     *         subscriptions will not be forwarded. Instead the former subscription's existing entries will still be
     *         used.
     */
    function subscribe(address registrant, address newSubscription) external onlyAddressOrOwner(registrant) {
        if (registrant == newSubscription) {
            revert CannotSubscribeToSelf();
        }
        if (newSubscription == address(0)) {
            revert CannotSubscribeToZeroAddress();
        }
        address registration = _registrations[registrant];
        if (registration == address(0)) {
            revert NotRegistered(registrant);
        }
        if (registration == newSubscription) {
            revert AlreadySubscribed(newSubscription);
        }
        address newSubscriptionRegistration = _registrations[newSubscription];
        if (newSubscriptionRegistration == address(0)) {
            revert NotRegistered(newSubscription);
        }
        if (newSubscriptionRegistration != newSubscription) {
            revert CannotSubscribeToRegistrantWithSubscription(newSubscription);
        }

        if (registration != registrant) {
            _subscribers[registration].remove(registrant);
            emit SubscriptionUpdated(registrant, registration, false);
        }
        _registrations[registrant] = newSubscription;
        _subscribers[newSubscription].add(registrant);
        emit SubscriptionUpdated(registrant, newSubscription, true);
    }

According to the function comments, if the registrant calls this function to subscribe a new subscription. Is that means the _filteredOperators[registrant] should contains _filteredOperators[newSubscription], but there is no copy code. And there is function copyEntriesOf, why not copy the entries of new subscription into registrant's filtered operators when call subscribe?

operatorfilterer commented 1 year ago

When one account "subscribes" to another, the isOperatorAllowed method refers directly to the subscription account's curated lists of filtered operators and codehashes. No data is copied when subscribing, since the isOperatorAllowed check looks directly at the other account's lists. Any updates the subscription account makes to its lists are automatically reflected in the check. In effect, when an account subscribes to another, they are delegating their curation to the second account.

Subscriptions can be removed or updated at any time.

Accounts may optionally copy the lists of other accounts instead of subscribing. In that case, however, any updates the second account makes will not be reflected by the first account - because the registry is looking at the curated lists of the original account, and not a separate subscription account.

tdergouzi commented 1 year ago

Thanks for helping me figured it out.