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.
This commit is contained in:
@@ -11,6 +11,20 @@ export default Ember.Object.extend({
|
|||||||
|
|
||||||
avatarURL: function() {
|
avatarURL: function() {
|
||||||
return `https\:\/\/avatars2.githubusercontent.com/u/${this.get('github_uid')}?v=3&s=128`;
|
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')
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export default Ember.Service.extend({
|
|||||||
storeFile(content) {
|
storeFile(content) {
|
||||||
let ipfs = this.get('ipfs');
|
let ipfs = this.get('ipfs');
|
||||||
return ipfs.add(new ipfs.Buffer(content)).then(res => {
|
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;
|
return res[0].hash;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -140,21 +140,25 @@ export default Ember.Service.extend({
|
|||||||
|
|
||||||
addContributor(address, name, ipfsHash, isCore, id) {
|
addContributor(address, name, ipfsHash, isCore, id) {
|
||||||
Ember.Logger.debug('[kredits] add contributor', name, address);
|
Ember.Logger.debug('[kredits] add contributor', name, 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({
|
let contributor = Contributor.create({
|
||||||
address: address,
|
address: address,
|
||||||
github_username: name,
|
github_username: name,
|
||||||
github_uid: id,
|
github_uid: id,
|
||||||
ipfsHash: ipfsHash,
|
|
||||||
kredits: 0,
|
kredits: 0,
|
||||||
isCurrentUser: this.get('currentUserAccounts').includes(address)
|
isCurrentUser: this.get('currentUserAccounts').includes(address)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return new Ember.RSVP.Promise((resolve, reject) => {
|
||||||
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
logKreditsContract: function() {
|
logKreditsContract: function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user