@xchainjs/xchain-doge 2.1.0 → 2.2.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/lib/client.d.ts +8 -4
- package/lib/clientKeystore.d.ts +3 -1
- package/lib/clientLedger.d.ts +13 -1
- package/lib/index.esm.js +68 -10
- package/lib/index.js +67 -9
- package/package.json +3 -3
package/lib/client.d.ts
CHANGED
|
@@ -94,11 +94,12 @@ declare abstract class Client extends UTXOClient {
|
|
|
94
94
|
* Build transaction with enhanced UTXO selection
|
|
95
95
|
* Note: Doge uses legacy P2PKH addresses (nonWitnessUtxo)
|
|
96
96
|
*/
|
|
97
|
-
buildTxEnhanced({ amount, recipient, memo, feeRate, sender, spendPendingUTXO, utxoSelectionPreferences, }: TxParams & {
|
|
97
|
+
buildTxEnhanced({ amount, recipient, memo, feeRate, sender, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: TxParams & {
|
|
98
98
|
feeRate: FeeRate;
|
|
99
99
|
sender: Address;
|
|
100
100
|
spendPendingUTXO?: boolean;
|
|
101
101
|
utxoSelectionPreferences?: UtxoSelectionPreferences;
|
|
102
|
+
selectedUtxos?: UTXO[];
|
|
102
103
|
}): Promise<{
|
|
103
104
|
psbt: Dogecoin.Psbt;
|
|
104
105
|
utxos: UTXO[];
|
|
@@ -107,22 +108,24 @@ declare abstract class Client extends UTXOClient {
|
|
|
107
108
|
/**
|
|
108
109
|
* Prepare transaction with enhanced UTXO selection
|
|
109
110
|
*/
|
|
110
|
-
prepareTxEnhanced({ sender, memo, amount, recipient, spendPendingUTXO, feeRate, utxoSelectionPreferences, }: TxParams & {
|
|
111
|
+
prepareTxEnhanced({ sender, memo, amount, recipient, spendPendingUTXO, feeRate, utxoSelectionPreferences, selectedUtxos, }: TxParams & {
|
|
111
112
|
sender: Address;
|
|
112
113
|
feeRate: FeeRate;
|
|
113
114
|
spendPendingUTXO?: boolean;
|
|
114
115
|
utxoSelectionPreferences?: UtxoSelectionPreferences;
|
|
116
|
+
selectedUtxos?: UTXO[];
|
|
115
117
|
}): Promise<PreparedTx>;
|
|
116
118
|
/**
|
|
117
119
|
* Send maximum possible amount (sweep)
|
|
118
120
|
*/
|
|
119
|
-
sendMax({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, }: {
|
|
121
|
+
sendMax({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: {
|
|
120
122
|
sender: Address;
|
|
121
123
|
recipient: Address;
|
|
122
124
|
memo?: string;
|
|
123
125
|
feeRate: FeeRate;
|
|
124
126
|
spendPendingUTXO?: boolean;
|
|
125
127
|
utxoSelectionPreferences?: UtxoSelectionPreferences;
|
|
128
|
+
selectedUtxos?: UTXO[];
|
|
126
129
|
}): Promise<{
|
|
127
130
|
psbt: Dogecoin.Psbt;
|
|
128
131
|
utxos: UTXO[];
|
|
@@ -133,13 +136,14 @@ declare abstract class Client extends UTXOClient {
|
|
|
133
136
|
/**
|
|
134
137
|
* Prepare max send transaction
|
|
135
138
|
*/
|
|
136
|
-
prepareMaxTx({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, }: {
|
|
139
|
+
prepareMaxTx({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: {
|
|
137
140
|
sender: Address;
|
|
138
141
|
recipient: Address;
|
|
139
142
|
memo?: string;
|
|
140
143
|
feeRate: FeeRate;
|
|
141
144
|
spendPendingUTXO?: boolean;
|
|
142
145
|
utxoSelectionPreferences?: UtxoSelectionPreferences;
|
|
146
|
+
selectedUtxos?: UTXO[];
|
|
143
147
|
}): Promise<PreparedTx & {
|
|
144
148
|
maxAmount: number;
|
|
145
149
|
fee: number;
|
package/lib/clientKeystore.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FeeRate, TxHash } from '@xchainjs/xchain-client';
|
|
2
2
|
import { Address } from '@xchainjs/xchain-util';
|
|
3
|
-
import { TxParams, UtxoSelectionPreferences } from '@xchainjs/xchain-utxo';
|
|
3
|
+
import { TxParams, UTXO, UtxoSelectionPreferences } from '@xchainjs/xchain-utxo';
|
|
4
4
|
import { Client } from './client';
|
|
5
5
|
/**
|
|
6
6
|
* Custom Doge client extended to support keystore functionality
|
|
@@ -51,6 +51,7 @@ declare class ClientKeystore extends Client {
|
|
|
51
51
|
transfer(params: TxParams & {
|
|
52
52
|
feeRate?: FeeRate;
|
|
53
53
|
utxoSelectionPreferences?: UtxoSelectionPreferences;
|
|
54
|
+
selectedUtxos?: UTXO[];
|
|
54
55
|
}): Promise<TxHash>;
|
|
55
56
|
/**
|
|
56
57
|
* Transfer the maximum amount of Dogecoin (sweep).
|
|
@@ -70,6 +71,7 @@ declare class ClientKeystore extends Client {
|
|
|
70
71
|
feeRate?: FeeRate;
|
|
71
72
|
walletIndex?: number;
|
|
72
73
|
utxoSelectionPreferences?: UtxoSelectionPreferences;
|
|
74
|
+
selectedUtxos?: UTXO[];
|
|
73
75
|
}): Promise<{
|
|
74
76
|
hash: TxHash;
|
|
75
77
|
maxAmount: number;
|
package/lib/clientLedger.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import AppBtc from '@ledgerhq/hw-app-btc';
|
|
2
2
|
import { FeeRate, TxHash } from '@xchainjs/xchain-client';
|
|
3
3
|
import { Address } from '@xchainjs/xchain-util';
|
|
4
|
-
import { TxParams, UtxoClientParams } from '@xchainjs/xchain-utxo';
|
|
4
|
+
import { TxParams, UTXO, UtxoClientParams, UtxoSelectionPreferences } from '@xchainjs/xchain-utxo';
|
|
5
5
|
import { Client } from './client';
|
|
6
6
|
/**
|
|
7
7
|
* Custom Ledger Bitcoin client
|
|
@@ -18,5 +18,17 @@ declare class ClientLedger extends Client {
|
|
|
18
18
|
transfer(params: TxParams & {
|
|
19
19
|
feeRate?: FeeRate;
|
|
20
20
|
}): Promise<TxHash>;
|
|
21
|
+
transferMax(params: {
|
|
22
|
+
recipient: Address;
|
|
23
|
+
memo?: string;
|
|
24
|
+
feeRate?: FeeRate;
|
|
25
|
+
walletIndex?: number;
|
|
26
|
+
utxoSelectionPreferences?: UtxoSelectionPreferences;
|
|
27
|
+
selectedUtxos?: UTXO[];
|
|
28
|
+
}): Promise<{
|
|
29
|
+
hash: TxHash;
|
|
30
|
+
maxAmount: number;
|
|
31
|
+
fee: number;
|
|
32
|
+
}>;
|
|
21
33
|
}
|
|
22
34
|
export { ClientLedger };
|
package/lib/index.esm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getSeed } from '@xchainjs/xchain-crypto';
|
|
|
4
4
|
import * as Dogecoin from 'bitcoinjs-lib';
|
|
5
5
|
import { ECPairFactory } from 'ecpair';
|
|
6
6
|
import { HDKey } from '@scure/bip32';
|
|
7
|
-
import { toBitcoinJS, Client as Client$1, UtxoError } from '@xchainjs/xchain-utxo';
|
|
7
|
+
import { toBitcoinJS, Client as Client$1, UtxoTransactionValidator, UtxoError } from '@xchainjs/xchain-utxo';
|
|
8
8
|
import accumulative from 'coinselect/accumulative.js';
|
|
9
9
|
import { AssetType } from '@xchainjs/xchain-util';
|
|
10
10
|
import { SochainProvider, SochainNetwork, BlockcypherProvider, BlockcypherNetwork, BitgoProvider } from '@xchainjs/xchain-utxo-providers';
|
|
@@ -405,7 +405,7 @@ class Client extends Client$1 {
|
|
|
405
405
|
* Note: Doge uses legacy P2PKH addresses (nonWitnessUtxo)
|
|
406
406
|
*/
|
|
407
407
|
buildTxEnhanced(_a) {
|
|
408
|
-
return __awaiter(this, arguments, void 0, function* ({ amount, recipient, memo, feeRate, sender, spendPendingUTXO = true, utxoSelectionPreferences, }) {
|
|
408
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, recipient, memo, feeRate, sender, spendPendingUTXO = true, utxoSelectionPreferences, selectedUtxos, }) {
|
|
409
409
|
try {
|
|
410
410
|
this.validateTransactionInputs({
|
|
411
411
|
amount,
|
|
@@ -414,8 +414,15 @@ class Client extends Client$1 {
|
|
|
414
414
|
sender,
|
|
415
415
|
feeRate,
|
|
416
416
|
});
|
|
417
|
-
|
|
418
|
-
|
|
417
|
+
let utxos;
|
|
418
|
+
if (selectedUtxos && selectedUtxos.length > 0) {
|
|
419
|
+
UtxoTransactionValidator.validateUtxoSet(selectedUtxos);
|
|
420
|
+
utxos = selectedUtxos;
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
const confirmedOnly = !spendPendingUTXO;
|
|
424
|
+
utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
|
|
425
|
+
}
|
|
419
426
|
const compiledMemo = memo ? this.compileMemo(memo) : null;
|
|
420
427
|
const targetValue = amount.amount().toNumber();
|
|
421
428
|
const extraOutputs = 1 + (compiledMemo ? 1 : 0);
|
|
@@ -460,7 +467,7 @@ class Client extends Client$1 {
|
|
|
460
467
|
* Prepare transaction with enhanced UTXO selection
|
|
461
468
|
*/
|
|
462
469
|
prepareTxEnhanced(_a) {
|
|
463
|
-
return __awaiter(this, arguments, void 0, function* ({ sender, memo, amount, recipient, spendPendingUTXO = true, feeRate, utxoSelectionPreferences, }) {
|
|
470
|
+
return __awaiter(this, arguments, void 0, function* ({ sender, memo, amount, recipient, spendPendingUTXO = true, feeRate, utxoSelectionPreferences, selectedUtxos, }) {
|
|
464
471
|
try {
|
|
465
472
|
const { psbt, utxos, inputs } = yield this.buildTxEnhanced({
|
|
466
473
|
sender,
|
|
@@ -470,6 +477,7 @@ class Client extends Client$1 {
|
|
|
470
477
|
memo,
|
|
471
478
|
spendPendingUTXO,
|
|
472
479
|
utxoSelectionPreferences,
|
|
480
|
+
selectedUtxos,
|
|
473
481
|
});
|
|
474
482
|
return { rawUnsignedTx: psbt.toBase64(), utxos, inputs };
|
|
475
483
|
}
|
|
@@ -485,7 +493,7 @@ class Client extends Client$1 {
|
|
|
485
493
|
* Send maximum possible amount (sweep)
|
|
486
494
|
*/
|
|
487
495
|
sendMax(_a) {
|
|
488
|
-
return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, }) {
|
|
496
|
+
return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, selectedUtxos, }) {
|
|
489
497
|
try {
|
|
490
498
|
if (!this.validateAddress(recipient)) {
|
|
491
499
|
throw UtxoError.invalidAddress(recipient, this.network);
|
|
@@ -493,8 +501,15 @@ class Client extends Client$1 {
|
|
|
493
501
|
if (!this.validateAddress(sender)) {
|
|
494
502
|
throw UtxoError.invalidAddress(sender, this.network);
|
|
495
503
|
}
|
|
496
|
-
|
|
497
|
-
|
|
504
|
+
let utxos;
|
|
505
|
+
if (selectedUtxos && selectedUtxos.length > 0) {
|
|
506
|
+
UtxoTransactionValidator.validateUtxoSet(selectedUtxos);
|
|
507
|
+
utxos = selectedUtxos;
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
const confirmedOnly = !spendPendingUTXO;
|
|
511
|
+
utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
|
|
512
|
+
}
|
|
498
513
|
const maxCalc = this.calculateMaxSendableAmount(utxos, Math.ceil(feeRate), !!memo, utxoSelectionPreferences);
|
|
499
514
|
const compiledMemo = memo ? this.compileMemo(memo) : null;
|
|
500
515
|
const psbt = new Dogecoin.Psbt({ network: dogeNetwork(this.network) });
|
|
@@ -534,7 +549,7 @@ class Client extends Client$1 {
|
|
|
534
549
|
* Prepare max send transaction
|
|
535
550
|
*/
|
|
536
551
|
prepareMaxTx(_a) {
|
|
537
|
-
return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, }) {
|
|
552
|
+
return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, selectedUtxos, }) {
|
|
538
553
|
try {
|
|
539
554
|
const { psbt, utxos, inputs, maxAmount, fee } = yield this.sendMax({
|
|
540
555
|
sender,
|
|
@@ -543,6 +558,7 @@ class Client extends Client$1 {
|
|
|
543
558
|
feeRate,
|
|
544
559
|
spendPendingUTXO,
|
|
545
560
|
utxoSelectionPreferences,
|
|
561
|
+
selectedUtxos,
|
|
546
562
|
});
|
|
547
563
|
return {
|
|
548
564
|
rawUnsignedTx: psbt.toBase64(),
|
|
@@ -649,7 +665,7 @@ class ClientKeystore extends Client {
|
|
|
649
665
|
const dogeKeys = this.getDogeKeys(this.phrase, fromAddressIndex);
|
|
650
666
|
const mergedPreferences = Object.assign({ minimizeFee: true, avoidDust: true, minimizeInputs: false }, params.utxoSelectionPreferences);
|
|
651
667
|
const { rawUnsignedTx } = yield this.prepareTxEnhanced(Object.assign(Object.assign({}, params), { feeRate,
|
|
652
|
-
sender, utxoSelectionPreferences: mergedPreferences }));
|
|
668
|
+
sender, utxoSelectionPreferences: mergedPreferences, selectedUtxos: params.selectedUtxos }));
|
|
653
669
|
const psbt = Dogecoin.Psbt.fromBase64(rawUnsignedTx, { maximumFeeRate: 7500000 });
|
|
654
670
|
psbt.signAllInputs(dogeKeys);
|
|
655
671
|
psbt.finalizeAllInputs();
|
|
@@ -681,6 +697,7 @@ class ClientKeystore extends Client {
|
|
|
681
697
|
memo: params.memo,
|
|
682
698
|
feeRate,
|
|
683
699
|
utxoSelectionPreferences: params.utxoSelectionPreferences,
|
|
700
|
+
selectedUtxos: params.selectedUtxos,
|
|
684
701
|
});
|
|
685
702
|
const dogeKeys = this.getDogeKeys(this.phrase, fromAddressIndex);
|
|
686
703
|
psbt.signAllInputs(dogeKeys);
|
|
@@ -770,6 +787,47 @@ class ClientLedger extends Client {
|
|
|
770
787
|
return txHash;
|
|
771
788
|
});
|
|
772
789
|
}
|
|
790
|
+
// Transfer max DOGE from Ledger (sweep transaction)
|
|
791
|
+
transferMax(params) {
|
|
792
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
793
|
+
const app = yield this.getApp();
|
|
794
|
+
const fromAddressIndex = (params === null || params === void 0 ? void 0 : params.walletIndex) || 0;
|
|
795
|
+
const feeRate = params.feeRate || (yield this.getFeeRates())[FeeOption.Fast];
|
|
796
|
+
checkFeeBounds(this.feeBounds, feeRate);
|
|
797
|
+
const sender = yield this.getAddressAsync(fromAddressIndex);
|
|
798
|
+
const { rawUnsignedTx, inputs, maxAmount, fee } = yield this.prepareMaxTx({
|
|
799
|
+
sender,
|
|
800
|
+
recipient: params.recipient,
|
|
801
|
+
memo: params.memo,
|
|
802
|
+
feeRate,
|
|
803
|
+
utxoSelectionPreferences: params.utxoSelectionPreferences,
|
|
804
|
+
selectedUtxos: params.selectedUtxos,
|
|
805
|
+
});
|
|
806
|
+
const psbt = Dogecoin.Psbt.fromBase64(rawUnsignedTx);
|
|
807
|
+
const ledgerInputs = inputs.map(({ txHex, hash, index }) => {
|
|
808
|
+
if (!txHex) {
|
|
809
|
+
throw Error(`Missing 'txHex' for UTXO (txHash ${hash})`);
|
|
810
|
+
}
|
|
811
|
+
const splittedTx = app.splitTransaction(txHex, false /* no segwit support */);
|
|
812
|
+
return [splittedTx, index, null, null];
|
|
813
|
+
});
|
|
814
|
+
const associatedKeysets = ledgerInputs.map(() => this.getFullDerivationPath(fromAddressIndex));
|
|
815
|
+
const unsignedHex = psbt.data.globalMap.unsignedTx.toBuffer().toString('hex');
|
|
816
|
+
const newTx = app.splitTransaction(unsignedHex, true);
|
|
817
|
+
const outputScriptHex = app.serializeTransactionOutputs(newTx).toString('hex');
|
|
818
|
+
const txHex = yield app.createPaymentTransaction({
|
|
819
|
+
inputs: ledgerInputs,
|
|
820
|
+
associatedKeysets,
|
|
821
|
+
outputScriptHex,
|
|
822
|
+
additionals: [],
|
|
823
|
+
});
|
|
824
|
+
const hash = yield this.broadcastTx(txHex);
|
|
825
|
+
if (!hash) {
|
|
826
|
+
throw Error('No Tx hash');
|
|
827
|
+
}
|
|
828
|
+
return { hash, maxAmount, fee };
|
|
829
|
+
});
|
|
830
|
+
}
|
|
773
831
|
}
|
|
774
832
|
|
|
775
833
|
/**
|
package/lib/index.js
CHANGED
|
@@ -432,7 +432,7 @@ class Client extends xchainUtxo.Client {
|
|
|
432
432
|
* Note: Doge uses legacy P2PKH addresses (nonWitnessUtxo)
|
|
433
433
|
*/
|
|
434
434
|
buildTxEnhanced(_a) {
|
|
435
|
-
return __awaiter(this, arguments, void 0, function* ({ amount, recipient, memo, feeRate, sender, spendPendingUTXO = true, utxoSelectionPreferences, }) {
|
|
435
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, recipient, memo, feeRate, sender, spendPendingUTXO = true, utxoSelectionPreferences, selectedUtxos, }) {
|
|
436
436
|
try {
|
|
437
437
|
this.validateTransactionInputs({
|
|
438
438
|
amount,
|
|
@@ -441,8 +441,15 @@ class Client extends xchainUtxo.Client {
|
|
|
441
441
|
sender,
|
|
442
442
|
feeRate,
|
|
443
443
|
});
|
|
444
|
-
|
|
445
|
-
|
|
444
|
+
let utxos;
|
|
445
|
+
if (selectedUtxos && selectedUtxos.length > 0) {
|
|
446
|
+
xchainUtxo.UtxoTransactionValidator.validateUtxoSet(selectedUtxos);
|
|
447
|
+
utxos = selectedUtxos;
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
const confirmedOnly = !spendPendingUTXO;
|
|
451
|
+
utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
|
|
452
|
+
}
|
|
446
453
|
const compiledMemo = memo ? this.compileMemo(memo) : null;
|
|
447
454
|
const targetValue = amount.amount().toNumber();
|
|
448
455
|
const extraOutputs = 1 + (compiledMemo ? 1 : 0);
|
|
@@ -487,7 +494,7 @@ class Client extends xchainUtxo.Client {
|
|
|
487
494
|
* Prepare transaction with enhanced UTXO selection
|
|
488
495
|
*/
|
|
489
496
|
prepareTxEnhanced(_a) {
|
|
490
|
-
return __awaiter(this, arguments, void 0, function* ({ sender, memo, amount, recipient, spendPendingUTXO = true, feeRate, utxoSelectionPreferences, }) {
|
|
497
|
+
return __awaiter(this, arguments, void 0, function* ({ sender, memo, amount, recipient, spendPendingUTXO = true, feeRate, utxoSelectionPreferences, selectedUtxos, }) {
|
|
491
498
|
try {
|
|
492
499
|
const { psbt, utxos, inputs } = yield this.buildTxEnhanced({
|
|
493
500
|
sender,
|
|
@@ -497,6 +504,7 @@ class Client extends xchainUtxo.Client {
|
|
|
497
504
|
memo,
|
|
498
505
|
spendPendingUTXO,
|
|
499
506
|
utxoSelectionPreferences,
|
|
507
|
+
selectedUtxos,
|
|
500
508
|
});
|
|
501
509
|
return { rawUnsignedTx: psbt.toBase64(), utxos, inputs };
|
|
502
510
|
}
|
|
@@ -512,7 +520,7 @@ class Client extends xchainUtxo.Client {
|
|
|
512
520
|
* Send maximum possible amount (sweep)
|
|
513
521
|
*/
|
|
514
522
|
sendMax(_a) {
|
|
515
|
-
return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, }) {
|
|
523
|
+
return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, selectedUtxos, }) {
|
|
516
524
|
try {
|
|
517
525
|
if (!this.validateAddress(recipient)) {
|
|
518
526
|
throw xchainUtxo.UtxoError.invalidAddress(recipient, this.network);
|
|
@@ -520,8 +528,15 @@ class Client extends xchainUtxo.Client {
|
|
|
520
528
|
if (!this.validateAddress(sender)) {
|
|
521
529
|
throw xchainUtxo.UtxoError.invalidAddress(sender, this.network);
|
|
522
530
|
}
|
|
523
|
-
|
|
524
|
-
|
|
531
|
+
let utxos;
|
|
532
|
+
if (selectedUtxos && selectedUtxos.length > 0) {
|
|
533
|
+
xchainUtxo.UtxoTransactionValidator.validateUtxoSet(selectedUtxos);
|
|
534
|
+
utxos = selectedUtxos;
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
const confirmedOnly = !spendPendingUTXO;
|
|
538
|
+
utxos = yield this.getValidatedUtxos(sender, confirmedOnly);
|
|
539
|
+
}
|
|
525
540
|
const maxCalc = this.calculateMaxSendableAmount(utxos, Math.ceil(feeRate), !!memo, utxoSelectionPreferences);
|
|
526
541
|
const compiledMemo = memo ? this.compileMemo(memo) : null;
|
|
527
542
|
const psbt = new Dogecoin__namespace.Psbt({ network: dogeNetwork(this.network) });
|
|
@@ -561,7 +576,7 @@ class Client extends xchainUtxo.Client {
|
|
|
561
576
|
* Prepare max send transaction
|
|
562
577
|
*/
|
|
563
578
|
prepareMaxTx(_a) {
|
|
564
|
-
return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, }) {
|
|
579
|
+
return __awaiter(this, arguments, void 0, function* ({ sender, recipient, memo, feeRate, spendPendingUTXO = true, utxoSelectionPreferences, selectedUtxos, }) {
|
|
565
580
|
try {
|
|
566
581
|
const { psbt, utxos, inputs, maxAmount, fee } = yield this.sendMax({
|
|
567
582
|
sender,
|
|
@@ -570,6 +585,7 @@ class Client extends xchainUtxo.Client {
|
|
|
570
585
|
feeRate,
|
|
571
586
|
spendPendingUTXO,
|
|
572
587
|
utxoSelectionPreferences,
|
|
588
|
+
selectedUtxos,
|
|
573
589
|
});
|
|
574
590
|
return {
|
|
575
591
|
rawUnsignedTx: psbt.toBase64(),
|
|
@@ -676,7 +692,7 @@ class ClientKeystore extends Client {
|
|
|
676
692
|
const dogeKeys = this.getDogeKeys(this.phrase, fromAddressIndex);
|
|
677
693
|
const mergedPreferences = Object.assign({ minimizeFee: true, avoidDust: true, minimizeInputs: false }, params.utxoSelectionPreferences);
|
|
678
694
|
const { rawUnsignedTx } = yield this.prepareTxEnhanced(Object.assign(Object.assign({}, params), { feeRate,
|
|
679
|
-
sender, utxoSelectionPreferences: mergedPreferences }));
|
|
695
|
+
sender, utxoSelectionPreferences: mergedPreferences, selectedUtxos: params.selectedUtxos }));
|
|
680
696
|
const psbt = Dogecoin__namespace.Psbt.fromBase64(rawUnsignedTx, { maximumFeeRate: 7500000 });
|
|
681
697
|
psbt.signAllInputs(dogeKeys);
|
|
682
698
|
psbt.finalizeAllInputs();
|
|
@@ -708,6 +724,7 @@ class ClientKeystore extends Client {
|
|
|
708
724
|
memo: params.memo,
|
|
709
725
|
feeRate,
|
|
710
726
|
utxoSelectionPreferences: params.utxoSelectionPreferences,
|
|
727
|
+
selectedUtxos: params.selectedUtxos,
|
|
711
728
|
});
|
|
712
729
|
const dogeKeys = this.getDogeKeys(this.phrase, fromAddressIndex);
|
|
713
730
|
psbt.signAllInputs(dogeKeys);
|
|
@@ -797,6 +814,47 @@ class ClientLedger extends Client {
|
|
|
797
814
|
return txHash;
|
|
798
815
|
});
|
|
799
816
|
}
|
|
817
|
+
// Transfer max DOGE from Ledger (sweep transaction)
|
|
818
|
+
transferMax(params) {
|
|
819
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
820
|
+
const app = yield this.getApp();
|
|
821
|
+
const fromAddressIndex = (params === null || params === void 0 ? void 0 : params.walletIndex) || 0;
|
|
822
|
+
const feeRate = params.feeRate || (yield this.getFeeRates())[xchainClient.FeeOption.Fast];
|
|
823
|
+
xchainClient.checkFeeBounds(this.feeBounds, feeRate);
|
|
824
|
+
const sender = yield this.getAddressAsync(fromAddressIndex);
|
|
825
|
+
const { rawUnsignedTx, inputs, maxAmount, fee } = yield this.prepareMaxTx({
|
|
826
|
+
sender,
|
|
827
|
+
recipient: params.recipient,
|
|
828
|
+
memo: params.memo,
|
|
829
|
+
feeRate,
|
|
830
|
+
utxoSelectionPreferences: params.utxoSelectionPreferences,
|
|
831
|
+
selectedUtxos: params.selectedUtxos,
|
|
832
|
+
});
|
|
833
|
+
const psbt = Dogecoin__namespace.Psbt.fromBase64(rawUnsignedTx);
|
|
834
|
+
const ledgerInputs = inputs.map(({ txHex, hash, index }) => {
|
|
835
|
+
if (!txHex) {
|
|
836
|
+
throw Error(`Missing 'txHex' for UTXO (txHash ${hash})`);
|
|
837
|
+
}
|
|
838
|
+
const splittedTx = app.splitTransaction(txHex, false /* no segwit support */);
|
|
839
|
+
return [splittedTx, index, null, null];
|
|
840
|
+
});
|
|
841
|
+
const associatedKeysets = ledgerInputs.map(() => this.getFullDerivationPath(fromAddressIndex));
|
|
842
|
+
const unsignedHex = psbt.data.globalMap.unsignedTx.toBuffer().toString('hex');
|
|
843
|
+
const newTx = app.splitTransaction(unsignedHex, true);
|
|
844
|
+
const outputScriptHex = app.serializeTransactionOutputs(newTx).toString('hex');
|
|
845
|
+
const txHex = yield app.createPaymentTransaction({
|
|
846
|
+
inputs: ledgerInputs,
|
|
847
|
+
associatedKeysets,
|
|
848
|
+
outputScriptHex,
|
|
849
|
+
additionals: [],
|
|
850
|
+
});
|
|
851
|
+
const hash = yield this.broadcastTx(txHex);
|
|
852
|
+
if (!hash) {
|
|
853
|
+
throw Error('No Tx hash');
|
|
854
|
+
}
|
|
855
|
+
return { hash, maxAmount, fee };
|
|
856
|
+
});
|
|
857
|
+
}
|
|
800
858
|
}
|
|
801
859
|
|
|
802
860
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xchainjs/xchain-doge",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Custom Doge client and utilities used by XChain clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Xchain",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@xchainjs/xchain-client": "2.0.10",
|
|
40
40
|
"@xchainjs/xchain-crypto": "1.0.6",
|
|
41
41
|
"@xchainjs/xchain-util": "2.0.5",
|
|
42
|
-
"@xchainjs/xchain-utxo": "2.1
|
|
43
|
-
"@xchainjs/xchain-utxo-providers": "2.0.
|
|
42
|
+
"@xchainjs/xchain-utxo": "2.2.1",
|
|
43
|
+
"@xchainjs/xchain-utxo-providers": "2.0.11",
|
|
44
44
|
"bitcoinjs-lib": "^6.1.7",
|
|
45
45
|
"coinselect": "3.1.12",
|
|
46
46
|
"ecpair": "2.1.0"
|