-
Notifications
You must be signed in to change notification settings - Fork 55
WIP Feat/adds tx signing #1476
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: develop
Are you sure you want to change the base?
WIP Feat/adds tx signing #1476
Conversation
- Add sign and signAndBroadcast methods to UTXO toolboxes (Bitcoin, Litecoin, Dogecoin, Zcash) - Add sign and signAndBroadcast methods to EVM toolbox - Add unified sign and signAndBroadcast methods to Solana toolbox - Handle BitcoinCash special case with TransactionBuilder instead of PSBT - Create implementation plans for full wallet integration
- Create getSignTransaction and getSignAndBroadcastTransaction functions - Use ethers.js TransactionRequest type for incoming transactions - Ensure sign and signAndBroadcast have matching signatures - Clean separation of concerns for signing logic
- Rename 'sign' to 'signTransaction' across all toolboxes - Rename 'signAndBroadcast' to 'signAndSendTransaction' across all toolboxes - Better naming convention that clearly indicates the action being performed - Consistent naming across UTXO, EVM, and Solana toolboxes
| @@ -1,416 +1,426 @@ | |||
| // biome-ignore assist/source/useSortedKeys: keys are sorted by topic | |||
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.
🙏
| .with(Chain.Tron, async () => { | ||
| const transaction = TronTransactionSchema.safeParse(tx); | ||
| if (!transaction.success) { | ||
| throw new SwapKitError("plugin_swapkit_invalid_tx_data", { chain, tx }); | ||
| } | ||
|
|
||
| return await getWallet(chain as Chain.Tron).signAndBroadcastTransaction(transaction.data); | ||
| }) |
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.
how about:
| .with(Chain.Tron, async () => { | |
| const transaction = TronTransactionSchema.safeParse(tx); | |
| if (!transaction.success) { | |
| throw new SwapKitError("plugin_swapkit_invalid_tx_data", { chain, tx }); | |
| } | |
| return await getWallet(chain as Chain.Tron).signAndBroadcastTransaction(transaction.data); | |
| }) | |
| .with(...CosmosChains, Chain.Near, Chain.Tron, async (chain) => { | |
| const transaction = safeTxParse({ chain, tx }) | |
| if (!transaction.success) { | |
| throw new SwapKitError("plugin_swapkit_invalid_tx_data", { chain, tx }); | |
| } | |
| return await getWallet(chain).signAndBroadcastTransaction(transaction.data); | |
| }) |
|
|
||
| const transaction = { ...tx, ...gasPrices, gasLimit }; | ||
|
|
||
| // Sign the transaction |
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.
| // Sign the transaction |
| // Sign the transaction | ||
| const signedTx = await signer.signTransaction(transaction); | ||
|
|
||
| // Broadcast the signed transaction |
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.
| // Broadcast the signed transaction |
| // Sign the transaction | ||
| const signedTx = await signTransaction(tx); | ||
|
|
||
| // Broadcast the signed transaction |
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.
😡
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.
those comments are always just rephrase code written below. Please remove
| signAndBroadcastTransaction: async (transaction: Transaction | VersionedTransaction) => { | ||
| const signedTx = await signTransaction(getConnection, signer)(transaction); | ||
| return broadcastTransaction(getConnection)(signedTx); | ||
| }, |
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.
I see a way to have it cleaner in future but we can keep it for now.
I.e. we could extract this signTransaction init a little bit earlier and just pass it's instance to those functions ;)
| Transaction, | ||
| TransactionBuilder, | ||
| // @ts-expect-error | ||
| } from "@psf/bitcoincashjs-lib"; |
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.
Do we remove this dep completely? PLEASE say yes
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.
I think we can 👀
6735d9c to
94e558a
Compare
1b0724e to
1e45499
Compare
No description provided.