Skip to content

Commit

Permalink
feat(phase): return block range on graphql phase
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Dec 14, 2022
1 parent 99880d9 commit 35260fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
17 changes: 10 additions & 7 deletions app/nemeton/phase.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package nemeton

import "time"
import (
"time"
)

type Phase struct {
Number int `bson:"_id"`
Name string `bson:"name"`
Description string `bson:"description"`
StartDate time.Time `bson:"startDate"`
EndDate time.Time `bson:"endDate"`
Tasks []Task `bson:"tasks"`
Number int `bson:"_id"`
Name string `bson:"name"`
Description string `bson:"description"`
StartDate time.Time `bson:"startDate"`
EndDate time.Time `bson:"endDate"`
Tasks []Task `bson:"tasks"`
Blocks BlockRange `bson:"blocks"`
}

func (p Phase) Started() bool {
Expand Down
9 changes: 9 additions & 0 deletions app/nemeton/range.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nemeton

// BlockRange Represents a blockchain block range.
type BlockRange struct {
// The block height the range begin, inclusive.
From int `bson:"from"`
// The block height the range end, inclusive.
To int `bson:"to"`
}
4 changes: 1 addition & 3 deletions app/nemeton/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"okp4/nemeton-leaderboard/app/util"

"github.com/cosmos/cosmos-sdk/types"
"github.com/rs/zerolog/log"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand Down Expand Up @@ -390,7 +389,7 @@ func (s *Store) completeTask(ctx context.Context, when time.Time, filter bson.M,
}

func (s *Store) UpdatePhaseBlocks(ctx context.Context, blockTime time.Time, height int64) error {
r, err := s.db.Collection(phasesCollectionName).UpdateOne(ctx, bson.M{
_, err := s.db.Collection(phasesCollectionName).UpdateOne(ctx, bson.M{
"startDate": bson.M{"$lte": blockTime},
"endDate": bson.M{"$gt": blockTime},
}, bson.A{
Expand All @@ -407,6 +406,5 @@ func (s *Store) UpdatePhaseBlocks(ctx context.Context, blockTime time.Time, heig
},
bson.M{"$set": bson.M{"blocks.to": height}},
})
log.Info().Interface("r", r)
return err
}
6 changes: 5 additions & 1 deletion graphql/schema.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func (r *mutationResolver) SubmitValidatorGenTx(ctx context.Context, twitter *st

// Blocks is the resolver for the blocks field.
func (r *phaseResolver) Blocks(ctx context.Context, obj *nemeton.Phase) (*model.BlockRange, error) {
panic(fmt.Errorf("not implemented: Blocks - blocks"))
return &model.BlockRange{
From: obj.Blocks.From,
To: obj.Blocks.To,
Count: obj.Blocks.To - obj.Blocks.From,
}, nil
}

// All is the resolver for the all field.
Expand Down

0 comments on commit 35260fd

Please sign in to comment.