hacking
This commit is contained in:
@@ -3,43 +3,63 @@ const Operator = artifacts.require('./Operator.sol');
|
||||
const Contributors = artifacts.require('./Contributors.sol');
|
||||
const promptly = require('promptly');
|
||||
|
||||
const IPFS = require('../lib/utils/ipfs');
|
||||
const ipfs = new IPFS();
|
||||
const bs58 = require('bs58');
|
||||
|
||||
function getBytes32FromMultiash(multihash) {
|
||||
const decoded = bs58.decode(multihash);
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
|
||||
return {
|
||||
digest: `0x${decoded.slice(2).toString('hex')}`,
|
||||
hashFunction: decoded[0],
|
||||
size: decoded[1],
|
||||
};
|
||||
async function prompt(message, options) {
|
||||
if (!options) {
|
||||
options = {default: ''}
|
||||
}
|
||||
return await promptly.prompt(message, options);
|
||||
}
|
||||
|
||||
module.exports = function(callback) {
|
||||
Registry.deployed().then(async (registry) => {
|
||||
var operatorAddress = await registry.getProxyFor('Operator');
|
||||
var contributorsAddress = await registry.getProxyFor('Contributors');
|
||||
|
||||
var operator = await Operator.at(operatorAddress);
|
||||
var contributors = await Contributors.at(contributorsAddress);
|
||||
console.log(`Using registry at: ${registry.address}`);
|
||||
let networkId = parseInt(web3.version.network);
|
||||
console.log(web3.currentProvider);
|
||||
let provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider,
|
||||
{ chainId: networkId }
|
||||
)
|
||||
console.log(provider.getSigner());
|
||||
const kredits = await new Kredits(provider, provider.getSigner(), {Registry: registry.address}).init();
|
||||
console.log(`Using contributors at: ${kredits.Contributor.address}`);
|
||||
let contributorAttributes = {
|
||||
account: await prompt('Contributor address: ', {}),
|
||||
name: await prompt('Name: '),
|
||||
isCore: await prompt('core? y/n') === 'y',
|
||||
kind: await prompt('Kind (default person): ', {default: 'person'}),
|
||||
url: await prompt('URL: '),
|
||||
github_username: await prompt('GitHub username: '),
|
||||
github_uid: await prompt('GitHub UID: '),
|
||||
wiki_username: await prompt('Wiki username: '),
|
||||
}
|
||||
|
||||
let contributorToAddAddress = await promptly.prompt('Contributor address: ');
|
||||
let ipfsHash = await promptly.prompt('IPFS hash (blank for default): ', { default: 'QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs' });
|
||||
|
||||
let contributorMultihash = getBytes32FromMultiash(ipfsHash);
|
||||
let isCore = true;
|
||||
let contributorResult = await contributors.addContributor(contributorToAddAddress, contributorMultihash.digest, contributorMultihash.hashFunction, contributorMultihash.size, isCore);
|
||||
console.log('Contributor added, tx: ', contributorResult.tx);
|
||||
|
||||
let contributorId = await contributors.getContributorIdByAddress(contributorToAddAddress);
|
||||
let proposalMultihash = getBytes32FromMultiash('QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs');
|
||||
let proposalResult = await operator.addProposal(contributorId, 23, proposalMultihash.digest, proposalMultihash.hashFunction, proposalMultihash.size);
|
||||
console.log('Proposal added, tx: ', proposalResult.tx);
|
||||
|
||||
let proposalId = await operator.proposalsCount();
|
||||
let votingResult = await operator.vote(proposalId.toNumber()-1);
|
||||
console.log('Voted for proposal', proposalId.toString(), votingResult.tx);
|
||||
|
||||
callback();
|
||||
contributorAttributes = {
|
||||
account: '0x398ac9cdb122e6f526c8bf8dd80eeeb18fce8821',
|
||||
name: 'bumi',
|
||||
isCore: '1'
|
||||
}
|
||||
console.log("\nCreating new contributor with following attributes:");
|
||||
console.log(contributorAttributes);
|
||||
kredits.Contributor.functions.addContributor('0x398ac9cdb122e6f526c8bf8dd80eeeb18fce8821',
|
||||
'0x272bbfc66166f26cae9c9b96b7f9590e095f02edf342ac2dd71e1667a12116ca', 18, 32, true).then((r) => {
|
||||
console.log(r);
|
||||
process.exit();
|
||||
});
|
||||
/*
|
||||
kredits.Contributor.add(contributorAttributes).then((result) => {
|
||||
console.log(result);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
console.log('Failed to create contributor');
|
||||
callback(error);
|
||||
});
|
||||
*/
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user