@@ -17,6 +17,7 @@ import {
17
17
batchGenAccts ,
18
18
batchGenAcctAddrs ,
19
19
batchGenAcctsAddrs ,
20
+ batchXkeyAddressGenerate ,
20
21
updateAllFunds ,
21
22
decryptKeystore ,
22
23
getStoredItems ,
@@ -28,6 +29,7 @@ import {
28
29
storedData ,
29
30
getUnusedChangeAddress ,
30
31
getAccountWallet ,
32
+ dashsight ,
31
33
} from './helpers/wallet.js'
32
34
33
35
import {
@@ -499,8 +501,8 @@ async function main() {
499
501
} )
500
502
501
503
appDialogs . addContact = await addContactRig ( {
502
- setupDialog, updateAllFunds,
503
- appDialogs, appState, appTools, store,
504
+ setupDialog, updateAllFunds, batchXkeyAddressGenerate ,
505
+ appDialogs, appState, appTools, store, dashsight ,
504
506
mainApp, wallet, userInfo, contactsList,
505
507
} )
506
508
@@ -742,7 +744,7 @@ async function main() {
742
744
743
745
getStoreData (
744
746
store . contacts ,
745
- res => {
747
+ async res => {
746
748
if ( res ) {
747
749
appState . contacts = res
748
750
@@ -751,7 +753,101 @@ async function main() {
751
753
userInfo,
752
754
} )
753
755
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 )
755
851
}
756
852
} ,
757
853
res => async v => {
0 commit comments