Comments (2)
Preflight checks are an important part of ensuring that transactions are valid before they are sent to the Solana network. However, I understand that there may be situations where skipping these checks is necessary, especially when bundling transactions that depend on each other.
One way to achieve this would be to modify the TransactionProcessor
class to include an optional parameter that allows you to skip preflight checks. Here's an example implementation:
import { Transaction, TransactionSignature, TransactionError } from '@solana/web3.js';
import { Connection } from '@solana/web3.js';
export class TransactionProcessor {
private connection: Connection;
constructor(connection: Connection) {
this.connection = connection;
}
async processTransaction(transaction: Transaction, skipPreflightCheck = false): Promise<TransactionSignature> {
if (!skipPreflightCheck) {
const { err } = await this.connection.getRecentBlockhash();
if (err) {
throw new Error(`Unable to get recent blockhash: ${err}`);
}
transaction.recentBlockhash = (await this.connection.getRecentBlockhash()).blockhash;
const { feeCalculator } = await this.connection.getFeeCalculatorForBlockhash(transaction.recentBlockhash);
transaction.feePayer = feeCalculator.target;
transaction.recentBlockhash = (await this.connection.getRecentBlockhash()).blockhash;
const { blockhash } = await this.connection.getRecentBlockhash();
const signers = transaction.getSignatures().map(({ publicKey }) => publicKey);
const { value: { err: preflightErr } } = await this.connection.getSignatureStatuses(
transaction.signature,
{ searchTransactionHistory: true }
);
if (preflightErr) {
throw new TransactionError('Transaction preflight checks failed', transaction, preflightErr);
}
}
const signature = await this.connection.sendRawTransaction(transaction.serialize());
return signature;
}
}
With this implementation, you can pass a boolean value as the second parameter to processTransaction
to skip preflight checks. For example:
const tx1 = new Transaction().add(...);
const tx2 = new Transaction().add(...);
const processor = new TransactionProcessor(connection);
const signature1 = await processor.processTransaction(tx1, true); // skip preflight check
const signature2 = await processor.processTransaction(tx2, true); // skip preflight check
Note that skipping preflight checks can be dangerous and should only be done if you know what you're doing. It's recommended that you only use this option if you're bundling transactions that depend on each other and you're sure that they will succeed.
from orca-sdks.
Preflight checks are an important part of ensuring the validity of transactions before they are sent to the Solana network. However, I understand that there may be situations where skipping preflight checks is necessary.
To add an option to skip preflight checks in the TransactionProcessor
, you can modify the send
method in the TransactionProcessor
class to include a boolean parameter that indicates whether or not to skip preflight checks.
Here's an example implementation:
import { Transaction, TransactionSignature } from "@solana/web3.js";
import { Provider } from "./provider";
export class TransactionProcessor {
private provider: Provider;
constructor(provider: Provider) {
this.provider = provider;
}
async send(transaction: Transaction, skipPreflight: boolean = false): Promise<TransactionSignature> {
if (!skipPreflight) {
await this.provider.connection.getMinimumBalanceForRentExemption(transaction.recentBlockhash);
await this.provider.connection.getTransactionCount("recent");
}
const signature = await this.provider.wallet.signTransaction(transaction);
return await this.provider.connection.sendRawTransaction(signature.serialize());
}
}
With this modification, you can now pass a boolean value as the second parameter to the send
method to skip preflight checks if necessary.
Keep in mind that skipping preflight checks can be risky and should only be done if you are confident that the transactions are valid.
from orca-sdks.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orca-sdks.