Skip to content

Commit

Permalink
validation service
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Apr 25, 2024
1 parent a1e5fd8 commit eda8919
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/identity/api/v1/identity_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Start transaction (SERIALIZABLE isolation level)
End transaction
*/
func (s *Service) PublishIdentityUpdate(ctx context.Context, req *api.PublishIdentityUpdateRequest) (*api.PublishIdentityUpdateResponse, error) {
return s.store.PublishIdentityUpdate(ctx, req)
return s.store.PublishIdentityUpdate(ctx, req, s.validationService)
}

func (s *Service) GetIdentityUpdates(ctx context.Context, req *api.GetIdentityUpdatesRequest) (*api.GetIdentityUpdatesResponse, error) {
Expand Down
12 changes: 10 additions & 2 deletions pkg/mls/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/uptrace/bun/migrate"
migrations "github.com/xmtp/xmtp-node-go/pkg/migrations/mls"
queries "github.com/xmtp/xmtp-node-go/pkg/mls/store/queries"
"github.com/xmtp/xmtp-node-go/pkg/mlsvalidate"
identity "github.com/xmtp/xmtp-node-go/pkg/proto/identity/api/v1"
"github.com/xmtp/xmtp-node-go/pkg/proto/identity/associations"
mlsv1 "github.com/xmtp/xmtp-node-go/pkg/proto/mls/api/v1"
Expand All @@ -30,7 +31,7 @@ type Store struct {
}

type IdentityStore interface {
PublishIdentityUpdate(ctx context.Context, req *identity.PublishIdentityUpdateRequest) (*identity.PublishIdentityUpdateResponse, error)
PublishIdentityUpdate(ctx context.Context, req *identity.PublishIdentityUpdateRequest, validationService mlsvalidate.MLSValidationService) (*identity.PublishIdentityUpdateResponse, error)
GetInboxLogs(ctx context.Context, req *identity.GetIdentityUpdatesRequest) (*identity.GetIdentityUpdatesResponse, error)
GetInboxIds(ctx context.Context, req *identity.GetInboxIdsRequest) (*identity.GetInboxIdsResponse, error)
}
Expand Down Expand Up @@ -99,7 +100,7 @@ func (s *Store) GetInboxIds(ctx context.Context, req *identity.GetInboxIdsReques
}, nil
}

func (s *Store) PublishIdentityUpdate(ctx context.Context, req *identity.PublishIdentityUpdateRequest) (*identity.PublishIdentityUpdateResponse, error) {
func (s *Store) PublishIdentityUpdate(ctx context.Context, req *identity.PublishIdentityUpdateRequest, validationService mlsvalidate.MLSValidationService) (*identity.PublishIdentityUpdateResponse, error) {
new_update := req.GetIdentityUpdate()
if new_update == nil {
return nil, errors.New("IdentityUpdate is required")
Expand All @@ -125,6 +126,7 @@ func (s *Store) PublishIdentityUpdate(ctx context.Context, req *identity.Publish
}
_ = append(updates, new_update)

validationService.GetAssociationState(ctx, updates, new_update)

Check failure on line 129 in pkg/mls/store/store.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use new_update (variable of type *associations.IdentityUpdate) as []*associations.IdentityUpdate value in argument to validationService.GetAssociationState) (typecheck)

Check failure on line 129 in pkg/mls/store/store.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use new_update (variable of type *associations.IdentityUpdate) as []*associations.IdentityUpdate value in argument to validationService.GetAssociationState) (typecheck)

Check failure on line 129 in pkg/mls/store/store.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use new_update (variable of type *associations.IdentityUpdate) as []*associations.IdentityUpdate value in argument to validationService.GetAssociationState) (typecheck)

Check failure on line 129 in pkg/mls/store/store.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use new_update (variable of type *associations.IdentityUpdate) as []*associations.IdentityUpdate value in argument to validationService.GetAssociationState (typecheck)

Check failure on line 129 in pkg/mls/store/store.go

View workflow job for this annotation

GitHub Actions / Build

cannot use new_update (variable of type *associations.IdentityUpdate) as []*associations.IdentityUpdate value in argument to validationService.GetAssociationState

Check failure on line 129 in pkg/mls/store/store.go

View workflow job for this annotation

GitHub Actions / Build

cannot use new_update (variable of type *associations.IdentityUpdate) as []*associations.IdentityUpdate value in argument to validationService.GetAssociationState
// TODO: Validate the updates, and abort transaction if failed

protoBytes, err := proto.Marshal(new_update)
Expand All @@ -141,7 +143,13 @@ func (s *Store) PublishIdentityUpdate(ctx context.Context, req *identity.Publish
if err != nil {
return err
}

// TODO: Insert or update the address_log table using sequence_id
/*
_, err = txQueries.InsertAddressLog(ctx, queries.InsertAddressLogParams{
})
*/

return nil
}); err != nil {
Expand Down

0 comments on commit eda8919

Please sign in to comment.