Add Reimbursement app
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
lib/abis/Reimbursement.json
Normal file
1
lib/abis/Reimbursement.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"4": "0x76e069b47b79442657eaf0555a32c6b16fa1b8b4",
|
||||
"8653663": "0x0Dd2b0F3F8Cba588fa865abf289594e2cfE30995",
|
||||
"18335577": "0xeE10a87d8D758B563E301F5C5d029bDD21166DCC"
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"4": "0xc34edf7d11b7f8433d597f0bb0697acdff55ef14",
|
||||
"8653663": "0x1F65f1E2d293c7773811b7016987f51683881703",
|
||||
"18335577": "0x29E33B66108fa2DC3a018f3DdE41D295eB0922D5"
|
||||
}
|
||||
@@ -3,6 +3,7 @@ module.exports = {
|
||||
Contribution: require('./contribution'),
|
||||
Proposal: require('./proposal'),
|
||||
Token: require('./token'),
|
||||
Reimbursement: require('./reimbursement'),
|
||||
Kernel: require('./kernel'),
|
||||
Acl: require('./acl'),
|
||||
};
|
||||
|
||||
45
lib/contracts/reimbursement.js
Normal file
45
lib/contracts/reimbursement.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const Record = require('./record');
|
||||
const ExpenseSerializer = require('../serializers/expense');
|
||||
|
||||
class Reimbursement extends Record {
|
||||
get count () {
|
||||
return this.functions.reimbursementsCount();
|
||||
}
|
||||
|
||||
getById (id) {
|
||||
return this.functions.getReimbursement(id)
|
||||
.then(data => {
|
||||
return this.ipfs.catAndMerge(data, ExpenseSerializer.deserialize);
|
||||
});
|
||||
}
|
||||
|
||||
getData (id) {
|
||||
return this.functions.getReimbursement(id);
|
||||
}
|
||||
|
||||
async add (attrs, callOptions = {}) {
|
||||
const reimbursement = new ExpenseSerializer(attrs);
|
||||
|
||||
try { await reimbursement.validate(); }
|
||||
catch (error) { return Promise.reject(error); }
|
||||
|
||||
const jsonStr = reimbursement.serialize();
|
||||
|
||||
return this.ipfs
|
||||
.add(jsonStr)
|
||||
.then(ipfsHashAttr => {
|
||||
let reimbursement = [
|
||||
attrs.amount,
|
||||
attrs.token,
|
||||
ipfsHashAttr.hashDigest,
|
||||
ipfsHashAttr.hashFunction,
|
||||
ipfsHashAttr.hashSize,
|
||||
];
|
||||
|
||||
console.log(reimbursement)
|
||||
return this.functions.add(...reimbursement, callOptions);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Reimbursement;
|
||||
@@ -6,6 +6,7 @@ const deprecate = require('./utils/deprecate');
|
||||
const ABIS = {
|
||||
Contributor: require('./abis/Contributor.json'),
|
||||
Contribution: require('./abis/Contribution.json'),
|
||||
Reimbursement: require('./abis/Reimbursement.json'),
|
||||
Token: require('./abis/Token.json'),
|
||||
Proposal: require('./abis/Proposal.json'),
|
||||
Kernel: require('./abis/Kernel.json'),
|
||||
@@ -16,6 +17,7 @@ const APP_CONTRACTS = [
|
||||
'Contribution',
|
||||
'Token',
|
||||
'Proposal',
|
||||
'Reimbursement',
|
||||
'Acl',
|
||||
];
|
||||
const DaoAddresses = require('./addresses/dao.json');
|
||||
@@ -121,6 +123,10 @@ class Kredits {
|
||||
return this.contractFor('Contribution');
|
||||
}
|
||||
|
||||
get Reimbursement () {
|
||||
return this.contractFor('Reimbursement');
|
||||
}
|
||||
|
||||
get Acl () {
|
||||
return this.contractFor('Acl');
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class KreditsKit {
|
||||
|
||||
appIdFor (contractName) {
|
||||
// see appIds in KreditsKit.sol for more details
|
||||
const knownContracts = ['Contribution', 'Contributor', 'Proposal', 'Token'];
|
||||
const knownContracts = ['Contribution', 'Contributor', 'Proposal', 'Reimbursement', 'Token'];
|
||||
return this.contract.functions.appIds(knownContracts.indexOf(contractName));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const schemas = require('kosmos-schemas');
|
||||
const schemas = require('@kosmos/schemas');
|
||||
const validator = require('../utils/validator');
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const schemas = require('kosmos-schemas');
|
||||
const schemas = require('@kosmos/schemas');
|
||||
const validator = require('../utils/validator');
|
||||
/**
|
||||
* Handle serialization for JSON-LD object of the contributor, according to
|
||||
|
||||
98
lib/serializers/expense.js
Normal file
98
lib/serializers/expense.js
Normal file
@@ -0,0 +1,98 @@
|
||||
let schemas = require('@kosmos/schemas');
|
||||
schemas['expense'] = require('@kosmos/schemas/schemas/expense.json');
|
||||
const validator = require('../utils/validator');
|
||||
|
||||
/**
|
||||
* Serialization and validation for JSON-LD document of the Expense
|
||||
*
|
||||
* @class
|
||||
* @public
|
||||
*/
|
||||
class Expense {
|
||||
|
||||
constructor (attrs) {
|
||||
Object.keys(attrs).forEach(a => this[a] = attrs[a]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize object to JSON
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
serialize () {
|
||||
let {
|
||||
title,
|
||||
description,
|
||||
currency,
|
||||
amount,
|
||||
date,
|
||||
url,
|
||||
tags,
|
||||
details,
|
||||
} = this;
|
||||
|
||||
let data = {
|
||||
'@context': 'https://schema.kosmos.org',
|
||||
'@type': 'Expense',
|
||||
title,
|
||||
description,
|
||||
currency,
|
||||
amount,
|
||||
date,
|
||||
'tags': tags || [],
|
||||
'details': details || {},
|
||||
};
|
||||
|
||||
if (url) {
|
||||
data['url'] = url;
|
||||
}
|
||||
|
||||
// Write it pretty to ipfs
|
||||
return JSON.stringify(data, null, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate serialized data against schema
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
validate () {
|
||||
const serialized = JSON.parse(this.serialize());
|
||||
console.log(schemas['expense']);
|
||||
const valid = validator.validate(serialized, schemas['expense']);
|
||||
return valid ? Promise.resolve() : Promise.reject(validator.error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize JSON to object
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
static deserialize (serialized) {
|
||||
let {
|
||||
title,
|
||||
description,
|
||||
currency,
|
||||
amount,
|
||||
date,
|
||||
url,
|
||||
tags,
|
||||
details,
|
||||
} = JSON.parse(serialized.toString('utf8'));
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
currency,
|
||||
amount,
|
||||
date,
|
||||
url,
|
||||
tags,
|
||||
details,
|
||||
ipfsData: serialized,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Expense;
|
||||
Reference in New Issue
Block a user