/* Arching Kaos Stellar Network * * Kaotisk Hund - 2024 * * @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 * */ 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")){ var small = document.createElement("span"); small.id = 'stellar-participants-sum'; stats.appendChild(small); } document.querySelector("#stellar-participants-sum").innerText = ' (' + number + ')'; archingKaosLog("Loading trustlines... Found "+number+"!"); progressPlaceholder.value++; stellarParticipants=number; stellarParticipantsScanned=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 ( index in records ){ holders.push(records[index].account_id); progressPlaceholder.max++; renderStellarAddress(records[index].account_id); checkAddressForConfigurationVariable(records[index].account_id); } if (json._links.next) getHolders(json._links.next.href); } function renderConfigurationIPNSLinkAndProceed(json, stellarAddress){ renderStellarAddress(stellarAddress); document.querySelector('#'+stellarAddress).style="color: #3dbb3d;" stellarNetworkConfiguredAddresses += 1; console.log(atob(json.value)); console.log(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); } archingKaosLog("Searching holders... Done!"); } function getStellarConfigurationVariableURL(stellarAddress){ return settings.stellar.horizon.list[settings.stellar.horizon.active]+ 'accounts/'+ stellarAddress+ '/data/'+ settings.stellar.variableNames.list[settings.stellar.variableNames.active]; } function checkAddressForConfigurationVariable(stellarAddress) { archingKaosLog("Checking configuration for "+ stellarAddress+ "..."); archingKaosFetchJSON(getStellarConfigurationVariableURL(stellarAddress), renderConfigurationIPNSLinkAndProceed, stellarAddress); progressPlaceholder.value++; } var server = new StellarSdk.Server(settings.stellar.horizon.list[settings.stellar.horizon.active], {allowHttp:true}); 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){ console.log("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(); // console.log(result); // } } function scanStellarNetworkForPeers(){ getTrustlines(); getHolders(); } // vim: tabstop=4 shiftwidth=4 expandtab softtabstop=4 // @license-end