Use kredits library in add-proposal script
This commit is contained in:
parent
1779d66ee6
commit
85032353ca
@ -1,38 +1,46 @@
|
|||||||
const Registry = artifacts.require('./Registry.sol');
|
const Registry = artifacts.require('./Registry.sol');
|
||||||
const Operator = artifacts.require('./Operator.sol');
|
|
||||||
const Contributors = artifacts.require('./Contributors.sol');
|
|
||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
|
|
||||||
const bs58 = require('bs58');
|
const ethers = require('ethers');
|
||||||
|
const Kredits = require('../lib/kredits');
|
||||||
function getBytes32FromMultiash(multihash) {
|
|
||||||
const decoded = bs58.decode(multihash);
|
|
||||||
|
|
||||||
return {
|
|
||||||
digest: `0x${decoded.slice(2).toString('hex')}`,
|
|
||||||
hashFunction: decoded[0],
|
|
||||||
size: decoded[1],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function(callback) {
|
module.exports = function(callback) {
|
||||||
Registry.deployed().then(async (registry) => {
|
Registry.deployed().then(async (registry) => {
|
||||||
var operatorAddress = await registry.getProxyFor('Operator');
|
const networkId = parseInt(web3.version.network);
|
||||||
var contributorsAddress = await registry.getProxyFor('Contributors');
|
const provider = new ethers.providers.Web3Provider(
|
||||||
|
web3.currentProvider, { chainId: networkId }
|
||||||
|
);
|
||||||
|
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||||
|
|
||||||
var operator = await Operator.at(operatorAddress);
|
console.log(`Using operator at: ${kredits.Operator.contract.address}`);
|
||||||
var contributors = await Contributors.at(contributorsAddress);
|
|
||||||
|
|
||||||
let recipientAddress = await promptly.prompt('Contributor address: ');
|
let contributor = await promptly.prompt('Contributor (address or id): ');
|
||||||
let ipfsHash = await promptly.prompt('IPFS hash (blank for default): ', { default: 'QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs' });
|
let contributorId;
|
||||||
|
if (contributor.length < 5) {
|
||||||
|
contributorId = contributor;
|
||||||
|
} else {
|
||||||
|
contributorId = await contributors.getContributorIdByAddress(contributor);
|
||||||
|
}
|
||||||
|
console.log(`Creating a proposal for contributor ID #${contributorId}`);
|
||||||
|
|
||||||
let multihash = getBytes32FromMultiash(ipfsHash);
|
let contributionAttributes = {
|
||||||
|
contributorId,
|
||||||
|
amount: await promptly.prompt('Amount: '),
|
||||||
|
description: await promptly.prompt('Description: '),
|
||||||
|
kind: await promptly.prompt('Kind: ', { default: 'dev' }),
|
||||||
|
url: await promptly.prompt('URL: ', { default: '' })
|
||||||
|
}
|
||||||
|
|
||||||
let contributorId = await contributors.getContributorIdByAddress(recipientAddress);
|
console.log("\nAdding proposal:");
|
||||||
|
console.log(contributionAttributes);
|
||||||
|
|
||||||
let result = await operator.addProposal(contributorId.toNumber(), 23, multihash.digest, multihash.hashFunction, multihash.size);
|
kredits.Operator.addProposal(contributionAttributes, { gasLimit: 300000 }).then((result) => {
|
||||||
console.log('Proposal added, tx: ', result.tx);
|
console.log("\n\nResult:");
|
||||||
|
console.log(result);
|
||||||
callback();
|
callback();
|
||||||
|
}).catch((error) => {
|
||||||
|
console.log('Failed to create proposal');
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user