|
@@ -9,13 +9,18 @@ import {
|
|
|
SolanaRpcSubscriptionsApi,
|
|
SolanaRpcSubscriptionsApi,
|
|
|
TransactionMessageWithBlockhashLifetime,
|
|
TransactionMessageWithBlockhashLifetime,
|
|
|
TransactionMessageWithFeePayer,
|
|
TransactionMessageWithFeePayer,
|
|
|
|
|
+ TransactionPlanExecutor,
|
|
|
|
|
+ TransactionPlanner,
|
|
|
TransactionSigner,
|
|
TransactionSigner,
|
|
|
airdropFactory,
|
|
airdropFactory,
|
|
|
appendTransactionMessageInstructions,
|
|
appendTransactionMessageInstructions,
|
|
|
assertIsSendableTransaction,
|
|
assertIsSendableTransaction,
|
|
|
|
|
+ assertIsTransactionWithBlockhashLifetime,
|
|
|
createSolanaRpc,
|
|
createSolanaRpc,
|
|
|
createSolanaRpcSubscriptions,
|
|
createSolanaRpcSubscriptions,
|
|
|
createTransactionMessage,
|
|
createTransactionMessage,
|
|
|
|
|
+ createTransactionPlanExecutor,
|
|
|
|
|
+ createTransactionPlanner,
|
|
|
generateKeyPairSigner,
|
|
generateKeyPairSigner,
|
|
|
getSignatureFromTransaction,
|
|
getSignatureFromTransaction,
|
|
|
lamports,
|
|
lamports,
|
|
@@ -83,12 +88,50 @@ export const signAndSendTransaction = async (
|
|
|
await signTransactionMessageWithSigners(transactionMessage);
|
|
await signTransactionMessageWithSigners(transactionMessage);
|
|
|
const signature = getSignatureFromTransaction(signedTransaction);
|
|
const signature = getSignatureFromTransaction(signedTransaction);
|
|
|
assertIsSendableTransaction(signedTransaction);
|
|
assertIsSendableTransaction(signedTransaction);
|
|
|
|
|
+ assertIsTransactionWithBlockhashLifetime(signedTransaction);
|
|
|
await sendAndConfirmTransactionFactory(client)(signedTransaction, {
|
|
await sendAndConfirmTransactionFactory(client)(signedTransaction, {
|
|
|
commitment,
|
|
commitment,
|
|
|
});
|
|
});
|
|
|
return signature;
|
|
return signature;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+export const createDefaultTransactionPlanner = (
|
|
|
|
|
+ client: Client,
|
|
|
|
|
+ feePayer: TransactionSigner
|
|
|
|
|
+): TransactionPlanner => {
|
|
|
|
|
+ return createTransactionPlanner({
|
|
|
|
|
+ createTransactionMessage: async () => {
|
|
|
|
|
+ const { value: latestBlockhash } = await client.rpc
|
|
|
|
|
+ .getLatestBlockhash()
|
|
|
|
|
+ .send();
|
|
|
|
|
+
|
|
|
|
|
+ return pipe(
|
|
|
|
|
+ createTransactionMessage({ version: 0 }),
|
|
|
|
|
+ (tx) => setTransactionMessageFeePayerSigner(feePayer, tx),
|
|
|
|
|
+ (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx)
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+export const createDefaultTransactionPlanExecutor = (
|
|
|
|
|
+ client: Client,
|
|
|
|
|
+ commitment: Commitment = 'confirmed'
|
|
|
|
|
+): TransactionPlanExecutor => {
|
|
|
|
|
+ return createTransactionPlanExecutor({
|
|
|
|
|
+ executeTransactionMessage: async (transactionMessage) => {
|
|
|
|
|
+ const signedTransaction =
|
|
|
|
|
+ await signTransactionMessageWithSigners(transactionMessage);
|
|
|
|
|
+ assertIsSendableTransaction(signedTransaction);
|
|
|
|
|
+ assertIsTransactionWithBlockhashLifetime(signedTransaction);
|
|
|
|
|
+ await sendAndConfirmTransactionFactory(client)(signedTransaction, {
|
|
|
|
|
+ commitment,
|
|
|
|
|
+ });
|
|
|
|
|
+ return { transaction: signedTransaction };
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
export const getBalance = async (client: Client, address: Address) =>
|
|
export const getBalance = async (client: Client, address: Address) =>
|
|
|
(await client.rpc.getBalance(address, { commitment: 'confirmed' }).send())
|
|
(await client.rpc.getBalance(address, { commitment: 'confirmed' }).send())
|
|
|
.value;
|
|
.value;
|