Commit 1f5a588b authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] Refactoring: replace dal:any by dal:FileDAL

parent 12a83175
......@@ -12,7 +12,7 @@
// GNU Affero General Public License for more details.
import {MiscIndexedBlockchain} from "./MiscIndexedBlockchain"
import {IindexEntry, IndexEntry, Indexer, MindexEntry, SindexEntry} from "../indexer"
import {FullIindexEntry, IindexEntry, IndexEntry, Indexer, MindexEntry, SindexEntry} from "../indexer"
import {BlockchainOperator} from "./interfaces/BlockchainOperator"
import {ConfDTO} from "../dto/ConfDTO"
import {BlockDTO} from "../dto/BlockDTO"
......@@ -26,16 +26,18 @@ import {MembershipDTO} from "../dto/MembershipDTO"
import {TransactionDTO} from "../dto/TransactionDTO"
import {CommonConstants} from "../common-libs/constants"
import {FileDAL} from "../dal/fileDAL"
import {DBTx} from "../dal/sqliteDAL/TxsDAL"
import {DataErrors} from "../common-libs/errors"
const _ = require('underscore')
export class DuniterBlockchain extends MiscIndexedBlockchain {
constructor(blockchainStorage:BlockchainOperator, dal:any) {
constructor(blockchainStorage:BlockchainOperator, dal:FileDAL) {
super(blockchainStorage, dal.mindexDAL, dal.iindexDAL, dal.sindexDAL, dal.cindexDAL)
}
static async checkBlock(block:BlockDTO, withPoWAndSignature:boolean, conf: ConfDTO, dal:any) {
static async checkBlock(block:BlockDTO, withPoWAndSignature:boolean, conf: ConfDTO, dal:FileDAL) {
const index = Indexer.localIndex(block, conf)
if (withPoWAndSignature) {
await CHECK.ASYNC.ALL_LOCAL(block, conf, index)
......@@ -175,7 +177,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
return { index, HEAD }
}
async pushTheBlock(obj:BlockDTO, index:IndexEntry[], HEAD:DBHead | null, conf:ConfDTO, dal:any, logger:any) {
async pushTheBlock(obj:BlockDTO, index:IndexEntry[], HEAD:DBHead | null, conf:ConfDTO, dal:FileDAL, logger:any) {
const start = Date.now();
const block = BlockDTO.fromJSONObject(obj)
try {
......@@ -202,7 +204,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
// await supra.recordIndex(index)
}
async saveBlockData(current:DBBlock, block:BlockDTO, conf:ConfDTO, dal:any, logger:any, index:IndexEntry[], HEAD:DBHead | null) {
async saveBlockData(current:DBBlock|null, block:BlockDTO, conf:ConfDTO, dal:FileDAL, logger:any, index:IndexEntry[], HEAD:DBHead | null) {
if (block.number == 0) {
await this.saveParametersForRoot(block, conf, dal);
}
......@@ -262,7 +264,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
return dbb
}
async saveParametersForRoot(block:BlockDTO, conf:ConfDTO, dal:any) {
async saveParametersForRoot(block:BlockDTO, conf:ConfDTO, dal:FileDAL) {
if (block.parameters) {
const bconf = BlockDTO.getConf(block)
conf.c = bconf.c;
......@@ -292,9 +294,10 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
}
}
async createNewcomers(iindex:IindexEntry[], dal:any, logger:any) {
for (const entry of iindex) {
if (entry.op == CommonConstants.IDX_CREATE) {
async createNewcomers(iindex:IindexEntry[], dal:FileDAL, logger:any) {
for (const i of iindex) {
if (i.op == CommonConstants.IDX_CREATE) {
const entry = i as FullIindexEntry
// Reserves a wotb ID
entry.wotb_id = dal.wotb.addNode();
logger.trace('%s was affected wotb_id %s', entry.uid, entry.wotb_id);
......@@ -342,9 +345,14 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
}
}
async revertBlock(number:number, hash:string, dal:any) {
async revertBlock(number:number, hash:string, dal:FileDAL) {
const blockstamp = [number, hash].join('-');
const block = await dal.getBlockByBlockstampOrNull(blockstamp)
if (!block) {
throw DataErrors[DataErrors.BLOCK_TO_REVERT_NOT_FOUND]
}
// Revert links
const writtenOn = await dal.cindexDAL.getWrittenOn(blockstamp);
......@@ -353,10 +361,10 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
const to = await dal.getWrittenIdtyByPubkeyForWotbID(entry.receiver);
if (entry.op == CommonConstants.IDX_CREATE) {
// We remove the created link
dal.wotb.removeLink(from.wotb_id, to.wotb_id, true);
dal.wotb.removeLink(from.wotb_id, to.wotb_id);
} else {
// We add the removed link
dal.wotb.addLink(from.wotb_id, to.wotb_id, true);
dal.wotb.addLink(from.wotb_id, to.wotb_id);
}
}
......@@ -374,7 +382,6 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
await dal.sindexDAL.removeBlock(blockstamp);
// Then: normal updates
const block = await dal.getBlockByBlockstampOrNull(blockstamp);
const previousBlock = await dal.getBlock(number - 1);
// Set the block as SIDE block (equivalent to removal from main branch)
await dal.blockDAL.setSideBlock(number, previousBlock);
......@@ -388,7 +395,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
return block
}
async undoMembersUpdate(blockstamp:string, dal:any) {
async undoMembersUpdate(blockstamp:string, dal:FileDAL) {
const joiners = await dal.iindexDAL.getWrittenOn(blockstamp);
for (const entry of joiners) {
// Undo 'join' which can be either newcomers or comebackers
......@@ -418,11 +425,11 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
}
}
async undoDeleteTransactions(block:BlockDTO, dal:any) {
async undoDeleteTransactions(block:DBBlock, dal:FileDAL) {
for (const obj of block.transactions) {
obj.currency = block.currency;
let tx = TransactionDTO.fromJSONObject(obj)
await dal.saveTransaction(tx);
await dal.saveTransaction(DBTx.fromTransactionDTO(tx))
}
}
......@@ -450,7 +457,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
* @param block Block in which are contained the certifications to remove from sandbox.
* @param dal The DAL
*/
async removeMembershipsFromSandbox(block:BlockDTO, dal:any) {
async removeMembershipsFromSandbox(block:BlockDTO, dal:FileDAL) {
const mss = block.joiners.concat(block.actives).concat(block.leavers);
for (const inlineMS of mss) {
let ms = MembershipDTO.fromInline(inlineMS)
......@@ -461,14 +468,14 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
}
}
async computeToBeRevoked(mindex:MindexEntry[], dal:any) {
async computeToBeRevoked(mindex:MindexEntry[], dal:FileDAL) {
const revocations = _.filter(mindex, (entry:MindexEntry) => entry.revoked_on);
for (const revoked of revocations) {
await dal.setRevoked(revoked.pub, true);
await dal.setRevoked(revoked.pub)
}
}
async deleteTransactions(block:BlockDTO, dal:any) {
async deleteTransactions(block:BlockDTO, dal:FileDAL) {
for (const obj of block.transactions) {
obj.currency = block.currency;
const tx = TransactionDTO.fromJSONObject(obj)
......@@ -498,7 +505,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
}
}
static pushStatsForBlocks(blocks:BlockDTO[], dal:any) {
static pushStatsForBlocks(blocks:BlockDTO[], dal:FileDAL) {
const stats: { [k:string]: { blocks: number[], lastParsedBlock:number }} = {};
// Stats
for (const block of blocks) {
......@@ -529,7 +536,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
return dal.pushStats(stats);
}
async pushSideBlock(obj:BlockDTO, dal:any, logger:any) {
async pushSideBlock(obj:BlockDTO, dal:FileDAL, logger:any) {
const start = Date.now();
const block = DBBlock.fromBlockDTO(BlockDTO.fromJSONObject(obj))
block.fork = true;
......
......@@ -12,6 +12,7 @@
// GNU Affero General Public License for more details.
import {BlockDTO} from "../dto/BlockDTO"
export interface SwitchBlock {
number:number
......@@ -22,7 +23,7 @@ export interface SwitchBlock {
export interface SwitcherDao<T extends SwitchBlock> {
getCurrent(): Promise<T>
getCurrent(): Promise<T|null>
getPotentials(numberStart:number, timeStart:number, maxNumber:number): Promise<T[]>
getBlockchainBlock(number:number, hash:string): Promise<T|null>
getSandboxBlock(number:number, hash:string): Promise<T|null>
......@@ -73,7 +74,7 @@ export class Switcher<T extends SwitchBlock> {
* Find all the suites' HEAD that we could potentially fork on, in the current fork window.
* @param current
*/
async findPotentialSuitesHeads(current:T) {
async findPotentialSuitesHeads(current:{ number:number, medianTime:number }) {
const numberStart = current.number - this.forkWindowSize
const timeStart = current.medianTime - this.forkWindowSize * this.avgGenTime
const suites = await this.findPotentialSuites(numberStart, timeStart)
......
export enum DataErrors {
LOCAL_BLOCK_NOT_FOUND_FOR_CRAWLER,
BLOCKCHAIN_NOT_INITIALIZED_YET,
CANNOT_DETERMINATE_MEMBERSHIP_AGE,
CANNOT_DETERMINATE_IDENTITY_AGE,
CERT_BASED_ON_UNKNOWN_BLOCK,
NO_TRANSACTION_POSSIBLE_IF_NOT_CURRENT_BLOCK,
CANNOT_REAPPLY_NO_CURRENT_BLOCK,
CANNOT_REVERT_NO_CURRENT_BLOCK,
BLOCK_TO_REVERT_NOT_FOUND,
MEMBER_NOT_FOUND
}
......@@ -16,6 +16,8 @@ import {BlockDTO} from "../dto/BlockDTO"
import {DuniterBlockchain} from "../blockchain/DuniterBlockchain"
import {QuickSynchronizer} from "./QuickSync"
import {DBHead} from "../db/DBHead"
import {FileDAL} from "../dal/fileDAL"
import {DBBlock} from "../db/DBBlock"
const _ = require('underscore');
const indexer = require('../indexer').Indexer
......@@ -24,7 +26,7 @@ const constants = require('../constants');
export class BlockchainContext {
private conf:any
private dal:any
private dal:FileDAL
private logger:any
private blockchain:DuniterBlockchain
private quickSynchronizer:QuickSynchronizer
......@@ -129,7 +131,7 @@ export class BlockchainContext {
return dbb.toBlockDTO()
}
async revertCurrentBlock(): Promise<BlockDTO> {
async revertCurrentBlock(): Promise<DBBlock> {
const head_1 = await this.dal.bindexDAL.head(1);
this.logger.debug('Reverting block #%s...', head_1.number);
const res = await this.blockchain.revertBlock(head_1.number, head_1.hash, this.dal)
......@@ -146,7 +148,7 @@ export class BlockchainContext {
throw constants.ERRORS.NO_POTENTIAL_FORK_AS_NEXT;
}
const block = forks[0];
await this.checkAndAddBlock(block)
await this.checkAndAddBlock(BlockDTO.fromJSONObject(block))
this.logger.debug('Applied block #%s', block.number);
}
......
......@@ -15,8 +15,11 @@
import {DuniterBlockchain} from "../blockchain/DuniterBlockchain";
import {BlockDTO} from "../dto/BlockDTO";
import {DBTransaction} from "../db/DBTransaction";
import {Indexer} from "../indexer";
import {AccountsGarbagingDAL, Indexer} from "../indexer";
import {CurrencyConfDTO} from "../dto/ConfDTO";
import {FileDAL} from "../dal/fileDAL"
import {DBBlock} from "../db/DBBlock"
import {DBTx} from "../dal/sqliteDAL/TxsDAL"
const _ = require('underscore')
const constants = require('../constants')
......@@ -32,7 +35,7 @@ let sync_expires: number[] = [];
let sync_nextExpiring = 0;
let sync_currConf: CurrencyConfDTO;
const sync_memoryWallets: any = {}
const sync_memoryDAL = {
const sync_memoryDAL:AccountsGarbagingDAL = {
getWallet: (conditions: string) => Promise.resolve(sync_memoryWallets[conditions] || { conditions, balance: 0 }),
saveWallet: async (wallet: any) => {
// Make a copy
......@@ -48,7 +51,7 @@ const sync_memoryDAL = {
export class QuickSynchronizer {
constructor(private blockchain:DuniterBlockchain, private conf: any, private dal: any, private logger: any) {
constructor(private blockchain:DuniterBlockchain, private conf: any, private dal:FileDAL, private logger: any) {
}
async saveBlocksInMainBranch(blocks: BlockDTO[]): Promise<void> {
......@@ -57,13 +60,13 @@ export class QuickSynchronizer {
await this.blockchain.saveParametersForRoot(blocks[0], this.conf, this.dal)
}
// Helper to retrieve a block with local cache
const getBlock = (number: number): Promise<BlockDTO> => {
const getBlock = async (number: number): Promise<BlockDTO> => {
const firstLocalNumber = blocks[0].number;
if (number >= firstLocalNumber) {
let offset = number - firstLocalNumber;
return Promise.resolve(blocks[offset])
}
return this.dal.getBlock(number);
return BlockDTO.fromJSONObject(await this.dal.getBlockWeHaveItForSure(number))
};
const getBlockByNumberAndHash = async (number: number, hash: string): Promise<BlockDTO> => {
const block = await getBlock(number);
......@@ -79,7 +82,7 @@ export class QuickSynchronizer {
}
// Transactions recording
await this.updateTransactionsForBlocks(blocks, getBlockByNumberAndHash);
await this.dal.blockDAL.saveBunch(blocks);
await this.dal.blockDAL.saveBunch(blocks.map(b => DBBlock.fromBlockDTO(b)));
await DuniterBlockchain.pushStatsForBlocks(blocks, this.dal);
}
......@@ -98,7 +101,7 @@ export class QuickSynchronizer {
}
txs = txs.concat(newOnes);
}
return this.dal.updateTransactions(txs);
return this.dal.updateTransactions(txs.map(t => DBTx.fromTransactionDTO(t)))
}
async quickApplyBlocks(blocks:BlockDTO[], to: number): Promise<void> {
......@@ -127,14 +130,14 @@ export class QuickSynchronizer {
sync_cindex = sync_cindex.concat(local_cindex);
sync_mindex = sync_mindex.concat(local_mindex);
const HEAD = await Indexer.quickCompleteGlobalScope(block, sync_currConf, sync_bindex, sync_iindex, sync_mindex, sync_cindex, {
const HEAD = await Indexer.quickCompleteGlobalScope(block, sync_currConf, sync_bindex, sync_iindex, sync_mindex, sync_cindex, ({
getBlock: (number: number) => {
return Promise.resolve(sync_allBlocks[number]);
},
getBlockByBlockstamp: (blockstamp: string) => {
return Promise.resolve(sync_allBlocks[parseInt(blockstamp)]);
}
});
}) as any);
sync_bindex.push(HEAD);
// Remember expiration dates
......
......@@ -172,11 +172,15 @@ export class FileDAL {
return this.peerDAL.getPeersWithEndpointsLike('WS2P')
}
async getBlock(number:number) {
async getBlock(number:number): Promise<DBBlock|null> {
const block = await this.blockDAL.getBlock(number)
return block || null;
}
async getBlockWeHaveItForSure(number:number): Promise<DBBlock> {
return (await this.blockDAL.getBlock(number)) as DBBlock
}
getAbsoluteBlockByNumberAndHash(number:number, hash:string) {
return this.blockDAL.getAbsoluteBlock(number, hash)
}
......@@ -205,7 +209,7 @@ export class FileDAL {
return this.getBlockByNumberAndHash(number, hash);
}
async getBlockByNumberAndHash(number:number, hash:string) {
async getBlockByNumberAndHash(number:number, hash:string): Promise<DBBlock> {
try {
const block = await this.getBlock(number);
if (!block || block.hash != hash)
......@@ -217,7 +221,7 @@ export class FileDAL {
}
}
async getBlockByNumberAndHashOrNull(number:number, hash:string) {
async getBlockByNumberAndHashOrNull(number:number, hash:string): Promise<DBBlock|null> {
try {
return await this.getBlockByNumberAndHash(number, hash)
} catch (e) {
......@@ -238,7 +242,7 @@ export class FileDAL {
async getCurrentBlockOrNull() {
let current = null;
let current:DBBlock|null = null;
try {
current = await this.getBlockCurrent()
} catch (e) {
......@@ -850,20 +854,22 @@ export class FileDAL {
}
}
async saveBlock(block:BlockDTO) {
const dbb = DBBlock.fromBlockDTO(block)
async saveBlock(dbb:DBBlock) {
dbb.wrong = false;
await Promise.all([
this.saveBlockInFile(dbb),
this.saveTxsInFiles(block.transactions, block.number, block.medianTime)
this.saveTxsInFiles(dbb.transactions, dbb.number, dbb.medianTime)
])
}
async generateIndexes(block:DBBlock, conf:ConfDTO, index:IndexEntry[], HEAD:DBHead) {
async generateIndexes(block:BlockDTO, conf:ConfDTO, index:IndexEntry[], aHEAD:DBHead|null) {
// We need to recompute the indexes for block#0
if (!index || !HEAD || HEAD.number == 0) {
let HEAD:DBHead
if (!index || !aHEAD || aHEAD.number == 0) {
index = indexer.localIndex(block, conf)
HEAD = await indexer.completeGlobalScope(block, conf, index, this)
} else {
HEAD = aHEAD
}
let mindex = indexer.mindex(index);
let iindex = indexer.iindex(index);
......@@ -903,7 +909,7 @@ export class FileDAL {
return true;
}
async trimSandboxes(block:DBBlock) {
async trimSandboxes(block:{ medianTime: number }) {
await this.certDAL.trimExpiredCerts(block.medianTime);
await this.msDAL.trimExpiredMemberships(block.medianTime);
await this.idtyDAL.trimExpiredIdentities(block.medianTime);
......@@ -926,7 +932,8 @@ export class FileDAL {
async saveTxsInFiles(txs:TransactionDTO[], block_number:number, medianTime:number) {
return Promise.all(txs.map(async (tx) => {
const sp = tx.blockstamp.split('-');
tx.blockstampTime = (await this.getBlockByNumberAndHash(parseInt(sp[0]), sp[1])).medianTime;
const basedBlock = (await this.getBlockByNumberAndHash(parseInt(sp[0]), sp[1])) as DBBlock
tx.blockstampTime = basedBlock.medianTime;
const txEntity = TransactionDTO.fromJSONObject(tx)
txEntity.computeAllHashes();
return this.txsDAL.addLinked(TransactionDTO.fromJSONObject(txEntity), block_number, medianTime);
......@@ -1111,11 +1118,11 @@ export class FileDAL {
}
async cleanCaches() {
await _.values(this.newDals).map((dal:any) => dal.cleanCache && dal.cleanCache())
await _.values(this.newDals).map((dal:Initiable) => dal.cleanCache && dal.cleanCache())
}
async close() {
await _.values(this.newDals).map((dal:any) => dal.cleanCache && dal.cleanCache())
await _.values(this.newDals).map((dal:Initiable) => dal.cleanCache && dal.cleanCache())
return this.sqliteDriver.closeConnection();
}
......
......@@ -25,4 +25,7 @@ export abstract class AbstractCFS extends Initiable {
super()
this.coreFS = new CFSCore(rootPath, qioFS)
}
cleanCache() {
}
}
......@@ -199,6 +199,12 @@ export abstract class AbstractSQLite<T> extends Initiable {
}
}
/**
* To redefine if necessary in subclasses.
*/
cleanCache() {
}
private toConditionsArray(obj:any): string[] {
return _.keys(obj).map((k:string) => {
if (obj[k].$lte !== undefined) {
......
......@@ -22,7 +22,7 @@ const IS_NOT_FORK = false;
export class BlockDAL extends AbstractSQLite<DBBlock> {
private current: any
private current: DBBlock|null
constructor(driver:SQLiteDriver) {
super(
......@@ -97,14 +97,14 @@ export class BlockDAL extends AbstractSQLite<DBBlock> {
if (!this.current) {
this.current = (await this.query('SELECT * FROM block WHERE NOT fork ORDER BY number DESC LIMIT 1'))[0];
}
return Promise.resolve(this.current)
return this.current
}
async getBlock(number:string | number) {
async getBlock(number:string | number): Promise<DBBlock|null> {
return (await this.query('SELECT * FROM block WHERE number = ? and NOT fork', [parseInt(String(number))]))[0];
}
async getAbsoluteBlock(number:number, hash:string) {
async getAbsoluteBlock(number:number, hash:string): Promise<DBBlock|null> {
return (await this.query('SELECT * FROM block WHERE number = ? and hash = ?', [number, hash]))[0];
}
......@@ -171,7 +171,7 @@ export class BlockDAL extends AbstractSQLite<DBBlock> {
return await this.saveEntity(block);
}
async setSideBlock(number:number, previousBlock:DBBlock) {
async setSideBlock(number:number, previousBlock:DBBlock|null) {
await this.query('UPDATE block SET fork = ? WHERE number = ?', [true, number]);
this.current = previousBlock;
}
......
export abstract class Initiable {
abstract init(): Promise<void>
abstract cleanCache(): void
}
......@@ -336,7 +336,7 @@ export class MetaDAL extends AbstractSQLite<DBMeta> {
await mindexDAL.exec('ALTER TABLE m_index ADD COLUMN chainable_on INTEGER NULL;')
const memberships = await mindexDAL.query('SELECT * FROM m_index WHERE op = ?', [CommonConstants.IDX_CREATE])
for (const ms of memberships) {
const reference = await blockDAL.getBlock(parseInt(ms.written_on.split('-')[0]))
const reference = (await blockDAL.getBlock(parseInt(ms.written_on.split('-')[0]))) as DBBlock
const updateQuery = 'UPDATE m_index SET chainable_on = ' + (reference.medianTime + conf.msPeriod) + ' WHERE pub = \'' + ms.pub + '\' AND op = \'CREATE\''
await mindexDAL.exec(updateQuery)
}
......@@ -371,7 +371,7 @@ export class MetaDAL extends AbstractSQLite<DBMeta> {
let mindexDAL = new MIndexDAL(this.driverCopy)
const memberships = await mindexDAL.query('SELECT * FROM m_index')
for (const ms of memberships) {
const reference = await blockDAL.getBlock(parseInt(ms.written_on.split('-')[0]))
const reference = (await blockDAL.getBlock(parseInt(ms.written_on.split('-')[0]))) as DBBlock
const msPeriod = conf.msWindow // It has the same value, as it was not defined on currency init
const updateQuery = 'UPDATE m_index SET chainable_on = ' + (reference.medianTime + msPeriod) + ' WHERE pub = \'' + ms.pub + '\' AND written_on = \'' + ms.written_on + '\''
await mindexDAL.exec(updateQuery)
......
......@@ -94,7 +94,7 @@ export class BIndexDAL extends AbstractSQLite<DBHead> {
* Get HEAD~n
* @param n Position
*/
async head(n:number) {
async head(n:number): Promise<DBHead> {
if (!n) {
throw "Cannot read HEAD~0, which is the incoming block"
}
......
......@@ -133,6 +133,10 @@ export class IIndexDAL extends AbstractIndex<IindexEntry> {
return this.entityOrNull('uid', uid, retrieveOnPubkey)
}
getFullFromPubkey(pub:string): Promise<FullIindexEntry> {
return this.entityOrNull('pub', pub) as Promise<FullIindexEntry>
}
getFullFromUID(uid:string): Promise<FullIindexEntry|null> {
return this.entityOrNull('uid', uid, true) as Promise<FullIindexEntry|null>
}
......
......@@ -15,6 +15,7 @@ import {Indexer, SindexEntry} from "../../../indexer"
import {SQLiteDriver} from "../../drivers/SQLiteDriver"
import {AbstractIndex} from "../AbstractIndex"
import {CommonConstants} from "../../../common-libs/constants"
const _ = require('underscore');
const constants = require('../../../constants');
......@@ -109,7 +110,7 @@ export class SIndexDAL extends AbstractIndex<SindexEntry> {
return this.getAvailableForConditions('%SIG(' + pubkey + ')%')
}
async getAvailableForConditions(conditionsStr:string) {
async getAvailableForConditions(conditionsStr:string): Promise<{ amount:number, base:number }[]> {
const potentials = await this.query('SELECT * FROM ' + this.table + ' s1 ' +
'WHERE s1.op = ? ' +
'AND conditions LIKE ? ' +
......
......@@ -24,6 +24,8 @@ import {CommonConstants} from "./common-libs/constants"
import {MembershipDTO} from "./dto/MembershipDTO"
import {UnlockMetadata} from "./common-libs/txunlock"
import {FileDAL} from "./dal/fileDAL"
import {DBWallet} from "./dal/sqliteDAL/WalletDAL"
import {DataErrors} from "./common-libs/errors"
const _ = require('underscore');
......@@ -167,6 +169,19 @@ function pushCindex(index: any[], entry: CindexEntry): void {
index.push(entry)
}
export interface AccountsGarbagingDAL {
getWallet: (conditions: string) => Promise<DBWallet>
saveWallet: (wallet: DBWallet) => Promise<void>
sindexDAL: {
getAvailableForConditions: (conditions: string) => any
}
}
export interface BlockchainBlocksDAL {
getBlock(number: number): Promise<BlockDTO>
getBlockByBlockstamp(blockstamp: string): Promise<BlockDTO>
}
export class Indexer {
static localIndex(block:BlockDTO, conf:CurrencyConfDTO): IndexEntry[] {
......@@ -451,7 +466,7 @@ export class Indexer {
return index;
}
static async quickCompleteGlobalScope(block: BlockDTO, conf: CurrencyConfDTO, bindex: DBHead[], iindex: IindexEntry[], mindex: MindexEntry[], cindex: CindexEntry[], dal: any) {