-
Notifications
You must be signed in to change notification settings - Fork 44
fix: properly serialize Solana transactions with empty signature placeholders #2089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1e68384
05406ad
e3c7725
faf2f19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,7 @@ export class Transaction { | |
| // Build transaction using micro-sol-signer | ||
| if (this._transaction) { | ||
| // If we have a decoded transaction, re-serialize it | ||
| console.log("[Transaction.serialize] Re-encoding existing transaction"); | ||
| return Buffer.from(sol.Transaction.encode(this._transaction)); | ||
| } | ||
|
|
||
|
|
@@ -98,13 +99,38 @@ export class Transaction { | |
| throw new Error("Transaction requires feePayer and recentBlockhash"); | ||
| } | ||
|
|
||
| const txHex = sol.createTxComplex( | ||
| console.log( | ||
| "[Transaction.serialize] Building new transaction with", | ||
| this._instructions.length, | ||
| "instructions", | ||
| ); | ||
| console.log("[Transaction.serialize] feePayer:", this.feePayer.toString()); | ||
| console.log( | ||
| "[Transaction.serialize] recentBlockhash:", | ||
| this.recentBlockhash, | ||
| ); | ||
|
|
||
| // Use createTxComplex which returns a base64-encoded transaction with empty signatures | ||
| const txBase64 = sol.createTxComplex( | ||
| this.feePayer.toString(), | ||
| this._instructions, | ||
| this.recentBlockhash, | ||
| ); | ||
|
|
||
| return Buffer.from(txHex, "hex"); | ||
| console.log( | ||
| "[Transaction.serialize] createTxComplex returned base64 length:", | ||
| txBase64.length, | ||
| ); | ||
|
|
||
| // Decode the base64 string to get the transaction bytes | ||
| const buffer = Buffer.from(txBase64, "base64"); | ||
| console.log("[Transaction.serialize] Final buffer length:", buffer.length); | ||
| console.log( | ||
| "[Transaction.serialize] First 32 bytes:", | ||
| Array.from(buffer.slice(0, 32)), | ||
| ); | ||
|
|
||
| return buffer; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Unintended Debug Logs in Production CodeMultiple debugging Additional Locations (2) |
||
| } | ||
|
|
||
| serializeMessage(): Buffer { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,7 +135,25 @@ export class PhantomWallet implements WalletAdapter { | |
| } | ||
|
|
||
| try { | ||
| console.log( | ||
| "[PhantomWallet.sendTransaction] Received serialized_txn length:", | ||
| serailized_txn.length, | ||
| ); | ||
| console.log( | ||
| "[PhantomWallet.sendTransaction] First 32 bytes:", | ||
| Array.from(serailized_txn.slice(0, 32)), | ||
| ); | ||
| console.log( | ||
| "[PhantomWallet.sendTransaction] Deserializing with Transaction.from...", | ||
| ); | ||
|
|
||
| const txn = Transaction.from(serailized_txn); | ||
|
|
||
| console.log("[PhantomWallet.sendTransaction] Successfully deserialized"); | ||
| console.log( | ||
| "[PhantomWallet.sendTransaction] Sending to Phantom provider...", | ||
| ); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const provider = this.getProvider(); | ||
| const result = await provider.signAndSendTransaction(txn); | ||
| return { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Base64 vs Hex Handling Mismatch
The
serialize()method now decodessol.createTxComplex()output as base64, butserializeMessage()still treats it as hex. This inconsistency meansserializeMessage()will produce incorrect transaction data. Additionally, several debuggingconsole.logstatements were left in theserialize()method.