@arkade-os/sdk 0.3.1-alpha.7 → 0.3.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/cjs/utils/arkTransaction.js +1 -1
- package/dist/cjs/wallet/serviceWorker/worker.js +5 -8
- package/dist/cjs/wallet/wallet.js +8 -10
- package/dist/esm/utils/arkTransaction.js +1 -1
- package/dist/esm/wallet/serviceWorker/worker.js +5 -8
- package/dist/esm/wallet/wallet.js +8 -10
- package/dist/types/wallet/serviceWorker/response.d.ts +3 -3
- package/package.json +1 -1
|
@@ -112,7 +112,7 @@ function hasBoardingTxExpired(coin, boardingTimelock) {
|
|
|
112
112
|
return false;
|
|
113
113
|
if (boardingTimelock.value === 0n)
|
|
114
114
|
return true;
|
|
115
|
-
if (boardingTimelock.type
|
|
115
|
+
if (boardingTimelock.type === "blocks")
|
|
116
116
|
return false; // TODO: handle get chain tip
|
|
117
117
|
// validate expiry in terms of seconds
|
|
118
118
|
const now = BigInt(Math.floor(Date.now() / 1000));
|
|
@@ -139,19 +139,16 @@ class Worker {
|
|
|
139
139
|
...spentVtxos,
|
|
140
140
|
]);
|
|
141
141
|
// notify all clients about the vtxo update
|
|
142
|
-
this.sendMessageToAllClients(response_1.Response.vtxoUpdate(newVtxos, spentVtxos));
|
|
142
|
+
await this.sendMessageToAllClients(response_1.Response.vtxoUpdate(newVtxos, spentVtxos));
|
|
143
143
|
}
|
|
144
144
|
if (funds.type === "utxo") {
|
|
145
|
-
const
|
|
146
|
-
if (newUtxos.length === 0) {
|
|
147
|
-
this.sendMessageToAllClients(response_1.Response.utxoUpdate([]));
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
145
|
+
const utxos = funds.coins.map((utxo) => (0, utils_1.extendCoin)(this.wallet, utxo));
|
|
150
146
|
const boardingAddress = await this.wallet?.getBoardingAddress();
|
|
151
147
|
// save utxos using unified repository
|
|
152
|
-
await this.walletRepository.
|
|
148
|
+
await this.walletRepository.clearUtxos(boardingAddress);
|
|
149
|
+
await this.walletRepository.saveUtxos(boardingAddress, utxos);
|
|
153
150
|
// notify all clients about the utxo update
|
|
154
|
-
this.sendMessageToAllClients(response_1.Response.utxoUpdate(
|
|
151
|
+
await this.sendMessageToAllClients(response_1.Response.utxoUpdate(utxos));
|
|
155
152
|
}
|
|
156
153
|
});
|
|
157
154
|
}
|
|
@@ -512,8 +512,8 @@ class Wallet {
|
|
|
512
512
|
...params.inputs.map((input) => `${input.txid}:${input.vout}`),
|
|
513
513
|
];
|
|
514
514
|
const settlementStream = this.arkProvider.getEventStream(abortController.signal, topics);
|
|
515
|
-
//
|
|
516
|
-
let
|
|
515
|
+
// batchId, sweepTapTreeRoot and forfeitOutputScript are set once the BatchStarted event is received
|
|
516
|
+
let batchId;
|
|
517
517
|
let sweepTapTreeRoot;
|
|
518
518
|
const vtxoChunks = [];
|
|
519
519
|
const connectorsChunks = [];
|
|
@@ -526,11 +526,7 @@ class Wallet {
|
|
|
526
526
|
switch (event.type) {
|
|
527
527
|
// the settlement failed
|
|
528
528
|
case ark_1.SettlementEventType.BatchFailed:
|
|
529
|
-
|
|
530
|
-
if (event.id === roundId) {
|
|
531
|
-
throw new Error(event.reason);
|
|
532
|
-
}
|
|
533
|
-
break;
|
|
529
|
+
throw new Error(event.reason);
|
|
534
530
|
case ark_1.SettlementEventType.BatchStarted:
|
|
535
531
|
if (step !== undefined) {
|
|
536
532
|
continue;
|
|
@@ -539,7 +535,7 @@ class Wallet {
|
|
|
539
535
|
if (!res.skip) {
|
|
540
536
|
step = event.type;
|
|
541
537
|
sweepTapTreeRoot = res.sweepTapTreeRoot;
|
|
542
|
-
|
|
538
|
+
batchId = res.roundId;
|
|
543
539
|
if (!hasOffchainOutputs) {
|
|
544
540
|
// if there are no offchain outputs, we don't have to handle musig2 tree signatures
|
|
545
541
|
// we can directly advance to the finalization step
|
|
@@ -644,8 +640,10 @@ class Wallet {
|
|
|
644
640
|
if (step !== ark_1.SettlementEventType.BatchFinalization) {
|
|
645
641
|
continue;
|
|
646
642
|
}
|
|
647
|
-
|
|
648
|
-
|
|
643
|
+
if (event.id === batchId) {
|
|
644
|
+
abortController.abort();
|
|
645
|
+
return event.commitmentTxid;
|
|
646
|
+
}
|
|
649
647
|
}
|
|
650
648
|
}
|
|
651
649
|
}
|
|
@@ -107,7 +107,7 @@ export function hasBoardingTxExpired(coin, boardingTimelock) {
|
|
|
107
107
|
return false;
|
|
108
108
|
if (boardingTimelock.value === 0n)
|
|
109
109
|
return true;
|
|
110
|
-
if (boardingTimelock.type
|
|
110
|
+
if (boardingTimelock.type === "blocks")
|
|
111
111
|
return false; // TODO: handle get chain tip
|
|
112
112
|
// validate expiry in terms of seconds
|
|
113
113
|
const now = BigInt(Math.floor(Date.now() / 1000));
|
|
@@ -136,19 +136,16 @@ export class Worker {
|
|
|
136
136
|
...spentVtxos,
|
|
137
137
|
]);
|
|
138
138
|
// notify all clients about the vtxo update
|
|
139
|
-
this.sendMessageToAllClients(Response.vtxoUpdate(newVtxos, spentVtxos));
|
|
139
|
+
await this.sendMessageToAllClients(Response.vtxoUpdate(newVtxos, spentVtxos));
|
|
140
140
|
}
|
|
141
141
|
if (funds.type === "utxo") {
|
|
142
|
-
const
|
|
143
|
-
if (newUtxos.length === 0) {
|
|
144
|
-
this.sendMessageToAllClients(Response.utxoUpdate([]));
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
142
|
+
const utxos = funds.coins.map((utxo) => extendCoin(this.wallet, utxo));
|
|
147
143
|
const boardingAddress = await this.wallet?.getBoardingAddress();
|
|
148
144
|
// save utxos using unified repository
|
|
149
|
-
await this.walletRepository.
|
|
145
|
+
await this.walletRepository.clearUtxos(boardingAddress);
|
|
146
|
+
await this.walletRepository.saveUtxos(boardingAddress, utxos);
|
|
150
147
|
// notify all clients about the utxo update
|
|
151
|
-
this.sendMessageToAllClients(Response.utxoUpdate(
|
|
148
|
+
await this.sendMessageToAllClients(Response.utxoUpdate(utxos));
|
|
152
149
|
}
|
|
153
150
|
});
|
|
154
151
|
}
|
|
@@ -475,8 +475,8 @@ export class Wallet {
|
|
|
475
475
|
...params.inputs.map((input) => `${input.txid}:${input.vout}`),
|
|
476
476
|
];
|
|
477
477
|
const settlementStream = this.arkProvider.getEventStream(abortController.signal, topics);
|
|
478
|
-
//
|
|
479
|
-
let
|
|
478
|
+
// batchId, sweepTapTreeRoot and forfeitOutputScript are set once the BatchStarted event is received
|
|
479
|
+
let batchId;
|
|
480
480
|
let sweepTapTreeRoot;
|
|
481
481
|
const vtxoChunks = [];
|
|
482
482
|
const connectorsChunks = [];
|
|
@@ -489,11 +489,7 @@ export class Wallet {
|
|
|
489
489
|
switch (event.type) {
|
|
490
490
|
// the settlement failed
|
|
491
491
|
case SettlementEventType.BatchFailed:
|
|
492
|
-
|
|
493
|
-
if (event.id === roundId) {
|
|
494
|
-
throw new Error(event.reason);
|
|
495
|
-
}
|
|
496
|
-
break;
|
|
492
|
+
throw new Error(event.reason);
|
|
497
493
|
case SettlementEventType.BatchStarted:
|
|
498
494
|
if (step !== undefined) {
|
|
499
495
|
continue;
|
|
@@ -502,7 +498,7 @@ export class Wallet {
|
|
|
502
498
|
if (!res.skip) {
|
|
503
499
|
step = event.type;
|
|
504
500
|
sweepTapTreeRoot = res.sweepTapTreeRoot;
|
|
505
|
-
|
|
501
|
+
batchId = res.roundId;
|
|
506
502
|
if (!hasOffchainOutputs) {
|
|
507
503
|
// if there are no offchain outputs, we don't have to handle musig2 tree signatures
|
|
508
504
|
// we can directly advance to the finalization step
|
|
@@ -607,8 +603,10 @@ export class Wallet {
|
|
|
607
603
|
if (step !== SettlementEventType.BatchFinalization) {
|
|
608
604
|
continue;
|
|
609
605
|
}
|
|
610
|
-
|
|
611
|
-
|
|
606
|
+
if (event.id === batchId) {
|
|
607
|
+
abortController.abort();
|
|
608
|
+
return event.commitmentTxid;
|
|
609
|
+
}
|
|
612
610
|
}
|
|
613
611
|
}
|
|
614
612
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletBalance, VirtualCoin, ArkTransaction, IWallet,
|
|
1
|
+
import { WalletBalance, VirtualCoin, ArkTransaction, IWallet, ExtendedCoin } from "..";
|
|
2
2
|
import { ExtendedVirtualCoin } from "../..";
|
|
3
3
|
import { SettlementEvent } from "../../providers/ark";
|
|
4
4
|
/**
|
|
@@ -116,8 +116,8 @@ export declare namespace Response {
|
|
|
116
116
|
function vtxoUpdate(newVtxos: ExtendedVirtualCoin[], spentVtxos: ExtendedVirtualCoin[]): VtxoUpdate;
|
|
117
117
|
interface UtxoUpdate extends Base {
|
|
118
118
|
type: "UTXO_UPDATE";
|
|
119
|
-
coins:
|
|
119
|
+
coins: ExtendedCoin[];
|
|
120
120
|
}
|
|
121
121
|
function isUtxoUpdate(response: Base): response is UtxoUpdate;
|
|
122
|
-
function utxoUpdate(coins:
|
|
122
|
+
function utxoUpdate(coins: ExtendedCoin[]): UtxoUpdate;
|
|
123
123
|
}
|