-
Notifications
You must be signed in to change notification settings - Fork 46
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
Add cluster API #65
Open
NorbertBodziony
wants to merge
3
commits into
anza-xyz:master
Choose a base branch
from
nightly-labs:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add cluster API #65
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
--- | ||
'@solana/wallet-standard-chains': minor | ||
'@solana/wallet-standard-features': minor | ||
--- | ||
|
||
Add `getCluster` and `setCluster` features |
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,31 +1,2 @@ | ||
import type { IdentifierString } from '@wallet-standard/base'; | ||
|
||
/** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */ | ||
export const SOLANA_MAINNET_CHAIN = 'solana:mainnet'; | ||
|
||
/** Solana Devnet cluster, e.g. https://api.devnet.solana.com */ | ||
export const SOLANA_DEVNET_CHAIN = 'solana:devnet'; | ||
|
||
/** Solana Testnet cluster, e.g. https://api.testnet.solana.com */ | ||
export const SOLANA_TESTNET_CHAIN = 'solana:testnet'; | ||
|
||
/** Solana Localnet cluster, e.g. http://localhost:8899 */ | ||
export const SOLANA_LOCALNET_CHAIN = 'solana:localnet'; | ||
|
||
/** Array of all Solana clusters */ | ||
export const SOLANA_CHAINS = [ | ||
SOLANA_MAINNET_CHAIN, | ||
SOLANA_DEVNET_CHAIN, | ||
SOLANA_TESTNET_CHAIN, | ||
SOLANA_LOCALNET_CHAIN, | ||
] as const; | ||
|
||
/** Type of all Solana clusters */ | ||
export type SolanaChain = (typeof SOLANA_CHAINS)[number]; | ||
|
||
/** | ||
* Check if a chain corresponds with one of the Solana clusters. | ||
*/ | ||
export function isSolanaChain(chain: IdentifierString): chain is SolanaChain { | ||
return SOLANA_CHAINS.includes(chain as SolanaChain); | ||
} | ||
export * from './solana.js'; | ||
export * from './sonic.js'; |
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,31 @@ | ||
import type { IdentifierString } from '@wallet-standard/base'; | ||
|
||
/** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */ | ||
export const SOLANA_MAINNET_CHAIN = 'solana:mainnet'; | ||
|
||
/** Solana Devnet cluster, e.g. https://api.devnet.solana.com */ | ||
export const SOLANA_DEVNET_CHAIN = 'solana:devnet'; | ||
|
||
/** Solana Testnet cluster, e.g. https://api.testnet.solana.com */ | ||
export const SOLANA_TESTNET_CHAIN = 'solana:testnet'; | ||
|
||
/** Solana Localnet cluster, e.g. http://localhost:8899 */ | ||
export const SOLANA_LOCALNET_CHAIN = 'solana:localnet'; | ||
|
||
/** Array of all Solana clusters */ | ||
export const SOLANA_CHAINS = [ | ||
SOLANA_MAINNET_CHAIN, | ||
SOLANA_DEVNET_CHAIN, | ||
SOLANA_TESTNET_CHAIN, | ||
SOLANA_LOCALNET_CHAIN, | ||
] as const; | ||
|
||
/** Type of all Solana clusters */ | ||
export type SolanaChain = (typeof SOLANA_CHAINS)[number]; | ||
|
||
/** | ||
* Check if a chain corresponds with one of the Solana clusters. | ||
*/ | ||
export function isSolanaChain(chain: IdentifierString): chain is SolanaChain { | ||
return SOLANA_CHAINS.includes(chain as SolanaChain); | ||
} |
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,31 @@ | ||
import type { IdentifierString } from '@wallet-standard/base'; | ||
|
||
/** Sonic Mainnet (beta) cluster, e.g. https://api.mainnet-beta.sonic.com */ | ||
export const SONIC_MAINNET_CHAIN = 'sonic:mainnet'; | ||
|
||
/** Sonic Devnet cluster, e.g. https://api.devnet.sonic.com */ | ||
export const SONIC_DEVNET_CHAIN = 'sonic:devnet'; | ||
|
||
/** Sonic Testnet cluster, e.g. https://api.testnet.sonic.com */ | ||
export const SONIC_TESTNET_CHAIN = 'sonic:testnet'; | ||
|
||
/** Sonic Localnet cluster, e.g. http://localhost:8899 */ | ||
export const SONIC_LOCALNET_CHAIN = 'sonic:localnet'; | ||
|
||
/** Array of all Sonic clusters */ | ||
export const SONIC_CHAINS = [ | ||
SONIC_MAINNET_CHAIN, | ||
SONIC_DEVNET_CHAIN, | ||
SONIC_TESTNET_CHAIN, | ||
SONIC_LOCALNET_CHAIN, | ||
] as const; | ||
|
||
/** Type of all Sonic clusters */ | ||
export type SonicChain = (typeof SONIC_CHAINS)[number]; | ||
|
||
/** | ||
* Check if a chain corresponds with one of the Sonic clusters. | ||
*/ | ||
export function isSonicChain(chain: IdentifierString): chain is SonicChain { | ||
return SONIC_CHAINS.includes(chain as SonicChain); | ||
} | ||
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,35 @@ | ||
import type { IdentifierString } from '@wallet-standard/base'; | ||
|
||
/** Name of the feature. */ | ||
export const SolanaGetCluster = 'solana:getCluster'; | ||
|
||
/** Represents the feature for getting the current Solana cluster name. */ | ||
export type SolanaGetClusterFeature = { | ||
/** Name of the feature. */ | ||
readonly [SolanaGetCluster]: { | ||
/** Version of the feature API. */ | ||
readonly version: SolanaGetClusterVersion; | ||
|
||
/** | ||
* Method to get the current Solana cluster name. | ||
* This method interacts with wallet to get currently enabled Solana cluster. | ||
* | ||
* @returns {Promise<readonly SolanaGetClusterOutput>} A promise that resolves to Solana cluster name. | ||
*/ | ||
readonly getCluster: SolanaGetClusterMethod; | ||
}; | ||
}; | ||
|
||
/** Version of the feature API. */ | ||
export type SolanaGetClusterVersion = '1.0.0'; | ||
|
||
/** | ||
* Method to get the current Solana cluster name. | ||
* This method returns a promise that resolves to Solana cluster name. | ||
* | ||
* @returns {Promise<readonly SolanaGetClusterOutput>} A promise that resolves to Solana cluster name. | ||
*/ | ||
export type SolanaGetClusterMethod = () => Promise<SolanaGetClusterOutput>; | ||
|
||
/** Output type representing the Solana cluster information. */ | ||
export type SolanaGetClusterOutput = IdentifierString; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { IdentifierString } from '@wallet-standard/base'; | ||
|
||
/** Name of the setCluster feature. */ | ||
export const SolanaSetCluster = 'solana:setCluster'; | ||
|
||
/** Represents the feature for setting the current Solana cluster. */ | ||
export type SolanaSetClusterFeature = { | ||
/** Name of the setCluster feature. */ | ||
readonly [SolanaSetCluster]: { | ||
/** Version of the setCluster feature API. */ | ||
readonly version: SolanaSetClusterVersion; | ||
|
||
/** | ||
* Method to set the current Solana cluster. | ||
* This method interacts with the wallet to set the currently enabled Solana cluster. | ||
* | ||
* @param clusterName - The name of the Solana cluster to set. | ||
* @returns {Promise<void>} A promise that resolves when the cluster has been set. | ||
*/ | ||
readonly setCluster: SolanaSetClusterMethod; | ||
}; | ||
}; | ||
|
||
/** Version of the setCluster feature API. */ | ||
export type SolanaSetClusterVersion = '1.0.0'; | ||
|
||
/** | ||
* Method to set the current Solana cluster. | ||
* This method returns a promise that resolves when the cluster has been set. | ||
* | ||
* @param clusterName - The name of the Solana cluster to set. | ||
* @returns {Promise<void>} A promise that resolves when the cluster has been set. | ||
*/ | ||
export type SolanaSetClusterMethod = (clusterName: SolanaClusterInput) => Promise<void>; | ||
|
||
/** Input type representing the Solana cluster to be set. */ | ||
export type SolanaClusterInput = IdentifierString; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The data should be stored in a json file IMO.
packages/core/data/chains.json
identifier:
{network}:{environment}:{endpoint}
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 am fine with that solution.
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.
Should maybe be flatter where network is combined with environment but I can imagine wallets wanting to let users drill down to an rpc endpoint.