Skip to content
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

Use version data from db #1998

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions packages/installer/src/ethClient/ethersProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,27 @@ import { EthClientStatusError, EthProviderError } from "@dappnode/types";
import { emitSyncedNotification } from "./syncedNotification.js";
import { ethereumClient } from "./index.js";
import { FetchRequest } from "ethers";
import { PackageVersionData } from "@dappnode/types";
import memoize from "memoizee";
import fs from "fs";

const getVersionData = memoize(function (): PackageVersionData {
try {
const data: PackageVersionData = JSON.parse(
fs.readFileSync(params.GIT_DATA_PATH, "utf8")
);
return data;
} catch (e) {
return { };
}
});

/**
* Returns the url of the JSON RPC an Eth multi-client status and target
* If the package target is not active it returns the remote URL
* @returns initialized ethers instance
*/
export async function getEthersProvider(url?: string, network?: string): Promise<ethers.JsonRpcProvider> {
const rpcUrl = url ?? await getEthUrl();
export async function getEthersProvider(
url?: string,
network?: string
): Promise<ethers.JsonRpcProvider> {
const rpcUrl = url ?? (await getEthUrl());
const rpcNetwork = network ?? "mainnet";
const fetchRequest = new FetchRequest(rpcUrl);
const versionData = getVersionData()
fetchRequest.setHeader("x-dappmanager-version", `${versionData.version}-${versionData.commit?.slice(0,8)}` );
return new ethers.JsonRpcProvider(fetchRequest, rpcNetwork, { staticNetwork: true });
const versionData = db.versionData.get();
fetchRequest.setHeader(
"x-dappmanager-version",
`${versionData.version}-${db.versionData.get().commit?.slice(0, 8)}`
);
return new ethers.JsonRpcProvider(fetchRequest, rpcNetwork, {
staticNetwork: true,
});
}

/**
Expand Down
Loading