Merge pull request #23 from vbaranov/master

npm packages instead storing libs in repo; web3 migration to 1.0x
This commit is contained in:
Victor 2017-11-22 19:55:18 +03:00 committed by GitHub
commit bf935063ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 80477 additions and 329 deletions

File diff suppressed because one or more lines are too long

View File

@ -9,21 +9,29 @@ function addValidator(web3, validatorViewObj, contractAddr, abi, cb) {
console.log(validatorViewObj);
console.log(oraclesContract);
var txHash;
var gasPrice = web3.utils.toWei(new web3.utils.BN(1), 'gwei')
var opts = {from: web3.eth.defaultAccount, gasPrice: gasPrice}
oraclesContract.addValidator.sendTransaction(
validatorViewObj.miningKey,
oraclesContract.methods.addValidator(validatorViewObj.miningKey,
validatorViewObj.zip,
validatorViewObj.licenseID,
validatorViewObj.licenseExpiredAt,
validatorViewObj.fullName,
validatorViewObj.streetName,
validatorViewObj.state,
function(err, txHash) {
if (err) {
cb(txHash, err);
return;
}
cb(txHash);
validatorViewObj.state
)
.send(opts)
.on('error', error => {
return cb(txHash, error);
})
.on('transactionHash', _txHash => {
console.log("contract method transaction: " + _txHash);
txHash = _txHash;
})
.on('receipt', receipt => {
return cb(txHash)
});
});
}

View File

