-
Notifications
You must be signed in to change notification settings - Fork 911
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
refactor(experimental): add cluster level API for transports #2053
refactor(experimental): add cluster level API for transports #2053
Conversation
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
111a034
to
8b5554c
Compare
I like this stack a lot. I love that only with types, we can cherry-pick the RPC methods available in different clusters. The only API change I want to put on the table is, instead of requesting a second type MainnetUrl = string & { '~cluster': 'mainnet' }
type DevnetUrl = string & { '~cluster': 'devnet' }
type TestnetUrl = string & { '~cluster': 'testnet' }
type ClusterUrl = string | MainnetUrl | DevnetUrl | TestnetUrl
function mainnet(putativeString: string): MainnetUrl { return putativeString as MainnetUrl }
function devnet(putativeString: string): DevnetUrl { return putativeString as DevnetUrl }
function testnet(putativeString: string): TestnetUrl { return putativeString as TestnetUrl }
// Devnet example.
const devnetTransport = createDefaultRpcTransport({ url: devnet('https://api.devnet.solana.com') });
createSolanaRpc({ transport: devnetTransport });
// ^ RpcDevnet<DevnetSolanaRpcMethods>
// Generic example.
const genericTransport = createDefaultRpcTransport({ url: 'http://127.0.0.1:8899' });
createSolanaRpc({ transport: genericTransport });
// ^ Rpc<SolanaRpcMethods> Wdyt? |
Interesting. Just thinking about your suggestion out loud here: For just
In either case, now that I look at it some more, when it comes to the main library in There is one problem here. If we put the cluster configuration on the URL as provided to Wdyt @lorisleiva ? P.S. I edited/re-wrote this after checking out the code some more. These commits are a tad old for me, had to refresh. |
8b5554c
to
3fbed8a
Compare
What if we don't tag the API methods with a cluster though? What if we just have various API methods types available like You can see them as various libraries of RPC methods available in different clusters. Then we select the one we need based on the given transport URL when we create the RPC (transport + api). Is this making any sense? 😅 |
I had them isolated into per-cluster sets when I originally created this stack (or one before it I forget). Is this what you're thinking? createJsonRpc({
api: createJsonRpcApi<SolanaRpcMethodsDevnet>(),
transport: createHttpTransport({ url: devnet('https://api.devnet.solana.com') }),
}); // RpcDevnet<SolanaRpcMethodsDevnet>
createJsonRpc({
api: createJsonRpcApi<SolanaRpcMethodsTestnet>(),
transport: createHttpTransport({ url: testnet('https://api.testnet.solana.com') }),
}); // RpcTestnet<SolanaRpcMethodsTestnet>
createJsonRpc({
api: createJsonRpcApi<SolanaRpcMethodsMainnet>(),
transport: createHttpTransport({ url: mainnet('https://api.mainnet-beta.solana.com') }),
}); // RpcMainnet<SolanaRpcMethodsMainnet> |
Yes, exactly that. Then it's the responsibility of |
No I think that will work fine. Anyone who creates their own RPC client from our libraries would just have to make sure they align the proper API based on cluster as well, similar to what I just did above. For our Solana-implemented helpers, we can wrap that. |
3fbed8a
to
d6e8247
Compare
d6e8247
to
0f48e23
Compare
export function createJsonRpc<TRpcMethods>( | ||
rpcConfig: Readonly<{ | ||
api: IRpcApi<TRpcMethods>; | ||
transport: IRpcTransportDevnet; | ||
}>, | ||
): RpcDevnet<TRpcMethods>; | ||
export function createJsonRpc<TRpcMethods>( | ||
rpcConfig: Readonly<{ | ||
api: IRpcApi<TRpcMethods>; | ||
transport: IRpcTransportTestnet; | ||
}>, | ||
): RpcTestnet<TRpcMethods>; | ||
export function createJsonRpc<TRpcMethods>( | ||
rpcConfig: Readonly<{ | ||
api: IRpcApi<TRpcMethods>; | ||
transport: IRpcTransportMainnet; | ||
}>, | ||
): RpcMainnet<TRpcMethods>; | ||
export function createJsonRpc<TRpcMethods>( | ||
rpcConfig: Readonly<{ | ||
api: IRpcApi<TRpcMethods>; | ||
transport: IRpcTransport; | ||
}>, | ||
): Rpc<TRpcMethods>; | ||
export function createJsonRpc<TRpcMethods, TConfig extends RpcConfig<TRpcMethods>>( | ||
rpcConfig: TConfig, | ||
): RpcFromTransport<TRpcMethods, TConfig['transport']> { | ||
return makeProxy(rpcConfig) as RpcFromTransport<TRpcMethods, TConfig['transport']>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with overloads here because we've designed this API for users to provide their RPC methods. It can be removed, but this function would then take 2 generic arguments, and the moment you provide your RPC methods it will complain you didn't provide TConfig
as well.
0f48e23
to
43492b5
Compare
43492b5
to
33d3cb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!
f883a80
to
c9bb45e
Compare
33d3cb8
to
9daa3c2
Compare
Merge activity
|
As per @lorisleiva's suggestion, here's some types for cluster URLs! Straight from [this comment](#2053 (comment))
9daa3c2
to
96362d5
Compare
🎉 This PR is included in version 1.90.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
This change introduces cluster-level transports as well as cluster-level JSON RPCs
that infer the cluster from the provided transport.