-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Grouping instructions into transactions and splitting a bit better th…
…e codebase
- Loading branch information
1 parent
6828197
commit 01b6529
Showing
7 changed files
with
127 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Wallet } from "../wallet"; | ||
import { | ||
Connection, | ||
sendAndConfirmRawTransaction, | ||
Transaction, | ||
BlockhashWithExpiryBlockHeight, | ||
} from "@solana/web3.js"; | ||
import base58 from "bs58"; | ||
|
||
/** | ||
* Utility function that sequentially sends and confirm already signed transactions. | ||
* | ||
* @param wallet | ||
* @param connection | ||
* @param transactions | ||
* @param recentBlockhash | ||
* @returns the signatures of each transaction | ||
*/ | ||
export async function sendTransactions( | ||
wallet: Wallet, | ||
connection: Connection, | ||
transactions: Transaction[], | ||
recentBlockhash: BlockhashWithExpiryBlockHeight | ||
): Promise<string[]> { | ||
const signedTxs = await wallet.signAllTransactions(transactions); | ||
|
||
const signatures: string[] = []; | ||
for (const signed of signedTxs) { | ||
const rawTransaction = signed.serialize(); | ||
const signature = await sendAndConfirmRawTransaction( | ||
connection, | ||
rawTransaction, | ||
{ | ||
signature: base58.encode(signed.signature!), | ||
blockhash: recentBlockhash.blockhash, | ||
lastValidBlockHeight: recentBlockhash.lastValidBlockHeight, | ||
}, | ||
{ | ||
commitment: "confirmed", | ||
} | ||
); | ||
|
||
signatures.push(signature); | ||
} | ||
|
||
return signatures; | ||
} |
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