-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web3js] refactor around anchor stuff
- Loading branch information
Showing
6 changed files
with
71 additions
and
55 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './error' | ||
export * from './wallet' | ||
export * from './validator' | ||
export * from './extendedProvider' | ||
export * from './validator' | ||
export * from './wallet' |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { sleep } from '@marinade.finance/ts-common' | ||
import { Provider, instanceOfProvider } from './provider' | ||
import { Connection } from '@solana/web3.js' | ||
|
||
export async function waitForEpoch( | ||
connection: Connection | Provider, | ||
targetEpoch: number, | ||
timeoutSeconds: number | ||
) { | ||
connection = instanceOfProvider(connection) | ||
? connection.connection | ||
: connection | ||
const startTime = Date.now() | ||
let currentEpoch = (await connection.getEpochInfo()).epoch | ||
if (currentEpoch < targetEpoch) { | ||
console.debug( | ||
`Waiting for the epoch ${targetEpoch}, current epoch is ${currentEpoch}` | ||
) | ||
} | ||
while (currentEpoch < targetEpoch) { | ||
if (Date.now() - startTime > timeoutSeconds * 1000) { | ||
throw new Error( | ||
`Timeout ${timeoutSeconds} elapsed when waiting for epoch ${targetEpoch} (current epoch: ${currentEpoch})` | ||
) | ||
} | ||
await sleep(1000) | ||
currentEpoch = (await connection.getEpochInfo()).epoch | ||
} | ||
} | ||
|
||
export async function waitForNextEpoch( | ||
connection: Connection | Provider, | ||
timeoutSeconds: number | ||
) { | ||
connection = instanceOfProvider(connection) | ||
? connection.connection | ||
: connection | ||
const currentEpoch = (await connection.getEpochInfo()).epoch | ||
await waitForEpoch(connection, currentEpoch + 1, timeoutSeconds) | ||
} |
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,12 +1,14 @@ | ||
export * from './account' | ||
export * from './borsh' | ||
export * from './epoch' | ||
export * from './error' | ||
export * from './execution' | ||
export * from './fileKeypair' | ||
export * from './tx' | ||
export * from './txToBase64' | ||
export * from './wallet' | ||
export * from './math' | ||
export * from './provider' | ||
export * from './execution' | ||
export * from './account' | ||
export * from './voteAccount' | ||
export * from './stakeAccount' | ||
export * from './tokenMetadata' | ||
export * from './tx' | ||
export * from './txToBase64' | ||
export * from './voteAccount' | ||
export * from './wallet' |
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