mirror of
https://github.com/status-im/thundercloud.git
synced 2025-02-28 10:50:30 +00:00
Added mykeys mode
This commit is contained in:
parent
2586615867
commit
9796e817f1
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ deploy/keys/*
|
||||
deploy/faucet/*
|
||||
!.gitkeep
|
||||
*.log
|
||||
.mykeys.json
|
5
.mykeys.example
Normal file
5
.mykeys.example
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"0x5a49AD36dcC0b7703232FC1e2772b9D225A9d96f": "0x75a0f81e2d07d5a1e9238d1db7713dc0dc897e7e4091aa30d7a423b97aab3a86",
|
||||
"0xf2f9E6e843d77cD13b22821f112Fec5Fa8652d9D": "0xe1e5e0dfb919afac0f2757dd576f5e4ecf14f4c6534e95793b38b79d274a9d62",
|
||||
"0x931C4939163d2942C47bA822B9A2B7cc57669e43": "0x2d87ce687f83d922e477e111c3cd8ed16124707f4dca0c0ef9ede1aa057e64fc"
|
||||
}
|
@ -20,9 +20,10 @@ The blockchain database will be stored in the `deploy/db` subfolder. The `deploy
|
||||
|
||||
#### Flags
|
||||
|
||||
Augment `start.js` with flags, .e.g. `node start.js v=50`:
|
||||
Augment `start.js` with flags, .e.g. `node start.js v=50 mykeys`:
|
||||
|
||||
- `v` : Number of validators to generate. These validators will be generated with 32.1 ether each and will auto-deposit 32 ether to the deposit contract. Their private keys will be in `deploy/keys` @TODO, `account_keys_path` in Ganache seems bugged.
|
||||
- `mykeys`: This is a boolean flag, so just include it to activate it. Passing this in will make the boostrapper read a `.mykeys.json` file in the root of the project, looking for private keys. The file should be a JSON object of address=>privkey pairs, `0x` included. These keys will then also be included as validators: they will be given 32.1 ether and deposit it into the contract. See `.mykeys.example` for example.
|
||||
|
||||
### Hosting
|
||||
|
||||
|
65
start.js
65
start.js
@ -35,6 +35,37 @@ if (arglist.v && arglist.v > 0) {
|
||||
startupOptions.accounts = accounts;
|
||||
}
|
||||
|
||||
var myAccounts = [];
|
||||
if (arglist.mykeys) {
|
||||
try {
|
||||
var mykeys = require("./.mykeys.json");
|
||||
|
||||
} catch (e) {
|
||||
console.error("Did you make sure .mykeys exists in this folder before running the command with the mykeys flag?");
|
||||
return;
|
||||
}
|
||||
|
||||
for (var key in mykeys) {
|
||||
if (mykeys.hasOwnProperty(key)) {
|
||||
console.log("Queueing account " + key);
|
||||
myAccounts.push({"balance": 0x1BD7A1BED4A0A0000, "secretKey": mykeys[key]});
|
||||
}
|
||||
}
|
||||
|
||||
if (startupOptions.hasOwnProperty("accounts")) {
|
||||
console.log("Merging own keys with pre-generated");
|
||||
startupOptions.accounts = startupOptions.accounts.concat(myAccounts);
|
||||
} else {
|
||||
console.log("Generating faucet account and appending queued keys.");
|
||||
myAccounts.unshift({"balance": 0xD3C21BCECCEDA1000000});
|
||||
startupOptions.accounts = myAccounts;
|
||||
}
|
||||
}
|
||||
|
||||
let unlockedAccounts =
|
||||
console.log("Bootstrapping with options:");
|
||||
console.log(startupOptions);
|
||||
|
||||
const ganache = require("ganache-cli");
|
||||
const provider = new ethers.providers.Web3Provider(ganache.provider(startupOptions));
|
||||
|
||||
@ -54,7 +85,7 @@ provider.listAccounts().then(function(result){
|
||||
console.log("Private key of faucet account "+ result[0] +" now in /deploy/keys/faucetkey.txt. It is seeded with ~" + faucetAmount + " ether.");
|
||||
});
|
||||
|
||||
deployDepositContract(mnemonicWallet.privateKey);
|
||||
deployDepositContract(mnemonicWallet.privateKey).then(makeValidatorDeposits);
|
||||
});
|
||||
|
||||
});
|
||||
@ -62,7 +93,7 @@ provider.listAccounts().then(function(result){
|
||||
async function deployDepositContract(pk) {
|
||||
let factory = new ethers.ContractFactory(deposit_contract_abi, deposit_contract_bytecode, new ethers.Wallet(pk, provider));
|
||||
let contract = await factory.deploy();
|
||||
console.log("Contract generated at " + contract.address + " via TX " + contract.deployTransaction.hash);
|
||||
console.log("Contract will be generated at " + contract.address + " when TX " + contract.deployTransaction.hash) + " is mined.";
|
||||
|
||||
fs.writeFile("deploy/keys/deposit_contract.txt", contract.address, function(err) {
|
||||
if(err) {
|
||||
@ -71,6 +102,32 @@ async function deployDepositContract(pk) {
|
||||
console.log("Contract address saved in deploy/keys.");
|
||||
});
|
||||
|
||||
// The contract is NOT deployed yet; we must wait until it is mined
|
||||
await contract.deployed()
|
||||
await contract.deployed().then(function(){console.log("Contract deployed and ready.")});
|
||||
}
|
||||
|
||||
async function makeValidatorDeposits() {
|
||||
console.log("Starting validator deposits")
|
||||
|
||||
provider.listAccounts().then(function(result) {
|
||||
// Remove first one (faucet account)
|
||||
var accounts = result.splice(1);
|
||||
|
||||
for (var i = 1; i < accounts.length; i++) {
|
||||
let signer = provider.getSigner(accounts[i]);
|
||||
|
||||
// TODO deposits, need to figure out BLS
|
||||
|
||||
// signer.sendTransaction({
|
||||
// to: accounts[0],
|
||||
// value: ethers.utils.parseEther('15.0')
|
||||
// }).then(function(txReceipt) {
|
||||
// provider.getBalance(accounts[0]).then(console.log);
|
||||
// }.bind(accounts));
|
||||
|
||||
}
|
||||
|
||||
// for (var i = 0; i < accounts.length; i++) {
|
||||
// provider.getBalance(accounts[i]).then(console.log);
|
||||
// }
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user