1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
// Arching Kaos Stellar Network
//
// Kaotisk Hund - 2024
//
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
//
import { archingKaosLog } from "./arching-kaos-log.js";
import { archingKaosFetchJSON } from "./arching-kaos-fetch.js";
import {
getStellarConfigurationVariableURL,
getTrustlinesURL,
getHoldersOfActiveAssetURL
} from "./url-generators.js";
import { progressPlaceholder } from "./app.js";
import {
increaseStellarNetworkConfiguredAddresses,
addToFoundHolders,
setStellarParticipants,
setStellarParticipantsScanned
} from "./environment-setup.js";
import { makeElement } from "./arching-kaos-generator.js";
import { getConfiguration } from "./arching-kaos-tools.js";
import { debugLog } from "./utils.js";
var lastPage = '';
function getNumberOfTrustlinesAndRenderThem(json){
var number = json._embedded.records[0].accounts.authorized;
var stats = document.querySelector('.stellar-network').querySelector('summary');
if(!document.querySelector("#stellar-participants-sum")){
makeElement({element: "span", id: 'stellar-participants-sum', innerText: `( ${number} )`}, stats);
}
archingKaosLog("Loading trustlines... Found "+number+"!");
progressPlaceholder().value++;
setStellarParticipants(number);
setStellarParticipantsScanned(number);
}
function renderStellarAddress(stellarAddress){
if (!document.querySelector('.stellar-network').querySelector('#'+stellarAddress)){
var stats = document.querySelector('.stellar-network');
var d = {
element:"details",
className:"stellar-address",
innerHTML:[
{element:"summary", innerText:stellarAddress, id:stellarAddress}
]
};
makeElement(d, stats);
}
}
function renderStellarAddressesAndProceed(json){
var records = json._embedded.records;
for ( var i = 0; i < records.length; i++ ){
addToFoundHolders(records[i].account_id);
progressPlaceholder().max++;
renderStellarAddress(records[i].account_id);
checkAddressForConfigurationVariable(records[i].account_id);
}
if (json._links.next) getHolders(json._links.next.href);
}
function renderConfigurationIPNSLinkAndProceed(json, stellarAddress){
renderStellarAddress(stellarAddress);
document.querySelector('#'+stellarAddress).style="color: #3dbb3d;"
increaseStellarNetworkConfiguredAddresses();
debugLog(atob(json.value));
debugLog(stellarAddress);
getConfiguration(atob(json.value),stellarAddress);
}
function getTrustlines(){
archingKaosLog("Loading trustlines...");
archingKaosFetchJSON(getTrustlinesURL(), getNumberOfTrustlinesAndRenderThem);
}
function getHolders(a=0){
var doIt = true
archingKaosLog("Searching holders...");
var url = '';
if ( a === 0 ) {
url=getHoldersOfActiveAssetURL();
} else {
if ( lastPage === '' ) {
url = a;
} else {
if ( a !== lastPage ) {
url = a;
} else {
doIt = false;
}
}
}
lastPage=url;
if (doIt) {
archingKaosFetchJSON(url, renderStellarAddressesAndProceed, null);
}
archingKaosLog("Searching holders... Done!");
}
function checkAddressForConfigurationVariable(stellarAddress) {
archingKaosLog("Checking configuration for "+ stellarAddress+ "...");
archingKaosFetchJSON(getStellarConfigurationVariableURL(stellarAddress), renderConfigurationIPNSLinkAndProceed, stellarAddress);
progressPlaceholder().value++;
}
function steptwo(i){
var ta=document.querySelector("#stellar-balances-table");
for (b in i.balances) {
x = i.balances[b];
var amount = {
element:"tr",
innerHTML:[
{ element:"td", innerText: x.balance },
{ element:"td", innerText: ( x.asset_code && x.asset_code != "undefined" ? x.asset_code : 'XLM')}
]
}
makeElement(amount, ta);
progressPlaceholder().max++;
progressPlaceholder().value++;
if(document.querySelector("#stellar-balances-not-found")) document.querySelector("#stellar-balances-not-found").hidden = true;
}
}
function letme(a){
debugLog("HERE WE GO");
server.accounts()
.accountId(a)
.call()
.then(
steptwo(r)
);
}
async function fetchNodeInfoFromClientWallet(stellarAddress){
archingKaosLog("Loading your profile...");
fetch(getStellarConfigurationVariableURL(stellarAddress), {
method:'GET',
headers:{
Accept: 'application/json'
}
}).then(response=>{
if(response.ok){
response.json().then(json=>{
var cnf = {
element:"p",
innerText:atob(json.value)
};
makeElement(cnf, document.querySelector('#stellar-data-config'));
progressPlaceholder().max++;
progressPlaceholder().value++;
getConfiguration(atob(json.value),stellarAddress);
});
}
});
}
function putKeyToField(k){
const address = k;
var base = document.querySelector("#stellar-freigher-connect-address-button");
base.innerText=address;
base.onclick='';
stellar_connection_status = 1;
checkAddressForConfigurationVariable(k);
}
// That's how we get the publicKey
const retrievePublicKey = async () => {
let publicKey = "";
let error = "";
try {
publicKey = await window.freighterApi.getPublicKey()
.then((publicKey) => {putKeyToField(publicKey);letme(publicKey)});
} catch (e) {
error = e;
}
if (error) {
return error;
}
return publicKey;
};
function connect(){
// if ( stellar_connection_status === 1 ){
// showStellar();
// } else {
const result = retrievePublicKey();
// debugLog(result);
// }
}
export function scanStellarNetworkForPeers(){
getTrustlines();
getHolders();
}
// vim: tabstop=4 shiftwidth=4 expandtab softtabstop=4
// @license-end
|