Improve helper scripts #41
@ -7,30 +7,43 @@ const Kredits = require('../lib/kredits');
|
||||
module.exports = function(callback) {
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
Registry.deployed().then(async (registry) => {
|
||||
let contractName = await promptly.prompt('Contract Name: ');
|
||||
let method = await promptly.prompt('Function: ');
|
||||
let argumentInput = await promptly.prompt('Arguments (comma separated): ', { default: '' });
|
||||
let args = [];
|
||||
if (argumentInput !== '') {
|
||||
args = argumentInput.split(',').map(a => a.trim());
|
||||
}
|
||||
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
|
||||
const contract = kredits[contractName].contract;
|
||||
console.log(`Using ${contractName} at ${contract.address}`);
|
||||
console.log(`Calling ${method} with ${JSON.stringify(args)}`);
|
||||
let contractName = await promptly.prompt('Contract Name: ');
|
||||
const contractWrapper = kredits[contractName];
|
||||
|
||||
if (!contract[method]) {
|
||||
let method;
|
||||
method = await promptly.prompt('Function (? for available functions): ');
|
||||
while (method === '?') {
|
||||
console.log(`Contract functions: ${JSON.stringify(Object.keys(contractWrapper.functions))}`);
|
||||
console.log(`\nWrapper functions: ${JSON.stringify(Object.getOwnPropertyNames(Object.getPrototypeOf(contractWrapper)))}`);
|
||||
console.log("\n");
|
||||
|
||||
method = await promptly.prompt('Function: ');
|
||||
}
|
||||
if (!contractWrapper[method] && !contractWrapper.functions[method]) {
|
||||
|
|
||||
callback(new Error(`Method ${method} is not defined on ${contractName}`));
|
||||
return;
|
||||
}
|
||||
let argumentInput = await promptly.prompt('Arguments (comma separated): ', { default: '' });
|
||||
let args = [];
|
||||
|
👀 nice! 👀 nice!
|
||||
if (argumentInput !== '') {
|
||||
args = argumentInput.split(',').map(a => a.trim());
|
||||
}
|
||||
console.log(`Using ${contractName} at ${contractWrapper.contract.address}`);
|
||||
console.log(`Calling ${method} with ${JSON.stringify(args)}`);
|
||||
|
||||
contract[method](...args).then((result) => {
|
||||
let func;
|
||||
if (contractWrapper[method]) {
|
||||
func = contractWrapper[method];
|
||||
} else {
|
||||
func = contractWrapper.functions[method];
|
||||
}
|
||||
func.apply(contractWrapper, args).then((result) => {
|
||||
console.log("\nResult:");
|
||||
|
Haha master of es6. I think you don’t need the if and the initial Haha master of es6. I think you don’t need the if and the initial `args`
`let args = argumentInput.split(',')` should return an empty array.
oh yeah, true. oh yeah, true.
ah noo. it returns an array with an empty string, that was the reason for the if. or what am I missing? ah noo. it returns an array with an empty string, that was the reason for the if. or what am I missing?
Ah ok. Ah ok.
But if input is already not an empty string, wouldn't it return an array with one argument string? But if input is already not an empty string, wouldn't it return an array with one argument string?
https://jsbin.com/qarikabane/edit?js,console it would return https://jsbin.com/qarikabane/edit?js,console
it would return `[""]` but if no arguments are given I need `[]`.
I was actually asking about the I was actually asking about the `trim` inside, but no idea why. It's for removing whitespace, so that's still needed.
yep, trim() for potential whitespace as for example in yep, trim() for potential whitespace as for example in `"first, second"`
|
||||
console.log(result);
|
||||
|
||||
@ -38,7 +51,7 @@ module.exports = function(callback) {
|
||||
console.log(`defined variables: result, ${contractName}, kredis`);
|
||||
let r = REPL.start();
|
||||
r.context.result = result;
|
||||
r.context[contractName] = contract;
|
||||
r.context[contractName] = contractWrapper;
|
||||
r.context.kredits = kredits;
|
||||
|
||||
r.on('exit', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user
So good that we went with upper case contract names and the properties instead of the functions!
But it will breaks on
Contributor, wouldn’t it? I think we should rename that contract next and align the module code to it. Will make the future much brighter!yes, agree on renaming it! and maybe adding an alias for Contributor <=> Contributors
I opened #44 for the alias