Use Bytes Primitive

This commit is contained in:
Jim Hamill
2025-07-23 00:27:41 +00:00
parent 9af5dc0087
commit e72c678785
10 changed files with 62 additions and 72 deletions
@@ -1,4 +1,4 @@
import { type WalletUTXO } from './types.js';
import { type TransactionTemplate, type WalletUTXO } from './types.js';
import { type UTXOSet, ExtMap, Outpoint } from '@xocash/primitives';
@@ -28,13 +28,26 @@ import {
*/
export class TransactionBuilder {
static build(
transaction: TransactionTemplateFixed<CompilerBCH>,
txTemplate: Partial<TransactionTemplate>,
unspents: Array<WalletUTXO> = [],
changeLockingBytecode: Uint8Array,
sourceOutputs: UTXOSet = new ExtMap(),
) {
// Populate the final transaction template by merging with defaults.
// NOTE: This is just a convenience to make this utility easier to use.
const txTemplateFinal: TransactionTemplate = {
...{
version: 2,
locktime: 0,
inputs: [],
outputs: [],
},
...txTemplate,
};
// Build the template.
const txBuilder = new TransactionBuilder(
transaction,
txTemplateFinal,
unspents,
sourceOutputs,
);
+1 -13
View File
@@ -305,18 +305,6 @@ export class WalletHD extends BaseWallet {
async signTransaction(
txTemplate: Partial<TransactionTemplate>,
): 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 = {
...{
version: 2,
locktime: 0,
inputs: [],
outputs: [],
},
...txTemplate,
};
// Get the receiving address of this wallet.
// NOTE: As per BIP44 spec, we set the change address to use the internal chain.
const changeAddress = await this.getReceivingAddress(CHAIN_EXTERNAL);
@@ -329,7 +317,7 @@ export class WalletHD extends BaseWallet {
// Build the transaction.
return TransactionBuilder.build(
txTemplateFinal,
txTemplate,
unspents.toArray(),
changeLockingBytecode,
);
+1 -13
View File
@@ -338,18 +338,6 @@ export class WalletP2PKH extends BaseWallet {
}
async signTransaction(txTemplate: Partial<TransactionTemplate>) {
// Populate the final transaction template by merging with defaults.
// NOTE: This is just a convenience to make "send" easier to use.
const txTemplateFinal: TransactionTemplate = {
...{
version: 2,
locktime: 0,
inputs: [],
outputs: [],
},
...txTemplate,
};
// Get the receiving address of this wallet.
const receivingAddress = await this.getReceivingAddress();
@@ -361,7 +349,7 @@ export class WalletP2PKH extends BaseWallet {
// Build the transaction.
return TransactionBuilder.build(
txTemplateFinal,
txTemplate,
unspents.toArray(),
changeLockingBytecode,
);