Skip to content

Commit

Permalink
feat(data): ✨ batch gen addrs for contacts list outgoing
Browse files Browse the repository at this point in the history
  • Loading branch information
jojobyte committed Apr 13, 2024
1 parent da9bdb2 commit 4ed124b
Showing 1 changed file with 100 additions and 4 deletions.
104 changes: 100 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
batchGenAccts,
batchGenAcctAddrs,
batchGenAcctsAddrs,
batchXkeyAddressGenerate,
updateAllFunds,
decryptKeystore,
getStoredItems,
Expand All @@ -28,6 +29,7 @@ import {
storedData,
getUnusedChangeAddress,
getAccountWallet,
dashsight,
} from './helpers/wallet.js'

import {
Expand Down Expand Up @@ -499,8 +501,8 @@ async function main() {
})

appDialogs.addContact = await addContactRig({
setupDialog, updateAllFunds,
appDialogs, appState, appTools, store,
setupDialog, updateAllFunds, batchXkeyAddressGenerate,
appDialogs, appState, appTools, store, dashsight,
mainApp, wallet, userInfo, contactsList,
})

Expand Down Expand Up @@ -742,7 +744,7 @@ async function main() {

getStoreData(
store.contacts,
res => {
async res => {
if (res) {
appState.contacts = res

Expand All @@ -751,7 +753,101 @@ async function main() {
userInfo,
})

console.log('contacts', res)
let allContactAddrs = {}

for await (let c of appState.contacts) {
let og = Object.values(c.outgoing)?.[0]
let xkey = og.xpub || og.xprv
if (xkey) {
let contactWallet = await deriveWalletData(
xkey,
)
let contactAddrs = await batchXkeyAddressGenerate(
contactWallet,
contactWallet.addressIndex,
)

contactAddrs.addresses.forEach(g => {
allContactAddrs[g.address] = {
alias: c.alias,
xkeyId: contactWallet.xkeyId,
}
})
}
}

dashsight.getAllTxs(
Object.keys(allContactAddrs)
).then(txs => {
console.log('contacts txs', txs)
let contactTxs = {}
let contactTxsByAlias = {}

for (let tx of txs) {
let conAddr
for (let vin of tx.vin) {
let addr = vin.addr
conAddr = allContactAddrs[
addr
]
if (conAddr) {
contactTxsByAlias[conAddr.alias] = {
...(contactTxsByAlias[conAddr.alias] || []),
[tx.txid]: {
addr,
...tx,
...conAddr,
}
}
contactTxs[addr] = [
...(contactTxs[addr] || []),
{
...tx,
...conAddr,
}
]

console.log(
'contact tx',
conAddr.alias, conAddr.xkeyId, tx,
)
}
}
for (let vout of tx.vout) {
let addr = vout.scriptPubKey.addresses[0]
conAddr = allContactAddrs[
addr
]
if (conAddr) {
contactTxsByAlias[conAddr.alias] = {
...(contactTxsByAlias[conAddr.alias] || []),
[tx.txid]: {
addr,
...tx,
...conAddr,
}
}
contactTxs[addr] = [
...(contactTxs[addr] || []),
{
...tx,
...conAddr,
}
]

console.log(
'contact tx',
conAddr.alias, conAddr.xkeyId, tx,
)
}
}
}

console.log('contactTxsByAlias', contactTxsByAlias)
console.log('contactTxs', contactTxs)
})

console.log('contacts', res, allContactAddrs)
}
},
res => async v => {
Expand Down

0 comments on commit 4ed124b

Please sign in to comment.