This repository was archived by the owner on Jan 22, 2025. It is now read-only.
[Draft] web3 versioned transaction support#27213
Closed
jstarry wants to merge 5 commits intosolana-labs:masterfrom
Closed
[Draft] web3 versioned transaction support#27213jstarry wants to merge 5 commits intosolana-labs:masterfrom
jstarry wants to merge 5 commits intosolana-labs:masterfrom
Conversation
ckamm
reviewed
Aug 18, 2022
| }); | ||
| const transaction = new VersionedTransaction( | ||
| new MessageV0({ | ||
| header: { |
Contributor
There was a problem hiding this comment.
So using the new compilation to build this transaction would work like this?
const transaction = new VersionedTransaction(
MessageV0.compile({
payerKey: payer.publicKey,
instructions: [transferIx],
recentBlockhash: blockhash,
addressLookupTableAccounts: [lookupTableAccount],
})
);
Sounds good to me.
Maybe this test could send a second transaction that was compiled that way? Possibly add a handful of testcases where the MessageV0.compile() output is compared to an expected result?
Contributor
Author
|
Here's a rough guide for how these new classes would be used:
const txMessage = new TransactionMessage({
instructions,
recentBlockhash,
payerKey,
});
// if desired, legacy transactions can still be used
const versionedTx = new VersionedTransaction(
txMessage.compile({version: 'legacy'}),
);
// if lookup tables are needed, v0 is required
const versionedTx = new VersionedTransaction(
txMessage.compile({
version: 0,
addressLookupTableAccounts,
});
);
// send via wallet for signing
const wallet = WalletAdapter.useWallet();
wallet.sendTransaction(versionedTx, connection);
const addressLookupTableAccounts = await Promise.all(
versionedTx.message.addressTableLookups.map((lookup) => {
return connection.getAddressLookupTable(lookup.tableKey);
});
);
// Decompile the transaction message to display details to the user
const txMessage = TransactionMessage.decompile({
message: versionedTx.message,
addressLookupTableAccounts,
});
// Simulate the transaction (not yet implemented)
await connection.simulateTransaction(versionedTx);
// Sign the transaction
versionedTx.sign([walletKeypair]);
// Send the transaction
await connection.sendRawTransaction(versionedTx);
// Fetch versioned transaction
const transactionResponse = await connection.getTransaction(signature, {
maxSupportedTransactionVersion: 0,
});
// Decompile the transaction message to display details to the user
const txMessage = TransactionMessage.decompile({
message: transactionResponse.transaction.message,
loadedAddresses: transactionResponse.meta.loadedAddresses,
}); |
9f8df2c to
d2252c1
Compare
d2252c1 to
5b326b0
Compare
Codecov Report
@@ Coverage Diff @@
## master #27213 +/- ##
=========================================
- Coverage 76.9% 72.8% -4.2%
=========================================
Files 48 54 +6
Lines 2505 2835 +330
Branches 355 387 +32
=========================================
+ Hits 1927 2064 +137
- Misses 448 638 +190
- Partials 130 133 +3 |
5b326b0 to
72c6339
Compare
Contributor
|
|
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This draft PR will be broken up into smaller PRs but gives a look at what all the versioned transaction classes and APIs look like together
Classes
Naming suggestions welcomed
TransactionMessageThis class should be used to:
- construct new transactions (legacy or v0)
- display not-yet-processed transactions (in wallets)
- display already-processed transactions (in explorers)
- convert compiled messages (legacy or v0) into a more usable form
VersionedTransactionThis class should be used to:
- sign compiled (legacy or v0) messages (by wallets)
- serialize into a wire transaction buffer
- deserialize a wire transaction buffer
MessageV0This class should be used to:
- serialize into a v0 message buffer for signing
- deserialize a v0 message buffer
MessageAccountKeysThis class won't be used directly by developers but is used internally to wrap static account keys and dynamic account keys loaded from lookup tables
CompiledKeysThis class won't be used directly by developers but is used internally to extract account keys that can be loaded from an address lookup table