Skip to content

Commit

Permalink
insert log
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Apr 25, 2024
1 parent 47bfca8 commit f084fc7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 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 @@ -97,5 +97,5 @@ func (s *Service) GetInboxIds(ctx context.Context, req *api.GetInboxIdsRequest)
for the address where revocation_sequence_id is lower or NULL
2. Return the value of the 'inbox_id' column
*/
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
return s.store.GetInboxIds(ctx, req)
}
30 changes: 22 additions & 8 deletions pkg/mls/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@ func (s *Store) PublishIdentityUpdate(ctx context.Context, req *identity.Publish
}
_ = append(updates, new_update)

validationService.GetAssociationState(ctx, updates, new_update)
// TODO: Validate the updates, and abort transaction if failed
state, err := validationService.GetAssociationState(ctx, updates, []*associations.IdentityUpdate{new_update})
if err != nil {
return err
}

protoBytes, err := proto.Marshal(new_update)
if err != nil {
return err
}

_, err = txQueries.InsertInboxLog(ctx, queries.InsertInboxLogParams{
sequence_id, err := txQueries.InsertInboxLog(ctx, queries.InsertInboxLogParams{
InboxID: new_update.GetInboxId(),
ServerTimestampNs: nowNs(),
IdentityUpdateProto: protoBytes,
Expand All @@ -144,12 +146,24 @@ func (s *Store) PublishIdentityUpdate(ctx context.Context, req *identity.Publish
return err
}

// TODO: Insert or update the address_log table using sequence_id
/*
_, err = txQueries.InsertAddressLog(ctx, queries.InsertAddressLogParams{
for _, new_member := range state.StateDiff.NewMembers {
if address, ok := new_member.Kind.(*associations.MemberIdentifier_Address); ok {
_, err = txQueries.InsertAddressLog(ctx, queries.InsertAddressLogParams{
Address: address.Address,
InboxID: state.AssociationState.InboxId,
AssociationSequenceID: sql.NullInt64{Valid: true, Int64: sequence_id},
RevocationSequenceID: sql.NullInt64{Valid: false},
})
if err != nil {
return err
}
}
}

// Update address log table
for _, removed_member := range state.StateDiff.RemovedMembers {

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

View workflow job for this annotation

GitHub Actions / Build

removed_member declared and not used

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

View workflow job for this annotation

GitHub Actions / Build

removed_member declared and not used

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

View workflow job for this annotation

GitHub Actions / Lint

removed_member declared and not used) (typecheck)

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

View workflow job for this annotation

GitHub Actions / Lint

removed_member declared and not used) (typecheck)

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

View workflow job for this annotation

GitHub Actions / Lint

removed_member declared and not used) (typecheck)

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

View workflow job for this annotation

GitHub Actions / Lint

removed_member declared and not used (typecheck)

})
*/
}

return nil
}); err != nil {
Expand Down
20 changes: 10 additions & 10 deletions pkg/mls/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ func TestInboxIds(t *testing.T) {
store, cleanup := NewTestStore(t)
defer cleanup()

seq, rev := uint64(1), uint64(5)
err := InsertAddressLog(store, "address", "inbox1", &seq, &rev)
seq := uint64(1)
err := InsertAddressLog(store, "address", "inbox1", &seq, nil)
require.NoError(t, err)
seq, rev = uint64(2), uint64(8)
err = InsertAddressLog(store, "address", "inbox1", &seq, &rev)
seq = uint64(2)
err = InsertAddressLog(store, "address", "inbox1", &seq, nil)
require.NoError(t, err)
seq, rev = uint64(3), uint64(9)
err = InsertAddressLog(store, "address", "inbox1", &seq, &rev)
seq = uint64(3)
err = InsertAddressLog(store, "address", "inbox1", &seq, nil)
require.NoError(t, err)
seq, rev = uint64(4), uint64(1)
err = InsertAddressLog(store, "address", "correct", &seq, &rev)
seq = uint64(4)
err = InsertAddressLog(store, "address", "correct", &seq, nil)
require.NoError(t, err)

reqs := make([]*identity.GetInboxIdsRequest_Request, 0)
Expand All @@ -83,8 +83,8 @@ func TestInboxIds(t *testing.T) {
req = &identity.GetInboxIdsRequest{
Requests: reqs,
}
seq, rev = uint64(8), uint64(2)
err = InsertAddressLog(store, "address2", "inbox2", &seq, &rev)
seq = uint64(8)
err = InsertAddressLog(store, "address2", "inbox2", &seq, nil)
require.NoError(t, err)
resp, _ = store.GetInboxIds(context.Background(), req)
require.Equal(t, "inbox2", *resp.Responses[1].InboxId)
Expand Down

0 comments on commit f084fc7

Please sign in to comment.