Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Improve scheduling via CLI #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 19 additions & 32 deletions src/Schedule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,39 @@ const schedule = async (options, program) => {
const defaultValues = await getDefaultValues(web3);

if (!await eac.Util.checkNetworkID()) {
throw new Error('Must be using the Kovan or Ropsten test network.');
throw new Error('You are not using a supported network. Please use Ethereum mainnet, ropsten, kovan or rinkeby.');
}

checkOptionsForWalletAndPassword(program);

const wallet = loadWalletFromKeystoreFile(web3, program.wallet, program.password);

// Initiate the shedule parameters.
let scheduleParams = {};
let jsonParams = {};
if (options.json) {
scheduleParams = JSON.parse(options.json);
jsonParams = JSON.parse(options.json);
}

// Initiate the input reader.
const readInput = new ReadInput(web3, options, defaultValues);
const temporalUnit = program.temporalUnit ? program.temporalUnit : jsonParams.temporalUnit;
const to = program.to ? program.to : jsonParams.to;
const callData = program.callData ? program.callData : jsonParams.callData;
const callGas = program.callGas ? program.callGas : jsonParams.callGas;
const callValue = program.callValue ? program.callValue : jsonParams.callValue;

// Start the wizard.
clear();
console.log('Welcome to the scheduling wizard!\n');
const windowStart = program.windowStart ? program.windowStart : jsonParams.windowStart;
const windowSize = program.windowSize ? program.windowSize : jsonParams.windowSize;

// See if we were provided the parameters in JSON or
// ask the user for them interactively.

const temporalUnit = scheduleParams.temporalUnit || readInput.readTemporalUnit();
const recipient = scheduleParams.recipient || readInput.readRecipientAddress();
const callData = scheduleParams.callData || readInput.readCallData();
const callGas = scheduleParams.callGas || readInput.readCallGas();
const callValue = scheduleParams.callValue || readInput.readCallValue();

const currentBlockNumber = await eac.Util.getBlockNumber();

const windowStart = scheduleParams.windowStart || readInput.readWindowStart(currentBlockNumber);
const windowSize = scheduleParams.windowSize || readInput.readWindowSize(temporalUnit);
const gasPrice = program.gasPrice ? program.gasPrice : jsonParams.gasPrice;
const fee = program.fee ? program.fee : jsonParams.fee;
const bounty = program.bounty ? program.bounty : jsonParams.bounty;
const requiredDeposit = program.requiredDeposit ? program.requiredDeposit : jsonParams.requiredDeposit;

// Validation
const soonestScheduleTime = currentBlockNumber + MINIMUM_PERIOD_BEFORE_SCHEDULE(temporalUnit);
if (windowStart < soonestScheduleTime) {
throw new Error(`Window start of ${windowStart} too soon.\nSoonest Schedule Time: ${soonestScheduleTime}`);
}

const gasPrice = scheduleParams.gasPrice || readInput.readGasPrice();
const fee = scheduleParams.fee || readInput.readFee();
const bounty = scheduleParams.bounty || readInput.readBounty();
const requiredDeposit = scheduleParams.deposit || readInput.readDeposit();

// Calculate the required endowment according to these params.
const endowment = eac.Util.calcEndowment(
new BigNumber(callGas),
Expand All @@ -83,10 +72,8 @@ const schedule = async (options, program) => {
new BigNumber(bounty),
);

// We have all the input we need, now we confirm with the user.
clear();

console.log(`Recipient: ${recipient}`);
console.log('You have inputted the following parameters: ')
console.log(`To: ${to}`);
console.log(`Call Data: ${callData}`);
console.log(`Call Gas: ${callGas}`);
console.log(`Window Size: ${windowSize}`);
Expand All @@ -97,7 +84,7 @@ const schedule = async (options, program) => {
console.log(`Required Deposit: ${requiredDeposit}`);
console.log('\n');
console.log(`Sending from: ${wallet.getAddresses()[0]}`);
console.log(`Endowment to send: ${web3.fromWei(endowment.toString())}`);
console.log(`Transaction will send: ${web3.fromWei(endowment.toString())} ether`);

const confirmed = rls.question('Are the above parameters correct? [Y/n]\n');
if (confirmed.toLowerCase() !== 'y' && confirmed !== '') {
Expand All @@ -110,7 +97,7 @@ const schedule = async (options, program) => {

try {
const { receipt, success } = await scheduleUsingWallet({
recipient,
to,
callData,
callGas,
callValue,
Expand Down
17 changes: 14 additions & 3 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ program
/** Schedule */
program
.command('schedule')
.description('Scheduled a transaction')
.option('--block')
.description('Schedule a transaction')
.option('--json <object>', 'Pass a JSON object of the params')
.option('--timestamp')

.option('--bounty', 'Sets the bounty for the scheduled transaction', '')
.option('--callData', 'Sets the call data for the scheduled transaction', '')
.option('--callGas', 'Sets the gas for the scheduled transaction', 0)
.option('--callValue', 'Sets the value for the scheduled transaction', 0)
.option('--fee', 'Sets the fee for the scheduled transaction')
.option('--gasPrice', 'Sets the minimum gas price for the scheduled transaction', 0)
.option('--requiredDeposit', 'Sets the required deposit', 0)
.option('--temporalUnit', 'Sets the parameters to use unit blocks or timestamps', 0)
.option('--to', 'Sets the recipient of the scheduled transactions', '')
.option('--windowSize', 'Sets the size of the execution window', 0)
.option('--windowStart', 'Sets the start of the execution window', 0)

.action((options) => catchErrors(schedule(options, program)))

/** TimeNode */
Expand Down