Skip to content

Commit 4ed124b

Browse files
committed
feat(data): ✨ batch gen addrs for contacts list outgoing
1 parent da9bdb2 commit 4ed124b

File tree

1 file changed

+100
-4
lines changed

1 file changed

+100
-4
lines changed

src/main.js

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
batchGenAccts,
1818
batchGenAcctAddrs,
1919
batchGenAcctsAddrs,
20+
batchXkeyAddressGenerate,
2021
updateAllFunds,
2122
decryptKeystore,
2223
getStoredItems,
@@ -28,6 +29,7 @@ import {
2829
storedData,
2930
getUnusedChangeAddress,
3031
getAccountWallet,
32+
dashsight,
3133
} from './helpers/wallet.js'
3234

3335
import {
@@ -499,8 +501,8 @@ async function main() {
499501
})
500502

501503
appDialogs.addContact = await addContactRig({
502-
setupDialog, updateAllFunds,
503-
appDialogs, appState, appTools, store,
504+
setupDialog, updateAllFunds, batchXkeyAddressGenerate,
505+
appDialogs, appState, appTools, store, dashsight,
504506
mainApp, wallet, userInfo, contactsList,
505507
})
506508

@@ -742,7 +744,7 @@ async function main() {
742744

743745
getStoreData(
744746
store.contacts,
745-
res => {
747+
async res => {
746748
if (res) {
747749
appState.contacts = res
748750

@@ -751,7 +753,101 @@ async function main() {
751753
userInfo,
752754
})
753755

754-
console.log('contacts', res)
756+
let allContactAddrs = {}
757+
758+
for await (let c of appState.contacts) {
759+
let og = Object.values(c.outgoing)?.[0]
760+
let xkey = og.xpub || og.xprv
761+
if (xkey) {
762+
let contactWallet = await deriveWalletData(
763+
xkey,
764+
)
765+
let contactAddrs = await batchXkeyAddressGenerate(
766+
contactWallet,
767+
contactWallet.addressIndex,
768+
)
769+
770+
contactAddrs.addresses.forEach(g => {
771+
allContactAddrs[g.address] = {
772+
alias: c.alias,
773+
xkeyId: contactWallet.xkeyId,
774+
}
775+
})
776+
}
777+
}
778+
779+
dashsight.getAllTxs(
780+
Object.keys(allContactAddrs)
781+
).then(txs => {
782+
console.log('contacts txs', txs)
783+
let contactTxs = {}
784+
let contactTxsByAlias = {}
785+
786+
for (let tx of txs) {
787+
let conAddr
788+
for (let vin of tx.vin) {
789+
let addr = vin.addr
790+
conAddr = allContactAddrs[
791+
addr
792+
]
793+
if (conAddr) {
794+
contactTxsByAlias[conAddr.alias] = {
795+
...(contactTxsByAlias[conAddr.alias] || []),
796+
[tx.txid]: {
797+
addr,
798+
...tx,
799+
...conAddr,
800+
}
801+
}
802+
contactTxs[addr] = [
803+
...(contactTxs[addr] || []),
804+
{
805+
...tx,
806+
...conAddr,
807+
}
808+
]
809+
810+
console.log(
811+
'contact tx',
812+
conAddr.alias, conAddr.xkeyId, tx,
813+
)
814+
}
815+
}
816+
for (let vout of tx.vout) {
817+
let addr = vout.scriptPubKey.addresses[0]
818+
conAddr = allContactAddrs[
819+
addr
820+
]
821+
if (conAddr) {
822+
contactTxsByAlias[conAddr.alias] = {
823+
...(contactTxsByAlias[conAddr.alias] || []),
824+
[tx.txid]: {
825+
addr,
826+
...tx,
827+
...conAddr,
828+
}
829+
}
830+
contactTxs[addr] = [
831+
...(contactTxs[addr] || []),
832+
{
833+
...tx,
834+
...conAddr,
835+
}
836+
]
837+
838+
console.log(
839+
'contact tx',
840+
conAddr.alias, conAddr.xkeyId, tx,
841+
)
842+
}
843+
}
844+
}
845+
846+
console.log('contactTxsByAlias', contactTxsByAlias)
847+
console.log('contactTxs', contactTxs)
848+
})
849+
850+
console.log('contacts', res, allContactAddrs)
755851
}
756852
},
757853
res => async v => {

0 commit comments

Comments
 (0)