@okxweb3/coin-bitcoin
Version:
@ok/coin-bitcoin is a Bitcoin SDK for building Web3 wallets and applications. It supports BTC, BSV, DOGE, LTC, and TBTC, enabling private key management, transaction signing, address generation, and inscriptions like BRC-20, Runes, CAT, and Atomicals.
32 lines • 906 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeFee = void 0;
const common_1 = require("../common");
function mergeFee(ecKey, feeUtxos, feeRate) {
const address = ecKey.getAddress();
const mergeTx = new common_1.btc.Transaction()
.from(feeUtxos)
.feePerByte(feeRate)
.change(address);
if (mergeTx.getChangeOutput() === null) {
throw new Error('Insufficient satoshis balance!');
}
const output = mergeTx.outputs[0];
output.satoshis -= 1;
if (ecKey.hasPrivateKey()) {
ecKey.signTx(mergeTx);
}
const mergedFeeUtxo = {
address,
txId: mergeTx.id,
outputIndex: 0,
script: output.script,
satoshis: output.satoshis,
};
return {
mergeTx,
feeUtxo: mergedFeeUtxo,
};
}
exports.mergeFee = mergeFee;
//# sourceMappingURL=merge.js.map