Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wormhole-foundation/wormhole-sdk-ts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d31e27e3402f08102409b427b6a7b38646faf826
Choose a base ref
..
head repository: wormhole-foundation/wormhole-sdk-ts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e773afa5aa7559028699ff77d6b774f6e1baf23d
Choose a head ref
Showing with 21 additions and 8 deletions.
  1. +2 −2 examples/src/helpers/helpers.ts
  2. +19 −6 platforms/solana/src/testing/sendSigner.ts
4 changes: 2 additions & 2 deletions examples/src/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import {
import { getAlgorandSigner } from "@wormhole-foundation/connect-sdk-algorand/src/testing";
import { getCosmwasmSigner } from "@wormhole-foundation/connect-sdk-cosmwasm/src/testing";
import { getEvmSigner } from "@wormhole-foundation/connect-sdk-evm/src/testing";
import { getSolanaSigner } from "@wormhole-foundation/connect-sdk-solana/src/testing";
import { getSolanaSignAndSendSigner } from "@wormhole-foundation/connect-sdk-solana/src/testing";

// Use .env.example as a template for your .env file and populate it with secrets
// for funded accounts on the relevant chain+network combos to run the example
@@ -56,7 +56,7 @@ export async function getStuff<
const platform = chain.platform.utils()._platform;
switch (platform) {
case "Solana":
signer = await getSolanaSigner(await chain.getRpc(), getEnv("SOL_PRIVATE_KEY"));
signer = await getSolanaSignAndSendSigner(await chain.getRpc(), getEnv("SOL_PRIVATE_KEY"));
break;
case "Cosmwasm":
signer = await getCosmwasmSigner(await chain.getRpc(), getEnv("COSMOS_MNEMONIC"));
25 changes: 19 additions & 6 deletions platforms/solana/src/testing/sendSigner.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ import { SolanaChains } from '../types';
import { SolanaUnsignedTransaction } from '../unsignedTransaction';
import { logTxDetails } from './debug';

// Number of blocks to wait before considering a transaction expired
const SOLANA_EXPIRED_BLOCKHEIGHT = 150;

export class SolanaSendSigner<
N extends Network,
C extends SolanaChains = 'Solana',
@@ -112,12 +115,22 @@ export class SolanaSendSigner<
} catch (e) {
if (!this.retryable(e)) throw e;

// TODO: check that the previous one is expired before
// re-signing

// If it is retryable, we should grab a new block hash
({ blockhash, lastValidBlockHeight } =
await SolanaPlatform.latestBlock(this._rpc));
// If it is retryable, we need to grab a new block hash
const {
blockhash: newBlockhash,
lastValidBlockHeight: newBlockHeight,
} = await SolanaPlatform.latestBlock(this._rpc);

// But we should _not_ submit if the blockhash hasnt expired
if (
newBlockHeight - lastValidBlockHeight <
SOLANA_EXPIRED_BLOCKHEIGHT
) {
throw e;
}

lastValidBlockHeight = newBlockHeight;
blockhash = newBlockhash;
}
}
}