diff --git a/app/modules/bma/lib/bma.ts b/app/modules/bma/lib/bma.ts index 850510edf212302c60f310e14f33d86424fb9a62..4576c5ce4e688f8baa83f2416f5df089337545f1 100644 --- a/app/modules/bma/lib/bma.ts +++ b/app/modules/bma/lib/bma.ts @@ -9,6 +9,9 @@ import {NetworkBinding} from "./controllers/network" import {WOTBinding} from "./controllers/wot" import {TransactionBinding} from "./controllers/transactions" import {UDBinding} from "./controllers/uds" +import {HttpBlock, HttpPeer, HttpTransactionOfBlock} from "./dtos"; +import {PeerDTO} from "../../../lib/dto/PeerDTO"; +import {BlockDTO} from "../../../lib/dto/BlockDTO"; const co = require('co'); const es = require('event-stream'); @@ -138,11 +141,70 @@ export const bma = function(server:Server, interfaces:NetworkInterface[], httpLo // Broadcast block if (data.joiners) { currentBlock = data; - wssBlock.broadcast(JSON.stringify(sanitize(currentBlock, dtos.Block))); + const blockDTO:BlockDTO = BlockDTO.fromJSONObject(currentBlock) + const blockResult:HttpBlock = { + version: blockDTO.version, + currency: blockDTO.currency, + number: blockDTO.number, + issuer: blockDTO.issuer, + issuersFrame: blockDTO.issuersFrame, + issuersFrameVar: blockDTO.issuersFrameVar, + issuersCount: blockDTO.issuersCount, + parameters: blockDTO.parameters, + membersCount: blockDTO.membersCount, + monetaryMass: blockDTO.monetaryMass, + powMin: blockDTO.powMin, + time: blockDTO.time, + medianTime: blockDTO.medianTime, + dividend: blockDTO.dividend, + unitbase: blockDTO.unitbase, + hash: blockDTO.hash, + previousHash: blockDTO.previousHash, + previousIssuer: blockDTO.previousIssuer, + identities: blockDTO.identities, + certifications: blockDTO.certifications, + joiners: blockDTO.joiners, + actives: blockDTO.actives, + leavers: blockDTO.leavers, + revoked: blockDTO.revoked, + excluded: blockDTO.excluded, + transactions: blockDTO.transactions.map((tx):HttpTransactionOfBlock => { + return { + version: tx.version, + currency: tx.currency, + comment: tx.comment, + locktime: tx.locktime, + issuers: tx.issuers, + signatures: tx.signatures, + outputs: tx.outputs, + inputs: tx.inputs, + unlocks: tx.unlocks, + block_number: tx.blockNumber, + blockstamp: tx.blockstamp, + blockstampTime: tx.blockstampTime, + time: tx.blockstampTime + } + }), + nonce: blockDTO.nonce, + inner_hash: blockDTO.inner_hash, + signature: blockDTO.signature, + raw: blockDTO.getRawSigned() + } + wssBlock.broadcast(JSON.stringify(blockResult)) } // Broadcast peer if (data.endpoints) { - wssPeer.broadcast(JSON.stringify(sanitize(data, dtos.Peer))); + const peerDTO = PeerDTO.fromJSONObject(data) + const peerResult:HttpPeer = { + version: peerDTO.version, + currency: peerDTO.currency, + pubkey: peerDTO.pubkey, + block: peerDTO.blockstamp, + endpoints: peerDTO.endpoints, + signature: peerDTO.signature, + raw: peerDTO.getRaw() + } + wssPeer.broadcast(JSON.stringify(peerResult)); } } catch (e) { logger && logger.error('error on ws mapSync:', e); diff --git a/app/modules/bma/lib/dtos.ts b/app/modules/bma/lib/dtos.ts index 0949bbb9f5b9a34aa9fac0deebd73a4c19239aec..5bd20deddb447e3ba34242d3774c499ea9f25527 100644 --- a/app/modules/bma/lib/dtos.ts +++ b/app/modules/bma/lib/dtos.ts @@ -91,6 +91,22 @@ export const TransactionOfBlock = { "issuers": [String] }; +export interface HttpTransactionOfBlock { + version: number + currency: string + comment: string + locktime: number + signatures: string[] + outputs: string[] + inputs: string[] + unlocks: string[] + block_number: number + blockstamp: string + blockstampTime: number + time: number + issuers: string[] +} + export const Block = { "version": Number, "currency": String, @@ -124,6 +140,39 @@ export const Block = { "raw": String }; +export interface HttpBlock { + version: number + currency: string + number: number + issuer: string + issuersFrame: number + issuersFrameVar: number + issuersCount: number + parameters: string + membersCount: number + monetaryMass: number + powMin: number + time: number + medianTime: number + dividend: number + unitbase: number + hash: string + previousHash: string + previousIssuer: string + identities: string[] + certifications: string[] + joiners: string[] + actives: string[] + leavers: string[] + revoked: string[] + excluded: string[] + transactions: HttpTransactionOfBlock[] + nonce: number + inner_hash: string + signature: string + raw: string +} + export const Hardship = { "block": Number, "level": Number @@ -161,6 +210,16 @@ export const Peer = { "raw": String }; +export interface HttpPeer { + version: number + currency: string + pubkey: string + block: string + endpoints: string[] + signature: string + raw: string +} + export const DBPeer = { "version": Number, "currency": String,