Refactor helper scripts to use kredits module
This reuses the kredits library functions in the helper scripts and seeds. We no longer need to add IPFS hashes manually but simply can provider contributor/proposal data.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
const REPL = require('repl');
|
||||
const promptly = require('promptly');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
|
||||
module.exports = function(callback) {
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
Registry.deployed().then(async (registry) => {
|
||||
@@ -12,26 +15,31 @@ module.exports = function(callback) {
|
||||
args = argumentInput.split(',').map(a => a.trim());
|
||||
}
|
||||
|
||||
let contractAddress = await registry.getProxyFor(contractName);
|
||||
console.log(`Using ${contractName} at ${contractAddress}`);
|
||||
let contract = await artifacts.require(`./${contractName}`).at(contractAddress);
|
||||
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)}`);
|
||||
|
||||
if (!contract[method]) {
|
||||
callback(new Error(`Method ${method} is not defined on ${contractName}`));
|
||||
return;
|
||||
}
|
||||
console.log(`Calling ${method} with ${JSON.stringify(args)}`);
|
||||
|
||||
contract[method](...args).then((result) => {
|
||||
console.log("\nResult:");
|
||||
console.log(result);
|
||||
|
||||
console.log("\nStartig a REPL. (type .exit to exit)");
|
||||
console.log(`defined variables: result, ${contractName}, web3`);
|
||||
console.log(`defined variables: result, ${contractName}, kredis`);
|
||||
let r = REPL.start();
|
||||
r.context.result = result;
|
||||
r.context[contractName] = contract;
|
||||
r.context.web3 = web3;
|
||||
r.context.kredits = kredits;
|
||||
|
||||
r.on('exit', () => {
|
||||
console.log('Bye');
|
||||
|
||||
Reference in New Issue
Block a user