Skip to content

Commit

Permalink
feat(Pathwar): Add ChallengeValidate go implementation wip
Browse files Browse the repository at this point in the history
  • Loading branch information
omniwired committed Aug 10, 2023
1 parent 406c3c6 commit b9940fb
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 761 deletions.
20 changes: 12 additions & 8 deletions api/pathwar/v1/pathwar.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ package pathwar.v1;
option go_package = "./pathwarpb";

service PathwarService {
rpc RegisterUser(RegisterUserRequest) returns (stream RegisterUserResponse);
rpc Leaderboard(LeaderboardRequest) returns (stream LeaderboardResponse);
rpc Resources(ResourcesRequest) returns (stream ResourcesResponse);
rpc Tournaments(TournamentsRequest) returns (stream TournamentsResponse);
rpc Challenge(ChallengeRequest) returns (stream ChallengeResponse);
rpc ChallengeListing(ChallengeListingRequest) returns (stream ChallengeListingResponse);
rpc ChallengeValidate(ChallengeValidateRequest) returns (stream ChallengeValidateResponse);
// rpc RegisterUser(RegisterUserRequest) returns (stream RegisterUserResponse);
// rpc Leaderboard(LeaderboardRequest) returns (stream LeaderboardResponse);
// rpc Resources(ResourcesRequest) returns (stream ResourcesResponse);
// rpc Tournaments(TournamentsRequest) returns (stream TournamentsResponse);
// rpc Challenge(ChallengeRequest) returns (stream ChallengeResponse);
// rpc ChallengeListing(ChallengeListingRequest) returns (stream ChallengeListingResponse);
rpc ChallengeValidate(ChallengeValidateRequest) returns (ChallengeValidateResponse);
}
// common

Expand Down Expand Up @@ -160,10 +160,14 @@ message ChallengeValidateRequest {
int32 id = 1;
string passphrase = 2;
string comment = 3;
string network_id = 4;
}

message ChallengeValidateResponse {
string status = 1;
string msg = 1;
string sig = 2;
string key = 3;
string network_id = 4; // not really sure if useful, just to confirm which network is this proof valid in
}

// challenge listing
Expand Down
43 changes: 43 additions & 0 deletions go/pkg/pathwar/pathwar_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pathwar

import (
"context"
"github.com/TERITORI/teritori-dapp/go/pkg/networks"
"github.com/TERITORI/teritori-dapp/go/pkg/pathwarpb"
"go.uber.org/zap"
"gorm.io/gorm"
)

type PathwarService struct {
pathwarpb.UnimplementedPathwarServiceServer
conf *Config
}

type Config struct {
Logger *zap.Logger
IndexerDB *gorm.DB
NetStore *networks.NetworkStore
}

func NewPathwarService(ctx context.Context, conf *Config) pathwarpb.PathwarServiceServer {
return &PathwarService{
conf: conf,
}
}

func (s *PathwarService) ChallengeValidate(ctx context.Context, req *pathwarpb.ChallengeValidateRequest) (*pathwarpb.ChallengeValidateResponse, error) {

networkId := req.GetNetworkId()
println(req.Passphrase)

if req.Passphrase != "valid" {
return nil, nil
}

return &pathwarpb.ChallengeValidateResponse{
Msg: "msg",
Sig: "oeu",
Key: "qjk",
NetworkId: networkId,
}, nil
}
160 changes: 77 additions & 83 deletions go/pkg/pathwarpb/pathwar.pb.go

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

Loading

0 comments on commit b9940fb

Please sign in to comment.