Skip to content
Snippets Groups Projects
Commit d2fa4f95 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

LokiJS: file persistence

parent f81fbd5e
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,7 @@ function WOTBinding (server) { ...@@ -60,7 +60,7 @@ function WOTBinding (server) {
var signed = yield server.dal.certsFrom(idty.pubkey); var signed = yield server.dal.certsFrom(idty.pubkey);
var validSigned = []; var validSigned = [];
for (let j = 0; j < signed.length; j++) { for (let j = 0; j < signed.length; j++) {
let cert = signed[j]; let cert = _.clone(signed[j]);
if (!(excluding && cert.block <= excluding.number)) { if (!(excluding && cert.block <= excluding.number)) {
cert.idty = yield server.dal.getIdentityByHashOrNull(cert.target); cert.idty = yield server.dal.getIdentityByHashOrNull(cert.target);
validSigned.push(cert); validSigned.push(cert);
...@@ -260,7 +260,6 @@ function WOTBinding (server) { ...@@ -260,7 +260,6 @@ function WOTBinding (server) {
next('Not a member'); next('Not a member');
return; return;
} }
cert.pubkey = idty.pubkey;
cert.uid = idty.uid; cert.uid = idty.uid;
cert.isMember = idty.member; cert.isMember = idty.member;
cert.wasMember = idty.wasMember; cert.wasMember = idty.wasMember;
...@@ -301,7 +300,7 @@ function WOTBinding (server) { ...@@ -301,7 +300,7 @@ function WOTBinding (server) {
}; };
idty.certs.forEach(function(cert){ idty.certs.forEach(function(cert){
json.certifications.push({ json.certifications.push({
pubkey: cert.pubkey, pubkey: cert.from,
uid: cert.uid, uid: cert.uid,
cert_time: cert.cert_time, cert_time: cert.cert_time,
isMember: cert.isMember, isMember: cert.isMember,
......
...@@ -40,7 +40,10 @@ module.exports = { ...@@ -40,7 +40,10 @@ module.exports = {
// Memory only service dals // Memory only service dals
loki = new lokijs('temp', { autosave: false }); loki = new lokijs('temp', { autosave: false });
} else { } else {
loki = new lokijs('ucoin', { autosave: true, autosaveInterval: 300 }); loki = new lokijs(path.join(params.home, 'ucoin.json'), {
autosave: true,
autosaveInterval: 300
});
} }
return new FileDAL(profile, params.home, "", params.fs, null, 'fileDal', null, loki); return new FileDAL(profile, params.home, "", params.fs, null, 'fileDal', null, loki);
}); });
......
...@@ -113,7 +113,11 @@ function AbstractLoki(collection, fileDAL, viewFields, loki) { ...@@ -113,7 +113,11 @@ function AbstractLoki(collection, fileDAL, viewFields, loki) {
})[0]; })[0];
}; };
this.lokiSave = (entity) => { this.lokiSave = (fullEntity) => {
let entity = fullEntity;
if (this.propsToSave) {
entity = _.pick(fullEntity, this.propsToSave || []);
}
let existing = this.lokiExisting(entity); let existing = this.lokiExisting(entity);
if (existing) { if (existing) {
if (!fileDAL.parentDAL) { if (!fileDAL.parentDAL) {
...@@ -123,6 +127,7 @@ function AbstractLoki(collection, fileDAL, viewFields, loki) { ...@@ -123,6 +127,7 @@ function AbstractLoki(collection, fileDAL, viewFields, loki) {
// Save in fork branch: overrides meta data // Save in fork branch: overrides meta data
existing.metaData[that.metaKey()] = _.pick(entity, this.metaProps); existing.metaData[that.metaKey()] = _.pick(entity, this.metaProps);
} }
console.log(existing);
collection.update(existing); collection.update(existing);
} else { } else {
entity.metaData = {}; entity.metaData = {};
...@@ -132,6 +137,7 @@ function AbstractLoki(collection, fileDAL, viewFields, loki) { ...@@ -132,6 +137,7 @@ function AbstractLoki(collection, fileDAL, viewFields, loki) {
_.pluck(entity, this.metaProps).forEach(function(metaProp){ _.pluck(entity, this.metaProps).forEach(function(metaProp){
entity[metaProp] = false; entity[metaProp] = false;
}); });
console.log(entity);
collection.insert(entity); collection.insert(entity);
} }
return Q(entity); return Q(entity);
......
...@@ -20,6 +20,16 @@ function CertDAL(fileDAL, loki) { ...@@ -20,6 +20,16 @@ function CertDAL(fileDAL, loki) {
this.idKeys = ['sig', 'from', 'target']; this.idKeys = ['sig', 'from', 'target'];
this.metaProps = ['linked']; this.metaProps = ['linked'];
this.propsToSave = [
'linked',
'sig',
'block_number',
'block_hash',
'target',
'to',
'from',
'block'
];
this.init = () => null; this.init = () => null;
......
...@@ -19,6 +19,20 @@ function IdentityDAL(fileDAL, loki) { ...@@ -19,6 +19,20 @@ function IdentityDAL(fileDAL, loki) {
this.idKeys = ['pubkey', 'uid', 'hash']; this.idKeys = ['pubkey', 'uid', 'hash'];
this.metaProps = ['kick', 'leaving', 'member', 'wasMember', 'written', 'currentMSN', 'revoked']; this.metaProps = ['kick', 'leaving', 'member', 'wasMember', 'written', 'currentMSN', 'revoked'];
this.propsToSave = [
'revoked',
'currentMSN',
'time',
'member',
'kick',
'leaving',
'wasMember',
'pubkey',
'uid',
'sig',
'hash',
'written'
];
this.init = () => null; this.init = () => null;
......
...@@ -20,6 +20,14 @@ function LinksDAL(fileDAL, loki) { ...@@ -20,6 +20,14 @@ function LinksDAL(fileDAL, loki) {
this.idKeys = ['source', 'target', 'block_number', 'block_hash']; this.idKeys = ['source', 'target', 'block_number', 'block_hash'];
this.metaProps = ['obsolete']; this.metaProps = ['obsolete'];
this.propsToSave = [
'source',
'target',
'timestamp',
'block_number',
'block_hash',
'obsolete'
];
this.init = () => null; this.init = () => null;
......
...@@ -21,6 +21,19 @@ function MembershipDAL(fileDAL, loki) { ...@@ -21,6 +21,19 @@ function MembershipDAL(fileDAL, loki) {
this.idKeys = ['issuer', 'signature']; this.idKeys = ['issuer', 'signature'];
this.metaProps = ['written']; this.metaProps = ['written'];
this.propsToSave = [
'membership',
'issuer',
'number',
'blockNumber',
'blockHash',
'userid',
'certts',
'block',
'fpr',
'written',
'signature'
];
this.init = () => null; this.init = () => null;
......
...@@ -20,6 +20,15 @@ function SourcesDAL(fileDAL, loki) { ...@@ -20,6 +20,15 @@ function SourcesDAL(fileDAL, loki) {
this.idKeys = ['pubkey', 'type', 'number', 'fingerprint', 'amount']; this.idKeys = ['pubkey', 'type', 'number', 'fingerprint', 'amount'];
this.metaProps = ['consumed']; this.metaProps = ['consumed'];
this.propsToSave = [
'pubkey',
'type',
'number',
'fingerprint',
'amount',
'block_hash',
'consumed'
];
this.init = () => null; this.init = () => null;
......
...@@ -21,6 +21,22 @@ function TxsDAL(fileDAL, loki) { ...@@ -21,6 +21,22 @@ function TxsDAL(fileDAL, loki) {
this.idKeys = ['hash', 'block_number']; this.idKeys = ['hash', 'block_number'];
this.metaProps = ['written', 'removed']; this.metaProps = ['written', 'removed'];
this.propsToSave = [
'inputs',
'outputs',
'issuers',
'signatories',
'signatures',
'comment',
'hash',
'version',
'currency',
'block_number',
'time',
'recipients',
'written',
'removed'
];
this.init = () => null; this.init = () => null;
......
...@@ -11,8 +11,7 @@ var Certification = function(json) { ...@@ -11,8 +11,7 @@ var Certification = function(json) {
that[key] = json[key]; that[key] = json[key];
}); });
this.from = this.fromKey = this.pubkey = this.from || this.fromKey || this.pubkey; this.from = this.pubkey = this.from || this.pubkey;
this.to = this.toKey = this.to || this.toKey;
this.block = this.block_number = parseInt(this.block || this.block_number); this.block = this.block_number = parseInt(this.block || this.block_number);
this.inline = function () { this.inline = function () {
......
...@@ -33,7 +33,7 @@ var Identity = function(json) { ...@@ -33,7 +33,7 @@ var Identity = function(json) {
var others = []; var others = [];
this.certs.forEach(function(cert){ this.certs.forEach(function(cert){
others.push({ others.push({
"pubkey": cert.pubkey, "pubkey": cert.from,
"meta": { "meta": {
"block_number": cert.block_number "block_number": cert.block_number
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment