forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts-sdk] Introduce SDK Connection class (MystenLabs#8088)
This is an idea to create a dedicated class to represent a `connection`, meaning a bag of configuration related to how to connect to a network. I thought about naming this `Network` but I thought that could be a little confusing. Maybe something like `Endpoints` would be a better class name? Open to suggestions on the naming.
- Loading branch information
1 parent
476f512
commit aa650aa
Showing
19 changed files
with
151 additions
and
132 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,6 @@ | ||
--- | ||
"@mysten/wallet-adapter-unsafe-burner": minor | ||
"@mysten/sui.js": minor | ||
--- | ||
|
||
Introduce new `Connection` class, which is used to define the endpoints that are used when interacting with the network. |
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,19 +1,39 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { JsonRpcProvider } from '@mysten/sui.js'; | ||
import { | ||
JsonRpcProvider, | ||
Connection, | ||
devnetConnection, | ||
localnetConnection, | ||
} from '@mysten/sui.js'; | ||
|
||
import { getEndpoint, Network } from './rpcSetting'; | ||
export enum Network { | ||
LOCAL = 'LOCAL', | ||
DEVNET = 'DEVNET', | ||
TESTNET = 'TESTNET', | ||
} | ||
|
||
export { Network, getEndpoint }; | ||
const CONNECTIONS: Record<Network, Connection> = { | ||
[Network.LOCAL]: localnetConnection, | ||
[Network.DEVNET]: devnetConnection, | ||
[Network.TESTNET]: new Connection({ | ||
fullnode: 'https://fullnode-explorer.testnet.sui.io:443', | ||
}), | ||
}; | ||
|
||
const defaultRpcMap: Map<Network | string, JsonRpcProvider> = new Map(); | ||
/** @deprecated This shouldn't be directly used, and instead should be used through `useRpc()`. */ | ||
export const DefaultRpcClient = (network: Network | string) => { | ||
const existingClient = defaultRpcMap.get(network); | ||
if (existingClient) return existingClient; | ||
|
||
const provider = new JsonRpcProvider(getEndpoint(network)); | ||
const connection = | ||
network in Network | ||
? CONNECTIONS[network as Network] | ||
: new Connection({ fullnode: network }); | ||
|
||
const provider = new JsonRpcProvider(connection); | ||
defaultRpcMap.set(network, provider); | ||
return provider; | ||
}; |
This file was deleted.
Oops, something went wrong.
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
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,12 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { JsonRpcProvider } from "@mysten/sui.js"; | ||
import { Connection, JsonRpcProvider } from "@mysten/sui.js"; | ||
|
||
import { config } from "../config"; | ||
|
||
const provider = new JsonRpcProvider(config.VITE_NETWORK); | ||
const provider = new JsonRpcProvider( | ||
new Connection({ fullnode: config.VITE_NETWORK }) | ||
); | ||
|
||
export default provider; |
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
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
Oops, something went wrong.