Skip to content

Commit

Permalink
chore: envio query and rename clients folder
Browse files Browse the repository at this point in the history
  • Loading branch information
guimroque committed Jan 8, 2025
1 parent 0b10bf0 commit 5f4a813
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 25 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import IORedis from "ioredis";

const { WORKER_REDIS_HOST, WORKER_REDIS_PORT } = process.env;

const isLocal = WORKER_REDIS_HOST?.includes("127.") ?? false;

export const redisConfig = {
host: WORKER_REDIS_HOST,
port: 6379,
...(!isLocal ? { tls: { rejectUnauthorized: false } } : {}),
};

const redisClient = new IORedis({
host: WORKER_REDIS_HOST,
port: Number(WORKER_REDIS_PORT),
Expand Down
4 changes: 2 additions & 2 deletions packages/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import express from "express";
import BalanceCron from "./queues/predicateBalance/scheduler";
import AssetCron from "./queues/assetsValue/scheduler";
import assetQueue from "./queues/assetsValue/queue";
import { MongoDatabase } from "./utils/mongoClient";
import { PsqlClient } from "./utils";
import { MongoDatabase } from "./clients/mongoClient";
import { PsqlClient } from "./clients";

const {
WORKER_PORT,
Expand Down
4 changes: 2 additions & 2 deletions packages/worker/src/queues/assetsValue/queue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Queue from "bull";
import { CollectionName, MongoDatabase } from "../../utils/mongoClient";
import { CollectionName, MongoDatabase } from "../../clients/mongoClient";
import { QUEUE_ASSET } from "./constants";
import { fetchQuotes } from "./utils";
import { redisConfig } from "@/utils/redis";
import { redisConfig } from "@/clients";

const assetQueue = new Queue(QUEUE_ASSET, {
redis: redisConfig,
Expand Down
4 changes: 2 additions & 2 deletions packages/worker/src/queues/predicateBalance/queue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Queue from "bull";
import { CollectionName, MongoDatabase, type SchemaPredicateBlocks, type SchemaFuelAssets, type SchemaPredicateBalance } from "../../utils/mongoClient";
import { CollectionName, MongoDatabase, type SchemaPredicateBlocks, type SchemaFuelAssets, type SchemaPredicateBalance } from "../../clients/mongoClient";
import { type QueueBalance, groupByTransaction, syncPredicateBlock, syncBalance, makeDeposits, syncAssets, QUEUE_BALANCE } from ".";
import { predicateTransactions } from "./utils/envioQuery";
import { redisConfig } from "@/utils/redis";
import { redisConfig } from "@/clients";


const balanceQueue = new Queue<QueueBalance>(QUEUE_BALANCE, {
Expand Down
4 changes: 2 additions & 2 deletions packages/worker/src/queues/predicateBalance/scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PsqlClient } from "../../utils/psqlClient";
import { PsqlClient } from "../../clients/psqlClient";
import balanceQueue from "./queue";
import cron from "node-cron";
import { CRON_EXPRESSION, INITIAL_DELAY, QUEUE_BALANCE } from "./constants";
Expand All @@ -7,7 +7,7 @@ const fn = async () => {
try {
const db = await PsqlClient.connect();
const predicates = await db.query(
`SELECT predicate_address
`SELECT predicate_address
FROM predicates`
);

Expand Down
11 changes: 7 additions & 4 deletions packages/worker/src/queues/predicateBalance/utils/envioQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CollectionName, MongoDatabase, type SchemaPredicateBlocks } from "../../../utils/mongoClient";

import { CollectionName, MongoDatabase, type SchemaPredicateBlocks } from "../../../clients/mongoClient";

export const makeQuery = ({
from_block,
Expand All @@ -13,11 +14,13 @@ export const makeQuery = ({
from_block,
inputs: [
{
inputType: [0, 2],
txStatus: [1],
owner: [predicate_address],
recipient: [predicate_address],
},
{
txStatus: [1],
recipient: [predicate_address],
}
],
outputs: [
{
Expand All @@ -43,7 +46,7 @@ export const predicateTransactions = async (predicate: string) => {
const last = await predicate_block.findOne({ _id: predicate });

const data = await fetch(
"https://fuel-legacy.hypersync.xyz/query",
"https://fuel.hypersync.xyz/query",
makeQuery({ from_block: last?.blockNumber ?? 0, predicate_address: predicate })
);
const response = await data.json();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InputType, bn, OutputType } from "fuels";
import type { SchemaPredicateBalance } from "../../../utils/mongoClient";
import type { SchemaPredicateBalance } from "../../../clients/mongoClient";
import { ETH } from "../constants";
import type { PredicateBalanceGrouped } from "../types";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Collection, WithId } from "mongodb";
import type {
SchemaPredicateBalance,
SchemaFuelAssets,
} from "../../../utils/mongoClient";
} from "../../../clients/mongoClient";

export async function syncAssets(
deposits: SchemaPredicateBalance[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Collection, WithId } from "mongodb";
import type {
SchemaPredicateBalance,
SchemaFuelAssets,
} from "../../../utils/mongoClient";
} from "../../../clients/mongoClient";

export async function syncBalance(
deposits: SchemaPredicateBalance[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Collection } from "mongodb";
import type { SchemaPredicateBlocks } from "../../../utils/mongoClient";
import type { SchemaPredicateBlocks } from "../../../clients/mongoClient";

export async function syncPredicateBlock(
block: SchemaPredicateBlocks,
Expand Down
9 changes: 0 additions & 9 deletions packages/worker/src/utils/redis.ts

This file was deleted.

0 comments on commit 5f4a813

Please sign in to comment.