signTransaction returns TransactionBuilder

This commit is contained in:
Jim Hamill
2025-06-18 06:53:30 +00:00
parent 6a3e6ee090
commit 4cf729f244
5 changed files with 57 additions and 19 deletions
+7 -9
View File
@@ -293,7 +293,7 @@ export class WalletHD extends BaseWallet {
async signTransaction(
txTemplate: Partial<TransactionTemplate>,
): Promise<Uint8Array> {
): Promise<TransactionBuilder> {
// Populate the final transaction template by merging with defaults.
// NOTE: This is just a convenience to make "send" easier to use.
const txTemplateFinal: TransactionTemplate = {
@@ -317,21 +317,19 @@ export class WalletHD extends BaseWallet {
const unspents = await this.getUnspentDirectives();
// Build the transaction.
const tx = TransactionBuilder.build(
return TransactionBuilder.build(
txTemplateFinal,
unspents.toArray(),
changeLockingBytecode,
);
// Generate the transaction.
const generatedTxBytes = tx.toBytes();
return generatedTxBytes;
}
async sendTransaction(txTemplate: Partial<TransactionTemplate>) {
// Sign the transaction template.
const generatedTxBytes = await this.signTransaction(txTemplate);
// Generate the transaction.
const generatedTx = await this.signTransaction(txTemplate);
// Convert the tx to bytes.
const generatedTxBytes = generatedTx.toBytes();
// Broadcast the transaction to the blockchain.
await this.blockchain.broadcastTransaction(generatedTxBytes);