-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: subscribe to bbn websocket new block events (#32)
- Loading branch information
Showing
11 changed files
with
347 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/babylonlabs-io/babylon-staking-indexer/internal/db/model" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func (db *Database) GetLastProcessedBbnHeight(ctx context.Context) (uint64, error) { | ||
var result model.LastProcessedHeight | ||
err := db.client.Database(db.dbName). | ||
Collection(model.LastProcessedHeightCollection). | ||
FindOne(ctx, bson.M{}).Decode(&result) | ||
if err == mongo.ErrNoDocuments { | ||
// If no document exists, return 0 | ||
return 0, nil | ||
} | ||
if err != nil { | ||
return 0, err | ||
} | ||
return result.Height, nil | ||
} | ||
|
||
func (db *Database) UpdateLastProcessedBbnHeight(ctx context.Context, height uint64) error { | ||
update := bson.M{"$set": bson.M{"height": height}} | ||
opts := options.Update().SetUpsert(true) | ||
_, err := db.client.Database(db.dbName). | ||
Collection(model.LastProcessedHeightCollection). | ||
UpdateOne(ctx, bson.M{}, update, opts) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package model | ||
|
||
type LastProcessedHeight struct { | ||
Height uint64 `bson:"height"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.