Skip to content

Commit

Permalink
Merge pull request #61 from goverland-labs/feature/vote_improvement
Browse files Browse the repository at this point in the history
Extend vote response with proposal identifier
  • Loading branch information
WertND authored Jul 3, 2024
2 parents f97ff8f + 03cfe4e commit 42103f2
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 149 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- Extend vote response with proposal identifier

## [0.1.19] - 2024-06-27

### Changed
Expand Down
12 changes: 9 additions & 3 deletions internal/vote/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vote
import (
"context"
"errors"

"gorm.io/gorm"

protoany "github.com/golang/protobuf/ptypes/any"
Expand Down Expand Up @@ -135,11 +136,16 @@ func (s *Server) Vote(ctx context.Context, req *storagepb.VoteRequest) (*storage
return nil, status.Error(codes.Internal, "failed to vote")
}

s.sp.FetchAndStoreVote(ctx, voteResp.ID)
vote := s.sp.FetchAndStoreVote(ctx, voteResp.ID)
var proposalID string
if vote != nil {
proposalID = vote.ProposalID
}

return &storagepb.VoteResponse{
Id: voteResp.ID,
Ipfs: voteResp.IPFS,
Id: voteResp.ID,
Ipfs: voteResp.IPFS,
ProposalId: proposalID,
Relayer: &storagepb.Relayer{
Address: voteResp.Relayer.Address,
Receipt: voteResp.Relayer.Receipt,
Expand Down
10 changes: 6 additions & 4 deletions internal/vote/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,22 @@ func (s *Service) Vote(ctx context.Context, req VoteRequest) (VoteResponse, erro
}, nil
}

func (s *Service) FetchAndStoreVote(ctx context.Context, id string) {
func (s *Service) FetchAndStoreVote(ctx context.Context, id string) *Vote {
vote, err := s.dsClient.GetVote(ctx, &votingpb.GetVoteRequest{
Id: id,
})
if err != nil {
log.Error().Err(err).Msgf("fetch vote: %s", id)
return
return nil
}

err = s.HandleVotes(ctx, []Vote{convertFromProtoToInternal(vote)})
internal := convertFromProtoToInternal(vote)
err = s.HandleVotes(ctx, []Vote{internal})
if err != nil {
log.Error().Err(err).Msgf("store vote: %s", id)
return
}

return &internal
}

func (s *Service) HandleResolvedAddresses(list []ResolvedAddress) error {
Expand Down
8 changes: 4 additions & 4 deletions protocol/storagepb/base.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions protocol/storagepb/dao.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions protocol/storagepb/dao_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions protocol/storagepb/ens.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions protocol/storagepb/ens_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 42103f2

Please sign in to comment.