Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yj-chore/update #62

Merged
merged 12 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<img alt="GoldRush Kit Logo" src="./assets/goldrush-decoder-banner.png" style="max-width: 100%;"/>
<img alt="GoldRush Decoder Logo" src="./assets/goldrush-decoder-banner.png" style="max-width: 100%;"/>
</div>

<p align="center">
Expand Down Expand Up @@ -41,7 +41,7 @@ This repository contains the logic for decoding a `raw_log_event` of a transacti
"<protocol-name>:<EventName>",
["<chain_name_1>", "<chain_name_2>", ...],
ABI as Abi,
async (log_event, tx, chain_name, covalent_client, options): Promise<EventType> => {
async (log_event, tx, chain_name, goldrush_client, options): Promise<EventType> => {
<!-- decoding logic -->
}
);
Expand All @@ -56,7 +56,7 @@ This repository contains the logic for decoding a `raw_log_event` of a transacti
1. `log_event`: The raw log event that is being decoded.
2. `tx`: The transaction object that generated this log.
3. `chain_name`: Name of the chain to which the log belongs to.
4. `covalent_client`: The covalent client created with your covalent API key.
4. `goldrush_client`: The covalent client created with your covalent API key.
5. `options`: Query parameters attached to the request for refining the response. These are of the following types
1. `raw_logs`: A `boolean` that attaches the raw log of the event along with the decoded response
2. `min_usd`: A minimum number value for a transaction to have to be decoded
Expand All @@ -67,7 +67,7 @@ This repository contains the logic for decoding a `raw_log_event` of a transacti
GoldRushDecoder.fallback(
"EventName",
ABI as Abi,
async (log_event, tx, chain_name, covalent_client, options): Promise<EventType> => {
async (log_event, tx, chain_name, goldrush_client, options): Promise<EventType> => {
<!-- decoding logic -->
}
);
Expand Down Expand Up @@ -148,4 +148,4 @@ Give a ⭐️ if this project helped you!

## License

This project is [MIT](LICENSE) licensed.
This project is [MIT](./LICENSE) licensed.
10 changes: 5 additions & 5 deletions api/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { txRouter } from "../microservices/tx/tx.routes";
import { GoldRushDecoder } from "../services";
import { timestampParser } from "../utils/functions";
import { timestampParser } from "@covalenthq/client-sdk";
import cors from "cors";
import { config as dotenvConfig } from "dotenv";
import express, {
type Express,
type NextFunction,
type Request,
type Response,
type NextFunction,
} from "express";

dotenvConfig();
Expand All @@ -34,11 +34,11 @@ app.use("*", (_req: Request, res: Response) => {
app.use(
(err: Error | any, _req: Request, res: Response, _next: NextFunction) => {
const now = new Date();
console.error("Server Error");
console.error(
`${now.toISOString()}: ${timestampParser(now, "descriptive")}`
"Server Error",
`${now.toISOString()}: ${timestampParser(now, "descriptive")}`,
err
);
console.error(err);
if (err.errorCode) {
res.status(err.errorCode).json({
success: false,
Expand Down
8 changes: 0 additions & 8 deletions jest.config.js

This file was deleted.

13 changes: 13 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Config } from "jest";

const config: Config = {
preset: "ts-jest",
testEnvironment: "node",
maxConcurrency: 10,
extensionsToTreatAsEsm: [".ts"],
coveragePathIgnorePatterns: ["./dist/*"],
verbose: true,
testTimeout: 500000,
};

export default config;
18 changes: 14 additions & 4 deletions microservices/tx/tx.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
type DecodeTXRequest,
} from "./tx.schema";
import { decodeLogsFromTx, fetchTxFromHash } from "./tx.service";
import { type Chain } from "@covalenthq/client-sdk";
import {
GoldRushClient,
type Chain,
type ChainName,
} from "@covalenthq/client-sdk";
import {
Router,
type NextFunction,
Expand All @@ -30,10 +34,16 @@ const handleDecode = async (
const raw_logs = (req.query as DecodeTXQuery)["raw_logs"] === "true";
const min_usd = (req.query as DecodeTXQuery)["min_usd"] ?? 0;
const { chain_name, tx_hash } = req.body as DecodeTXRequest;

const goldrushClient = new GoldRushClient(goldrushApiKey, {
source: "GoldRush Decoder",
threadCount: 5,
});

const tx = await fetchTxFromHash(
chain_name as Chain,
tx_hash,
goldrushApiKey
goldrushClient
);
const {
log_events,
Expand All @@ -44,9 +54,9 @@ const handleDecode = async (
...tx_metadata
} = tx;
const events = await decodeLogsFromTx(
chain_name as Chain,
chain_name as ChainName,
tx,
goldrushApiKey,
goldrushClient,
{
raw_logs,
min_usd,
Expand Down
9 changes: 5 additions & 4 deletions microservices/tx/tx.schema.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Chains } from "@covalenthq/client-sdk";
import { ChainName } from "@covalenthq/client-sdk";
import * as yup from "yup";

export const decodeTXBodySchema = yup.object({
chain_name: yup
.mixed()
.oneOf(Object.values(Chains), "chain_name is incorrect")
.required("chain_name is required"),
.string()
.trim()
.oneOf(Object.values(ChainName), "chain_name is incorrect")
.required(),
tx_hash: yup.string().trim().required("tx_hash is required"),
});

Expand Down
15 changes: 7 additions & 8 deletions microservices/tx/tx.service.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { GoldRushDecoder } from "../../services";
import { type QueryOptions } from "../../services/decoder/decoder.types";
import {
CovalentClient,
type Chain,
type ChainName,
type GoldRushClient,
type Transaction,
} from "@covalenthq/client-sdk";

export const fetchTxFromHash = async (
chain_name: Chain,
tx_hash: string,
covalentApiKey: string
goldrush_client: GoldRushClient
): Promise<Transaction> => {
const covalentClient = new CovalentClient(covalentApiKey);
const { data, error_code, error_message } =
await covalentClient.TransactionService.getTransaction(
await goldrush_client.TransactionService.getTransaction(
chain_name,
tx_hash,
{
noLogs: false,
quoteCurrency: "USD",
withNftSales: false,
withSafe: false,
}
);
Expand All @@ -35,15 +34,15 @@ export const fetchTxFromHash = async (
};

export const decodeLogsFromTx = async (
chain_name: Chain,
chain_name: ChainName,
tx: Transaction,
apiKey: string,
goldrush_client: GoldRushClient,
options: QueryOptions
) => {
const events = await GoldRushDecoder.decode(
chain_name,
tx,
apiKey,
goldrush_client,
options
);
return events;
Expand Down
Loading
Loading