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

option for dependency injection of RpcClient #692

Open
turadg opened this issue Nov 6, 2024 · 0 comments
Open

option for dependency injection of RpcClient #692

turadg opened this issue Nov 6, 2024 · 0 comments

Comments

@turadg
Copy link
Contributor

turadg commented Nov 6, 2024

Problem

The rpc.query.ts that Telescope generates is like,

export const createRPCQueryClient = async ({
  rpcEndpoint,
}: {
  rpcEndpoint: string | HttpEndpoint;
}) => {
  const tmClient = await Tendermint34Client.connect(rpcEndpoint);
  const client = new QueryClient(tmClient);

Such a construction depends on ambient authority of Tendermint34Client.connect.

This causes a couple problems:

Prototype lockdown

The module with connect imports axios and that fails to load in Hardened JS:

Ambient authority

fetch may not always be available, for example if run in a hardened compartment.

Mocking in tests

To test code with a fake RpcClient requires hacking into the module loader to intercept Axios.

Possible solution

You could move to just using Fetch API but that would still be an ambient authority.

Better would be an option for the createRPCQueryClient helper (or whatever it be called) to take an RpcClient instead of an endpoint. Then consumers can make their own RpcClient using whatever authorities are available, including a test mock.

Inside the function you can create the Tendermint client from the RpcClient argument,

const tmClient = await Tendermint34Client.create(rpcClient);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant