Skip to content

Commit 1be69cc

Browse files
authored
Yj-chore/update (#62)
1 parent 0fef525 commit 1be69cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+11172
-9012
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div align="center">
2-
<img alt="GoldRush Kit Logo" src="./assets/goldrush-decoder-banner.png" style="max-width: 100%;"/>
2+
<img alt="GoldRush Decoder Logo" src="./assets/goldrush-decoder-banner.png" style="max-width: 100%;"/>
33
</div>
44

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

149149
## License
150150

151-
This project is [MIT](LICENSE) licensed.
151+
This project is [MIT](./LICENSE) licensed.

api/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { txRouter } from "../microservices/tx/tx.routes";
22
import { GoldRushDecoder } from "../services";
3-
import { timestampParser } from "../utils/functions";
3+
import { timestampParser } from "@covalenthq/client-sdk";
44
import cors from "cors";
55
import { config as dotenvConfig } from "dotenv";
66
import express, {
77
type Express,
8+
type NextFunction,
89
type Request,
910
type Response,
10-
type NextFunction,
1111
} from "express";
1212

1313
dotenvConfig();
@@ -34,11 +34,11 @@ app.use("*", (_req: Request, res: Response) => {
3434
app.use(
3535
(err: Error | any, _req: Request, res: Response, _next: NextFunction) => {
3636
const now = new Date();
37-
console.error("Server Error");
3837
console.error(
39-
`${now.toISOString()}: ${timestampParser(now, "descriptive")}`
38+
"Server Error",
39+
`${now.toISOString()}: ${timestampParser(now, "descriptive")}`,
40+
err
4041
);
41-
console.error(err);
4242
if (err.errorCode) {
4343
res.status(err.errorCode).json({
4444
success: false,

jest.config.js

-8
This file was deleted.

jest.config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Config } from "jest";
2+
3+
const config: Config = {
4+
preset: "ts-jest",
5+
testEnvironment: "node",
6+
maxConcurrency: 10,
7+
extensionsToTreatAsEsm: [".ts"],
8+
coveragePathIgnorePatterns: ["./dist/*"],
9+
verbose: true,
10+
testTimeout: 500000,
11+
};
12+
13+
export default config;

microservices/tx/tx.routes.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
type DecodeTXRequest,
99
} from "./tx.schema";
1010
import { decodeLogsFromTx, fetchTxFromHash } from "./tx.service";
11-
import { type Chain } from "@covalenthq/client-sdk";
11+
import {
12+
GoldRushClient,
13+
type Chain,
14+
type ChainName,
15+
} from "@covalenthq/client-sdk";
1216
import {
1317
Router,
1418
type NextFunction,
@@ -30,10 +34,16 @@ const handleDecode = async (
3034
const raw_logs = (req.query as DecodeTXQuery)["raw_logs"] === "true";
3135
const min_usd = (req.query as DecodeTXQuery)["min_usd"] ?? 0;
3236
const { chain_name, tx_hash } = req.body as DecodeTXRequest;
37+
38+
const goldrushClient = new GoldRushClient(goldrushApiKey, {
39+
source: "GoldRush Decoder",
40+
threadCount: 5,
41+
});
42+
3343
const tx = await fetchTxFromHash(
3444
chain_name as Chain,
3545
tx_hash,
36-
goldrushApiKey
46+
goldrushClient
3747
);
3848
const {
3949
log_events,
@@ -44,9 +54,9 @@ const handleDecode = async (
4454
...tx_metadata
4555
} = tx;
4656
const events = await decodeLogsFromTx(
47-
chain_name as Chain,
57+
chain_name as ChainName,
4858
tx,
49-
goldrushApiKey,
59+
goldrushClient,
5060
{
5161
raw_logs,
5262
min_usd,

microservices/tx/tx.schema.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { Chains } from "@covalenthq/client-sdk";
1+
import { ChainName } from "@covalenthq/client-sdk";
22
import * as yup from "yup";
33

44
export const decodeTXBodySchema = yup.object({
55
chain_name: yup
6-
.mixed()
7-
.oneOf(Object.values(Chains), "chain_name is incorrect")
8-
.required("chain_name is required"),
6+
.string()
7+
.trim()
8+
.oneOf(Object.values(ChainName), "chain_name is incorrect")
9+
.required(),
910
tx_hash: yup.string().trim().required("tx_hash is required"),
1011
});
1112

microservices/tx/tx.service.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import { GoldRushDecoder } from "../../services";
22
import { type QueryOptions } from "../../services/decoder/decoder.types";
33
import {
4-
CovalentClient,
54
type Chain,
5+
type ChainName,
6+
type GoldRushClient,
67
type Transaction,
78
} from "@covalenthq/client-sdk";
89

910
export const fetchTxFromHash = async (
1011
chain_name: Chain,
1112
tx_hash: string,
12-
covalentApiKey: string
13+
goldrush_client: GoldRushClient
1314
): Promise<Transaction> => {
14-
const covalentClient = new CovalentClient(covalentApiKey);
1515
const { data, error_code, error_message } =
16-
await covalentClient.TransactionService.getTransaction(
16+
await goldrush_client.TransactionService.getTransaction(
1717
chain_name,
1818
tx_hash,
1919
{
2020
noLogs: false,
2121
quoteCurrency: "USD",
22-
withNftSales: false,
2322
withSafe: false,
2423
}
2524
);
@@ -35,15 +34,15 @@ export const fetchTxFromHash = async (
3534
};
3635

3736
export const decodeLogsFromTx = async (
38-
chain_name: Chain,
37+
chain_name: ChainName,
3938
tx: Transaction,
40-
apiKey: string,
39+
goldrush_client: GoldRushClient,
4140
options: QueryOptions
4241
) => {
4342
const events = await GoldRushDecoder.decode(
4443
chain_name,
4544
tx,
46-
apiKey,
45+
goldrush_client,
4746
options
4847
);
4948
return events;

0 commit comments

Comments
 (0)