Refactor kredits init in helper scripts
This now also supports readonly providers like infura
This commit is contained in:
parent
94832d4d07
commit
4bd1aed197
@ -1,16 +1,15 @@
|
|||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
|
|
||||||
const ethers = require('ethers');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const Kredits = require('../lib/kredits');
|
|
||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
let kredits;
|
||||||
const provider = new ethers.providers.Web3Provider(
|
try {
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
kredits = await initKredits(web3);
|
||||||
);
|
} catch(e) {
|
||||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
callback(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Using Contributions at: ${kredits.Contribution.contract.address}`);
|
console.log(`Using Contributions at: ${kredits.Contribution.contract.address}`);
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
|
|
||||||
const ethers = require('ethers');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const Kredits = require('../lib/kredits');
|
|
||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
async function prompt(message, options) {
|
async function prompt(message, options) {
|
||||||
if (!options) {
|
if (!options) {
|
||||||
@ -13,11 +10,13 @@ async function prompt(message, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
let kredits;
|
||||||
const provider = new ethers.providers.Web3Provider(
|
try {
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
kredits = await initKredits(web3);
|
||||||
);
|
} catch(e) {
|
||||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
callback(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Using contributors at: ${kredits.Contributor.contract.address}`);
|
console.log(`Using contributors at: ${kredits.Contributor.contract.address}`);
|
||||||
|
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
|
|
||||||
const ethers = require('ethers');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const Kredits = require('../lib/kredits');
|
|
||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
let kredits;
|
||||||
const provider = new ethers.providers.Web3Provider(
|
try {
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
kredits = await initKredits(web3);
|
||||||
);
|
} catch(e) {
|
||||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
callback(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`);
|
console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`);
|
||||||
|
|
||||||
|
@ -1,18 +1,10 @@
|
|||||||
const REPL = require('repl');
|
const REPL = require('repl');
|
||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
|
|
||||||
const ethers = require('ethers');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const Kredits = require('../lib/kredits');
|
|
||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
initKredits(web3).then(async function(kredits) {
|
||||||
const provider = new ethers.providers.Web3Provider(
|
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
|
||||||
);
|
|
||||||
|
|
||||||
new Kredits(provider, provider.getSigner()).init().then(async function(kredits) {
|
|
||||||
let contractName = await promptly.prompt('Contract Name: ');
|
let contractName = await promptly.prompt('Contract Name: ');
|
||||||
const contractWrapper = kredits[contractName];
|
const contractWrapper = kredits[contractName];
|
||||||
|
|
||||||
|
25
scripts/helpers/init_kredits.js
Normal file
25
scripts/helpers/init_kredits.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const ethers = require('ethers');
|
||||||
|
const getNetworkId = require('./networkid.js')
|
||||||
|
const Kredits = require('../../lib/kredits');
|
||||||
|
|
||||||
|
module.exports = async function(web3) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
getNetworkId(web3).then(networkId => {
|
||||||
|
const provider = new ethers.providers.Web3Provider(
|
||||||
|
web3.currentProvider, { chainId: parseInt(networkId) }
|
||||||
|
);
|
||||||
|
let signer = provider.getSigner();
|
||||||
|
// checking if siner supports signing transactions
|
||||||
|
signer.getAddress().then(_ => {
|
||||||
|
new Kredits(provider, signer).init().then(kredits => {
|
||||||
|
resolve(kredits);
|
||||||
|
})
|
||||||
|
}).catch(e => {
|
||||||
|
console.log(`Signer account not available; readonly connection (${e.message}`);
|
||||||
|
new Kredits(provider, null).init().then(kredits => {
|
||||||
|
resolve(kredits);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
@ -1,17 +1,16 @@
|
|||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
const Table = require('cli-table');
|
const Table = require('cli-table');
|
||||||
|
|
||||||
const ethers = require('ethers');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const Kredits = require('../lib/kredits');
|
|
||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
let kredits;
|
||||||
const provider = new ethers.providers.Web3Provider(
|
try {
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
kredits = await initKredits(web3);
|
||||||
);
|
} catch(e) {
|
||||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
callback(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
|
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
|
||||||
|
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
const Table = require('cli-table');
|
const Table = require('cli-table');
|
||||||
|
|
||||||
const ethers = require('ethers');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const Kredits = require('../lib/kredits');
|
|
||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
let kredits;
|
||||||
const provider = new ethers.providers.Web3Provider(
|
try {
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
kredits = await initKredits(web3);
|
||||||
);
|
} catch(e) {
|
||||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
callback(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
|
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
|
||||||
|
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
const Table = require('cli-table');
|
const Table = require('cli-table');
|
||||||
|
|
||||||
const ethers = require('ethers');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const Kredits = require('../lib/kredits');
|
|
||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
let kredits;
|
||||||
const provider = new ethers.providers.Web3Provider(
|
try {
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
kredits = await initKredits(web3);
|
||||||
);
|
} catch(e) {
|
||||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
callback(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`);
|
console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`);
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
const REPL = require('repl');
|
const REPL = require('repl');
|
||||||
|
|
||||||
const ethers = require('ethers');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const Kredits = require('../lib/kredits');
|
|
||||||
|
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
function promiseEval (repl) {
|
function promiseEval (repl) {
|
||||||
const currentEval = repl.eval;
|
const currentEval = repl.eval;
|
||||||
@ -21,12 +18,14 @@ function promiseEval (repl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
let kredits;
|
||||||
const provider = new ethers.providers.Web3Provider(
|
try {
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
kredits = await initKredits(web3);
|
||||||
);
|
} catch(e) {
|
||||||
|
callback(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
new Kredits(provider, provider.getSigner()).init().then((kredits) => {
|
|
||||||
console.log(`Defined variables: kredits, web3`);
|
console.log(`Defined variables: kredits, web3`);
|
||||||
let r = REPL.start();
|
let r = REPL.start();
|
||||||
r.context.kredits = kredits;
|
r.context.kredits = kredits;
|
||||||
@ -37,5 +36,4 @@ module.exports = async function(callback) {
|
|||||||
console.log('Bye');
|
console.log('Bye');
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,17 @@ const path = require('path');
|
|||||||
const each = require('async-each-series');
|
const each = require('async-each-series');
|
||||||
const ethers = require('ethers');
|
const ethers = require('ethers');
|
||||||
|
|
||||||
const Kredits = require('../lib/kredits');
|
const initKredits = require('./helpers/init_kredits.js');
|
||||||
const getNetworkId = require('./helpers/networkid.js')
|
|
||||||
|
|
||||||
const seeds = require(path.join(__dirname, '..', '/config/seeds.js'));
|
const seeds = require(path.join(__dirname, '..', '/config/seeds.js'));
|
||||||
|
|
||||||
module.exports = async function(callback) {
|
module.exports = async function(callback) {
|
||||||
const networkId = await getNetworkId(web3)
|
let kredits;
|
||||||
const provider = new ethers.providers.Web3Provider(
|
try {
|
||||||
web3.currentProvider, { chainId: parseInt(networkId) }
|
kredits = await initKredits(web3);
|
||||||
);
|
} catch(e) {
|
||||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
callback(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let fundingAmount = 2;
|
let fundingAmount = 2;
|
||||||
each(seeds.funds, (address, next) => {
|
each(seeds.funds, (address, next) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user