diff --git a/app/modules/bma/lib/controllers/wot.ts b/app/modules/bma/lib/controllers/wot.ts index 51d1768999c3740ca49e6f2f2e4dc03b3ae0d591..9e7553ea4c77d2ec33eff55499eb2e9e8f01ec32 100644 --- a/app/modules/bma/lib/controllers/wot.ts +++ b/app/modules/bma/lib/controllers/wot.ts @@ -1,6 +1,8 @@ +import { IindexEntry } from './../../../../lib/indexer'; import {AbstractController} from "./AbstractController"; import {BMAConstants} from "../constants"; import {DBIdentity} from "../../../../lib/dal/sqliteDAL/IdentityDAL"; +import { IdentityForRequirements } from '../../../../service/BlockchainService'; import { HttpCert, HttpCertIdentity, HttpCertifications, @@ -153,7 +155,30 @@ export class WOTBinding extends AbstractController { async requirementsOfPending(req:any): Promise<HttpRequirements> { const minsig = ParametersService.getMinSig(req) - const identities = await this.server.dal.idtyDAL.query('SELECT i.*, count(c.sig) as nbSig FROM idty i, cert c WHERE c.target = i.hash group by i.hash having nbSig >= ?', minsig) + let identities:IdentityForRequirements[] = await this.server.dal.idtyDAL.query( + 'SELECT i.*, count(c.sig) as nbSig ' + + 'FROM idty i, cert c ' + + 'WHERE c.target = i.hash group by i.hash having nbSig >= ?', + minsig) + const members:IdentityForRequirements[] = (await this.server.dal.idtyDAL.query( + 'SELECT i.*, count(c.sig) as nbSig ' + + 'FROM i_index i, cert c ' + + 'WHERE c.`to` = i.pub group by i.pub having nbSig >= ?', + minsig)).map((i:IindexEntry):IdentityForRequirements => { + return { + hash: i.hash || "", + member: i.member || false, + wasMember: i.wasMember || false, + pubkey: i.pub, + uid: i.uid || "", + buid: i.created_on || "", + sig: i.sig || "", + revocation_sig: "", + revoked: false, + revoked_on: 0 + } + }) + identities = identities.concat(members) const all = await this.BlockchainService.requirementsOfIdentities(identities, false); if (!all || !all.length) { throw BMAConstants.ERRORS.NO_IDTY_MATCHING_PUB_OR_UID; diff --git a/app/modules/ws2p/lib/impl/WS2PReqMapperByServer.ts b/app/modules/ws2p/lib/impl/WS2PReqMapperByServer.ts index 368757b0b457e9ccc1e94298b33688ce6ac0d27f..74eed972dc3ea5db0d3e8b720165d6dc964fdc88 100644 --- a/app/modules/ws2p/lib/impl/WS2PReqMapperByServer.ts +++ b/app/modules/ws2p/lib/impl/WS2PReqMapperByServer.ts @@ -1,6 +1,8 @@ +import { IdentityForRequirements } from './../../../../service/BlockchainService'; import {Server} from "../../../../../server" import {WS2PReqMapper} from "../interface/WS2PReqMapper" import {BlockDTO} from "../../../../lib/dto/BlockDTO" +import { IindexEntry } from '../../../../lib/indexer'; export class WS2PReqMapperByServer implements WS2PReqMapper { @@ -27,7 +29,30 @@ export class WS2PReqMapperByServer implements WS2PReqMapper { } async getRequirementsOfPending(minsig: number): Promise<any> { - const identities = await this.server.dal.idtyDAL.query('SELECT i.*, count(c.sig) as nbSig FROM idty i, cert c WHERE c.target = i.hash group by i.hash having nbSig >= ?', minsig) + let identities:IdentityForRequirements[] = await this.server.dal.idtyDAL.query( + 'SELECT i.*, count(c.sig) as nbSig ' + + 'FROM idty i, cert c ' + + 'WHERE c.target = i.hash group by i.hash having nbSig >= ?', + minsig) + const members:IdentityForRequirements[] = (await this.server.dal.idtyDAL.query( + 'SELECT i.*, count(c.sig) as nbSig ' + + 'FROM i_index i, cert c ' + + 'WHERE c.`to` = i.pub group by i.pub having nbSig >= ?', + minsig)).map((i:IindexEntry):IdentityForRequirements => { + return { + hash: i.hash || "", + member: i.member || false, + wasMember: i.wasMember || false, + pubkey: i.pub, + uid: i.uid || "", + buid: i.created_on || "", + sig: i.sig || "", + revocation_sig: "", + revoked: false, + revoked_on: 0 + } + }) + identities = identities.concat(members) const all = await this.server.BlockchainService.requirementsOfIdentities(identities, false) return { identities: all diff --git a/app/service/BlockchainService.ts b/app/service/BlockchainService.ts index 0348efea6405183e165af9d025427b104859ef90..ba652048307abf4a5d3bbacc9da9f89edd562bce 100644 --- a/app/service/BlockchainService.ts +++ b/app/service/BlockchainService.ts @@ -1,3 +1,4 @@ +import { IdentityForRequirements } from './BlockchainService'; "use strict"; import {Server} from "../../server" import {GlobalFifoPromise} from "./GlobalFifoPromise" @@ -20,6 +21,18 @@ import {OtherConstants} from "../lib/other_constants" const _ = require('underscore'); const constants = require('../lib/constants'); +export interface IdentityForRequirements { + hash:string + member:boolean + wasMember:boolean + pubkey:string + uid:string + buid:string + sig:string + revocation_sig:string + revoked:boolean + revoked_on:number +} export class BlockchainService extends FIFOService { mainContext:BlockchainContext @@ -234,7 +247,7 @@ export class BlockchainService extends FIFOService { } - async requirementsOfIdentities(identities:DBIdentity[], computeDistance = true) { + async requirementsOfIdentities(identities:IdentityForRequirements[], computeDistance = true) { let all:HttpIdentityRequirement[] = []; let current = await this.dal.getCurrentBlockOrNull(); for (const obj of identities) { @@ -248,7 +261,7 @@ export class BlockchainService extends FIFOService { return all; } - async requirementsOfIdentity(idty:DBIdentity, current:DBBlock, computeDistance = true): Promise<HttpIdentityRequirement> { + async requirementsOfIdentity(idty:IdentityForRequirements, current:DBBlock, computeDistance = true): Promise<HttpIdentityRequirement> { // TODO: this is not clear let expired = false; let outdistanced = false;