mainnet-js 2.7.34 → 3.0.0-next.1
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/index.html +1 -1
- package/dist/{mainnet-2.7.34.js → mainnet-3.0.0-next.1.js} +728 -708
- package/dist/module/cache/MemoryCache.d.ts +0 -1
- package/dist/module/cache/MemoryCache.d.ts.map +1 -1
- package/dist/module/cache/MemoryCache.js +5 -7
- package/dist/module/cache/MemoryCache.js.map +1 -1
- package/dist/module/cache/index.d.ts +1 -0
- package/dist/module/cache/index.d.ts.map +1 -1
- package/dist/module/cache/index.js +1 -0
- package/dist/module/cache/index.js.map +1 -1
- package/dist/module/cache/walletCache.d.ts +45 -0
- package/dist/module/cache/walletCache.d.ts.map +1 -0
- package/dist/module/cache/walletCache.js +140 -0
- package/dist/module/cache/walletCache.js.map +1 -0
- package/dist/module/chain.d.ts +1 -1
- package/dist/module/chain.js +1 -1
- package/dist/module/chain.js.map +1 -1
- package/dist/module/constant.d.ts +1 -1
- package/dist/module/constant.d.ts.map +1 -1
- package/dist/module/constant.js +1 -1
- package/dist/module/constant.js.map +1 -1
- package/dist/module/enum.d.ts +1 -7
- package/dist/module/enum.d.ts.map +1 -1
- package/dist/module/enum.js +0 -6
- package/dist/module/enum.js.map +1 -1
- package/dist/module/history/{electrumTransformer.d.ts → getHistory.d.ts} +3 -3
- package/dist/module/history/getHistory.d.ts.map +1 -0
- package/dist/module/history/{electrumTransformer.js → getHistory.js} +17 -14
- package/dist/module/history/getHistory.js.map +1 -0
- package/dist/module/index.d.ts +3 -1
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +3 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/interface.d.ts +7 -2
- package/dist/module/interface.d.ts.map +1 -1
- package/dist/module/interface.js.map +1 -1
- package/dist/module/message/interface.d.ts +2 -2
- package/dist/module/message/interface.d.ts.map +1 -1
- package/dist/module/message/interface.js +0 -3
- package/dist/module/message/interface.js.map +1 -1
- package/dist/module/message/signed.d.ts +5 -5
- package/dist/module/message/signed.d.ts.map +1 -1
- package/dist/module/message/signed.js +8 -8
- package/dist/module/message/signed.js.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.d.ts +2 -2
- package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.js +3 -2
- package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
- package/dist/module/network/NetworkProvider.d.ts +2 -2
- package/dist/module/network/NetworkProvider.d.ts.map +1 -1
- package/dist/module/network/constant.js +4 -4
- package/dist/module/network/constant.js.map +1 -1
- package/dist/module/network/getRelayFeeCache.js +2 -2
- package/dist/module/network/getRelayFeeCache.js.map +1 -1
- package/dist/module/rate/ExchangeRate.d.ts +2 -1
- package/dist/module/rate/ExchangeRate.d.ts.map +1 -1
- package/dist/module/rate/ExchangeRate.js +4 -1
- package/dist/module/rate/ExchangeRate.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +25 -23
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +26 -25
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/transaction/allocateFee.d.ts +3 -3
- package/dist/module/transaction/allocateFee.d.ts.map +1 -1
- package/dist/module/transaction/allocateFee.js +5 -6
- package/dist/module/transaction/allocateFee.js.map +1 -1
- package/dist/module/util/amountInSatoshi.d.ts +1 -1
- package/dist/module/util/amountInSatoshi.d.ts.map +1 -1
- package/dist/module/util/amountInSatoshi.js +3 -9
- package/dist/module/util/amountInSatoshi.js.map +1 -1
- package/dist/module/util/asSendRequestObject.d.ts.map +1 -1
- package/dist/module/util/asSendRequestObject.js +10 -7
- package/dist/module/util/asSendRequestObject.js.map +1 -1
- package/dist/module/util/checkUtxos.d.ts +2 -2
- package/dist/module/util/checkUtxos.d.ts.map +1 -1
- package/dist/module/util/checkUtxos.js +11 -12
- package/dist/module/util/checkUtxos.js.map +1 -1
- package/dist/module/util/convert.d.ts +3 -0
- package/dist/module/util/convert.d.ts.map +1 -1
- package/dist/module/util/convert.js +12 -0
- package/dist/module/util/convert.js.map +1 -1
- package/dist/module/util/deriveCashaddr.d.ts.map +1 -1
- package/dist/module/util/deriveCashaddr.js +6 -0
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/util/deriveNetwork.js +1 -1
- package/dist/module/util/deriveNetwork.js.map +1 -1
- package/dist/module/util/hd.d.ts +3 -0
- package/dist/module/util/hd.d.ts.map +1 -0
- package/dist/module/util/hd.js +11 -0
- package/dist/module/util/hd.js.map +1 -0
- package/dist/module/util/index.d.ts +3 -3
- package/dist/module/util/index.d.ts.map +1 -1
- package/dist/module/util/index.js +3 -3
- package/dist/module/util/index.js.map +1 -1
- package/dist/module/util/satoshiToAmount.d.ts +1 -1
- package/dist/module/util/satoshiToAmount.d.ts.map +1 -1
- package/dist/module/util/satoshiToAmount.js +3 -9
- package/dist/module/util/satoshiToAmount.js.map +1 -1
- package/dist/module/util/sumSendRequestAmounts.d.ts.map +1 -1
- package/dist/module/util/sumSendRequestAmounts.js +3 -4
- package/dist/module/util/sumSendRequestAmounts.js.map +1 -1
- package/dist/module/util/sumUtxoValue.d.ts +3 -3
- package/dist/module/util/sumUtxoValue.d.ts.map +1 -1
- package/dist/module/util/sumUtxoValue.js +2 -2
- package/dist/module/util/sumUtxoValue.js.map +1 -1
- package/dist/module/wallet/Base.d.ts +45 -103
- package/dist/module/wallet/Base.d.ts.map +1 -1
- package/dist/module/wallet/Base.js +99 -298
- package/dist/module/wallet/Base.js.map +1 -1
- package/dist/module/wallet/HDWallet.d.ts +164 -0
- package/dist/module/wallet/HDWallet.d.ts.map +1 -0
- package/dist/module/wallet/HDWallet.js +486 -0
- package/dist/module/wallet/HDWallet.js.map +1 -0
- package/dist/module/wallet/Util.js +1 -1
- package/dist/module/wallet/Util.js.map +1 -1
- package/dist/module/wallet/Watch.d.ts +151 -0
- package/dist/module/wallet/Watch.d.ts.map +1 -0
- package/dist/module/wallet/Watch.js +307 -0
- package/dist/module/wallet/Watch.js.map +1 -0
- package/dist/module/wallet/Wif.d.ts +23 -29
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +204 -267
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/createWallet.d.ts +7 -1
- package/dist/module/wallet/createWallet.d.ts.map +1 -1
- package/dist/module/wallet/createWallet.js +26 -17
- package/dist/module/wallet/createWallet.js.map +1 -1
- package/dist/module/wallet/interface.d.ts +5 -6
- package/dist/module/wallet/interface.d.ts.map +1 -1
- package/dist/module/wallet/model.d.ts +15 -19
- package/dist/module/wallet/model.d.ts.map +1 -1
- package/dist/module/wallet/model.js +5 -25
- package/dist/module/wallet/model.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/cache/MemoryCache.ts +5 -5
- package/src/cache/index.ts +1 -0
- package/src/cache/walletCache.ts +239 -0
- package/src/chain.ts +1 -1
- package/src/constant.ts +1 -1
- package/src/enum.ts +0 -6
- package/src/history/{electrumTransformer.test.ts → getHistory.test.ts} +26 -53
- package/src/history/{electrumTransformer.ts → getHistory.ts} +31 -15
- package/src/index.ts +3 -1
- package/src/interface.ts +8 -2
- package/src/message/interface.ts +2 -28
- package/src/message/signed.test.ts +36 -48
- package/src/message/signed.ts +9 -12
- package/src/network/Connection.test.ts +3 -3
- package/src/network/ElectrumNetworkProvider.ts +5 -5
- package/src/network/NetworkProvider.ts +2 -2
- package/src/network/Rpc.test.ts +3 -4
- package/src/network/constant.ts +4 -4
- package/src/network/getRelayFeeCache.ts +2 -2
- package/src/rate/ExchangeRate.test.ts +2 -44
- package/src/rate/ExchangeRate.ts +5 -2
- package/src/transaction/Wif.ts +59 -52
- package/src/transaction/allocateFee.test.ts +110 -131
- package/src/transaction/allocateFee.ts +14 -15
- package/src/util/amountInSatoshi.test.ts +1 -9
- package/src/util/amountInSatoshi.ts +6 -10
- package/src/util/asSendRequestObject.ts +12 -7
- package/src/util/checkUtxos.ts +21 -26
- package/src/util/convert.ts +18 -0
- package/src/util/deriveCashaddr.ts +8 -0
- package/src/util/deriveNetwork.ts +1 -1
- package/src/util/derivePublicKeyHash.test.ts +0 -13
- package/src/util/hd.ts +16 -0
- package/src/util/index.ts +3 -7
- package/src/util/satoshiToAmount.test.ts +1 -1
- package/src/util/satoshiToAmount.ts +4 -10
- package/src/util/sumSendRequestAmounts.ts +3 -4
- package/src/util/sumUtxoValue.ts +7 -7
- package/src/wallet/Base.ts +147 -420
- package/src/wallet/Cashtokens.test.headless.js +11 -11
- package/src/wallet/Cashtokens.test.ts +36 -37
- package/src/wallet/HDWallet.test.ts +515 -0
- package/src/wallet/HDWallet.ts +764 -0
- package/src/wallet/Util.ts +1 -1
- package/src/wallet/Watch.ts +447 -0
- package/src/wallet/Wif.bip39.test.ts +1 -1
- package/src/wallet/Wif.test.ts +108 -133
- package/src/wallet/Wif.ts +258 -283
- package/src/wallet/createWallet.ts +28 -18
- package/src/wallet/interface.ts +5 -6
- package/src/wallet/model.test.ts +4 -7
- package/src/wallet/model.ts +19 -51
- package/dist/module/history/electrumTransformer.d.ts.map +0 -1
- package/dist/module/history/electrumTransformer.js.map +0 -1
- package/dist/module/util/balanceObjectFromSatoshi.d.ts +0 -8
- package/dist/module/util/balanceObjectFromSatoshi.d.ts.map +0 -1
- package/dist/module/util/balanceObjectFromSatoshi.js +0 -35
- package/dist/module/util/balanceObjectFromSatoshi.js.map +0 -1
- package/src/util/balanceObjectFromSatoshi.test.ts +0 -58
- package/src/util/balanceObjectFromSatoshi.ts +0 -52
package/src/transaction/Wif.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
walletTemplateP2pkhNonHd,
|
|
3
|
-
walletTemplateToCompilerBCH,
|
|
4
3
|
cashAddressToLockingBytecode,
|
|
5
4
|
Compiler,
|
|
6
5
|
encodeTransaction,
|
|
@@ -8,14 +7,15 @@ import {
|
|
|
8
7
|
importWalletTemplate,
|
|
9
8
|
AnyCompilerConfiguration,
|
|
10
9
|
AuthenticationProgramStateCommon,
|
|
11
|
-
CompilationContextBCH,
|
|
12
10
|
Output,
|
|
13
11
|
hexToBin,
|
|
14
12
|
verifyTransactionTokens,
|
|
15
13
|
decodeTransaction,
|
|
16
14
|
TransactionTemplateFixed,
|
|
15
|
+
CompilationContextBch,
|
|
16
|
+
walletTemplateToCompilerBch,
|
|
17
17
|
} from "@bitauth/libauth";
|
|
18
|
-
import { NFTCapability, TokenI,
|
|
18
|
+
import { NFTCapability, TokenI, Utxo } from "../interface.js";
|
|
19
19
|
import { allocateFee } from "./allocateFee.js";
|
|
20
20
|
|
|
21
21
|
import { DUST_UTXO_THRESHOLD } from "../constant.js";
|
|
@@ -26,30 +26,34 @@ import {
|
|
|
26
26
|
SourceOutput,
|
|
27
27
|
TokenSendRequest,
|
|
28
28
|
} from "../wallet/model.js";
|
|
29
|
-
import { amountInSatoshi } from "../util/amountInSatoshi.js";
|
|
30
29
|
import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
|
|
31
30
|
import { sumUtxoValue } from "../util/sumUtxoValue.js";
|
|
32
31
|
import { FeePaidByEnum } from "../wallet/enum.js";
|
|
32
|
+
import { WalletCache } from "../cache/walletCache.js";
|
|
33
|
+
|
|
34
|
+
export const placeholderPrivateKey =
|
|
35
|
+
"0000000000000000000000000000000000000000000000000000000000000001";
|
|
36
|
+
export const placeholderPrivateKeyBin = hexToBin(placeholderPrivateKey);
|
|
33
37
|
|
|
34
38
|
// Build a transaction for a p2pkh transaction for a non HD wallet
|
|
35
39
|
export async function buildP2pkhNonHdTransaction({
|
|
36
40
|
inputs,
|
|
37
41
|
outputs,
|
|
38
42
|
signingKey,
|
|
39
|
-
|
|
40
|
-
fee = 0,
|
|
43
|
+
fee = 0n,
|
|
41
44
|
discardChange = false,
|
|
42
45
|
feePaidBy = FeePaidByEnum.change,
|
|
43
46
|
changeAddress = "",
|
|
47
|
+
walletCache,
|
|
44
48
|
}: {
|
|
45
|
-
inputs:
|
|
49
|
+
inputs: Utxo[];
|
|
46
50
|
outputs: Array<SendRequest | TokenSendRequest | OpReturnData>;
|
|
47
|
-
signingKey
|
|
48
|
-
|
|
49
|
-
fee?: number;
|
|
51
|
+
signingKey?: Uint8Array;
|
|
52
|
+
fee?: bigint;
|
|
50
53
|
discardChange?: boolean;
|
|
51
54
|
feePaidBy?: FeePaidByEnum;
|
|
52
55
|
changeAddress?: string;
|
|
56
|
+
walletCache?: WalletCache;
|
|
53
57
|
}) {
|
|
54
58
|
if (!signingKey) {
|
|
55
59
|
throw new Error("Missing signing key when building transaction");
|
|
@@ -60,8 +64,8 @@ export async function buildP2pkhNonHdTransaction({
|
|
|
60
64
|
throw new Error("Transaction template error");
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
const compiler =
|
|
64
|
-
const inputAmount =
|
|
67
|
+
const compiler = walletTemplateToCompilerBch(template);
|
|
68
|
+
const inputAmount = sumUtxoValue(inputs);
|
|
65
69
|
|
|
66
70
|
const sendAmount = await sumSendRequestAmounts(outputs);
|
|
67
71
|
|
|
@@ -72,7 +76,7 @@ export async function buildP2pkhNonHdTransaction({
|
|
|
72
76
|
const lockedOutputs = await prepareOutputs(outputs);
|
|
73
77
|
|
|
74
78
|
if (!changeAddress) {
|
|
75
|
-
changeAddress =
|
|
79
|
+
changeAddress = inputs[0].address;
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
if (discardChange !== true) {
|
|
@@ -92,7 +96,7 @@ export async function buildP2pkhNonHdTransaction({
|
|
|
92
96
|
inputs,
|
|
93
97
|
compiler,
|
|
94
98
|
signingKey,
|
|
95
|
-
|
|
99
|
+
walletCache,
|
|
96
100
|
});
|
|
97
101
|
const result = generateTransaction({
|
|
98
102
|
inputs: preparedInputs,
|
|
@@ -121,16 +125,16 @@ export function prepareInputs({
|
|
|
121
125
|
inputs,
|
|
122
126
|
compiler,
|
|
123
127
|
signingKey,
|
|
124
|
-
|
|
128
|
+
walletCache,
|
|
125
129
|
}: {
|
|
126
|
-
inputs:
|
|
130
|
+
inputs: Utxo[];
|
|
127
131
|
compiler: Compiler<
|
|
128
|
-
|
|
129
|
-
AnyCompilerConfiguration<
|
|
132
|
+
CompilationContextBch,
|
|
133
|
+
AnyCompilerConfiguration<CompilationContextBch>,
|
|
130
134
|
AuthenticationProgramStateCommon
|
|
131
135
|
>;
|
|
132
136
|
signingKey: Uint8Array;
|
|
133
|
-
|
|
137
|
+
walletCache?: WalletCache;
|
|
134
138
|
}) {
|
|
135
139
|
const preparedInputs: any[] = [];
|
|
136
140
|
const sourceOutputs: any[] = [];
|
|
@@ -160,7 +164,9 @@ export function prepareInputs({
|
|
|
160
164
|
}
|
|
161
165
|
: undefined,
|
|
162
166
|
};
|
|
163
|
-
const key =
|
|
167
|
+
const key =
|
|
168
|
+
walletCache?.get(i.address)?.privateKey ??
|
|
169
|
+
(signingKey?.length ? signingKey : Uint8Array.from(Array(32)));
|
|
164
170
|
const newInput = {
|
|
165
171
|
outpointIndex: utxoIndex,
|
|
166
172
|
outpointTransactionHash: utxoOutpointTransactionHash,
|
|
@@ -178,7 +184,7 @@ export function prepareInputs({
|
|
|
178
184
|
|
|
179
185
|
preparedInputs.push(newInput);
|
|
180
186
|
|
|
181
|
-
const lockingBytecode = cashAddressToLockingBytecode(
|
|
187
|
+
const lockingBytecode = cashAddressToLockingBytecode(i.address);
|
|
182
188
|
if (typeof lockingBytecode === "string") {
|
|
183
189
|
throw lockingBytecode;
|
|
184
190
|
}
|
|
@@ -224,7 +230,7 @@ export async function prepareOutputs(
|
|
|
224
230
|
if (typeof outputLockingBytecode === "string")
|
|
225
231
|
throw new Error(outputLockingBytecode);
|
|
226
232
|
|
|
227
|
-
const sendAmount =
|
|
233
|
+
const sendAmount = Number(output.value);
|
|
228
234
|
if (sendAmount % 1 !== 0) {
|
|
229
235
|
throw Error(
|
|
230
236
|
`Cannot send ${sendAmount} satoshis, (fractional sats do not exist, yet), please use an integer number.`
|
|
@@ -292,22 +298,22 @@ export function prepareTokenOutputs(request: TokenSendRequest): Output {
|
|
|
292
298
|
* @returns A promise to a list of unspent outputs
|
|
293
299
|
*/
|
|
294
300
|
export async function getSuitableUtxos(
|
|
295
|
-
inputs:
|
|
301
|
+
inputs: Utxo[],
|
|
296
302
|
amountRequired: bigint | undefined,
|
|
297
303
|
bestHeight: number,
|
|
298
304
|
feePaidBy: FeePaidByEnum,
|
|
299
305
|
requests: SendRequestType[],
|
|
300
|
-
ensureUtxos:
|
|
306
|
+
ensureUtxos: Utxo[] = [],
|
|
301
307
|
tokenOperation: "send" | "genesis" | "mint" | "burn" = "send"
|
|
302
|
-
): Promise<
|
|
303
|
-
const suitableUtxos:
|
|
308
|
+
): Promise<Utxo[]> {
|
|
309
|
+
const suitableUtxos: Utxo[] = [...ensureUtxos];
|
|
304
310
|
let amountAvailable = BigInt(0);
|
|
305
311
|
const tokenRequests = requests.filter(
|
|
306
312
|
(val) => val instanceof TokenSendRequest
|
|
307
313
|
) as TokenSendRequest[];
|
|
308
314
|
|
|
309
315
|
const availableInputs = inputs.slice();
|
|
310
|
-
const selectedInputs:
|
|
316
|
+
const selectedInputs: Utxo[] = [];
|
|
311
317
|
|
|
312
318
|
// find matching utxos for token transfers
|
|
313
319
|
if (tokenOperation === "send") {
|
|
@@ -438,14 +444,13 @@ export async function getFeeAmountSimple({
|
|
|
438
444
|
relayFeePerByteInSatoshi,
|
|
439
445
|
discardChange,
|
|
440
446
|
}: {
|
|
441
|
-
utxos:
|
|
447
|
+
utxos: Utxo[];
|
|
442
448
|
sendRequests: Array<SendRequest | TokenSendRequest | OpReturnData>;
|
|
443
|
-
privateKey: Uint8Array;
|
|
444
449
|
sourceAddress: string;
|
|
445
450
|
relayFeePerByteInSatoshi: number;
|
|
446
451
|
feePaidBy: FeePaidByEnum;
|
|
447
452
|
discardChange?: boolean;
|
|
448
|
-
}) {
|
|
453
|
+
}): Promise<bigint> {
|
|
449
454
|
const inputSizeP2pkh = 148;
|
|
450
455
|
const outputSizeP2pkh = 34;
|
|
451
456
|
|
|
@@ -462,10 +467,8 @@ export async function getFeeAmountSimple({
|
|
|
462
467
|
0
|
|
463
468
|
);
|
|
464
469
|
|
|
465
|
-
const outputSize = (sendRequest) => {
|
|
466
|
-
if (sendRequest.hasOwnProperty("
|
|
467
|
-
return outputSizeP2pkh;
|
|
468
|
-
} else if (sendRequest.hasOwnProperty("tokenId")) {
|
|
470
|
+
const outputSize = (sendRequest: SendRequestType) => {
|
|
471
|
+
if (sendRequest.hasOwnProperty("tokenId")) {
|
|
469
472
|
const tokenRequest = sendRequest as TokenSendRequest;
|
|
470
473
|
return (
|
|
471
474
|
outputSizeP2pkh +
|
|
@@ -476,17 +479,19 @@ export async function getFeeAmountSimple({
|
|
|
476
479
|
);
|
|
477
480
|
} else if (sendRequest.hasOwnProperty("buffer")) {
|
|
478
481
|
return 9 + (sendRequest as OpReturnData).buffer.length;
|
|
482
|
+
} else {
|
|
483
|
+
return outputSizeP2pkh;
|
|
479
484
|
}
|
|
480
|
-
|
|
481
|
-
return 0;
|
|
482
485
|
};
|
|
483
486
|
|
|
484
487
|
const outputTotalSize =
|
|
485
488
|
sendRequests.reduce((prev, curr) => prev + outputSize(curr), 0) +
|
|
486
489
|
(discardChange ? 0 : outputSizeP2pkh);
|
|
487
490
|
|
|
488
|
-
return
|
|
489
|
-
(
|
|
491
|
+
return BigInt(
|
|
492
|
+
Math.ceil(
|
|
493
|
+
(inputTotalSize + outputTotalSize + 16) * relayFeePerByteInSatoshi
|
|
494
|
+
)
|
|
490
495
|
);
|
|
491
496
|
}
|
|
492
497
|
|
|
@@ -494,19 +499,19 @@ export async function getFeeAmountSimple({
|
|
|
494
499
|
export async function getFeeAmount({
|
|
495
500
|
utxos,
|
|
496
501
|
sendRequests,
|
|
497
|
-
privateKey,
|
|
498
502
|
sourceAddress,
|
|
499
503
|
relayFeePerByteInSatoshi,
|
|
500
504
|
feePaidBy,
|
|
501
505
|
discardChange,
|
|
506
|
+
walletCache,
|
|
502
507
|
}: {
|
|
503
|
-
utxos:
|
|
508
|
+
utxos: Utxo[];
|
|
504
509
|
sendRequests: Array<SendRequest | TokenSendRequest | OpReturnData>;
|
|
505
|
-
privateKey: Uint8Array;
|
|
506
510
|
sourceAddress: string;
|
|
507
511
|
relayFeePerByteInSatoshi: number;
|
|
508
512
|
feePaidBy: FeePaidByEnum;
|
|
509
513
|
discardChange?: boolean;
|
|
514
|
+
walletCache?: WalletCache;
|
|
510
515
|
}) {
|
|
511
516
|
// build transaction
|
|
512
517
|
if (utxos) {
|
|
@@ -515,15 +520,17 @@ export async function getFeeAmount({
|
|
|
515
520
|
await buildEncodedTransaction({
|
|
516
521
|
inputs: utxos,
|
|
517
522
|
outputs: sendRequests,
|
|
518
|
-
signingKey:
|
|
519
|
-
|
|
520
|
-
fee: 0, //DUST_UTXO_THRESHOLD
|
|
523
|
+
signingKey: placeholderPrivateKeyBin,
|
|
524
|
+
fee: 0n, //DUST_UTXO_THRESHOLD
|
|
521
525
|
discardChange: discardChange ?? false,
|
|
522
526
|
feePaidBy,
|
|
523
527
|
changeAddress: "",
|
|
528
|
+
walletCache,
|
|
524
529
|
});
|
|
525
530
|
|
|
526
|
-
return
|
|
531
|
+
return BigInt(
|
|
532
|
+
Math.ceil(draftTransaction.length * relayFeePerByteInSatoshi + 1)
|
|
533
|
+
);
|
|
527
534
|
} else {
|
|
528
535
|
throw Error(
|
|
529
536
|
"The available inputs in the wallet cannot satisfy this send request"
|
|
@@ -536,32 +543,32 @@ export async function buildEncodedTransaction({
|
|
|
536
543
|
inputs,
|
|
537
544
|
outputs,
|
|
538
545
|
signingKey,
|
|
539
|
-
|
|
540
|
-
fee = 0,
|
|
546
|
+
fee = 0n,
|
|
541
547
|
discardChange = false,
|
|
542
548
|
feePaidBy = FeePaidByEnum.change,
|
|
543
549
|
changeAddress = "",
|
|
544
550
|
buildUnsigned = false,
|
|
551
|
+
walletCache,
|
|
545
552
|
}: {
|
|
546
|
-
inputs:
|
|
553
|
+
inputs: Utxo[];
|
|
547
554
|
outputs: Array<SendRequest | TokenSendRequest | OpReturnData>;
|
|
548
555
|
signingKey: Uint8Array;
|
|
549
|
-
|
|
550
|
-
fee?: number;
|
|
556
|
+
fee?: bigint;
|
|
551
557
|
discardChange?: boolean;
|
|
552
558
|
feePaidBy?: FeePaidByEnum;
|
|
553
559
|
changeAddress?: string;
|
|
554
560
|
buildUnsigned?: boolean;
|
|
561
|
+
walletCache?: WalletCache;
|
|
555
562
|
}) {
|
|
556
563
|
const { transaction, sourceOutputs } = await buildP2pkhNonHdTransaction({
|
|
557
564
|
inputs,
|
|
558
565
|
outputs,
|
|
559
566
|
signingKey,
|
|
560
|
-
sourceAddress,
|
|
561
567
|
fee,
|
|
562
568
|
discardChange,
|
|
563
569
|
feePaidBy,
|
|
564
570
|
changeAddress,
|
|
571
|
+
walletCache,
|
|
565
572
|
});
|
|
566
573
|
|
|
567
574
|
if (buildUnsigned === true) {
|
|
@@ -592,7 +599,7 @@ export async function signUnsignedTransaction(
|
|
|
592
599
|
throw new Error("Transaction template error");
|
|
593
600
|
}
|
|
594
601
|
|
|
595
|
-
const compiler =
|
|
602
|
+
const compiler = walletTemplateToCompilerBch(template);
|
|
596
603
|
const transactionTemplate: Readonly<
|
|
597
604
|
TransactionTemplateFixed<typeof compiler>
|
|
598
605
|
> = { ...decoded };
|