Skip to content

Commit

Permalink
Remove UTXO sync mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JSKitty committed Nov 28, 2022
1 parent fb83020 commit 52d27fe
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 104 deletions.
6 changes: 0 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
<li class="nav-item"><a class="nav-link tablinks active" id="Testnet" onclick="toggleTestnet()"></a></li>
<li class="nav-item"><a class="nav-link tablinks active" id="Network" onclick="toggleNetwork()"></a></li>
<li class="nav-item"><a class="nav-link tablinks active" id="Debug" onclick="toggleDebug()"></a></li>
<li class="nav-item"><a class="nav-link tablinks active" id="SyncMode" onclick="toggleSyncMode()"></a></li>
</ul>
</div>

Expand Down Expand Up @@ -854,11 +853,6 @@ <h4 id="signed-raw">Signed Raw Transaction</h4>
<span class="buttoni-text">Toggle Debug Mode</span>
<span class="buttoni-arrow"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M23.328 16.707L13.121 26.914a.5.5 0 01-.707 0l-2.828-2.828a.5.5 0 010-.707L16.964 16 9.586 8.621a.5.5 0 010-.707l2.828-2.828a.5.5 0 01.707 0l10.207 10.207a1 1 0 010 1.414z"></path></svg></span>
</button>
<button class="pivx-button-big" onclick="toggleSyncMode()">
<span class="buttoni-icon"><i class="fas fa-sync fa-tiny-margin"></i></span>
<span class="buttoni-text">Toggle Sync Mode</span>
<span class="buttoni-arrow"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M23.328 16.707L13.121 26.914a.5.5 0 01-.707 0l-2.828-2.828a.5.5 0 010-.707L16.964 16 9.586 8.621a.5.5 0 010-.707l2.828-2.828a.5.5 0 01.707 0l10.207 10.207a1 1 0 010 1.414z"></path></svg></span>
</button>
<button class="pivx-button-big" onclick="toggleTestnet()">
<span class="buttoni-icon"><i class="fas fa-network-wired fa-tiny-margin"></i></span>
<span class="buttoni-text">Toggle Testnet Mode</span>
Expand Down
90 changes: 1 addition & 89 deletions scripts/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,102 +20,14 @@ if (networkEnabled) {
domBalanceReloadStaking.classList.remove("playAnim");
if (data.backend.blocks > cachedBlockCount) {
console.log("New block detected! " + cachedBlockCount + " --> " + data.backend.blocks);
getUTXOs();
getUTXOsHeavy();
getStakingRewards();
}
cachedBlockCount = data.backend.blocks;
}
request.send();
}

var arrUTXOsToValidate = [], nTimeSyncStart = 0;
var acceptUTXO = () => {
// Cancel if the queue is empty: no wasting precious bandwidth & CPU cycles!
if (!arrUTXOsToValidate.length) {
getNewAddress(true);
// If allowed by settings: submit a sync performance measurement to Labs Analytics
return submitAnalytics('time_to_sync', { time: (Date.now() / 1000) - nTimeSyncStart, explorer: cExplorer.name });
}

const request = new XMLHttpRequest();
request.open('GET', cExplorer.url + "/api/v2/tx-specific/" + arrUTXOsToValidate[0].txid, true);
request.onerror = networkError;

request.onload = function() {
// Fetch the single output of the UTXO
const cVout = JSON.parse(this.response).vout[arrUTXOsToValidate[0].vout];

console.log(arrUTXOsToValidate[0]);
let path;
if(arrUTXOsToValidate[0].path) {
path = arrUTXOsToValidate[0].path.split("/")
path[2] = (masterKey.isHardwareWallet ? cChainParams.current.BIP44_TYPE_LEDGER : cChainParams.current.BIP44_TYPE) + "'";
lastWallet = Math.max(parseInt(path[5]), lastWallet);
path = path.join("/");
}

// Convert to MPW format
const cUTXO = {
'id': arrUTXOsToValidate[0].txid,
'vout': cVout.n,
'sats': Math.round(cVout.value * COIN),
'script': cVout.scriptPubKey.hex,
path,
}

// Determine the UTXO type, and use it accordingly
if (cVout.scriptPubKey.type === 'pubkeyhash') {
// P2PKH type (Pay-To-Pub-Key-Hash)
//mempool.addUTXO...
} else
if (cVout.scriptPubKey.type === 'coldstake') {
// Cold Stake type
// mempool.addUTXO...
}

// Shift the queue and update the UI
getBalance(true);
getStakingBalance(true);
updateMasternodeTab();

// Loop validation until queue is empty
arrUTXOsToValidate.shift();
acceptUTXO();
}
request.send();
}

var getUTXOs = async () => {
// Don't fetch UTXOs if we're already scanning for them!
if (arrUTXOsToValidate.length) return;

// Heavy Sync: if enabled, we cancel the regular UTXO call for a full TX history and a manual UTXO search
if (fAlternativeSync) {
return getUTXOsHeavy();
}

const request = new XMLHttpRequest()
let publicKey;
if(masterKey.isHD) {
const derivationPath = getDerivationPath(masterKey.isHardwareWallet).split("/").slice(0, 4).join("/");
publicKey = await masterKey.getxpub(derivationPath);
} else {
publicKey = await masterKey.getAddress();
}
console.log(cExplorer.url + "/api/v2/utxo/" + publicKey)
request.open('GET', cExplorer.url + "/api/v2/utxo/" + publicKey, true);
request.onerror = networkError;
request.onload = function() {
arrUTXOsToValidate = JSON.parse(this.response);
// Clear our UTXOs and begin accepting refreshed ones (TODO: build an efficient 'set merge' algo)
if (arrUTXOsToValidate.length) {
nTimeSyncStart = Date.now() / 1000;
acceptUTXO();
}
}
request.send();
}

var sendTransaction = async function(hex, msg = '') {
try {
const data = await (await fetch(cExplorer.url + "/api/v2/sendtx/",
Expand Down
9 changes: 0 additions & 9 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// --- Default Settings
var debug = false; // A mode that emits verbose console info for internal MPW operations
var networkEnabled = true; // A lock which blocks ALL network requests in totality
var fAlternativeSync = true; // A more resource-intensive but deep UTXO set sync mode

var cExplorer = cChainParams.current.Explorers[0];
let cNode = cChainParams.current.Nodes[0];
Expand Down Expand Up @@ -38,15 +37,13 @@ var fWalletLoaded = false;
// --- DOM Cache
const domNetwork = document.getElementById('Network');
const domDebug = document.getElementById('Debug');
const domSyncMode = document.getElementById('SyncMode');
const domTestnet = document.getElementById('Testnet');
const domExplorerSelect = document.getElementById('explorer');
const domNodeSelect = document.getElementById('node');

// Display the default settings directly in the UI
domNetwork.innerHTML = '<b> Network:</b> ' + (networkEnabled ? 'Enabled' : 'Disabled');
domDebug.innerHTML = debug ? '<b>DEBUG MODE ON</b>' : '';
domSyncMode.innerHTML = fAlternativeSync ? '<b>Experimental Sync Active</b>' : '';
domTestnet.innerHTML = cChainParams.current.isTestnet ? '<b>Testnet Mode On</b>' : '';

// --- Settings Functions
Expand Down Expand Up @@ -112,12 +109,6 @@ function toggleTestnet() {
updateStakingRewardsGUI();
}

function toggleSyncMode() {
fAlternativeSync = !fAlternativeSync;
domSyncMode.innerHTML = fAlternativeSync ? '<b>Experimental Sync Active</b>' : '';
createAlert('success', '<b>Switched sync mode!</b><br>Now using ' + (fAlternativeSync ? 'experimental' : 'stable') + ' sync', 3000);
}

function toggleDebug() {
debug = !debug;
domDebug.innerHTML = debug ? '<b>DEBUG MODE ON</b>' : '';
Expand Down

0 comments on commit 52d27fe

Please sign in to comment.