Skip to content

Commit

Permalink
fix: Make auxiliary functions create their own URL instances internally
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Aug 14, 2024
1 parent 40d739d commit 1b42462
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/artifact/internal/chainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,5 @@ export function resolveApiUrl(apiUrlIsh: string) {
entry.network.toLowerCase() == apiUrlIsh.toLowerCase()
);

return new URL(entry ? entry.urls.apiURL : apiUrlIsh);
return entry ? entry.urls.apiURL : apiUrlIsh;
}
16 changes: 9 additions & 7 deletions src/artifact/internal/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export default async function verify(
/**
* Checks if the given URL is reachable.
*
* @param {URL} url - The URL to check.
* @param {string} url - The URL to check.
* @returns {Promise<boolean>} True if the URL is reachable, false otherwise.
*/
async function isLiveUrl(url: URL): Promise<boolean> {
async function isLiveUrl(url: string): Promise<boolean> {
try {
const response = await fetch(url, { method: "HEAD" });
return response.ok;
Expand All @@ -111,22 +111,23 @@ async function isLiveUrl(url: URL): Promise<boolean> {
* Validates the given API key.
*
* @param {Object} params - The function parameters.
* @param {URL} params.url - The API URL.
* @param {string} params.url - The API URL.
* @param {string} params.apiKey - The API key to validate.
* @returns {Promise<boolean>} True if the API key is valid, false otherwise.
*/
async function isValidApiKey({
url,
url: _url,
apiKey,
}: {
url: URL;
url: string;
apiKey: string;
}): Promise<boolean> {
const parameters = new URLSearchParams({
apikey: apiKey,
module: "stats",
action: "ethprice",
});
const url = new URL(_url);
url.search = parameters.toString();

const response = await fetch(url, {
Expand All @@ -146,21 +147,22 @@ async function isValidApiKey({
*
* @param {string} address - The address of the contract.
* @param {Object} params - The function parameters.
* @param {URL} params.url - The API URL.
* @param {string} params.url - The API URL.
* @param {string} params.apiKey - The API key.
* @returns {Promise<boolean>} True if the contract is verified, false otherwise.
* @throws {Error} If the verification status cannot be determined.
*/
async function isVerified(
address: string,
{ url, apiKey }: { url: URL; apiKey: string }
{ url: _url, apiKey }: { url: string; apiKey: string }
): Promise<boolean> {
const parameters = new URLSearchParams({
apikey: apiKey,
module: "contract",
action: "getsourcecode",
address,
});
const url = new URL(_url);
url.search = parameters.toString();

const response = await fetch(url, {
Expand Down

0 comments on commit 1b42462

Please sign in to comment.