Commit a9875021 authored by Cédric Moreau's avatar Cédric Moreau

[enh] #1037 Migrate FileDAL

parent d5f1792c
......@@ -9,5 +9,6 @@ app/lib/dal/drivers/*.js
app/lib/dal/sqliteDAL/*.js
app/lib/dal/sqliteDAL/index/*.js
app/lib/dal/fileDALs/*.js
app/lib/dal/fileDAL.js
test/*.js
test/**/*.js
\ No newline at end of file
......@@ -45,4 +45,6 @@ app/lib/indexer.js*
app/lib/dal/drivers/*.js*
app/lib/dal/sqliteDAL/*.js*
app/lib/dal/sqliteDAL/index/*.js*
app/lib/dal/fileDALs/*.js*
\ No newline at end of file
app/lib/dal/fileDALs/*.js*
app/lib/dal/fileDAL.js*
app/lib/wot.js*
\ No newline at end of file
......@@ -89,7 +89,7 @@ export class BlockchainContext {
*/
async getIssuerPersonalizedDifficulty(issuer: string): Promise<any> {
const local_vHEAD = await this.getvHeadCopy({ issuer });
await indexer.preparePersonalizedPoW(local_vHEAD, this.vHEAD_1, this.dal.range, this.conf)
await indexer.preparePersonalizedPoW(local_vHEAD, this.vHEAD_1, (n:number, m:number, p = "") => this.dal.range(n,m,p), this.conf)
return local_vHEAD.issuerDiff;
}
......
import {AbstractSQLite} from "./AbstractSQLite";
import {SQLiteDriver} from "../drivers/SQLiteDriver";
import {DBBlock} from "../../db/DBBlock";
const Q = require('q');
const constants = require('../../constants');
const IS_FORK = true;
const IS_NOT_FORK = false;
export interface DBBlock {
fork: boolean
hash: string
inner_hash: string
signature: string
currency: string
issuer: string
parameters: string
previousHash: string
previousIssuer: string
version: string
membersCount: string
monetaryMass: string
UDTime: string
medianTime: string
dividend: string
unitbase: string
time: string
powMin: string
number: string
nonce: string
transactions: string
certifications: string
identities: string
joiners: string
actives: string
leavers: string
revoked: string
excluded: string
created: string
updated: string
}
export class BlockDAL extends AbstractSQLite<DBBlock> {
private current: any
......
......@@ -33,6 +33,8 @@ export class DBBlock {
parameters: string
monetaryMass: number
dividend: number | null
UDTime: number
wrong = false
constructor(
) {
......@@ -69,6 +71,8 @@ export class DBBlock {
dbb.inner_hash = b.inner_hash
dbb.signature = b.signature
dbb.nonce = b.nonce
dbb.UDTime = b.UDTime
dbb.monetaryMass = b.monetaryMass
return dbb
}
}
\ No newline at end of file
......@@ -30,6 +30,8 @@ export class BlockDTO {
fork: boolean
parameters: string
signature: string
monetaryMass: number
UDTime: number
constructor(
) {}
......
......@@ -509,8 +509,8 @@ export class Indexer {
const cindex = Indexer.cindex(index);
const sindex = Indexer.sindex(index);
const range = dal.range;
const head = dal.head;
const range = (n:number,m:number,p = "") => dal.range(n, m, p)
const head = (n:number) => dal.head(n)
const HEAD = new DBHead()
......
......@@ -51,7 +51,7 @@ const dir = module.exports = {
yield someDelayFix();
if (isMemory) {
params.dbf = () => new SQLiteDriver(':memory:');
params.wotb = require('../wot').memoryInstance();
params.wotb = require('../wot').WoTBObject.memoryInstance();
} else {
const sqlitePath = path.join(home, dir.DUNITER_DB_NAME + '.db');
params.dbf = () => new SQLiteDriver(sqlitePath);
......@@ -60,7 +60,7 @@ const dir = module.exports = {
if (!existsFile) {
fs.closeSync(fs.openSync(wotbFilePath, 'w'));
}
params.wotb = require('../wot').fileInstance(wotbFilePath);
params.wotb = require('../wot').WoTBObject.fileInstance(wotbFilePath);
}
return params;
}),
......
"use strict";
const wotb = require('wotb');
module.exports = {
fileInstance: (filepath) => wotb.newFileInstance(filepath),
memoryInstance: () => wotb.newMemoryInstance(),
setVerbose: wotb.setVerbose
};
const wotb = require('wotb');
export interface WoTBInterface {
fileInstance: (filepath:string) => any
memoryInstance: (filepath:string) => any
setVerbose: (verbose:boolean) => void
}
export const WoTBObject:WoTBInterface = {
fileInstance: (filepath:string) => wotb.newFileInstance(filepath),
memoryInstance: () => wotb.newMemoryInstance(),
setVerbose: wotb.setVerbose
}
......@@ -1094,7 +1094,7 @@ Réessayez avec une valeur autre que `abc` pour voir la valeur changer au niveau
### Voir le nombre d’identités trouvées
Regardez la ligne 27 du fichier wot.js que nous débogons actuellement :
Regardez la ligne 27 du fichier wot.ts que nous débogons actuellement :
```js
const identities = yield IdentityService.searchIdentities(search);
......
......@@ -11,7 +11,7 @@ const fs = require('fs');
const daemonize = require("daemonize2")
const parsers = require('duniter-common').parsers;
const constants = require('./app/lib/constants');
const fileDAL = require('./app/lib/dal/fileDAL');
const FileDAL = require('./app/lib/dal/fileDAL').FileDAL
const jsonpckg = require('./package.json');
const keyring = require('duniter-common').keyring;
const directory = require('./app/lib/system/directory');
......@@ -70,7 +70,7 @@ function Server (home, memoryOnly, overrideConf) {
this.plugFileSystem = () => co(function *() {
logger.debug('Plugging file system...');
const params = yield paramsP;
that.dal = fileDAL(params);
that.dal = new FileDAL(params);
yield that.onPluggedFSHook()
});
......
......@@ -3,7 +3,7 @@ var co = require('co');
var _ = require('underscore');
var should = require('should');
var assert = require('assert');
var dal = require('../../app/lib/dal/fileDAL');
var dal = require('../../app/lib/dal/fileDAL').FileDAL
var dir = require('../../app/lib/system/directory');
var constants = require('../../app/lib/constants');
var Peer = require('../../app/lib/entity/peer');
......@@ -95,7 +95,7 @@ describe("DAL", function(){
before(() => co(function *() {
let params = yield dir.getHomeParams(true, 'db0');
fileDAL = dal(params);
fileDAL = new dal(params);
yield fileDAL.init();
return fileDAL.saveConf({ currency: "meta_brouzouf" });
}));
......@@ -114,7 +114,7 @@ describe("DAL", function(){
it('should have 1 peer if 1 is created', function(){
return fileDAL.savePeer(new Peer(mocks.peer1))
.then(fileDAL.listAllPeers)
.then(() => fileDAL.listAllPeers())
.then(function(peers){
peers.should.have.length(1);
peers[0].should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
......
"use strict";
const co = require('co');
const should = require('should');
const FileDAL = require('../../app/lib/dal/fileDAL');
const FileDAL = require('../../app/lib/dal/fileDAL').FileDAL
const dir = require('../../app/lib/system/directory');
const indexer = require('../../app/lib/indexer').Indexer
const toolbox = require('../integration/tools/toolbox');
......@@ -11,7 +11,7 @@ let dal;
describe("Source DAL", function(){
before(() => co(function *() {
dal = FileDAL(yield dir.getHomeParams(true, 'db0'));
dal = new FileDAL(yield dir.getHomeParams(true, 'db0'));
yield dal.init();
}));
......
"use strict";
const co = require('co');
const should = require('should');
const FileDAL = require('../../app/lib/dal/fileDAL');
const FileDAL = require('../../app/lib/dal/fileDAL').FileDAL
const dir = require('../../app/lib/system/directory');
const indexer = require('../../app/lib/indexer').Indexer
const toolbox = require('../integration/tools/toolbox');
......@@ -11,7 +11,7 @@ let dal;
describe("Triming", function(){
before(() => co(function *() {
dal = FileDAL(yield dir.getHomeParams(true, 'db0'));
dal = new FileDAL(yield dir.getHomeParams(true, 'db0'));
yield dal.init();
}));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment