Skip to content

Commit

Permalink
get random day on create proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
zarmluo committed Nov 6, 2024
1 parent 355bc55 commit 40bb675
Show file tree
Hide file tree
Showing 37 changed files with 2,027 additions and 687 deletions.
929 changes: 549 additions & 380 deletions power-snapshot/api/proto/query.pb.go

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions power-snapshot/api/proto/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ service Snapshot {
rpc SyncAllAddrPower(SyncAllAddrPowerRequest) returns (SyncAllAddrPowerResponse){}
rpc SyncAllDeveloperWeight(SyncAllDeveloperWeightRequest) returns (SyncAllDeveloperWeightResponse) {}
rpc SyncDeveloperWeight(SyncDeveloperWeightRequest) returns (SyncDeveloperWeightResponse) {}
rpc GetDataHeight(DataHeightRequest) returns (DataHeightResponse) {}
rpc GetAddressPowerByDay(AddressPowerByDayRequest) returns (AddressPowerResponse) {}
rpc GetAllAddrPowerByDay(GetAllAddrPowerByDayRequest) returns (GetAllAddrPowerByDayResponse) {}
}

message GetAllAddrPowerByDayRequest {
string day = 1;
int64 netId = 2;
}

message GetAllAddrPowerByDayResponse {
string day = 1;
string info = 3;
int64 netId = 4;
}

message SyncAllAddrPowerRequest {
Expand All @@ -46,6 +60,22 @@ message SyncAddrPowerRequest {
string address = 2;
}

message DataHeightRequest{
int64 netId = 1;
string day = 2;
}

message AddressPowerByDayRequest{
int64 netId = 1;
string address = 2;
string day = 3;
}

message DataHeightResponse {
string day = 1;
int64 height = 2;
}

message AddressPowerResponse {
string address = 1;
string sp_power = 2;
Expand Down
137 changes: 130 additions & 7 deletions power-snapshot/api/proto/query_grpc.pb.go

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

1 change: 0 additions & 1 deletion power-snapshot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
Expand Down
54 changes: 53 additions & 1 deletion power-snapshot/handler/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package handler

import (
"context"
"encoding/json"

"github.com/golang-module/carbon"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -53,6 +56,55 @@ func (s *Snapshot) GetAddressPower(ctx context.Context, req *pb.AddressPowerRequ
}, nil
}

func (s *Snapshot) GetAddressPowerByDay(ctx context.Context, req *pb.AddressPowerByDayRequest) (*pb.AddressPowerResponse, error) {
day := req.GetDay()
dayTime := carbon.Parse(day).EndOfDay().ToStdTime()
m, err := s.querySrv.GetAddressPowerByDay(ctx, req.GetNetId(), req.GetAddress(), day, dayTime)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &pb.AddressPowerResponse{
Address: m.Address,
SpPower: m.SpPower.String(),
ClientPower: m.ClientPower.String(),
TokenHolderPower: m.TokenHolderPower.String(),
DeveloperPower: m.DeveloperPower.String(),
BlockHeight: m.BlockHeight,
DateStr: m.DateStr,
}, nil
}

func (s *Snapshot) GetDataHeight(_ context.Context, req *pb.DataHeightRequest) (*pb.DataHeightResponse, error) {
height, err := s.querySrv.GetDataHeight(context.Background(), req.GetNetId(), req.GetDay())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &pb.DataHeightResponse{
Day: req.GetDay(),
Height: height,
}, nil
}

func (s *Snapshot) GetAllAddrPowerByDay(_ context.Context, req *pb.GetAllAddrPowerByDayRequest) (*pb.GetAllAddrPowerByDayResponse, error) {
addrPowers, err := s.querySrv.GetAllAddressPowerByDay(context.Background(), req.GetNetId(), req.GetDay())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

jsonRes, err := json.Marshal(addrPowers)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &pb.GetAllAddrPowerByDayResponse{
Day: req.Day,
Info: string(jsonRes),
NetId: req.NetId,
}, nil
}

func (s *Snapshot) SyncDateHeight(_ context.Context, req *pb.SyncDateHeightRequest) (*pb.SyncDateHeightResponse, error) {
err := s.syncSrv.SyncDateHeight(context.Background(), req.GetNetId())
if err != nil {
Expand Down Expand Up @@ -89,7 +141,7 @@ func (s *Snapshot) SyncAllDeveloperWeight(context.Context, *pb.SyncAllDeveloperW
return &pb.SyncAllDeveloperWeightResponse{}, nil
}

func (s *Snapshot) SyncDeveloperPower(ctx context.Context, req *pb.SyncDeveloperWeightRequest) (*pb.SyncDeveloperWeightResponse, error) {
func (s *Snapshot) SyncDeveloperWeight(ctx context.Context, req *pb.SyncDeveloperWeightRequest) (*pb.SyncDeveloperWeightResponse, error) {
err := s.syncSrv.SyncDeveloperWeight(context.Background(), req.GetDateStr())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand Down
5 changes: 5 additions & 0 deletions power-snapshot/internal/model/sync_power.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ type AddrInfo struct {
MinerIDs []uint64 `json:"minerIDs"`
GithubAccount string `json:"githubAccount"`
}

type DayHeight struct {
Day string `json:"day"`
Height int64 `json:"height"`
}
Loading

0 comments on commit 40bb675

Please sign in to comment.