Merge pull request #7 from Swader/master

Parametrized more options, fixes #5
This commit is contained in:
Bruno Škvorc 2019-07-31 11:35:53 +02:00 committed by GitHub
commit 38b92817f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 18 deletions

View File

@ -1 +1,6 @@
MNEMONIC=main blouse fashion brand own rocket fluid notable vacuum gain guitar leaf
MNEMONIC=main blouse fashion brand own rocket fluid notable vacuum gain guitar leaf
PORT=8545
FAUCET_PORT=5001
# Amount is in Ether
FAUCET_AMOUNT=1000000
NETWORK_ID=666

View File

@ -8,7 +8,7 @@ You will have to pollute your system a little for this to work. Luckily, it work
- Install NVM to have a working NodeJS setup. If you don't, nodeJS and npm will probably break in many, many ways. Once you have NVM, set it to Node version 10.
- Install the Yarn package manager: https://yarnpkg.com/lang/en/docs/install/
- Run `yarn install` to install dependencies
- Run `yarn install && cd deploy/faucet && yarn install` to install dependencies
### Start

View File

@ -1,6 +1,7 @@
{
"environment": "prod",
"debug": false,
"port": "FAUCET_PORT",
"Captcha": {
"secret": "",
"sitekey": ""
@ -8,7 +9,7 @@
"Tweeter": {
"similarityTreshold": 0.75,
"cooldown": 8,
"predefinedTweet": "I'm using the Thundercloud (https://github.com/swader/thundercloud) Faucet to get some Test Ether to launch an Ethereum 2.0 Genesis event",
"predefinedTweet": "I'm using the Thundercloud (https://github.com/status-im/thundercloud) Faucet to get some Test Ether to launch an Ethereum 2.0 Genesis event",
"predefinedHashTags": "ethereum, eth2, serenity"
},
"Ethereum": {
@ -16,9 +17,9 @@
"milliEtherToTransferWithoutTweet": 1000,
"gasLimit": "21000",
"prod": {
"rpc": "http://127.0.0.1:8545",
"account": "0x471e0575bFC76d7e189ab3354E0ecb70FCbf3E46",
"privateKey": "2960a712dcbcd755be598955b08ee0f697b372aed31005bd55fd02949b6917bb"
"rpc": "http://127.0.0.1:PORT",
"account": "ADDRESS",
"privateKey": "PRIVATE_KEY_WITHOUT_0x"
}
}
}

View File

@ -46,7 +46,7 @@ app.configureWeb3(config)
});
});
app.set('port', (process.env.PORT || 5000));
app.set('port', (process.env.PORT || app.config.port || 5000));
app.listen(app.get('port'), function () {
console.log('Thundercloud faucet is running on port', app.get('port'));

View File

@ -11,7 +11,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/swader/thundercloud"
"url": "https://github.com/status-im/thundercloud"
},
"author": "swader",
"license": "MIT",

View File

@ -24,7 +24,7 @@ html
.inner
h1.hidden Thundercloud Testnet Faucet
.allign-middle
a(href='https://github.com/swader/thundercloud')
a(href='https://github.com/status-im/thundercloud')
img.center-logo-img(src='assets/images/cloud.png' alt='Thundercloud Logo')
main.inner.content(role='main')

View File

@ -26,13 +26,12 @@ args.forEach(function (val, index, array) {
}
});
// @TODO make faucet balance configurable
const startupOptions = {
"mnemonic": process.env.mnemonic,
"default_balance_ether": 1000000,
"mnemonic": process.env.MNEMONIC,
"default_balance_ether": process.env.FAUCET_AMOUNT,
"total_accounts": 1,
"db_path": "./deploy/db",
"network_id": 666,
"network_id": process.env.NETWORK_ID,
"account_keys_path": "./deploy/keys/validators.json" // Does not work yet: https://github.com/trufflesuite/ganache-cli/issues/663
};
@ -45,7 +44,7 @@ if (!arglist.v && !arglist.mykeys) {
// Generate `v` number of accounts with 32.1 ether each
var accounts = [];
if (arglist.v && arglist.v > 0) {
accounts.push({"balance": 0xD3C21BCECCEDA1000000});
accounts.push({"balance": ethers.utils.bigNumberify(process.env.FAUCET_AMOUNT + "000000000000000000").toHexString()});
console.log("Creating " + arglist.v + " validator accounts and making deposits for them. Find their private keys in deploy/keys");
for (var i = 0; i < arglist.v; i++) {
accounts.push({"balance": 0x1BD7A1BED4A0A0000}); // 32.1 ether to each validator
@ -76,7 +75,7 @@ if (arglist.mykeys) {
startupOptions.accounts = startupOptions.accounts.concat(myAccounts);
} else {
console.log("Generating faucet account and appending queued keys.");
myAccounts.unshift({"balance": 0xD3C21BCECCEDA1000000});
myAccounts.unshift({"balance": ethers.utils.bigNumberify(process.env.FAUCET_AMOUNT + "000000000000000000").toHexString()});
startupOptions.accounts = myAccounts;
}
}
@ -94,7 +93,7 @@ provider.listAccounts().then(function(result){
faucetAmount = balanceResult / 1e18;
let mnemonic = process.env.mnemonic;
let mnemonic = process.env.MNEMONIC;
let mnemonicWallet = ethers.Wallet.fromMnemonic(mnemonic);
fs.writeFile("deploy/keys/faucetkey.txt", mnemonicWallet.privateKey + ":" + mnemonicWallet.address, function(err) {
@ -102,6 +101,7 @@ provider.listAccounts().then(function(result){
return console.log(err);
}
console.log("Private key of faucet account "+ result[0] +" now in /deploy/keys/faucetkey.txt. It is seeded with ~" + faucetAmount + " ether.");
fwdFaucetConfiguration(mnemonicWallet);
});
deployDepositContract(mnemonicWallet.privateKey).then(makeValidatorDeposits);
@ -147,7 +147,7 @@ async function makeValidatorDeposits() {
if (arglist.v) {
console.log("Generating keys for "+ arglist.v +" auto-generated accounts");
for (var i = 0; i <= arglist.v; i++) {
let mnemonicWallet = new ethers.Wallet.fromMnemonic(process.env.mnemonic, "m/44'/60'/0'/0/"+i);
let mnemonicWallet = new ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/"+i);
let pk = mnemonicWallet.privateKey;
let bls_key_sign = new keypair.Keypair(privateKey.PrivateKey.fromHexString(pk)).privateKey.toHexString();
@ -270,7 +270,7 @@ async function makeValidatorDeposits() {
async function serverStart() {
const server = ganache.server(startupOptions);
server.listen(8545, function(err, blockchain) {
server.listen(process.env.PORT, function(err, blockchain) {
// The server starts, you can connect to it with RPC now.
console.log("Server is running, feel free to connect!");
@ -283,4 +283,28 @@ async function serverStart() {
function invertHex(hexString) {
hexString = hexString.replace("0x", "");
return "0x" + hexString.split("").reverse().join("");
}
function fwdFaucetConfiguration(walletInfo) {
console.log("Configuring faucet.");
// check if config.json exists, if not, copy from config.json.example
if (!fs.existsSync("./deploy/faucet/config.json")) {
fs.copyFileSync("./deploy/faucet/config.json.example", "./deploy/faucet/config.json");
console.log("Config file created.");
let faucet_config = require("./deploy/faucet/config.json");
faucet_config.port = process.env.FAUCET_PORT;
faucet_config.Ethereum.prod.rpc = 'http://127.0.0.1:' + process.env.PORT;
faucet_config.Ethereum.prod.account = walletInfo.address;
faucet_config.Ethereum.prod.privateKey = walletInfo.privateKey;
fs.writeFile("./deploy/faucet/config.json", JSON.stringify(faucet_config), function(err) {
if(err) {
return console.log(err);
}
console.log("Saved new faucet configuration.");
});
} else {
console.log("Config file for faucet already exists. Edit it manually or delete to regenerate it.");
}
}