Skip to content

Commit

Permalink
avoid posting uncessary outtx confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Nov 22, 2023
1 parent b1c5881 commit 2036618
Show file tree
Hide file tree
Showing 9 changed files with 802 additions and 164 deletions.
29 changes: 29 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27520,6 +27520,30 @@ paths:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/observer/has_voted/{ballot_identifier}/{voter_address}:
get:
summary: Query if a voter has voted for a ballot
operationId: Query_HasVoted
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/observerQueryHasVotedResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: ballot_identifier
in: path
required: true
type: string
- name: voter_address
in: path
required: true
type: string
tags:
- Query
/zeta-chain/observer/keygen:
get:
summary: Queries a keygen by index.
Expand Down Expand Up @@ -51296,6 +51320,11 @@ definitions:
properties:
node_account:
$ref: '#/definitions/observerNodeAccount'
observerQueryHasVotedResponse:
type: object
properties:
has_voted:
type: boolean
observerQueryObserversByChainResponse:
type: object
properties:
Expand Down
13 changes: 13 additions & 0 deletions proto/observer/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/zeta-chain/observer/params";
}
// Query if a voter has voted for a ballot
rpc HasVoted(QueryHasVotedRequest) returns (QueryHasVotedResponse) {
option (google.api.http).get = "/zeta-chain/observer/has_voted/{ballot_identifier}/{voter_address}";
}
// Queries a list of VoterByIdentifier items.
rpc BallotByIdentifier(QueryBallotByIdentifierRequest) returns (QueryBallotByIdentifierResponse) {
option (google.api.http).get = "/zeta-chain/observer/ballot_by_identifier/{ballot_identifier}";
Expand Down Expand Up @@ -119,6 +123,15 @@ message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}

message QueryHasVotedRequest {
string ballot_identifier = 1;
string voter_address = 2;
}

message QueryHasVotedResponse {
bool has_voted = 1;
}

message QueryBallotByIdentifierRequest {
string ballot_identifier = 1;
}
Expand Down
18 changes: 18 additions & 0 deletions x/observer/keeper/ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ func (k Keeper) GetMaturedBallotList(ctx sdk.Context) []string {

// Queries

func (k Keeper) HasVoted(goCtx context.Context, req *types.QueryHasVotedRequest) (*types.QueryHasVotedResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
ballot, found := k.GetBallot(ctx, req.BallotIdentifier)
if !found {
return &types.QueryHasVotedResponse{
HasVoted: false,
}, nil
}
hasVoted := ballot.HasVoted(req.VoterAddress)

return &types.QueryHasVotedResponse{
HasVoted: hasVoted,
}, nil
}

func (k Keeper) BallotByIdentifier(goCtx context.Context, req *types.QueryBallotByIdentifierRequest) (*types.QueryBallotByIdentifierResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
Expand Down
Loading

0 comments on commit 2036618

Please sign in to comment.