Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support group keys for RFQ negotiation flows #1382

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions rfq/manager.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rfq

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -965,6 +966,33 @@ func (m *Manager) GetAssetGroupKey(ctx context.Context,
return groupKeyBytes, nil
}

// AssetMatchesSpecifier checks if the provided asset satisfies the provided
// specifier. If the specifier includes a group key, we will check if the asset
// belongs to that group.
func (m *Manager) AssetMatchesSpecifier(ctx context.Context,
specifier asset.Specifier, id asset.ID) (bool, error) {

switch {
case specifier.HasGroupPubKey():
group, err := m.GetAssetGroupKey(ctx, id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we should return the public key instead of the bytes here. Then can use .IsEqual() on it.

if err != nil {
return false, err
}

specifierGK := specifier.UnwrapGroupKeyToPtr()

return bytes.Equal(group, specifierGK.SerializeCompressed()),
nil

case specifier.HasId():
specifierID := specifier.UnwrapIdToPtr()

return specifierID.IsEqual(id), nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I guess the IsEqual is convenient because we can call it on a pointer as well as on a struct. But it kind of also hides the fact that specifierID might be nil here (it's not because of .HasId() above.
IMO *specifierID == id still is more explicit.

}

return false, fmt.Errorf("specifier is empty")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: I find it easier to read if a switch has a default case that has the error return. But personal preference I guess.

}

// publishSubscriberEvent publishes an event to all subscribers.
func (m *Manager) publishSubscriberEvent(event fn.Event) {
// Iterate over the subscribers and deliver the event to each one.
Expand Down