-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc-web3js: Allow passing Connection class directly (#96)
* rpc-web3js: Allow Connection class directly * add to createUmi & allow chunk size param * changeset * Update rpc.md * merge doc code blocks
- Loading branch information
Showing
7 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@metaplex-foundation/umi-rpc-chunk-get-accounts': patch | ||
'@metaplex-foundation/umi-bundle-defaults': patch | ||
'@metaplex-foundation/umi-rpc-web3js': patch | ||
--- | ||
|
||
Allow instancing umi/RPCInterface with Connection class or RPC url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
import { Umi, createUmi as baseCreateUmi } from '@metaplex-foundation/umi'; | ||
import type { ChunkGetAccountsRpcOptions } from '@metaplex-foundation/umi-rpc-chunk-get-accounts'; | ||
import type { Web3JsRpcOptions } from '@metaplex-foundation/umi-rpc-web3js'; | ||
import type { Connection as Web3JsConnection } from '@solana/web3.js'; | ||
import { defaultPlugins } from './plugin'; | ||
|
||
export const createUmi = ( | ||
export function createUmi( | ||
endpoint: string, | ||
rpcOptions?: Web3JsRpcOptions | ||
): Umi => baseCreateUmi().use(defaultPlugins(endpoint, rpcOptions)); | ||
rpcOptions?: Web3JsRpcOptions & ChunkGetAccountsRpcOptions | ||
): Umi; | ||
export function createUmi( | ||
connection: Web3JsConnection, | ||
rpcOptions?: ChunkGetAccountsRpcOptions | ||
): Umi; | ||
export function createUmi( | ||
endpointOrConnection: string | Web3JsConnection, | ||
rpcOptions?: Web3JsRpcOptions & ChunkGetAccountsRpcOptions | ||
): Umi { | ||
return baseCreateUmi().use( | ||
typeof endpointOrConnection === 'string' | ||
? defaultPlugins(endpointOrConnection, rpcOptions) | ||
: defaultPlugins(endpointOrConnection, rpcOptions) | ||
); | ||
} | ||
|
||
export * from './plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/umi-rpc-chunk-get-accounts/src/createChunkGetAccountsRpc.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
import { UmiPlugin } from '@metaplex-foundation/umi'; | ||
import type { Connection as Web3JsConnection } from '@solana/web3.js'; | ||
import { createWeb3JsRpc, Web3JsRpcOptions } from './createWeb3JsRpc'; | ||
|
||
export const web3JsRpc = ( | ||
export function web3JsRpc( | ||
endpoint: string, | ||
rpcOptions?: Web3JsRpcOptions | ||
): UmiPlugin => ({ | ||
install(umi) { | ||
umi.rpc = createWeb3JsRpc(umi, endpoint, rpcOptions); | ||
}, | ||
}); | ||
): UmiPlugin; | ||
export function web3JsRpc(connection: Web3JsConnection): UmiPlugin; | ||
export function web3JsRpc( | ||
endpointOrConnection: string | Web3JsConnection, | ||
rpcOptions?: Web3JsRpcOptions | ||
): UmiPlugin { | ||
return { | ||
install(umi) { | ||
umi.rpc = | ||
typeof endpointOrConnection === 'string' | ||
? createWeb3JsRpc(umi, endpointOrConnection, rpcOptions) | ||
: createWeb3JsRpc(umi, endpointOrConnection); | ||
}, | ||
}; | ||
} |