Get contributions from minted events (WIP)

This commit is contained in:
2017-08-14 17:15:11 +02:00
parent 8fbecd928b
commit b8f4040def
6 changed files with 413 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import Ember from 'ember';
export default Ember.Object.extend({
// blockNumber: null,
// blockHash: null,
// transactionHash: null,
recipientAddress: null,
contributorId: null,
ipfsHash: null,
amount: null,
contribution: null,
kind: null,
description: null,
url: null,
details: null,
/**
* Loads the contribution details from IPFS and sets local instance
* properties from it
*
* @method
* @public
*/
loadDetails(ipfs) {
let promise = new Ember.RSVP.Promise((resolve, reject) => {
ipfs.getFile(this.get('ipfsHash')).then(content => {
let contributionJSON = JSON.parse(content);
let contribution = Ember.Object.create(contributionJSON);
this.setProperties({
kind: contribution.get('kind'),
description: contribution.get('description'),
url: contribution.get('url')
});
// TODO load details
// let details = profile.get('accounts');
Ember.Logger.debug('[proposal] loaded contribution details', contributionJSON);
resolve();
}).catch((err) => {
Ember.Logger.error('[proposal] error trying to load contribution details', this.get('ipfsHash'), err);
reject(err);
});
});
return promise;
},
});
+1
View File
@@ -26,6 +26,7 @@ export default Ember.Route.extend({
contributors: kredits.getContributors(), contributors: kredits.getContributors(),
totalSupply: kredits.getValueFromContract('tokenContract', 'totalSupply'), totalSupply: kredits.getValueFromContract('tokenContract', 'totalSupply'),
proposals: kredits.getProposals(), proposals: kredits.getProposals(),
contributions: kredits.getContributions(),
newContributor: Contributor.create({ kind: 'person' }) newContributor: Contributor.create({ kind: 'person' })
}); });
} }
+51
View File
@@ -3,6 +3,7 @@ import Web3 from 'npm:web3';
import config from 'kredits-web/config/environment'; import config from 'kredits-web/config/environment';
import Contributor from 'kredits-web/models/contributor'; import Contributor from 'kredits-web/models/contributor';
import Proposal from 'kredits-web/models/proposal'; import Proposal from 'kredits-web/models/proposal';
import Contribution from 'kredits-web/models/contribution';
import kreditsContracts from 'npm:kredits-contracts'; import kreditsContracts from 'npm:kredits-contracts';
import uuid from 'npm:uuid'; import uuid from 'npm:uuid';
@@ -226,6 +227,56 @@ export default Service.extend({
}); });
}, },
getTokenMintedEvents(fromBlock=0, toBlock='latest') {
return new Ember.RSVP.Promise((resolve, reject) => {
const minted = this.get('tokenContract')
.Minted({}, {fromBlock: fromBlock, toBlock: toBlock});
minted.get((err, res) => {
if (err) {
Ember.Logger.error('[kredits] Error reading Token#Minted events', res);
reject(err);
return;
}
Ember.Logger.warn('[kredits] Token#Minted events', res);
resolve(res);
});
});
},
getContributions() {
// this.getTokenMintedEvents().then(events => {
let contributions = [];
config.fixtures.mintedEvents.forEach(mintedEvent => {
contributions.push(this.getContributionData(mintedEvent));
});
return Ember.RSVP.all(contributions);
// });
},
getContributionData(mintedEvent) {
return new Ember.RSVP.Promise((resolve, reject) => {
let contribution = Contribution.create({
recipientAddress: mintedEvent.args.recipientAddress,
contributorId: mintedEvent.args.contributorId,
amount: mintedEvent.args.amount,
ipfsHash: mintedEvent.args.reference
});
if (contribution.get('ipfsHash')) {
contribution.loadDetails(this.get('ipfs')).then(
() => resolve(contribution),
err => reject(err)
);
} else {
Ember.Logger.warn('[kredits] contribution from Minted event is missing IPFS hash', contribution);
resolve(contribution);
}
});
},
// logKreditsContract: function() { // logKreditsContract: function() {
// Ember.Logger.debug('[kredits] kreditsContract', this.get('kreditsContract')); // Ember.Logger.debug('[kredits] kreditsContract', this.get('kreditsContract'));
// }.on('init') // }.on('init')
+4
View File
@@ -1,4 +1,6 @@
/* jshint node: true */ /* jshint node: true */
const fs = require('fs');
module.exports = function(environment) { module.exports = function(environment) {
var ENV = { var ENV = {
modulePrefix: 'kredits-web', modulePrefix: 'kredits-web',
@@ -65,6 +67,8 @@ module.exports = function(environment) {
port: '5001', port: '5001',
protocol: 'http' protocol: 'http'
}; };
const mintedEvents = JSON.parse(fs.readFileSync('config/fixtures-token-minted.json'));
ENV.fixtures = { mintedEvents: mintedEvents };
} }
if (environment === 'test') { if (environment === 'test') {
+291
View File
@@ -0,0 +1,291 @@
[
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x70ba4415fc788d9481b5c2e557a55ce698de15b02eb5fba514a0b33027796c5a",
"blockNumber": 46,
"logIndex": 0,
"transactionHash": "0x3d4baea1f8a63f5b80491d5e67f2a833a4a6db7427a0c07ca181a852cd29dedb",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xd4a64570b12da659ee4bbd41c3509b7b1f9c51ac",
"contributorId": 1,
"amount": "150",
"reference": "QmWj7XC6sSu1D7zmcH1tHFV9711P96m1z4qFP8yALZMWem"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x0112ca39f27dbc17ec7478336a9ba63ede0930cad0ead68b6fd441269950d6cc",
"blockNumber": 47,
"logIndex": 0,
"transactionHash": "0x8d1277270c51afdb9b6345015de176260412d7a649dfb00307dc8e7c513a250e",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xd4a64570b12da659ee4bbd41c3509b7b1f9c51ac",
"contributorId": 2,
"amount": "150",
"reference": "QmSfgMxbBHNouW9vwD8DHkfdbMjAuMpv1fpBB6uPCazRCA"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x98fc834495394b8b26520fcd503508b953f7977a89df49a2a2d6711f2aa4d0c6",
"blockNumber": 48,
"logIndex": 0,
"transactionHash": "0x8f21b1df6ea33520c437bf9252a611603f52dca397ba93a3e2680da2c31d28e1",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xf18e631ea191ae4ebe70046fcb01a43655441c6d",
"contributorId": 1,
"amount": "1000",
"reference": "QmNbmsh3Rozksv6a5cTQM5mapQNpksU4Zcy9zMLcWsJoUf"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0xf34ce94de4496441cb3972525f4010370b6957bbc09deba15501a169d063fa59",
"blockNumber": 50,
"logIndex": 0,
"transactionHash": "0x328ffbe2b34ba80c861445768b6069bc43eb511e196e7c22042a1f714aad78fa",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xd4a64570b12da659ee4bbd41c3509b7b1f9c51ac",
"contributorId": 3,
"amount": "150",
"reference": "QmYE2ipsfbk9fwLJQ5wBrc9WKtneHjEGfV2RfngsxdKe1g"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0xf6f8c1686497c7dc0ae4af2c87d7547b75bdffb960dce52a62bf74c1976980fb",
"blockNumber": 51,
"logIndex": 0,
"transactionHash": "0x694796b4b1bd82cadea6471eb2f718323ca85fed00ddb9b8a73524dec31141e6",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xd4a64570b12da659ee4bbd41c3509b7b1f9c51ac",
"contributorId": 2,
"amount": "50",
"reference": "QmZZVbZN6hQTA5ZxrUywehdC2cCHkD6wvkVbVWJP21UmgR"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x771045eecdd57959e9cb9ac613df988eeee8b800e8f9edebfdf01a8f1a4f3c5d",
"blockNumber": 52,
"logIndex": 0,
"transactionHash": "0xaf9f073f80b8b492a7e822cfd38e5d13474a99aaef9be0c3bc0ffaf8c653a5f4",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xf18e631ea191ae4ebe70046fcb01a43655441c6d",
"contributorId": 1,
"amount": "50",
"reference": "QmbrszXGexzCZaWer6nFxjj4EXp5y4WT3WYPrbeNooQMyy"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x86ee58b0e36f3d199b0d241f3efb868a7276fdf084cff48ef045bdfe235c0506",
"blockNumber": 53,
"logIndex": 0,
"transactionHash": "0x9c7076b2fa49988fe706639376413bc79e4c5549c0145f00d7f27af6088c7128",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xf18e631ea191ae4ebe70046fcb01a43655441c6d",
"contributorId": 1,
"amount": "150",
"reference": "QmV5wSKLRBdXXbRuxWneQ1tDZP75Dpjv3adQHGye8CemEb"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0xc2b3f860e0b8d4037529eca9b7d539332b3cc08741165378ac8368c22c6a18b3",
"blockNumber": 54,
"logIndex": 0,
"transactionHash": "0xfd2f5439e265e8899be5e2e18a9df56f4706e618d5459aa8f206aec091f7c0d9",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0x805bf817be0e53bf618eb41ae0775ac314f989a1",
"contributorId": 2,
"amount": "50",
"reference": "QmNp6ggpaR3yNuEWZbCttnUBjshQonFWE766iyVLAKfq7M"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x860667b8f67ae22ac97bd67d9ccb245eb98312eb5cb22303d1a8a383defbb5fc",
"blockNumber": 60,
"logIndex": 0,
"transactionHash": "0xbe153f64a31a1669ef1bffa16b0aeb1657b1b9fe779c38f6455d05fe3d96fd5b",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0x805bf817be0e53bf618eb41ae0775ac314f989a1",
"contributorId": 1,
"amount": "50",
"reference": "QmY2eBgBtFir4edYbw91KQNidMNHnCCem2LCJpTJ56Q87U"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x2c5da053f98cb5462a8aa4fa6bb2a5e7bb324baa404fbbd8ea25fdaaaac1b0db",
"blockNumber": 65,
"logIndex": 0,
"transactionHash": "0x1df5a2819a6312d170c323b517b03a7186a789845ecfe896d37de6fa482b924c",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0x805bf817be0e53bf618eb41ae0775ac314f989a1",
"contributorId": 3,
"amount": "50",
"reference": "QmeVbzGiXmPz4qgi5PfktZi2Esb4EVPQZLRnWnUPVatJgF"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x0e478ae9cf6e09e2ca8c4413c874f39decfb9d51c976467ef14d99efa79c9bcb",
"blockNumber": 75,
"logIndex": 0,
"transactionHash": "0xf16ace4f72c599c3b738bdaa4518f59a47dcdc304a8f24308c5d121ae0ae5b97",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0x0536806df512d6cdde913cf95c9886f65b1d3462",
"contributorId": 1,
"amount": "100",
"reference": "QmS3cywqGhHh6QBLnyBWXPTas2UnHEW8ZV8zZy6pVw95Zx"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0x31e91da869e9b87949e75ee14879005b172df96267f9ffd76d5024a46fe48a3c",
"blockNumber": 76,
"logIndex": 0,
"transactionHash": "0x735eb48c81f6868b886d3afede6b031323e78b221f3e2653ad2186c3e4e1abe9",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xd4a64570b12da659ee4bbd41c3509b7b1f9c51ac",
"contributorId": 2,
"amount": "500",
"reference": "QmP5RPzjgRdtq9Uj6tXxgMfA1GkY9Fh5ghXpDYBtc9YwMp"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0xd41a4c3caae9e52632eba047d038e430b50920138e3a625b50a0a887e719a487",
"blockNumber": 77,
"logIndex": 0,
"transactionHash": "0x075beb007d18b38344599fe5b4dc315633aebedf08201ab9537f7d407811b0a2",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0x805bf817be0e53bf618eb41ae0775ac314f989a1",
"contributorId": 2,
"amount": "1000",
"reference": "QmTxwugByKfyPX2czyVDGhXK3NLZkA3uh2DbNnaAMVrVJB"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0xcb3863eb681873a2c5954e07e085d4004a2824fcd17364b647e2fff1bea3ad4b",
"blockNumber": 78,
"logIndex": 0,
"transactionHash": "0xdf680c7a0bc60ef02619def582f68230bdd0fd8a945c9006841212ebcd6b80db",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xf18e631ea191ae4ebe70046fcb01a43655441c6d",
"contributorId": 3,
"amount": "300",
"reference": "QmYXyGSK6RyXQHNPHAADjpJ4P3mrz5Lf1bNnrp2yRaDxNo"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0xe322d5292506ef1c4c915e875a4e8c1882d154fd9b711522809045bbb884e11d",
"blockNumber": 89,
"logIndex": 0,
"transactionHash": "0x5d90bf8c74b18b602e8b04fbca8678033589f6527b1ced08c0ee7d6c96f71949",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xb2d955733e6a470533f68f72d0af442070f24f55",
"contributorId": 1,
"amount": "300",
"reference": "QmZdUuq4NMz2S5bD3m9h9MNNsbTVeFVHzQss4uS1ZqPLsw"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0xbb84cfc9c3298b045d4ae70afa9cc966db578b00e897f3d6988b08deeca0e3d9",
"blockNumber": 120,
"logIndex": 0,
"transactionHash": "0xf91a038b17cfd9b5eac8f4474d5e4d9a5034dead51fc2fffc9e88afdefd9129c",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0xf18e631ea191ae4ebe70046fcb01a43655441c6d",
"contributorId": 1,
"amount": "500",
"reference": "QmdQWivxwjuEHEYVu3ezZCzEWps6wEvQ8ePUHbQ7htSN8V"
}
},
{
"address": "0x63770f81fbe0d2b4159b6752eda99ee7c44ca5e4",
"blockHash": "0xc85a520ffc16b5f84d5f5bd29478d0871a045356e598c72be9a44ae3e6826bb5",
"blockNumber": 121,
"logIndex": 0,
"transactionHash": "0x59a2e3e1f81b8113b3b71eba26f28f75ba18d60b6dda6a4a216d566d7d68a31d",
"transactionIndex": 0,
"transactionLogIndex": "0x0",
"type": "mined",
"event": "Minted",
"args": {
"recipientAddress": "0x805bf817be0e53bf618eb41ae0775ac314f989a1",
"contributorId": 1,
"amount": "50",
"reference": "QmfDG3vCAgQsqkxkb6jCnLqw11wjw3uUpiZRbRBLZ9GpYi"
}
}
]
+14
View File
@@ -0,0 +1,14 @@
import { moduleFor, test } from 'ember-qunit';
// import schemas from 'npm:kosmos-schemas';
// import tv4 from 'npm:tv4';
moduleFor('model:contribution', 'Unit | Model | contribution', {
// Specify the other units that are required for this test.
needs: []
});
test('it exists', function(assert) {
let model = this.subject();
// let store = this.store();
assert.ok(!!model);
});