mainnet-js 4.0.0-next.12 → 4.0.0-next.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/db/EncryptedStorageProvider.d.ts +6 -6
- package/dist/module/db/EncryptedStorageProvider.js +7 -7
- package/dist/module/db/EncryptedStorageProvider.js.map +1 -1
- package/dist/module/history/getHistory.js +1 -1
- package/dist/module/history/getHistory.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +11 -4
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +82 -35
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/transaction/coin-control/fee.d.ts +32 -0
- package/dist/module/transaction/coin-control/fee.d.ts.map +1 -0
- package/dist/module/transaction/coin-control/fee.js +37 -0
- package/dist/module/transaction/coin-control/fee.js.map +1 -0
- package/dist/module/transaction/coin-control/index.d.ts +6 -0
- package/dist/module/transaction/coin-control/index.d.ts.map +1 -0
- package/dist/module/transaction/coin-control/index.js +5 -0
- package/dist/module/transaction/coin-control/index.js.map +1 -0
- package/dist/module/transaction/coin-control/input-order.d.ts +22 -0
- package/dist/module/transaction/coin-control/input-order.d.ts.map +1 -0
- package/dist/module/transaction/coin-control/input-order.js +54 -0
- package/dist/module/transaction/coin-control/input-order.js.map +1 -0
- package/dist/module/transaction/coin-control/output-order.d.ts +22 -0
- package/dist/module/transaction/coin-control/output-order.d.ts.map +1 -0
- package/dist/module/transaction/coin-control/output-order.js +77 -0
- package/dist/module/transaction/coin-control/output-order.js.map +1 -0
- package/dist/module/transaction/coin-control/selection.d.ts +54 -0
- package/dist/module/transaction/coin-control/selection.d.ts.map +1 -0
- package/dist/module/transaction/coin-control/selection.js +135 -0
- package/dist/module/transaction/coin-control/selection.js.map +1 -0
- package/dist/module/transaction/coin-control/types.d.ts +62 -0
- package/dist/module/transaction/coin-control/types.d.ts.map +1 -0
- package/dist/module/transaction/coin-control/types.js +2 -0
- package/dist/module/transaction/coin-control/types.js.map +1 -0
- package/dist/module/wallet/Base.d.ts.map +1 -1
- package/dist/module/wallet/Base.js +10 -2
- package/dist/module/wallet/Base.js.map +1 -1
- package/dist/module/wallet/interface.d.ts +9 -0
- package/dist/module/wallet/interface.d.ts.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default fee strategy: relayFeePerByte * txSizeBytes, rounded up. Matches
|
|
3
|
+
* the historical behaviour of mainnet-js when no `fee` option is supplied.
|
|
4
|
+
*/
|
|
5
|
+
export const feeFromRelay = (ctx) => BigInt(Math.ceil(ctx.txSizeBytes * ctx.relayFeePerByte));
|
|
6
|
+
/**
|
|
7
|
+
* Factory: charge a fixed rate (sats per byte) regardless of the network's
|
|
8
|
+
* advertised relay fee. Useful when the caller wants to prioritise a tx
|
|
9
|
+
* (higher rate) or save fees (lower, at the risk of slower propagation).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* send(requests, { fee: feeFixedPerByte(2) });
|
|
13
|
+
*/
|
|
14
|
+
export function feeFixedPerByte(satsPerByte) {
|
|
15
|
+
return (ctx) => BigInt(Math.ceil(ctx.txSizeBytes * satsPerByte));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Factory: charge a fixed rate expressed in sats per kilobyte.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* send(requests, { fee: feeFixedPerKb(1000) }); // ~1 sat/byte
|
|
22
|
+
*/
|
|
23
|
+
export function feeFixedPerKb(satsPerKb) {
|
|
24
|
+
return (ctx) => BigInt(Math.ceil((ctx.txSizeBytes * satsPerKb) / 1000));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Factory: pay a fixed absolute fee, ignoring transaction size. Caller takes
|
|
28
|
+
* responsibility for the fee being large enough to relay; under-paying can
|
|
29
|
+
* lead to the transaction being rejected by the network.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* send(requests, { fee: feeAbsolute(500n) });
|
|
33
|
+
*/
|
|
34
|
+
export function feeAbsolute(sats) {
|
|
35
|
+
return () => sats;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=fee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fee.js","sourceRoot":"","sources":["../../../../src/transaction/coin-control/fee.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAU,CAAC,GAAG,EAAE,EAAE,CACzC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB;IACjD,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { feeAbsolute, feeFixedPerByte, feeFixedPerKb, feeFromRelay, } from "./fee.js";
|
|
2
|
+
export { inputOrderBip69, inputOrderNatural, inputOrderRandom, } from "./input-order.js";
|
|
3
|
+
export { outputOrderBip69, outputOrderNatural, outputOrderRandom, } from "./output-order.js";
|
|
4
|
+
export { selectAccumulative, selectBranchAndBound, selectLargestFirst, selectNatural, selectNewestFirst, selectOldestFirst, selectRandom, selectSmallestFirst, } from "./selection.js";
|
|
5
|
+
export type { CoinSelectionContext, CoinSelectionFn, FeeContext, FeeFn, InputOrderingContext, InputOrderingFn, OutputOrderingContext, OutputOrderingFn, TxOutput, } from "./types.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transaction/coin-control/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,KAAK,EACL,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,QAAQ,GACT,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { feeAbsolute, feeFixedPerByte, feeFixedPerKb, feeFromRelay, } from "./fee.js";
|
|
2
|
+
export { inputOrderBip69, inputOrderNatural, inputOrderRandom, } from "./input-order.js";
|
|
3
|
+
export { outputOrderBip69, outputOrderNatural, outputOrderRandom, } from "./output-order.js";
|
|
4
|
+
export { selectAccumulative, selectBranchAndBound, selectLargestFirst, selectNatural, selectNewestFirst, selectOldestFirst, selectRandom, selectSmallestFirst, } from "./selection.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/transaction/coin-control/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,GACpB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { InputOrderingFn } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Preserve the selection order. This is the default when no `inputOrdering`
|
|
4
|
+
* option is supplied.
|
|
5
|
+
*/
|
|
6
|
+
export declare const inputOrderNatural: InputOrderingFn;
|
|
7
|
+
/**
|
|
8
|
+
* BIP69 input ordering: sort lexicographically by reversed txid then by
|
|
9
|
+
* vout ascending. This matches the convention used by Bitcoin Core and
|
|
10
|
+
* many other wallets.
|
|
11
|
+
*
|
|
12
|
+
* Note: Bitcoin transactions internally serialize txids in reverse byte
|
|
13
|
+
* order, which is what BIP69 sorts on. The `Utxo.txid` field in mainnet-js
|
|
14
|
+
* is in the user-facing big-endian hex form, so we compare its byte-reversal.
|
|
15
|
+
*/
|
|
16
|
+
export declare const inputOrderBip69: InputOrderingFn;
|
|
17
|
+
/**
|
|
18
|
+
* Shuffle the inputs. Improves privacy by hiding the upstream selection
|
|
19
|
+
* order (which can leak the chosen selection strategy).
|
|
20
|
+
*/
|
|
21
|
+
export declare const inputOrderRandom: InputOrderingFn;
|
|
22
|
+
//# sourceMappingURL=input-order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-order.d.ts","sourceRoot":"","sources":["../../../../src/transaction/coin-control/input-order.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAAqC,CAAC;AAEtE;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,EAAE,eACY,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,eAA8C,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preserve the selection order. This is the default when no `inputOrdering`
|
|
3
|
+
* option is supplied.
|
|
4
|
+
*/
|
|
5
|
+
export const inputOrderNatural = (ctx) => ctx.inputs;
|
|
6
|
+
/**
|
|
7
|
+
* BIP69 input ordering: sort lexicographically by reversed txid then by
|
|
8
|
+
* vout ascending. This matches the convention used by Bitcoin Core and
|
|
9
|
+
* many other wallets.
|
|
10
|
+
*
|
|
11
|
+
* Note: Bitcoin transactions internally serialize txids in reverse byte
|
|
12
|
+
* order, which is what BIP69 sorts on. The `Utxo.txid` field in mainnet-js
|
|
13
|
+
* is in the user-facing big-endian hex form, so we compare its byte-reversal.
|
|
14
|
+
*/
|
|
15
|
+
export const inputOrderBip69 = (ctx) => [...ctx.inputs].sort(compareBip69Inputs);
|
|
16
|
+
/**
|
|
17
|
+
* Shuffle the inputs. Improves privacy by hiding the upstream selection
|
|
18
|
+
* order (which can leak the chosen selection strategy).
|
|
19
|
+
*/
|
|
20
|
+
export const inputOrderRandom = (ctx) => shuffle(ctx.inputs);
|
|
21
|
+
// ----------------------------------------------------------------------------
|
|
22
|
+
// Helpers
|
|
23
|
+
// ----------------------------------------------------------------------------
|
|
24
|
+
function compareBip69Inputs(a, b) {
|
|
25
|
+
// Compare reversed txid bytes (Bitcoin's internal serialization order).
|
|
26
|
+
const ar = reverseHex(a.txid);
|
|
27
|
+
const br = reverseHex(b.txid);
|
|
28
|
+
if (ar < br)
|
|
29
|
+
return -1;
|
|
30
|
+
if (ar > br)
|
|
31
|
+
return 1;
|
|
32
|
+
// Equal txid -> break tie on vout ascending.
|
|
33
|
+
return a.vout - b.vout;
|
|
34
|
+
}
|
|
35
|
+
function reverseHex(hex) {
|
|
36
|
+
// Split into 2-char bytes and reverse. Falls back to lexicographic compare
|
|
37
|
+
// when the string isn't a clean hex tx id.
|
|
38
|
+
if (hex.length % 2 !== 0)
|
|
39
|
+
return hex;
|
|
40
|
+
let out = "";
|
|
41
|
+
for (let i = hex.length - 2; i >= 0; i -= 2) {
|
|
42
|
+
out += hex.slice(i, i + 2);
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
function shuffle(arr) {
|
|
47
|
+
const out = [...arr];
|
|
48
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
49
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
50
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=input-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-order.js","sourceRoot":"","sources":["../../../../src/transaction/coin-control/input-order.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAoB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC;AAEtE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoB,CAAC,GAAG,EAAE,EAAE,CACtD,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAoB,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAE9E,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E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AAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OutputOrderingFn } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Preserve the order produced by the caller (with change last when present).
|
|
4
|
+
* Default when no `outputOrdering` option is supplied.
|
|
5
|
+
*/
|
|
6
|
+
export declare const outputOrderNatural: OutputOrderingFn;
|
|
7
|
+
/**
|
|
8
|
+
* BIP69 output ordering: sort by output value ascending, breaking ties on
|
|
9
|
+
* locking bytecode bytes ascending. Token data is intentionally not part of
|
|
10
|
+
* the comparison key -- strict BIP69 is defined only for the value and the
|
|
11
|
+
* `scriptPubKey`.
|
|
12
|
+
*
|
|
13
|
+
* The change output (if present) takes part in the sort like any other
|
|
14
|
+
* output.
|
|
15
|
+
*/
|
|
16
|
+
export declare const outputOrderBip69: OutputOrderingFn;
|
|
17
|
+
/**
|
|
18
|
+
* Shuffle the outputs. Improves privacy by making the change position
|
|
19
|
+
* unguessable.
|
|
20
|
+
*/
|
|
21
|
+
export declare const outputOrderRandom: OutputOrderingFn;
|
|
22
|
+
//# sourceMappingURL=output-order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-order.d.ts","sourceRoot":"","sources":["../../../../src/transaction/coin-control/output-order.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAY,MAAM,YAAY,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAAuC,CAAC;AAEzE;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBACa,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,gBACV,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { cashAddressToLockingBytecode } from "@bitauth/libauth";
|
|
2
|
+
import { OpReturnData, SendRequest, TokenSendRequest, } from "../../wallet/model.js";
|
|
3
|
+
/**
|
|
4
|
+
* Preserve the order produced by the caller (with change last when present).
|
|
5
|
+
* Default when no `outputOrdering` option is supplied.
|
|
6
|
+
*/
|
|
7
|
+
export const outputOrderNatural = (ctx) => ctx.outputs;
|
|
8
|
+
/**
|
|
9
|
+
* BIP69 output ordering: sort by output value ascending, breaking ties on
|
|
10
|
+
* locking bytecode bytes ascending. Token data is intentionally not part of
|
|
11
|
+
* the comparison key -- strict BIP69 is defined only for the value and the
|
|
12
|
+
* `scriptPubKey`.
|
|
13
|
+
*
|
|
14
|
+
* The change output (if present) takes part in the sort like any other
|
|
15
|
+
* output.
|
|
16
|
+
*/
|
|
17
|
+
export const outputOrderBip69 = (ctx) => [...ctx.outputs].sort(compareBip69Outputs);
|
|
18
|
+
/**
|
|
19
|
+
* Shuffle the outputs. Improves privacy by making the change position
|
|
20
|
+
* unguessable.
|
|
21
|
+
*/
|
|
22
|
+
export const outputOrderRandom = (ctx) => shuffle(ctx.outputs);
|
|
23
|
+
// ----------------------------------------------------------------------------
|
|
24
|
+
// Helpers
|
|
25
|
+
// ----------------------------------------------------------------------------
|
|
26
|
+
function compareBip69Outputs(a, b) {
|
|
27
|
+
const av = outputValueSats(a);
|
|
28
|
+
const bv = outputValueSats(b);
|
|
29
|
+
if (av < bv)
|
|
30
|
+
return -1;
|
|
31
|
+
if (av > bv)
|
|
32
|
+
return 1;
|
|
33
|
+
const abc = outputLockingBytecode(a);
|
|
34
|
+
const bbc = outputLockingBytecode(b);
|
|
35
|
+
return compareBytes(abc, bbc);
|
|
36
|
+
}
|
|
37
|
+
function outputValueSats(output) {
|
|
38
|
+
if (output instanceof OpReturnData)
|
|
39
|
+
return 0n;
|
|
40
|
+
if (output instanceof TokenSendRequest)
|
|
41
|
+
return output.value ?? 1000n;
|
|
42
|
+
if (output instanceof SendRequest)
|
|
43
|
+
return output.value;
|
|
44
|
+
// Plain-object outputs (rare on this path); be defensive.
|
|
45
|
+
const v = output.value;
|
|
46
|
+
return typeof v === "bigint" ? v : 0n;
|
|
47
|
+
}
|
|
48
|
+
function outputLockingBytecode(output) {
|
|
49
|
+
if (output instanceof OpReturnData)
|
|
50
|
+
return output.buffer;
|
|
51
|
+
const cashaddr = output instanceof SendRequest || output instanceof TokenSendRequest
|
|
52
|
+
? output.cashaddr
|
|
53
|
+
: output.cashaddr;
|
|
54
|
+
if (!cashaddr)
|
|
55
|
+
return new Uint8Array(0);
|
|
56
|
+
const decoded = cashAddressToLockingBytecode(cashaddr);
|
|
57
|
+
if (typeof decoded === "string")
|
|
58
|
+
return new Uint8Array(0);
|
|
59
|
+
return decoded.bytecode;
|
|
60
|
+
}
|
|
61
|
+
function compareBytes(a, b) {
|
|
62
|
+
const len = Math.min(a.length, b.length);
|
|
63
|
+
for (let i = 0; i < len; i++) {
|
|
64
|
+
if (a[i] !== b[i])
|
|
65
|
+
return a[i] - b[i];
|
|
66
|
+
}
|
|
67
|
+
return a.length - b.length;
|
|
68
|
+
}
|
|
69
|
+
function shuffle(arr) {
|
|
70
|
+
const out = [...arr];
|
|
71
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
72
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
73
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=output-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-order.js","sourceRoot":"","sources":["../../../../src/transaction/coin-control/output-order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,YAAY,EACZ,WAAW,EACX,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAG/B;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAqB,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;AAEz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,CAAC,CAAC;QAC9C,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { CoinSelectionContext, CoinSelectionFn } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Walk the available UTXOs in the order they were given and accumulate until
|
|
4
|
+
* `amountRequired` is met. This reproduces the historical behaviour of
|
|
5
|
+
* mainnet-js prior to the coin-control API; it is the default when no
|
|
6
|
+
* `coinSelection` option is supplied.
|
|
7
|
+
*/
|
|
8
|
+
export declare const selectNatural: CoinSelectionFn;
|
|
9
|
+
/**
|
|
10
|
+
* Pick the largest UTXOs first. Minimises input count but consolidates value;
|
|
11
|
+
* spends "big bills" before small change.
|
|
12
|
+
*/
|
|
13
|
+
export declare const selectLargestFirst: CoinSelectionFn;
|
|
14
|
+
/**
|
|
15
|
+
* Pick the smallest UTXOs first. Maximises input count but tidies up dust
|
|
16
|
+
* over time.
|
|
17
|
+
*/
|
|
18
|
+
export declare const selectSmallestFirst: CoinSelectionFn;
|
|
19
|
+
/**
|
|
20
|
+
* Oldest (lowest block height) first. UTXOs without a `height` are treated as
|
|
21
|
+
* unconfirmed and sorted to the end. Useful for privacy: spend coins that
|
|
22
|
+
* have aged the most.
|
|
23
|
+
*/
|
|
24
|
+
export declare const selectOldestFirst: CoinSelectionFn;
|
|
25
|
+
/**
|
|
26
|
+
* Newest (highest block height) first; unconfirmed UTXOs come first.
|
|
27
|
+
*/
|
|
28
|
+
export declare const selectNewestFirst: CoinSelectionFn;
|
|
29
|
+
/**
|
|
30
|
+
* Shuffle the available UTXOs and walk in that order. Improves privacy by
|
|
31
|
+
* making the input set less linkable to deterministic strategies. Uses
|
|
32
|
+
* `Math.random` -- not cryptographically secure, but fine for selection.
|
|
33
|
+
*/
|
|
34
|
+
export declare const selectRandom: CoinSelectionFn;
|
|
35
|
+
/**
|
|
36
|
+
* Accumulative: walk the available UTXOs in their given order and include
|
|
37
|
+
* each one until the required amount is met. Same algorithm as
|
|
38
|
+
* `selectNatural` but kept as a separately-named export for clarity when
|
|
39
|
+
* the caller wants to be explicit.
|
|
40
|
+
*/
|
|
41
|
+
export declare const selectAccumulative: CoinSelectionFn;
|
|
42
|
+
/**
|
|
43
|
+
* Branch-and-bound: try to find a subset of `available` whose total is within
|
|
44
|
+
* `[amountRequired, amountRequired + costOfChange]`, i.e. a "perfect" or
|
|
45
|
+
* near-perfect match that avoids a change output entirely. Falls back to
|
|
46
|
+
* `selectLargestFirst` when no such subset is found within a bounded search.
|
|
47
|
+
*
|
|
48
|
+
* `costOfChange` is approximated from `feePerByte * P2PKH_OUTPUT_SIZE` (34 B)
|
|
49
|
+
* so the search has a chance to skip change outputs that would cost more than
|
|
50
|
+
* the dust they save.
|
|
51
|
+
*/
|
|
52
|
+
export declare const selectBranchAndBound: CoinSelectionFn;
|
|
53
|
+
export type { CoinSelectionContext, CoinSelectionFn };
|
|
54
|
+
//# sourceMappingURL=selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../../../src/transaction/coin-control/selection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,eAC8B,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAC6C,CAAC;AAE/E;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,eAC2C,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAC2C,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAC4C,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,eACwC,CAAC;AAEpE;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAA+B,CAAC;AAEjE;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,EAAE,eA6ClC,CAAC;AAoDF,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walk the available UTXOs in the order they were given and accumulate until
|
|
3
|
+
* `amountRequired` is met. This reproduces the historical behaviour of
|
|
4
|
+
* mainnet-js prior to the coin-control API; it is the default when no
|
|
5
|
+
* `coinSelection` option is supplied.
|
|
6
|
+
*/
|
|
7
|
+
export const selectNatural = (ctx) => accumulateUntilFunded(ctx.available, ctx.amountRequired);
|
|
8
|
+
/**
|
|
9
|
+
* Pick the largest UTXOs first. Minimises input count but consolidates value;
|
|
10
|
+
* spends "big bills" before small change.
|
|
11
|
+
*/
|
|
12
|
+
export const selectLargestFirst = (ctx) => accumulateUntilFunded(sortBySatoshisDesc(ctx.available), ctx.amountRequired);
|
|
13
|
+
/**
|
|
14
|
+
* Pick the smallest UTXOs first. Maximises input count but tidies up dust
|
|
15
|
+
* over time.
|
|
16
|
+
*/
|
|
17
|
+
export const selectSmallestFirst = (ctx) => accumulateUntilFunded(sortBySatoshisAsc(ctx.available), ctx.amountRequired);
|
|
18
|
+
/**
|
|
19
|
+
* Oldest (lowest block height) first. UTXOs without a `height` are treated as
|
|
20
|
+
* unconfirmed and sorted to the end. Useful for privacy: spend coins that
|
|
21
|
+
* have aged the most.
|
|
22
|
+
*/
|
|
23
|
+
export const selectOldestFirst = (ctx) => accumulateUntilFunded(sortByHeightAsc(ctx.available), ctx.amountRequired);
|
|
24
|
+
/**
|
|
25
|
+
* Newest (highest block height) first; unconfirmed UTXOs come first.
|
|
26
|
+
*/
|
|
27
|
+
export const selectNewestFirst = (ctx) => accumulateUntilFunded(sortByHeightDesc(ctx.available), ctx.amountRequired);
|
|
28
|
+
/**
|
|
29
|
+
* Shuffle the available UTXOs and walk in that order. Improves privacy by
|
|
30
|
+
* making the input set less linkable to deterministic strategies. Uses
|
|
31
|
+
* `Math.random` -- not cryptographically secure, but fine for selection.
|
|
32
|
+
*/
|
|
33
|
+
export const selectRandom = (ctx) => accumulateUntilFunded(shuffle(ctx.available), ctx.amountRequired);
|
|
34
|
+
/**
|
|
35
|
+
* Accumulative: walk the available UTXOs in their given order and include
|
|
36
|
+
* each one until the required amount is met. Same algorithm as
|
|
37
|
+
* `selectNatural` but kept as a separately-named export for clarity when
|
|
38
|
+
* the caller wants to be explicit.
|
|
39
|
+
*/
|
|
40
|
+
export const selectAccumulative = selectNatural;
|
|
41
|
+
/**
|
|
42
|
+
* Branch-and-bound: try to find a subset of `available` whose total is within
|
|
43
|
+
* `[amountRequired, amountRequired + costOfChange]`, i.e. a "perfect" or
|
|
44
|
+
* near-perfect match that avoids a change output entirely. Falls back to
|
|
45
|
+
* `selectLargestFirst` when no such subset is found within a bounded search.
|
|
46
|
+
*
|
|
47
|
+
* `costOfChange` is approximated from `feePerByte * P2PKH_OUTPUT_SIZE` (34 B)
|
|
48
|
+
* so the search has a chance to skip change outputs that would cost more than
|
|
49
|
+
* the dust they save.
|
|
50
|
+
*/
|
|
51
|
+
export const selectBranchAndBound = (ctx) => {
|
|
52
|
+
const target = ctx.amountRequired;
|
|
53
|
+
const costOfChange = BigInt(Math.ceil(ctx.feePerByte * 34));
|
|
54
|
+
const upperBound = target + costOfChange;
|
|
55
|
+
// Sort descending to prune the search aggressively (largest contributions
|
|
56
|
+
// come first; once a partial sum exceeds the upper bound we backtrack).
|
|
57
|
+
const sorted = sortBySatoshisDesc(ctx.available);
|
|
58
|
+
let bestMatch = null;
|
|
59
|
+
const tryInclude = new Array(sorted.length).fill(false);
|
|
60
|
+
let total = 0n;
|
|
61
|
+
let depth = 0;
|
|
62
|
+
// Iterative search with a budget so degenerate inputs don't hang.
|
|
63
|
+
let iterations = 0;
|
|
64
|
+
const maxIterations = 100_000;
|
|
65
|
+
outer: while (iterations < maxIterations) {
|
|
66
|
+
iterations++;
|
|
67
|
+
if (total >= target && total <= upperBound) {
|
|
68
|
+
bestMatch = tryInclude
|
|
69
|
+
.map((picked, i) => (picked ? i : -1))
|
|
70
|
+
.filter((i) => i >= 0);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (total > upperBound || depth === sorted.length) {
|
|
74
|
+
// Backtrack: unwind until we find a position we can flip off.
|
|
75
|
+
while (depth > 0) {
|
|
76
|
+
depth--;
|
|
77
|
+
if (tryInclude[depth]) {
|
|
78
|
+
tryInclude[depth] = false;
|
|
79
|
+
total -= sorted[depth].satoshis;
|
|
80
|
+
depth++;
|
|
81
|
+
continue outer;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
tryInclude[depth] = true;
|
|
87
|
+
total += sorted[depth].satoshis;
|
|
88
|
+
depth++;
|
|
89
|
+
}
|
|
90
|
+
if (bestMatch) {
|
|
91
|
+
return bestMatch.map((i) => sorted[i]);
|
|
92
|
+
}
|
|
93
|
+
// Fallback when no exact subset found.
|
|
94
|
+
return accumulateUntilFunded(sorted, target);
|
|
95
|
+
};
|
|
96
|
+
// ----------------------------------------------------------------------------
|
|
97
|
+
// Helpers
|
|
98
|
+
// ----------------------------------------------------------------------------
|
|
99
|
+
function accumulateUntilFunded(utxos, required) {
|
|
100
|
+
const picked = [];
|
|
101
|
+
let total = 0n;
|
|
102
|
+
for (const u of utxos) {
|
|
103
|
+
picked.push(u);
|
|
104
|
+
total += u.satoshis;
|
|
105
|
+
if (total >= required)
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return picked;
|
|
109
|
+
}
|
|
110
|
+
function sortBySatoshisDesc(utxos) {
|
|
111
|
+
return [...utxos].sort((a, b) => b.satoshis < a.satoshis ? -1 : b.satoshis > a.satoshis ? 1 : 0);
|
|
112
|
+
}
|
|
113
|
+
function sortBySatoshisAsc(utxos) {
|
|
114
|
+
return [...utxos].sort((a, b) => a.satoshis < b.satoshis ? -1 : a.satoshis > b.satoshis ? 1 : 0);
|
|
115
|
+
}
|
|
116
|
+
function heightOrInfinity(u) {
|
|
117
|
+
return typeof u.height === "number" && u.height > 0
|
|
118
|
+
? u.height
|
|
119
|
+
: Number.POSITIVE_INFINITY;
|
|
120
|
+
}
|
|
121
|
+
function sortByHeightAsc(utxos) {
|
|
122
|
+
return [...utxos].sort((a, b) => heightOrInfinity(a) - heightOrInfinity(b));
|
|
123
|
+
}
|
|
124
|
+
function sortByHeightDesc(utxos) {
|
|
125
|
+
return [...utxos].sort((a, b) => heightOrInfinity(b) - heightOrInfinity(a));
|
|
126
|
+
}
|
|
127
|
+
function shuffle(arr) {
|
|
128
|
+
const out = [...arr];
|
|
129
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
130
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
131
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../../../src/transaction/coin-control/selection.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAoB,CAAC,GAAG,EAAE,EAAE,CACpD,qBAAqB,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAoB,CAAC,GAAG,EAAE,EAAE,CACzD,qBAAqB,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;AAE/E;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAoB,CAAC,GAAG,EAAE,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C,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;QACjD,CAAC,CAAC,CAAC,CAAC,MAAM;QACV,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC;AAC/B,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,OAAO,CAAI,GAAQ;IAC1B,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Utxo } from "../../interface.js";
|
|
2
|
+
import type { OpReturnData, SendRequest, TokenSendRequest } from "../../wallet/model.js";
|
|
3
|
+
export type TxOutput = SendRequest | TokenSendRequest | OpReturnData;
|
|
4
|
+
export interface CoinSelectionContext {
|
|
5
|
+
/**
|
|
6
|
+
* Plain BCH UTXOs that are eligible to top up the BCH portion of the
|
|
7
|
+
* transaction. Token-bearing UTXOs needed to satisfy token requests have
|
|
8
|
+
* already been picked by the built-in token-aware logic and are *not*
|
|
9
|
+
* included here.
|
|
10
|
+
*/
|
|
11
|
+
available: Utxo[];
|
|
12
|
+
/**
|
|
13
|
+
* UTXOs already pinned to the transaction (via `options.ensureUtxos` or by
|
|
14
|
+
* the operation type, e.g. token genesis/mint/burn). The selection function
|
|
15
|
+
* does not need to include these; they are added automatically.
|
|
16
|
+
*/
|
|
17
|
+
pinned: Utxo[];
|
|
18
|
+
/**
|
|
19
|
+
* Total satoshis the transaction still needs to be funded with from
|
|
20
|
+
* `available`. Accounts for outputs + estimated fee minus value already
|
|
21
|
+
* contributed by `pinned` and any token UTXOs.
|
|
22
|
+
*/
|
|
23
|
+
amountRequired: bigint;
|
|
24
|
+
/** Network relay fee in sats/byte at the current best height. */
|
|
25
|
+
feePerByte: number;
|
|
26
|
+
/** Best block height -- useful for age-aware strategies. */
|
|
27
|
+
bestHeight: number;
|
|
28
|
+
}
|
|
29
|
+
export type CoinSelectionFn = (ctx: CoinSelectionContext) => Utxo[];
|
|
30
|
+
export interface InputOrderingContext {
|
|
31
|
+
/**
|
|
32
|
+
* Inputs in the order produced by the selection step. The function should
|
|
33
|
+
* return a permutation of this array.
|
|
34
|
+
*/
|
|
35
|
+
inputs: Utxo[];
|
|
36
|
+
}
|
|
37
|
+
export type InputOrderingFn = (ctx: InputOrderingContext) => Utxo[];
|
|
38
|
+
export interface OutputOrderingContext {
|
|
39
|
+
/**
|
|
40
|
+
* Outputs in the order produced by the caller, with the change output
|
|
41
|
+
* appended last when present.
|
|
42
|
+
*/
|
|
43
|
+
outputs: TxOutput[];
|
|
44
|
+
/**
|
|
45
|
+
* Index of the change output within `outputs`, if any. `undefined` when
|
|
46
|
+
* the transaction has no change (e.g. `discardChange` or change below the
|
|
47
|
+
* dust threshold).
|
|
48
|
+
*/
|
|
49
|
+
changeOutputIndex?: number;
|
|
50
|
+
}
|
|
51
|
+
export type OutputOrderingFn = (ctx: OutputOrderingContext) => TxOutput[];
|
|
52
|
+
export interface FeeContext {
|
|
53
|
+
/** Encoded transaction size in bytes (computed by the build pipeline). */
|
|
54
|
+
txSizeBytes: number;
|
|
55
|
+
/**
|
|
56
|
+
* Network relay fee in sats/byte at the current best height. Strategies
|
|
57
|
+
* are free to ignore this if they encode a fixed rate.
|
|
58
|
+
*/
|
|
59
|
+
relayFeePerByte: number;
|
|
60
|
+
}
|
|
61
|
+
export type FeeFn = (ctx: FeeContext) => bigint;
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/transaction/coin-control/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,gBAAgB,GAAG,YAAY,CAAC;AAIrE,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,SAAS,EAAE,IAAI,EAAE,CAAC;IAClB;;;;OAIG;IACH,MAAM,EAAE,IAAI,EAAE,CAAC;IACf;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,EAAE,CAAC;AAIpE,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,MAAM,EAAE,IAAI,EAAE,CAAC;CAChB;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,EAAE,CAAC;AAIpE,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,EAAE,QAAQ,EAAE,CAAC;IACpB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,qBAAqB,KAAK,QAAQ,EAAE,CAAC;AAI1E,MAAM,WAAW,UAAU;IACzB,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,UAAU,KAAK,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/transaction/coin-control/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base.d.ts","sourceRoot":"","sources":["../../../src/wallet/Base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,wBAAwB,EAAU,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,eAAe,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAwB,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,UAAU,EAEV,GAAG,EACH,IAAI,EAEL,MAAM,iBAAiB,CAAC;AAEzB,OAAO,uBAAuB,MAAM,uCAAuC,CAAC;AAE5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAiBjE,OAAO,EAAiB,cAAc,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,yBAAyB,EACzB,0BAA0B,EAC1B,OAAO,EACP,WAAW,EACZ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M,CAAA;KAAE,CAAC;IAc3E;;;OAGG;IACU,sBAAsB,IAAI,OAAO,CAAC;QAC7C,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;KAC5B,CAAC;CAcH;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,WAAqB,UAAU,SAU9D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAsB7B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,GACb,eAAe,GAAG,SAAS,CAK7B"}
|
|
@@ -689,10 +689,16 @@ export class BaseWallet {
|
|
|
689
689
|
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
690
690
|
feePaidBy: feePaidBy,
|
|
691
691
|
});
|
|
692
|
-
const
|
|
693
|
-
|
|
692
|
+
const selectedUtxos = await getSuitableUtxos(utxos, spendAmount + feeEstimate, bestHeight, feePaidBy, sendRequests, options?.ensureUtxos || [], options?.tokenOperation, {
|
|
693
|
+
coinSelection: options?.coinSelection,
|
|
694
|
+
feePerByte: relayFeePerByteInSatoshi,
|
|
695
|
+
});
|
|
696
|
+
if (selectedUtxos.length === 0) {
|
|
694
697
|
throw Error("The available inputs couldn't satisfy the request with fees");
|
|
695
698
|
}
|
|
699
|
+
const fundingUtxos = options?.inputOrdering
|
|
700
|
+
? options.inputOrdering({ inputs: selectedUtxos })
|
|
701
|
+
: selectedUtxos;
|
|
696
702
|
const fee = await getFeeAmount({
|
|
697
703
|
utxos: fundingUtxos,
|
|
698
704
|
sendRequests: sendRequests,
|
|
@@ -700,6 +706,7 @@ export class BaseWallet {
|
|
|
700
706
|
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
701
707
|
feePaidBy: feePaidBy,
|
|
702
708
|
walletCache: this.walletCache,
|
|
709
|
+
fee: options?.fee,
|
|
703
710
|
});
|
|
704
711
|
const { encodedTransaction, sourceOutputs } = await buildEncodedTransaction({
|
|
705
712
|
inputs: fundingUtxos,
|
|
@@ -711,6 +718,7 @@ export class BaseWallet {
|
|
|
711
718
|
changeAddress,
|
|
712
719
|
buildUnsigned: options?.buildUnsigned === true,
|
|
713
720
|
walletCache: this.walletCache,
|
|
721
|
+
outputOrdering: options?.outputOrdering,
|
|
714
722
|
});
|
|
715
723
|
const categories = [
|
|
716
724
|
...fundingUtxos
|