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

[fix] #1042 Fix returned JSON via websockets

parent 7f0cce70
Branches
Tags
No related merge requests found
......@@ -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);
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment