refactoring
This commit is contained in:
parent
8635dad56e
commit
3938fc6bdd
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
File diff suppressed because one or more lines are too long
|
@ -1,8 +1,17 @@
|
|||
function SHA3Encrypt(web3, str) {
|
||||
var strEncode = web3.sha3(str);
|
||||
var strEncode = web3.utils.sha3(str);
|
||||
return strEncode;
|
||||
}
|
||||
|
||||
function attachToContract(web3, abi, addr, cb) {
|
||||
web3.eth.defaultAccount = web3.eth.accounts[0];
|
||||
console.log("web3.eth.defaultAccount:" + web3.eth.defaultAccount);
|
||||
|
||||
var contractInstance = new web3.eth.Contract(abi, addr);
|
||||
|
||||
if (cb) cb(null, contractInstance);
|
||||
}
|
||||
|
||||
function call(web3, acc, contractAddr, data, cb) {
|
||||
let props;
|
||||
if (acc) props = { from: acc, data: data, to: contractAddr };
|
||||
|
@ -13,7 +22,7 @@ function call(web3, acc, contractAddr, data, cb) {
|
|||
});
|
||||
}
|
||||
|
||||
function getContractStringDataFromAddressKey(web3, func, inputVal, i, contractAddr, cb) {
|
||||
/*function getContractStringDataFromAddressKey(web3, func, inputVal, i, contractAddr, cb) {
|
||||
const funcParamsNumber = 1;
|
||||
const standardLength = 32;
|
||||
|
||||
|
@ -28,7 +37,7 @@ function getContractStringDataFromAddressKey(web3, func, inputVal, i, contractAd
|
|||
call(web3, null, contractAddr, data, function(respHex) {
|
||||
cb(i, hex2a(respHex));
|
||||
});
|
||||
}
|
||||
}*/
|
||||
|
||||
function getContractIntDataFromAddressKey(web3, func, inputVal, i, contractAddr, cb) {
|
||||
const funcParamsNumber = 1;
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
async function checkNetworkVersion(web3, cb) {
|
||||
var msgNotOracles = "You aren't connected to Oracles network. Please, switch on Oracles plugin and choose Oracles network. Check Oracles network <a href='https://github.com/oraclesorg/oracles-wiki' target='blank'>wiki</a> for more info.";
|
||||
let config = await getConfig()
|
||||
web3.version.getNetwork(function(err, connectedNetworkID) {
|
||||
if (err) console.log(err);
|
||||
web3.eth.net.getId().then(function(connectedNetworkID) {
|
||||
console.log("connectedNetworkID: " + connectedNetworkID);
|
||||
connectedNetworkID = parseInt(connectedNetworkID);
|
||||
switch (connectedNetworkID) {
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
async function getConfig(cb) {
|
||||
let config = await $.getJSON("./assets/javascripts/config.json")
|
||||
let contractAddress = config.Ethereum[config.environment].contractAddress
|
||||
let abi = config.Ethereum[config.environment].abi
|
||||
let networkID = config.networkID
|
||||
let configJSON = {
|
||||
contractAddress,
|
||||
networkID
|
||||
networkID,
|
||||
abi
|
||||
}
|
||||
if (cb) cb(configJSON)
|
||||
return configJSON;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function getValidators(web3, func, contractAddress, disabled, cb) {
|
||||
function getValidators(web3, func, contractAddress, abi, disabled, cb) {
|
||||
let funcEncode = SHA3Encrypt(web3, func);
|
||||
var funcEncodePart = funcEncode.substring(0,10);
|
||||
|
||||
|
@ -29,44 +29,44 @@ function getValidators(web3, func, contractAddress, disabled, cb) {
|
|||
if (disabled)
|
||||
validatorDataCount = 7;
|
||||
for (var i = 0; i < validatorsArray.length; i++) {
|
||||
getValidatorFullName(web3, validatorsArray[i], i, contractAddress, function(_i, resp) {
|
||||
getValidatorFullName(web3, validatorsArray[i], i, contractAddress, abi, function(_i, resp) {
|
||||
iasync++;
|
||||
validatorsArrayOut = getPropertyCallback("fullName", resp, _i, iasync, validatorsArray, validatorDataCount, validatorsArrayOut, cb);
|
||||
if (iasync == validatorsArray.length * validatorDataCount) {console.log(validatorsArrayOut); cb(validatorsArrayOut)};
|
||||
});
|
||||
|
||||
getValidatorStreetName(web3, validatorsArray[i], i, contractAddress, function(_i, resp) {
|
||||
getValidatorStreetName(web3, validatorsArray[i], i, contractAddress, abi, function(_i, resp) {
|
||||
iasync++;
|
||||
validatorsArrayOut = getPropertyCallback("streetName", resp, _i, iasync, validatorsArray, validatorDataCount, validatorsArrayOut, cb);
|
||||
if (iasync == validatorsArray.length * validatorDataCount) {console.log(validatorsArrayOut); cb(validatorsArrayOut)};
|
||||
});
|
||||
|
||||
getValidatorState(web3, validatorsArray[i], i, contractAddress, function(_i, resp) {
|
||||
getValidatorState(web3, validatorsArray[i], i, contractAddress, abi, function(_i, resp) {
|
||||
iasync++;
|
||||
validatorsArrayOut = getPropertyCallback("state", resp, _i, iasync, validatorsArray, validatorDataCount, validatorsArrayOut, cb);
|
||||
if (iasync == validatorsArray.length * validatorDataCount) {console.log(validatorsArrayOut); cb(validatorsArrayOut)};
|
||||
});
|
||||
|
||||
getValidatorLicenseExpiredAt(web3, validatorsArray[i], i, contractAddress, function(_i, resp) {
|
||||
getValidatorLicenseExpiredAt(web3, validatorsArray[i], i, contractAddress, abi, function(_i, resp) {
|
||||
iasync++;
|
||||
validatorsArrayOut = getPropertyCallback("licenseExpiredAt", resp, _i, iasync, validatorsArray, validatorDataCount, validatorsArrayOut, cb);
|
||||
if (iasync == validatorsArray.length * validatorDataCount) {console.log(validatorsArrayOut); cb(validatorsArrayOut)};
|
||||
});
|
||||
|
||||
getValidatorZip(web3, validatorsArray[i], i, contractAddress, function(_i, resp) {
|
||||
getValidatorZip(web3, validatorsArray[i], i, contractAddress, abi, function(_i, resp) {
|
||||
iasync++;
|
||||
validatorsArrayOut = getPropertyCallback("zip", resp, _i, iasync, validatorsArray, validatorDataCount, validatorsArrayOut, cb);
|
||||
if (iasync == validatorsArray.length * validatorDataCount) {console.log(validatorsArrayOut); cb(validatorsArrayOut)};
|
||||
});
|
||||
|
||||
getValidatorLicenseID(web3, validatorsArray[i], i, contractAddress, function(_i, resp) {
|
||||
getValidatorLicenseID(web3, validatorsArray[i], i, contractAddress, abi, function(_i, resp) {
|
||||
iasync++;
|
||||
validatorsArrayOut = getPropertyCallback("licenseID", resp, _i, iasync, validatorsArray, validatorDataCount, validatorsArrayOut, cb);
|
||||
if (iasync == validatorsArray.length * validatorDataCount) {console.log(validatorsArrayOut); cb(validatorsArrayOut)};
|
||||
});
|
||||
|
||||
if (disabled) {
|
||||
getValidatorDisablingDate(web3, validatorsArray[i], i, contractAddress, function(_i, resp) {
|
||||
getValidatorDisablingDate(web3, validatorsArray[i], i, contractAddress, abi, function(_i, resp) {
|
||||
iasync++;
|
||||
validatorsArrayOut = getPropertyCallback("disablingDate", resp, _i, iasync, validatorsArray, validatorDataCount, validatorsArrayOut, cb);
|
||||
if (iasync == validatorsArray.length * validatorDataCount) {console.log(validatorsArrayOut); cb(validatorsArrayOut)};
|
||||
|
|
|
@ -1,34 +1,88 @@
|
|||
function getValidatorFullName(web3, addr, i, contractAddr, cb) {
|
||||
var func = "getValidatorFullName(address)";
|
||||
getContractStringDataFromAddressKey(web3, func, addr, i, contractAddr, cb);
|
||||
function getValidatorFullName(web3, addr, i, contractAddr, abi, cb) {
|
||||
attachToContract(web3, abi, contractAddr, function(err, oraclesContract) {
|
||||
console.log("attach to oracles contract");
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return cb();
|
||||
}
|
||||
|
||||
oraclesContract.methods.getValidatorFullName(addr).call(function(err, fullname) {
|
||||
cb(i, fullname);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getValidatorStreetName(web3, addr, i, contractAddr, cb) {
|
||||
var func = "getValidatorStreetName(address)";
|
||||
getContractStringDataFromAddressKey(web3, func, addr, i, contractAddr, cb);
|
||||
function getValidatorStreetName(web3, addr, i, contractAddr, abi, cb) {
|
||||
attachToContract(web3, abi, contractAddr, function(err, oraclesContract) {
|
||||
console.log("attach to oracles contract");
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return cb();
|
||||
}
|
||||
|
||||
oraclesContract.methods.getValidatorStreetName(addr).call(function(err, streetname) {
|
||||
cb(i, streetname);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getValidatorState(web3, addr, i, contractAddr, cb) {
|
||||
var func = "getValidatorState(address)";
|
||||
getContractStringDataFromAddressKey(web3, func, addr, i, contractAddr, cb);
|
||||
function getValidatorState(web3, addr, i, contractAddr, abi, cb) {
|
||||
attachToContract(web3, abi, contractAddr, function(err, oraclesContract) {
|
||||
console.log("attach to oracles contract");
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return cb();
|
||||
}
|
||||
|
||||
oraclesContract.methods.getValidatorState(addr).call(function(err, state) {
|
||||
cb(i, state);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getValidatorLicenseExpiredAt(web3, addr, i, contractAddr, cb) {
|
||||
var func = "getValidatorLicenseExpiredAt(address)";
|
||||
getContractIntDataFromAddressKey(web3, func, addr, i, contractAddr, cb);
|
||||
function getValidatorLicenseExpiredAt(web3, addr, i, contractAddr, abi, cb) {
|
||||
attachToContract(web3, abi, contractAddr, function(err, oraclesContract) {
|
||||
console.log("attach to oracles contract");
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return cb();
|
||||
}
|
||||
|
||||
oraclesContract.methods.getValidatorLicenseExpiredAt(addr).call(function(err, licenseExpiredAt) {
|
||||
cb(i, licenseExpiredAt);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getValidatorDisablingDate(web3, addr, i, contractAddr, cb) {
|
||||
var func = "getValidatorDisablingDate(address)";
|
||||
getContractIntDataFromAddressKey(web3, func, addr, i, contractAddr, cb);
|
||||
function getValidatorDisablingDate(web3, addr, i, contractAddr, abi, cb) {
|
||||
attachToContract(web3, abi, contractAddr, function(err, oraclesContract) {
|
||||
console.log("attach to oracles contract");
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return cb();
|
||||
}
|
||||
|
||||
oraclesContract.methods.getValidatorDisablingDate(addr).call(function(err, disablingDate) {
|
||||
cb(i, disablingDate);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getValidatorZip(web3, addr, i, contractAddr, cb) {
|
||||
var func = "getValidatorZip(address)";
|
||||
getContractIntDataFromAddressKey(web3, func, addr, i, contractAddr, cb);
|
||||
function getValidatorZip(web3, addr, i, contractAddr, abi, cb) {
|
||||
attachToContract(web3, abi, contractAddr, function(err, oraclesContract) {
|
||||
console.log("attach to oracles contract");
|
||||
if (err) {
|
||||
console.log(err)
|
||||
return cb();
|
||||
}
|
||||
|
||||
oraclesContract.methods.getValidatorZip(addr).call(function(err, zip) {
|
||||
cb(i, zip);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getValidatorLicenseID(web3, addr, i, contractAddr, cb) {
|
||||
function getValidatorLicenseID(web3, addr, i, contractAddr, abi, cb) {
|
||||
var func = "getValidatorLicenseID(address)";
|
||||
getContractIntDataFromAddressKey(web3, func, addr, i, contractAddr, cb);
|
||||
}
|
|
@ -13,7 +13,7 @@ function startDapp(web3, isOraclesNetwork) {
|
|||
async function startDappInner(web3) {
|
||||
var validators;
|
||||
let config = await getConfig()
|
||||
getValidators(web3, "getValidators()", config.contractAddress, false, function(_validatorsArray) {
|
||||
getValidators(web3, "getValidators()", config.contractAddress, config.abi, false, function(_validatorsArray) {
|
||||
$(".loading-container").hide();
|
||||
validators = _validatorsArray;
|
||||
for(var i = 0; i < _validatorsArray.length; i++) {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +0,0 @@
|
|||
//=require jquery.min.js
|
||||
//=require web3.js
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -16,7 +16,6 @@
|
|||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="./assets/stylesheets/index.css">
|
||||
<link rel="stylesheet" type="text/css" href="./assets/stylesheets/sweetalert2.min.css">
|
||||
<link rel="apple-touch-icon" href="./favicons/favicon-192x192.png">
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="./favicons/favicon-192x192.png">
|
||||
<link rel="mask-icon" color="#6151cc" href="./favicons/safari-pinned-tab.svg">
|
||||
|
@ -62,7 +61,7 @@
|
|||
<p class="footer-rights">2017 Oracles Network. All rights reserved.</p>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="./assets/javascripts/modules.js"></script>
|
||||
<script src="./assets/javascripts/application.js?v=1.19"></script>
|
||||
<script src="./assets/javascripts/sweetalert2.min.js" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
let jquery = require("jquery");
|
||||
let sweetalert2 = require("sweetalert2");
|
||||
let Web3 = require("web3");
|
||||
|
||||
window.$ = jquery;
|
||||
window.swal = sweetalert2;
|
||||
window.Web3 = Web3;
|
File diff suppressed because it is too large
Load Diff
|
@ -31,5 +31,10 @@
|
|||
"keywords": [],
|
||||
"author": "oraclesorg",
|
||||
"license": "MIT",
|
||||
"homepage": "https://oracles.org/"
|
||||
"homepage": "https://oracles.org/",
|
||||
"dependencies": {
|
||||
"jquery": "^3.2.1",
|
||||
"sweetalert2": "^7.0.3",
|
||||
"web3": "^1.0.0-beta.26"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue