| … | … | @@ -401,6 +401,21 @@ async function getAddresses(chain) { |
| 401 | 401 | } |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | // For Ethereum, also include ERC-20 token addresses (they share the same address space) |
| 405 | // When querying 'testnet-ethereum', also return 'testnet-ethereum-usdt' addresses |
| 406 | if (!chain.includes('all') && (chain.includes('ethereum') && !chain.includes('-usdt'))) { |
| 407 | const tokenPrefix = `${prefix}usdt:` |
| 408 | for await (const entry of txHistoryDb.createReadStream()) { |
| 409 | if (entry.key.startsWith(tokenPrefix)) { |
| 410 | const addr = JSON.parse(entry.value) |
| 411 | // Check if we already have this index (don't duplicate) |
| 412 | if (!addresses.find(a => a.index === addr.index)) { |
| 413 | addresses.push(addr) |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 404 | 419 | return addresses.sort((a, b) => a.index - b.index) |
| 405 | 420 | } |
| 406 | 421 | |
| … | … | @@ -421,7 +436,15 @@ async function getNextAddressIndex(chain) { |
| 421 | 436 | * @returns {Object|null} - Latest address or null if none exist |
| 422 | 437 | */ |
| 423 | 438 | async function getCurrentAddress(chain) { |
| 424 | | const addresses = await getAddresses(chain) |
| 439 | let addresses = await getAddresses(chain) |
| 440 | |
| 441 | // For ERC-20 tokens (like USDT), fall back to base Ethereum addresses |
| 442 | // since they share the same address space |
| 443 | if (addresses.length === 0 && chain.includes('-usdt')) { |
| 444 | const baseChain = chain.replace('-usdt', '') |
| 445 | addresses = await getAddresses(baseChain) |
| 446 | } |
| 447 | |
| 425 | 448 | if (addresses.length === 0) return null |
| 426 | 449 | |
| 427 | 450 | // Find address marked as current, or return latest |