Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up provider/providerMut (#223)
* Adds method to getAccountInfo of a Provider. * Split up read operations from provider write operations * more readonlyprovider stuff * readonly provider
- Loading branch information
Showing
8 changed files
with
179 additions
and
85 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
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,2 +1,3 @@ | ||
export * from "./isPublicKey"; | ||
export * from "./sendAll"; | ||
export * from "./simulateTransaction"; |
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,56 @@ | ||
import type { | ||
Commitment, | ||
Connection, | ||
RpcResponseAndContext, | ||
SimulatedTransactionResponse, | ||
Transaction, | ||
} from "@solana/web3.js"; | ||
|
||
/** | ||
* Copy of Connection.simulateTransaction that takes a commitment parameter. | ||
*/ | ||
export async function simulateTransactionWithCommitment( | ||
connection: Connection, | ||
transaction: Transaction, | ||
commitment: Commitment = "recent" | ||
): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> { | ||
const connectionInner = connection as Connection & { | ||
_disableBlockhashCaching: boolean; | ||
_recentBlockhash: (disableBlockhashCaching: boolean) => Promise<string>; | ||
_rpcRequest: ( | ||
rpc: "simulateTransaction", | ||
args: [ | ||
string, | ||
{ | ||
encoding: string; | ||
commitment: Commitment; | ||
} | ||
] | ||
) => Promise<{ | ||
error: Error; | ||
result: RpcResponseAndContext<SimulatedTransactionResponse>; | ||
}>; | ||
}; | ||
const transactionTyped = transaction as Transaction & { | ||
_serialize: (buffer: Buffer) => Buffer; | ||
}; | ||
|
||
transaction.recentBlockhash = await connectionInner._recentBlockhash( | ||
connectionInner._disableBlockhashCaching | ||
); | ||
|
||
const signData = transaction.serializeMessage(); | ||
|
||
const wireTransaction = transactionTyped._serialize(signData); | ||
const encodedTransaction = wireTransaction.toString("base64"); | ||
const config = { encoding: "base64", commitment }; | ||
|
||
const res = await connectionInner._rpcRequest("simulateTransaction", [ | ||
encodedTransaction, | ||
config, | ||
]); | ||
if (res.error) { | ||
throw new Error("failed to simulate transaction: " + res.error.message); | ||
} | ||
return res.result; | ||
} |
Oops, something went wrong.