Skip to content

Commit 88b0fbd

Browse files
committed
feat(data): ♻️ batch generate utils for xkeys
1 parent 7e73b65 commit 88b0fbd

File tree

1 file changed

+55
-13
lines changed

1 file changed

+55
-13
lines changed

src/helpers/wallet.js

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import blake from 'blakejs'
2727
import { keccak_256 } from '@noble/hashes/sha3'
2828

2929
// @ts-ignore
30-
let dashsight = DashSight.create({
30+
export const dashsight = DashSight.create({
3131
baseUrl: 'https://insight.dash.org',
3232
// baseUrl: 'https://dashsight.dashincubator.dev',
3333
});
@@ -559,16 +559,34 @@ export async function encryptKeystore(
559559
}
560560

561561
export async function generateAddressIterator(
562+
xkey,
563+
xkeyId,
564+
addressIndex,
565+
) {
566+
let key = await xkey.deriveAddress(addressIndex);
567+
let address = await DashHd.toAddr(key.publicKey);
568+
569+
return {
570+
address,
571+
addressIndex,
572+
usageIndex: xkey.index,
573+
xkeyId,
574+
}
575+
}
576+
577+
export async function generateAndStoreAddressIterator(
562578
xkey,
563579
xkeyId,
564580
walletId,
565581
accountIndex,
566582
addressIndex,
567583
usageIndex = DashHd.RECEIVE,
568584
) {
569-
// let xkeyId = await DashHd.toId(xkey);
570-
let key = await xkey.deriveAddress(addressIndex);
571-
let address = await DashHd.toAddr(key.publicKey);
585+
let { address } = await generateAddressIterator(
586+
xkey,
587+
xkeyId,
588+
addressIndex,
589+
)
572590

573591
// console.log(
574592
// 'generateAddressIterator',
@@ -606,6 +624,30 @@ export async function generateAddressIterator(
606624
}
607625
}
608626

627+
export async function batchXkeyAddressGenerate(
628+
wallet,
629+
addressIndex = 0,
630+
batchSize = 20,
631+
) {
632+
let batchLimit = addressIndex + batchSize
633+
let addresses = []
634+
635+
for (let addrIdx = addressIndex; addrIdx < batchLimit; addrIdx++) {
636+
addresses.push(
637+
await generateAddressIterator(
638+
wallet.xkey,
639+
wallet.xkeyId,
640+
addrIdx,
641+
)
642+
)
643+
}
644+
645+
return {
646+
addresses,
647+
finalAddressIndex: batchLimit,
648+
}
649+
}
650+
609651
export async function batchAddressGenerate(
610652
wallet,
611653
accountIndex = 0,
@@ -628,7 +670,7 @@ export async function batchAddressGenerate(
628670

629671
for (let addrIdx = addressIndex; addrIdx < batchLimit; addrIdx++) {
630672
addresses.push(
631-
await generateAddressIterator(
673+
await generateAndStoreAddressIterator(
632674
xkey,
633675
xkeyId,
634676
wallet.id,
@@ -667,7 +709,7 @@ export async function batchAddressUsageGenerate(
667709

668710
for (let addrIdx = addressIndex; addrIdx < batchLimit; addrIdx++) {
669711
addresses.push(
670-
await generateAddressIterator(
712+
await generateAndStoreAddressIterator(
671713
xkeyReceive,
672714
xkeyId,
673715
wallet.id,
@@ -677,7 +719,7 @@ export async function batchAddressUsageGenerate(
677719
)
678720
)
679721
addresses.push(
680-
await generateAddressIterator(
722+
await generateAndStoreAddressIterator(
681723
xkeyChange,
682724
xkeyId,
683725
wallet.id,
@@ -1305,9 +1347,9 @@ export async function deriveTxWallet(
13051347
coreUtxos = await dashsight.getMultiCoreUtxos(
13061348
Object.keys(privateKeys)
13071349
)
1308-
transactions = await dashsight.getAllTxs(
1309-
Object.keys(privateKeys)
1310-
)
1350+
// transactions = await dashsight.getAllTxs(
1351+
// Object.keys(privateKeys)
1352+
// )
13111353
} else {
13121354
tmpWallet = await deriveWalletData(
13131355
fromWallet.recoveryPhrase,
@@ -1327,9 +1369,9 @@ export async function deriveTxWallet(
13271369
coreUtxos = await dashsight.getCoreUtxos(
13281370
tmpWallet.address
13291371
)
1330-
transactions = await dashsight.getAllTxs(
1331-
[tmpWallet.address]
1332-
)
1372+
// transactions = await dashsight.getAllTxs(
1373+
// [tmpWallet.address]
1374+
// )
13331375
}
13341376

13351377
console.log('getAllTxs', transactions)

0 commit comments

Comments
 (0)