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

Thin RPC method impls should not be provided #1536

Open
turbocrime opened this issue Jul 23, 2024 · 0 comments
Open

Thin RPC method impls should not be provided #1536

turbocrime opened this issue Jul 23, 2024 · 0 comments
Labels
refactor Improving existing system with new design rpc Related to proto rpc services/methods

Comments

@turbocrime
Copy link
Contributor

a few impls like this exist

export const timestampByHeight: Impl['timestampByHeight'] = async (req, ctx) => {
const services = await ctx.values.get(servicesCtx)();
const { querier } = await services.getWalletServices();
return querier.sct.timestampByHeight(req);
};

a service proxying utility exists in transport-dom that should be preferred to stub or no-op implementations

/**
* Creates a proxy implementation of a service, suitable for hosting in a
* ConnectRouter, from a given service type definition and a matching client to
* some other host of the service.
*
* To do this, it iterates over each method in the service type definition,
* creating a method on the proxy impl that calls the provided client.
*
* You can provide a contextHandler function to modify any request or the
* client-side contextValues of any request.
*
* The optional makePartialServiceImpl parameter can be provided to override the
* generated proxy methods with your own implementations.
*/
export const createProxyImpl = <S extends ServiceType>(
service: S,
client: PromiseClient<S>,
contextHandler = defaultContextHandler,
makePartialServiceImpl?: (c: PromiseClient<S>) => Partial<ServiceImpl<S>>,
) => {
const makeAnyProxyMethod: CreateAnyMethodImpl<S> = (method, localName) => {
const clientMethod = client[localName] as (cI: unknown, cOpt: CallOptions) => unknown;
const impl = (hI: unknown, hCtx: HandlerContext) => clientMethod(...contextHandler(hI, hCtx));
return impl as MethodImpl<typeof method>;
};
return {
...makeAnyServiceImpl(service, makeAnyProxyMethod),
...makePartialServiceImpl?.(client),
};
};

proxy utility is already used in prax https://github.com/prax-wallet/web/blob/4137be5690be143bef73ba378a1dcd6c2a893765/apps/extension/src/rpc/index.ts

@turbocrime turbocrime added rpc Related to proto rpc services/methods refactor Improving existing system with new design labels Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Improving existing system with new design rpc Related to proto rpc services/methods
Projects
Status: 🗄️ Backlog
Development

No branches or pull requests

1 participant