integrate kredits contract to add proposals

This commit is contained in:
2017-05-05 20:22:08 +02:00
parent ddd4f87799
commit 6b67c04e0a
59 changed files with 42 additions and 8155 deletions

View File

@@ -4,12 +4,47 @@
// Configuration:
// KREDITS_WEBHOOK_TOKEN: A string for building your secret webhook URL
// KREDITS_ROOM: Kredit proposals are posted to this chatroom
// KREDITS_WALLET_PATH: Path to a etherum wallet JSON file
// KREDITS_WALLET_PASSWORD: Wallet password
//
// Authors:
// Sebastian Kippe <sebastian@kip.pe>
// const fs = require('fs');
//
const fetch = require('node-fetch');
const kreditsContracts = require('kredits-contracts');
const fs = require('fs');
const ProviderEngine = require('web3-provider-engine');
const Wallet = require('ethereumjs-wallet');
const WalletSubprovider = require('ethereumjs-wallet/provider-engine');
const Web3Subprovider = require('web3-provider-engine/subproviders/web3.js');
const Web3 = require('web3');
let engine = new ProviderEngine();
let walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
let walletJson = fs.readFileSync(walletPath);
let wallet = Wallet.fromV3(JSON.parse(walletJson), process.env.KREDITS_WALLET_PASSWORD);
let providerUrl = process.env.KREDITS_PROVIDER_URL || 'http://localhost:8545';
let hubotWalletAddress = '0x' + wallet.getAddress().toString('hex');
engine.addProvider(new WalletSubprovider(wallet, {}));
engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(providerUrl)));
engine.start();
let web3 = new Web3(engine);
let contracts = kreditsContracts(web3);
let Kredits = contracts['Kredits'];
let Token = contracts['Token'];
console.log('[HUBOT-KREDITS] wallet address: ' + hubotWalletAddress);
web3.eth.getBalance('eee2de74de31d2e3ef24cb0f6959fd88b59267bd', function (err, balance) {
if (err) { console.log('[HUBOT-KREDITS] error checking balance'); return; }
if (!balance > 0) {
console.log('[HUBOT-KREDITS] Hubot is broke. Please sond some eth to ' + hubotWalletAddress);
}
});
(function() {
"use strict";
@@ -44,7 +79,8 @@ const fetch = require('node-fetch');
// TODO write metaData to IPFS
console.log(`Creating proposal to issue ${amount}₭S to ${recipient} for ${url}...`);
// robot.messageRoom(process.env.KREDITS_ROOM, message);
Kredits.addProposal(recipient, amount, url, '');
robot.messageRoom(process.env.KREDITS_ROOM, `new proposal: ${amount} for ${recipient}`);
resolve();
});
}