Skip to content

Commit 223559e

Browse files
authored
[contract_manager] make solana rpcs configurable (#1646)
I'm hitting errors using the mainnet-beta endpoint when trying to deploy the entropy contract. This change makes the RPCs configurable in the functions so I can pass in a different RPC in the script. The right thing to do here is probably to load the solana rpc urls from configuration files in the chains directory, but doesn't seem worth it to do that now.
1 parent 0763cb0 commit 223559e

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

contract_manager/src/governance.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class InvalidTransactionError extends Error {
4242
}
4343
}
4444

45+
// A registry of solana RPC nodes for each cluster.
46+
export type SolanaRpcRegistry = (cluster: PythCluster) => string;
47+
4548
export class SubmittedWormholeMessage {
4649
constructor(
4750
public emitter: PublicKey,
@@ -58,12 +61,10 @@ export class SubmittedWormholeMessage {
5861
*/
5962
static async fromTransactionSignature(
6063
signature: string,
61-
cluster: PythCluster
64+
cluster: PythCluster,
65+
registry: SolanaRpcRegistry = getPythClusterApiUrl
6266
): Promise<SubmittedWormholeMessage> {
63-
const connection = new Connection(
64-
getPythClusterApiUrl(cluster),
65-
"confirmed"
66-
);
67+
const connection = new Connection(registry(cluster), "confirmed");
6768

6869
const txDetails = await connection.getParsedTransaction(signature);
6970
const sequenceLogPrefix = "Sequence: ";
@@ -151,9 +152,12 @@ export class WormholeEmitter {
151152
return this.wallet.publicKey;
152153
}
153154

154-
async sendMessage(payload: Buffer) {
155+
async sendMessage(
156+
payload: Buffer,
157+
registry: SolanaRpcRegistry = getPythClusterApiUrl
158+
) {
155159
const provider = new AnchorProvider(
156-
new Connection(getPythClusterApiUrl(this.cluster), "confirmed"),
160+
new Connection(registry(this.cluster), "confirmed"),
157161
this.wallet,
158162
{
159163
commitment: "confirmed",
@@ -296,11 +300,11 @@ export class Vault extends Storable {
296300
* The wallet should be a multisig signer of the vault
297301
* @param wallet
298302
*/
299-
public connect(wallet: Wallet): void {
300-
this.squad = SquadsMesh.endpoint(
301-
getPythClusterApiUrl(this.cluster),
302-
wallet
303-
);
303+
public connect(
304+
wallet: Wallet,
305+
registry: SolanaRpcRegistry = getPythClusterApiUrl
306+
): void {
307+
this.squad = SquadsMesh.endpoint(registry(this.cluster), wallet);
304308
}
305309

306310
getSquadOrThrow(): SquadsMesh {
@@ -311,9 +315,9 @@ export class Vault extends Storable {
311315
/**
312316
* Gets the emitter address of the vault
313317
*/
314-
public async getEmitter() {
318+
public async getEmitter(registry: SolanaRpcRegistry = getPythClusterApiUrl) {
315319
const squad = SquadsMesh.endpoint(
316-
getPythClusterApiUrl(this.cluster),
320+
registry(this.cluster),
317321
new NodeWallet(Keypair.generate()) // dummy wallet
318322
);
319323
return squad.getAuthorityPDA(this.key, 1);

0 commit comments

Comments
 (0)