@ -1,46 +1,3 @@
function SHA3Encrypt(web3, str) {
var strEncode = web3.sha3(str);
return strEncode;
}
function estimateGas(web3, from, to, data, val, cb) {
var props;
if (val)
props = { from: from, value: val, data: null, to: to };
else
props = { from: from, data: data, to: to };
web3.eth.estimateGas(props, function(err, estimatedGas) {
if (err) console.log(err);
console.log(estimatedGas);
cb(estimatedGas);
});
}
function sendTx(web3, from, to, data, val, estimatedGas, gasPrice, cb) {
var props;
if (val)
props = { from: from, value: val, to: to, gas: estimatedGas, gasPrice: gasPrice };
else
props = { from: from, data: data, to: to, gas: estimatedGas, gasPrice: gasPrice };
web3.eth.sendTransaction(props, function(err, txHash) {
cb(txHash, err);
});
}
function call(web3, from, to, data, cb) {
var props;
if (from)
props = { from: from, data: data, to: to };
else
props = { data: data, to: to };
web3.eth.call(props, function(err, data) {
cb(data);
});
}
function getBalance(address, cb) {
web3.eth.getBalance(address, function(err, balance) {
if (err) {
@ -53,31 +10,11 @@ function getBalance(address, cb) {
});
}
function getGasPrice(cb) {
web3.eth.getGasPrice(function(err, gasPriceObj) {
if (err) {
console.log(err);
$(".loading-container").hide();
return;
}
console.log(gasPriceObj);
var gasPrice = gasPriceObj.c[0];
cb(gasPrice);
});
}
function attachToContract(web3, abi, addr, cb) {
if(!web3.isConnected()) {
if (cb) cb({code: 200, title: "Error", message: "check RPC availability"});
} else {
web3.eth.defaultAccount = web3.eth.accounts[0];
console.log("web3.eth.defaultAccount:" + web3.eth.defaultAccount);
var MyContract = web3.eth.contract(abi);
var contractInstance = MyContract.at(addr);
if (cb) cb(null, contractInstance);
}
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);
}

View File

@ -1,19 +1,16 @@
function checkInitialKey(web3, func, initialKey, contractAddr, cb) {
var funcParamsNumber = 1;
var standardLength = 32;
function checkInitialKey(web3, func, initialKey, contractAddr, abi, cb) {
attachToContract(web3, abi, contractAddr, function(err, oraclesContract) {
console.log("attach to oracles contract");
if (err) {
console.log(err)
return cb();
}
let funcEncode = SHA3Encrypt(web3, func)
var funcEncodePart = funcEncode.substring(0,10);
var data = funcEncodePart
+ toUnifiedLengthLeft(initialKey);
console.log(data);
console.log("0x" + initialKey);
console.log(contractAddr);
call(web3, "0x" + initialKey, contractAddr, data, function(respHex) {
console.log(respHex);
cb(parseInt(respHex, 16));
});
oraclesContract.methods.checkInitialKey("0x" + initialKey).call(function(err, isNew) {
if (err) {
console.log(err)
}
cb(isNew);
})
})
}

View File

@ -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) {

View File

@ -8,17 +8,22 @@ function createKeys(web3, keys, contractAddr, abi, cb) {
}
console.log(keys);
var txHash;
var gasPrice = web3.utils.toWei(new web3.utils.BN(1), 'gwei')
var opts = {from: web3.eth.defaultAccount, gasPrice: gasPrice}
oraclesContract.createKeys.sendTransaction(
"0x" + keys.miningKey.miningKeyObject.address,
oraclesContract.methods.createKeys("0x" + keys.miningKey.miningKeyObject.address,
"0x" + keys.payoutKey.payoutKeyObject.address,
"0x" + keys.votingKey.votingKeyObject.address,
function(err, txHash) {
if (err) {
cb(txHash, err);
return;
}
cb(txHash);
"0x" + keys.votingKey.votingKeyObject.address
).send(opts).on('error', error => {
return cb(txHash, error);
})
.on('transactionHash', _txHash => {
console.log("contract method transaction: " + _txHash);
txHash = _txHash;
})
.on('receipt', receipt => {
return cb(txHash)
});
});
}

View File

@ -27,6 +27,7 @@ function startDapp(web3, isOraclesNetwork) {
"checkInitialKey(address)",
possibleInitialKey,
contractAddress,
abi,
function(_isNew) {
_isNew = !!+_isNew;
if (!_isNew) swal("Warning", "Current key isn't valid initial key. Please, choose your initial key in MetaMask and reload the page. Check Oracles network <a href='https://github.com/oraclesorg/oracles-wiki' target='blank'>wiki</a> for more info.", "warning");
@ -76,6 +77,7 @@ function startDapp(web3, isOraclesNetwork) {
"checkInitialKey(address)",
address,
contractAddress,
abi,
function(_isNew) {
_isNew = !!+_isNew;
@ -198,33 +200,17 @@ function startDapp(web3, isOraclesNetwork) {
var to = "0x" + keys.payoutKey.payoutKeyObject.address;
//gets balance of initial key
getBalance(address, function(balance) {
//gets gas price
getGasPrice(function(gasPrice) {
//estimates gas
estimateGasForTx(address, to, balance, function(estimatedGas) {
//calculates how many coins we can send from initial key to payout key
calculateAmmountToSend(estimatedGas, gasPrice, balance, function(ammountToSend) {
transferCoinsToPayoutKeyTx(estimatedGas, gasPrice, address, to, ammountToSend);
});
});
//calculates how many coins we can send from initial key to payout key
var estimatedGas = new web3.utils.BN(21000);
var gasPrice = web3.utils.toWei(new web3.utils.BN(1), 'gwei')
calculateAmmountToSend(estimatedGas, gasPrice, balance, function(ammountToSend) {
transferCoinsToPayoutKeyTx(estimatedGas, gasPrice, address, to, ammountToSend);
});
});
}
function estimateGasForTx(address, to, balance, cb) {
estimateGas(web3, address, to, null, parseInt(balance/2), function(estimatedGas, err) {
if (err) {
console.log(err);
loadingFinished();
return;
}
cb(estimatedGas);
});
}
function calculateAmmountToSend(estimatedGas, gasPrice, balance, cb) {
var ammountToSend = balance - 20 * estimatedGas * gasPrice;
var ammountToSend = balance.sub(new web3.utils.BN(20).mul(estimatedGas).mul(gasPrice));
console.log("ammountToSend: " + ammountToSend);
cb(ammountToSend);
}
@ -299,7 +285,7 @@ function startDapp(web3, isOraclesNetwork) {
var clipboard = new Clipboard( el );
clipboard.on( "success", function( event ) {
toastr.success(msg);
window.toastr.success(msg);
});
}
});

File diff suppressed because one or more lines are too long

74697
assets/javascripts/modules.js Normal file

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

File diff suppressed because one or more lines are too long

View File

@ -1,3 +0,0 @@
//=require jquery.min.js
//=require web3.js
//=require clipboard.min.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,8 +12,6 @@
<!-- <meta property="og:image" content="https://www.notarycoin.com/assets/images/share.png"> -->
<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="stylesheet" type="text/css" href="./assets/stylesheets/toastr.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">
@ -78,9 +76,7 @@
<p class="footer-rights">2017 Oracles Network. All rights reserved.</p>
</div>
</footer>
<script src="./assets/javascripts/sweetalert2.min.js" type="text/javascript"></script>
<script src="./assets/javascripts/modules.js" type="text/javascript"></script>
<script src="./assets/javascripts/application.js?v=1.39" type="text/javascript"></script>
<script src="./assets/javascripts/keythereum.min.js" type="text/javascript"></script>
<script src="./assets/javascripts/toastr.min.js" type="text/javascript"></script>
</body>
</html>

15
modules.js Normal file
View File

@ -0,0 +1,15 @@
let keythereum = require("keythereum");
let passwordGenerator = require("password-generator");
let sweetalert2 = require("sweetalert2");
let toastr = require("toastr");
let jquery = require("jquery");
let Clipboard = require("clipboard");
let Web3 = require("web3");
window.keythereum = keythereum;
window.passwordGenerator = passwordGenerator;
window.swal = sweetalert2;
window.toastr = toastr;
window.$ = jquery;
window.Clipboard = Clipboard;
window.Web3 = Web3;

5631
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@
"sass": "gulp sass",
"coffee": "gulp javascript",
"watch": "gulp watch",
"start": "gulp javascript && http-server -a localhost -p 8000"
"start": "browserify modules.js -o assets/javascripts/modules.js && gulp javascript && gulp sass && http-server -a localhost -p 8000"
},
"repository": {
"type": "git",
@ -31,5 +31,14 @@
"keywords": [],
"author": "oraclesorg",
"license": "MIT",
"homepage": "https://oracles.org/"
"homepage": "https://oracles.org/",
"dependencies": {
"clipboard": "^1.7.1",
"jquery": "^3.2.1",
"keythereum": "^1.0.2",
"password-generator": "^2.2.0",
"sweetalert2": "^7.0.3",
"toastr": "^2.1.2",
"web3": "^1.0.0-beta.26"
}
}