-
Notifications
You must be signed in to change notification settings - Fork 19
/
Refund.ts
44 lines (40 loc) · 1.14 KB
/
Refund.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* This file is based on the repository github.com/submarineswaps/swaps-service created by Alex Bosworth
*/
import { Transaction } from 'bitcoinjs-lib';
import { getHexBuffer } from '../Utils';
import { ClaimDetails, RefundDetails } from '../consts/Types';
import { constructClaimTransaction } from './Claim';
const dummyPreimage = getHexBuffer('0x00');
/**
* Refund swaps
*
* @param utxos UTXOs that should be refunded
* @param destinationScript the output script to which the funds should be sent
* @param timeoutBlockHeight locktime of the transaction
* @param fee how many satoshis should be paid as fee
* @param isRbf whether the transaction should signal full Replace-by-Fee
*/
export const constructRefundTransaction = (
utxos: RefundDetails[],
destinationScript: Buffer,
timeoutBlockHeight: number,
fee: number,
isRbf = true,
): Transaction => {
const claimUtxos: ClaimDetails[] = [];
utxos.forEach((utxo) => {
claimUtxos.push({
...utxo,
preimage: dummyPreimage,
});
});
return constructClaimTransaction(
claimUtxos,
destinationScript,
fee,
isRbf,
timeoutBlockHeight,
true,
);
};