2016-07-29 11:46:59 +03:00
< html >
< head >
< title > Ethereum Classic Split Tool< / title >
2016-08-05 03:12:50 +03:00
< link rel = "stylesheet" type = "text/css" href = "../style.css" >
2016-07-29 11:46:59 +03:00
< / head >
< body >
< div class = "centerer" >
< div class = "centered" >
< h1 > Split Ether Classic< / h1 >
< hr / >
< h2 > What does this tool do?< / h2 >
< p >
This tool will take a < i > geth< / i > (or crowdsale) JSON wallet, decrypt it and
send all its funds to < a href = "http://etherscan.io/address/0x3474627d4f63a678266bc17171d87f8570936622#code" > this contract< / a > ,
which will:
< / p >
< ul >
< li > On the ETH branch — send the funds back to the original address< / li >
2016-08-05 03:12:50 +03:00
< li > On the ETC branch — send the funds to the provided target address (for example, a < a href = "https://www.poloniex.com" > Poloniex< / a > deposit address)< / li >
2016-07-29 11:46:59 +03:00
< / ul >
< br / >
< h3 > Disclaimer:< / h3 >
< p >
I threw this together in couple of hours, mainly to split my own ether
and test my < i > ethers-wallet< / i > library (which is still missing features
and is itself not ready for production use). Testing has been fairly minimal
beyond trying it on a few wallets. < b > Use this at your own risk.< / b >
< / p >
< hr / >
< h2 > Check Current ETC Balance< / h2 >
< table >
< tr >
< th > ETC Address:< / th >
< td > < input type = "text" id = "checkAddress" / > < / td >
< / tr >
< tr >
< td > < / td >
< td >
< div id = "submitCheck" class = "submit disable" > Check Classic Ether Balance< / div >
< / td >
< / tr >
< / table >
< hr / >
< h2 > Split ETC/ETH< / h2 >
< table >
< tr >
< th > JSON Wallet:< / th >
2016-08-05 03:12:50 +03:00
< td > < div class = "file" id = "drop" > Drop JSON wallet file here< / div > < input type = "file" id = "json" / > < / td >
2016-07-29 11:46:59 +03:00
< / tr >
< tr >
< th > Password:< / th >
< td > < input type = "password" id = "password" / > < / td >
< / tr >
< tr >
< th > Target ETC Address:< / th >
< td > < input type = "text" id = "targetAddress" / > < / td >
< / tr >
< tr >
< td > < / td >
< td >
< div id = "submitSplit" class = "submit disable" > Split Classic Ether< / div >
< / td >
< / tr >
< / table >
< / div >
< / div >
< script type = "text/javascript" src = "../../dist/ethers-wallet.js" > < / script >
< script type = "text/javascript" >
var submitCheck = document.getElementById('submitCheck');
var submitSplit = document.getElementById('submitSplit');
var inputJson = document.getElementById('json');
var inputCheckAddress = document.getElementById('checkAddress')
var inputTargetAddress = document.getElementById('targetAddress')
var inputPassword = document.getElementById('password');
2016-08-05 03:12:50 +03:00
var targetDrop = document.getElementById('drop');
2016-07-29 11:46:59 +03:00
2016-08-05 03:12:50 +03:00
var provider = new Wallet.providers.HttpProvider('https://linode-newark.ethers.ws:8002');
2016-07-29 11:46:59 +03:00
var contractAddress = '0x3474627d4f63a678266bc17171d87f8570936622';
var contractAbi = JSON.parse('[{"constant":false,"inputs":[{"name":"balance","type":"uint256"}],"name":"claimDonations","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"isClassic","outputs":[{"name":"","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"classicAddress","type":"address"}],"name":"split","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"}]');
submitCheck.onclick = function() {
if (submitCheck.classList.contains('disable')) { return; }
var address = document.getElementById('checkAddress').value;
try {
address = Wallet.getAddress(address);
} catch (error) {
console.log(error);
alert('invalid address');
return;
}
2016-08-05 03:12:50 +03:00
provider.getBalance(address, 'latest').then(function(balance) {
alert('Balance: ' + Wallet.formatEther(balance, {commify: true}) + ' ' + Wallet.etherSymbol);
2016-07-29 11:46:59 +03:00
}, function(error) {
if (error) {
console.log(error);
alert('Faied to get balance');
}
});
console.log('check', address);
}
submitSplit.onclick = function() {
if (submitSplit.classList.contains('disable')) { return; }
function done() {
submitSplit.textContent = 'Split Classic Ether';
inputJson.readOnly = false;
inputPassword.readOnly = false;
inputTargetAddress.readOnly = false;
checkSplit();
}
inputJson.readOnly = true;
inputPassword.readOnly = true;
inputTargetAddress.readOnly = true;
submitSplit.classList.add('disable');
var files = inputJson.files;
if (files.length !== 1) {
alert('No wallet found');
return done();
}
var password = new Wallet.utils.Buffer(inputPassword.value, 'utf8');
var targetAddress = document.getElementById('targetAddress').value;
try {
targetAddress = Wallet.getAddress(targetAddress);
} catch (error) {
console.log(error);
alert('invalid target address');
return done();
}
function processWallet(wallet) {
2016-08-05 03:12:50 +03:00
console.log(wallet);
2016-07-29 11:46:59 +03:00
if (wallet.address === targetAddress) {
alert('Wallet address and target address cannot be the same.');
return done();
}
submitSplit.textContent = 'Decrypted \u2014 Processing (please wait)';
var contract = wallet.getContract(contractAddress, contractAbi);
var data = contract.interface.split(targetAddress).data;
var transaction = {
to: contractAddress,
data: data
};
Promise.all([
2016-08-05 03:12:50 +03:00
provider.getBalance(wallet.address, 'latest'),
provider.getTransactionCount(wallet.address, 'latest'),
provider.getGasPrice(),
// provider.estimateGas(transaction)
2016-07-29 11:46:59 +03:00
]).then(function(results) {
var balance = results[0];
var transactionCount = results[1];
var gasPrice = results[2];
2016-08-05 03:12:50 +03:00
var gasEstimate = new Wallet.utils.BN('29735');
//results[3].add(new Wallet.utils.BN(21000));
2016-07-29 11:46:59 +03:00
transaction.gasPrice = '0x' + gasPrice.toString(16);
transaction.nonce = transactionCount;
2016-08-05 03:12:50 +03:00
transaction.gasLimit = gasEstimate;
2016-07-29 11:46:59 +03:00
2016-08-05 03:12:50 +03:00
var toSend = balance.sub(gasPrice.mul(gasEstimate));
2016-07-29 11:46:59 +03:00
transaction.value = toSend;
2016-08-05 03:12:50 +03:00
console.log(transaction);
var accept = confirm('Balance: ' + Wallet.formatEther(balance, {commify: true}) + ' ' + Wallet.etherSymbol + '. Are you sure you want to split Classic Ether to ' + targetAddress + '?');
2016-07-29 11:46:59 +03:00
if (accept) {
var signedTransaction = wallet.sign(transaction);
function showError(error) {
console.log(error);
2016-08-05 03:12:50 +03:00
done();
2016-07-29 11:46:59 +03:00
alert('Error sending transaction');
}
2016-08-05 03:12:50 +03:00
provider.sendTransaction(signedTransaction).then(function(txid) {
2016-07-29 11:46:59 +03:00
if (txid.match(/^0x0+$/)) {
showError(new Error('txid was zero'));
return;
}
done();
console.log('txid:' + txid);
alert('Success \u2014 ' + txid);
}, function(error) {
showError(error);
});
} else {
done();
}
}, function(error) {
done();
console.log(error);
alert('Error: Faied to fetch info');
});
}
var fileReader = new FileReader();
fileReader.onload = function(e) {
var json = e.target.result;
if (Wallet.isCrowdsaleWallet(json)) {
var wallet = Wallet.decryptCrowdsale(json, password);
processWallet(wallet);
} else if (Wallet.isValidWallet(json)) {
Wallet.decrypt(json, password, function(error, wallet, progress) {
if (error) {
done();
console.log(error);
if (error.message === 'invalid password') {
alert('Wrong Password');
} else {
alert('Error Decrypting Wallet');
}
} else if (wallet) {
processWallet(wallet);
} else {
submitSplit.textContent = 'Decrypting \u2014 ' + (parseInt(progress * 100) + '%');
}
});
} else {
alert('unknown walet format');
done();
}
}
fileReader.readAsText(files[0]);
}
inputCheckAddress.oninput = function() {
try {
Wallet.getAddress(inputCheckAddress.value);
submitCheck.classList.remove('disable');
} catch (error) {
submitCheck.classList.add('disable');
}
}
function checkSplit() {
2016-08-05 03:12:50 +03:00
if (!inputJson.files || inputJson.files.length !== 1) {
2016-07-29 11:46:59 +03:00
submitSplit.classList.add('disable');
return;
}
2016-08-05 03:12:50 +03:00
targetDrop.textContent = inputJson.files[0].name;
try {
Wallet.getAddress(inputTargetAddress.value);
} catch (error) {
2016-07-29 11:46:59 +03:00
submitSplit.classList.add('disable');
return;
}
2016-08-05 03:12:50 +03:00
2016-07-29 11:46:59 +03:00
submitSplit.classList.remove('disable');
}
inputTargetAddress.oninput = checkSplit;
inputJson.onchange = checkSplit;
2016-08-05 03:12:50 +03:00
inputJson.addEventListener('dragover', function(event) {
event.preventDefault();
event.stopPropagation();
targetDrop.classList.add('highlight');
}, true);
inputJson.addEventListener('drop', function(event) {
targetDrop.classList.remove('highlight');
}, true);
2016-07-29 11:46:59 +03:00
var check
< / script >
< / body >
< / html >