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,34 +1,39 @@
|
||||
const path = require('path');
|
||||
const seeds = require(path.join(__dirname, '..', '/config/seeds.js'));
|
||||
const IPFS = require('ipfs-api');
|
||||
|
||||
var ipfs = IPFS({host: 'localhost', port: '5001', protocol: 'http'})
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
|
||||
const each = require('async-each-series');
|
||||
|
||||
module.exports = function(callback) {
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
|
||||
const contracts = {};
|
||||
Registry.deployed().then((registry) => {
|
||||
Object.keys(seeds.contractCalls).forEach(async (contract) => {
|
||||
var address = await registry.getProxyFor(contract);
|
||||
console.log(`Using ${contract} at ${address}`);
|
||||
contracts[contract] = await artifacts.require(contract).at(address);
|
||||
Registry.deployed().then(async (registry) => {
|
||||
|
||||
Object.keys(seeds.contractCalls[contract]).forEach((method) => {
|
||||
seeds.contractCalls[contract][method].forEach((args) => {
|
||||
console.log(`[Sending] ${contract}.#${method}(${JSON.stringify(args)})`);
|
||||
contracts[contract][method](...args).then((result) => {
|
||||
console.log(`[Result] ${contract}.${method}(${JSON.stringify(args)}) => ${result.tx}`);
|
||||
});
|
||||
});
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
|
||||
each(seeds.contractCalls, (call, next) => {
|
||||
let [contractName, method, args] = call;
|
||||
let contractWrapper = kredits[contractName];
|
||||
let func;
|
||||
if (contractWrapper[method]) {
|
||||
func = contractWrapper[method];
|
||||
} else {
|
||||
func = contractWrapper.functions[method];
|
||||
}
|
||||
func.apply(contractWrapper, args).then((result) => {
|
||||
console.log(`[OK] kredits.${contractName}.${method}(${JSON.stringify(args)}) => ${result.hash}`);
|
||||
next();
|
||||
}).catch((error) => {
|
||||
console.log(`[FAILD] kredits.${contractName}.${method}(${JSON.stringify(args)})`);
|
||||
callback(error)
|
||||
});
|
||||
});
|
||||
}, () => { console.log("\nDone!") });
|
||||
|
||||
});
|
||||
|
||||
|
||||
seeds.ipfsContent.forEach((content) => {
|
||||
ipfs.add(new ipfs.Buffer(JSON.stringify(content))).then((result) => { console.log(`[IPFS] added ${result[0].hash}`) });
|
||||
});
|
||||
|
||||
callback();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user