prep for frontend
This commit is contained in:
parent
fc6eb4f599
commit
2799d0cb91
2
Tiltfile
2
Tiltfile
|
@ -68,7 +68,7 @@ if server:
|
|||
k8s_resource(
|
||||
"server",
|
||||
port_forwards = [
|
||||
port_forward(3000, name = "Server [:3000]", host = webHost),
|
||||
port_forward(4000, name = "Server [:4000]", host = webHost),
|
||||
],
|
||||
resource_deps = ["mongo"]
|
||||
)
|
||||
|
|
|
@ -10,7 +10,7 @@ spec:
|
|||
selector:
|
||||
app: server
|
||||
ports:
|
||||
- port: 3000
|
||||
- port: 4000
|
||||
name: server
|
||||
protocol: TCP
|
||||
---
|
||||
|
@ -38,10 +38,10 @@ spec:
|
|||
value: mongodb://root:example@mongo:27017/
|
||||
readinessProbe:
|
||||
tcpSocket:
|
||||
port: 3000
|
||||
port: 4000
|
||||
periodSeconds: 1
|
||||
failureThreshold: 300
|
||||
ports:
|
||||
- containerPort: 3000
|
||||
- containerPort: 4000
|
||||
name: server
|
||||
protocol: TCP
|
||||
|
|
22
fly/main.go
22
fly/main.go
|
@ -32,8 +32,8 @@ var (
|
|||
p2pNetworkID string
|
||||
p2pPort uint
|
||||
p2pBootstrap string
|
||||
nodeKeyPath string
|
||||
logLevel string
|
||||
nodeKeyPath string
|
||||
logLevel string
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -41,7 +41,7 @@ func main() {
|
|||
p2pPort = 8999
|
||||
p2pBootstrap = "/dns4/wormhole-mainnet-v2-bootstrap.certus.one/udp/8999/quic/p2p/12D3KooWQp644DK27fd3d4Km3jr7gHiuJJ5ZGmy8hH4py7fP4FP7"
|
||||
nodeKeyPath = "/tmp/node.key"
|
||||
logLevel = "info"
|
||||
logLevel = "warn"
|
||||
common.SetRestrictiveUmask()
|
||||
|
||||
lvl, err := ipfslog.LevelFromString(logLevel)
|
||||
|
@ -50,7 +50,7 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger := ipfslog.Logger("wormhole-spy").Desugar()
|
||||
logger := ipfslog.Logger("wormhole-fly").Desugar()
|
||||
|
||||
ipfslog.SetAllLoggers(lvl)
|
||||
|
||||
|
@ -103,6 +103,7 @@ func main() {
|
|||
gst := common.NewGuardianSetState(heartbeatC)
|
||||
|
||||
// Bootstrap guardian set, otherwise heartbeats would be skipped
|
||||
// TODO: fetch this and probably figure out how to update it live
|
||||
gst.Set(&common.GuardianSet{
|
||||
Index: 2,
|
||||
Keys: []eth_common.Address{
|
||||
|
@ -134,9 +135,10 @@ func main() {
|
|||
select {
|
||||
case <-rootCtx.Done():
|
||||
return
|
||||
case o := <- obsvC:
|
||||
case o := <-obsvC:
|
||||
id := fmt.Sprintf("%s/%s", o.MessageId, hex.EncodeToString(o.Addr))
|
||||
update := bson.D{{Key: "$set", Value: o}, {Key: "$set", Value: bson.D{{Key: "updatedAt", Value: time.Now()}}}, {Key: "$setOnInsert", Value: bson.D{{Key: "createdAt", Value: time.Now()}}}}
|
||||
now := time.Now()
|
||||
update := bson.D{{Key: "$set", Value: o}, {Key: "$set", Value: bson.D{{Key: "updatedAt", Value: now}}}, {Key: "$setOnInsert", Value: bson.D{{Key: "createdAt", Value: now}}}}
|
||||
opts := options.Update().SetUpsert(true)
|
||||
_, err := obsColl.UpdateByID(context.TODO(), id, update, opts)
|
||||
if err != nil {
|
||||
|
@ -158,7 +160,8 @@ func main() {
|
|||
logger.Error("Error parsing vaa", zap.Error(vaa_err))
|
||||
}
|
||||
id := vaa.MessageID()
|
||||
update := bson.D{{Key: "$set", Value: v}, {Key: "$set", Value: bson.D{{Key: "updatedAt", Value: time.Now()}}}, {Key: "$setOnInsert", Value: bson.D{{Key: "createdAt", Value: time.Now()}}}}
|
||||
now := time.Now()
|
||||
update := bson.D{{Key: "$set", Value: v}, {Key: "$set", Value: bson.D{{Key: "updatedAt", Value: now}}}, {Key: "$setOnInsert", Value: bson.D{{Key: "createdAt", Value: now}}}}
|
||||
opts := options.Update().SetUpsert(true)
|
||||
_, err := vaaColl.UpdateByID(context.TODO(), id, update, opts)
|
||||
if err != nil {
|
||||
|
@ -174,9 +177,10 @@ func main() {
|
|||
select {
|
||||
case <-rootCtx.Done():
|
||||
return
|
||||
case hb := <- heartbeatC:
|
||||
case hb := <-heartbeatC:
|
||||
id := hb.GuardianAddr
|
||||
update := bson.D{{Key: "$set", Value: hb}, {Key: "$set", Value: bson.D{{Key: "updatedAt", Value: time.Now()}}}, {Key: "$setOnInsert", Value: bson.D{{Key: "createdAt", Value: time.Now()}}}}
|
||||
now := time.Now()
|
||||
update := bson.D{{Key: "$set", Value: hb}, {Key: "$set", Value: bson.D{{Key: "updatedAt", Value: now}}}, {Key: "$setOnInsert", Value: bson.D{{Key: "createdAt", Value: now}}}}
|
||||
opts := options.Update().SetUpsert(true)
|
||||
_, err := hbColl.UpdateByID(context.TODO(), id, update, opts)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const express = require("express");
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
const port = 4000;
|
||||
|
||||
const { MongoClient } = require("mongodb");
|
||||
const mongoURI = process.env.MONGODB_URI;
|
||||
|
@ -10,6 +10,21 @@ if (!mongoURI) {
|
|||
}
|
||||
const mongoClient = new MongoClient(mongoURI);
|
||||
|
||||
async function paginatedFind(collection, req) {
|
||||
const limit =
|
||||
req.query?.limit && req.query.limit <= 100 ? req.query.limit : 20;
|
||||
const skip = req.query?.page ? req.query?.page * limit : undefined;
|
||||
const query = req.query?.before
|
||||
? { createdAt: { $lt: new Date(req.query.before) } }
|
||||
: {};
|
||||
const cursor = await collection.find(query, {
|
||||
sort: { createdAt: -1 },
|
||||
skip,
|
||||
limit,
|
||||
});
|
||||
return cursor;
|
||||
}
|
||||
|
||||
app.get("/api/heartbeats", async (req, res) => {
|
||||
const database = mongoClient.db("wormhole");
|
||||
const heartbeats = database.collection("heartbeats");
|
||||
|
@ -33,17 +48,7 @@ app.get("/api/vaas/:chain/:emitter/:sequence", async (req, res) => {
|
|||
app.get("/api/vaas", async (req, res) => {
|
||||
const database = mongoClient.db("wormhole");
|
||||
const vaas = database.collection("vaas");
|
||||
const limit =
|
||||
req.query?.limit && req.query.limit <= 100 ? req.query.limit : 20;
|
||||
const skip = req.query?.page ? req.query?.page * limit : undefined;
|
||||
const query = req.query?.before
|
||||
? { createdAt: { $lt: new Date(req.query.before) } }
|
||||
: {};
|
||||
const cursor = await vaas.find(query, {
|
||||
sort: { createdAt: -1 },
|
||||
skip,
|
||||
limit,
|
||||
});
|
||||
const cursor = await paginatedFind(vaas, req);
|
||||
const result = await cursor.toArray();
|
||||
if (result.length === 0) {
|
||||
res.sendStatus(404);
|
||||
|
@ -68,17 +73,7 @@ app.get("/api/observations/:chain/:emitter/:sequence", async (req, res) => {
|
|||
app.get("/api/observations", async (req, res) => {
|
||||
const database = mongoClient.db("wormhole");
|
||||
const observations = database.collection("observations");
|
||||
const limit =
|
||||
req.query?.limit && req.query.limit <= 100 ? req.query.limit : 20;
|
||||
const skip = req.query?.page ? req.query?.page * limit : undefined;
|
||||
const query = req.query?.before
|
||||
? { createdAt: { $lt: new Date(req.query.before) } }
|
||||
: {};
|
||||
const cursor = await observations.find(query, {
|
||||
sort: { createdAt: -1 },
|
||||
skip,
|
||||
limit,
|
||||
});
|
||||
const cursor = await paginatedFind(observations, req);
|
||||
const result = await cursor.toArray();
|
||||
if (result.length === 0) {
|
||||
res.sendStatus(404);
|
||||
|
|
Loading…
Reference in New Issue