feat: update validate address endpoint#1263
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughThe changes replace the Elliptic SDK for address validation with a new OFAC-based implementation. This includes introducing a new Changes
Sequence Diagram(s)sequenceDiagram
participant App as App Startup
participant Ofac
participant HTTP as HTTP Client
participant Parser as XML Parser
participant Cache as Address Cache
participant Controller as Controller
App->>Ofac: initialize()
Ofac->>HTTP: fetch OFAC SDN XML
HTTP-->>Ofac: XML content
Ofac->>Parser: parse XML
Parser->>Parser: extract Digital Currency Addresses
Parser-->>Ofac: sanctioned addresses set
Ofac->>Cache: store addresses
Ofac->>Ofac: start 24h refresh interval
Ofac-->>App: initialized
Controller->>Ofac: validateAddress(address)
Ofac->>Cache: check sanctioned set
alt Address in sanctioned set
Ofac-->>Controller: { valid: false }
else Address not found
Ofac-->>Controller: { valid: true }
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
d2b8ef0 to
a55a3df
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
node/proxy/api/package.json (1)
14-19:⚠️ Potential issue | 🟡 MinorMissing direct dependencies:
axiosandviem.
node/proxy/api/src/ofac.tsimportsaxios(line 1) and{ getAddress, isAddress }fromviem(line 4), but neither is declared in this package.json. While both are currently available via workspace hoisting from the root package.json, this creates a fragility risk: independent deployment of this package or changes to the workspace layout could break the build.Proposed fix
"dependencies": { "@shapeshiftoss/common-api": "^10.0.0", "@shapeshiftoss/prometheus": "^10.0.0", + "axios": "^1.6.2", "bottleneck": "^2.19.5", - "fast-xml-parser": "^4.3.0" + "fast-xml-parser": "^4.3.0", + "viem": "^2.33.2" }
🤖 Fix all issues with AI agents
In `@node/proxy/api/src/app.ts`:
- Line 88: The top-level call to main() currently has no rejection handling;
wrap the invocation so any thrown/rejected error (e.g., from ofac.initialize()
or server bind in main()) is caught, logged, and exits with non-zero status.
Update the bare main() invocation to main().catch(err => { /* log error */
process.exit(1) }); — use the existing logger if available (e.g.,
processLogger.error) or console.error to record err and a clear message before
calling process.exit(1).
In `@node/proxy/api/src/ofac.ts`:
- Around line 49-52: The axios call in fetchAndParseOfacList currently has no
timeout and can hang; update the axios.get in fetchAndParseOfacList to include a
finite timeout option (e.g., timeout: 10000 ms or a configured value) so the
request to OFAC_SDN_URL fails fast on network stalls and then continue to call
this.parseXml(data) only on successful responses; ensure you add the timeout to
the options object passed to axios.get and keep existing responseType: 'text'.
- Around line 35-38: The catch block that currently does "this.logger.error({
err }, 'Failed to initialize OFAC service, failing open')" then "throw err" is
inconsistent; either make it truly fail-open by swallowing the error (remove the
throw), set the internal sanctioned-set/state to empty/allow-all, and ensure the
existing refresh/retry loop (e.g., the OFAC refresh/polling mechanism) will
attempt to reload later, or make it fail-closed by keeping the throw and
changing the log text to accurately say "failing closed" (or similar). Locate
the catch around OFAC initialization (the block with this.logger.error and throw
err) and implement one of these two fixes so log and runtime behavior match.
🧹 Nitpick comments (2)
node/proxy/api/src/ofac.ts (1)
41-47:validateAddressdoesn't need to beasync.The method body is fully synchronous — it only reads from an in-memory
Set. Theasynckeyword wraps the return value in an unnecessaryPromise. If the interface contract requiresPromise<{ valid: boolean }>for future extensibility, this is fine, but worth noting.node/proxy/api/src/controller.ts (1)
4-4: Circular import:controller.ts → app.ts → (routes) → controller.ts.This works because
ofacis a module-level const that's fully initialized before any request arrives, and Node.js module caching breaks the cycle. It's a common Express pattern but worth noting — ifapp.tsis ever refactored to use theofacreference at import time (rather than at request time), this could break. Consider extractingofacinto a dedicated module (e.g.,./ofac-instance.ts) to eliminate the cycle entirely.
Move away from elliptic as it is cost prohibitive and replace with direct SDN list until a more comprehensive AML screening tool can be determined.
Summary by CodeRabbit
Release Notes
New Features
Refactor