-
Notifications
You must be signed in to change notification settings - Fork 47
fix scripts #433
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
base: master
Are you sure you want to change the base?
fix scripts #433
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { BigNumber, BigNumberish } from "ethers"; | ||
| import { getRelayAPIKEY, getRelayUrl } from "./utils"; | ||
| import { axiosPost } from "@socket.tech/dl-common"; | ||
| import { axiosGet, axiosPost } from "@socket.tech/dl-common"; | ||
| import { mode } from "../config/config"; | ||
| import { ChainSlugToId } from "../../../src"; | ||
|
|
||
|
|
@@ -17,7 +17,6 @@ interface RequestObj { | |
| export const relayTx = async (params: RequestObj) => { | ||
| try { | ||
| let { to, data, chainSlug, gasPrice, value, type, gasLimit } = params; | ||
| let url = await getRelayUrl(mode); | ||
| let config = { | ||
| headers: { | ||
| "x-api-key": getRelayAPIKEY(mode), | ||
|
|
@@ -34,7 +33,26 @@ export const relayTx = async (params: RequestObj) => { | |
| sequential: false, | ||
| source: "LoadTester", | ||
| }; | ||
| let response = await axiosPost(url!, body, config); | ||
| let response = await axiosPost( | ||
| `${await getRelayUrl(mode)}/relay`, | ||
| body, | ||
| config | ||
| ); | ||
| if (response?.success) return response?.data; | ||
| else { | ||
| console.log("error in relaying tx", response); | ||
| return { hash: "" }; | ||
| } | ||
| } catch (error) { | ||
| console.log("uncaught error", error); | ||
| } | ||
|
Comment on lines
+36
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, find and display the relayer.ts file
find . -name "relayer.ts" -type f | head -20Repository: SocketDotTech/socket-DL Length of output: 100 🏁 Script executed: # Once found, examine the full file
cat -n scripts/deploy/utils/relayer.tsRepository: SocketDotTech/socket-DL Length of output: 2078 🏁 Script executed: # Search for all usages of relayTx and getStatus to understand what callers expect
rg -n "relayTx|getStatus" --type ts --type js -B 2 -A 2 scripts srcRepository: SocketDotTech/socket-DL Length of output: 2762 🏁 Script executed: # Also check for txId or txHash usage near relayTx calls
rg -n "txId|txHash|hash" --type ts --type js -B 3 -A 3 | grep -A 5 -B 5 "relayTx\|getStatus"Repository: SocketDotTech/socket-DL Length of output: 1391 Both Lines 36-48 and 51-63 return This violates the coding guideline to check for edge cases and unhandled errors. Either throw errors so callers can bail out, or return a consistent nullable type with explicit error signals. 🛠️ Suggested fix-export const relayTx = async (params: RequestObj) => {
+export const relayTx = async (
+ params: RequestObj
+): Promise<{ txId?: string; hash?: string } | null> => {
try {
@@
- if (response?.success) return response?.data;
- else {
- console.log("error in relaying tx", response);
- return { hash: "" };
- }
+ if (!response?.success) {
+ console.log("error in relaying tx", response);
+ return null;
+ }
+ return response.data;
} catch (error) {
console.log("uncaught error", error);
+ throw error;
}
};🤖 Prompt for AI Agents |
||
| }; | ||
|
|
||
| export const getStatus = async (txId: string) => { | ||
| try { | ||
| const response = await axiosGet( | ||
| `${await getRelayUrl(mode)}/status?txId=${txId}` | ||
| ); | ||
| if (response?.success) return response?.data; | ||
| else { | ||
| console.log("error in relaying tx", response); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against missing
txIdbefore status lookup.Line 139-148 calls
getStatus(response?.txId)even when the relay response failed or is undefined, producing/status?txId=undefinedand misleading tracking logs. This should bail out early iftxIdis missing.As per coding guidelines, Check for resource leaks, race conditions, and unhandled edge cases.
🛠️ Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents