From e7fa188797b656b2bb948bd187a20b6e98cb0181 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 18 Feb 2017 18:44:14 +0800 Subject: [PATCH] Store contributor profile data in IPFS This stores the GitHub username and UID in IPFS, and stores the resulting IPFS hash in the contract. Now we can remove the GitHub profile data from the contract entirely. --- app/models/contributor.js | 16 +++++++++++++++- app/services/ipfs.js | 1 + app/services/kredits.js | 26 +++++++++++++++----------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/models/contributor.js b/app/models/contributor.js index 7840199..ebe41ea 100644 --- a/app/models/contributor.js +++ b/app/models/contributor.js @@ -11,6 +11,20 @@ export default Ember.Object.extend({ avatarURL: function() { return `https\:\/\/avatars2.githubusercontent.com/u/${this.get('github_uid')}?v=3&s=128`; - }.property('github_uid') + }.property('github_uid'), + + serialize() { + return JSON.stringify({ + profiles: { + 'github.com': { + uid: this.get('github_uid'), + username: this.get('github_username'), + } + // 'wiki.kosmos.org': { + // username: this.get('wiki_username') + // } + } + }); + } }); diff --git a/app/services/ipfs.js b/app/services/ipfs.js index e3f9f41..453a005 100644 --- a/app/services/ipfs.js +++ b/app/services/ipfs.js @@ -18,6 +18,7 @@ export default Ember.Service.extend({ storeFile(content) { let ipfs = this.get('ipfs'); return ipfs.add(new ipfs.Buffer(content)).then(res => { + Ember.Logger.debug('[ipfs] stored content in IPFS', content, res[0].hash); return res[0].hash; }); }, diff --git a/app/services/kredits.js b/app/services/kredits.js index 2f3d7d1..6479360 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -140,19 +140,23 @@ export default Ember.Service.extend({ addContributor(address, name, ipfsHash, isCore, id) { Ember.Logger.debug('[kredits] add contributor', name, address); + + let contributor = Contributor.create({ + address: address, + github_username: name, + github_uid: id, + kredits: 0, + isCurrentUser: this.get('currentUserAccounts').includes(address) + }); + return new Ember.RSVP.Promise((resolve, reject) => { - this.get('kreditsContract').addContributor(address, name, ipfsHash, isCore, id, (err, data) => { - if (err) { reject(err); } - Ember.Logger.debug('[kredits] add contributor response', data); - let contributor = Contributor.create({ - address: address, - github_username: name, - github_uid: id, - ipfsHash: ipfsHash, - kredits: 0, - isCurrentUser: this.get('currentUserAccounts').includes(address) + this.get('ipfs').storeFile(contributor.serialize()).then(ipfsHash => { + contributor.set('ipfsHash', ipfsHash); + this.get('kreditsContract').addContributor(address, name, ipfsHash, isCore, id, (err, data) => { + if (err) { reject(err); } + Ember.Logger.debug('[kredits] add contributor response', data); + resolve(contributor); }); - resolve(contributor); }); }); },