Fix wrong output format of peers (#4270) (#4442)

* Fix wrong output format of peers

* Add outPeer tests
This commit is contained in:
Jaco Greeff
2017-02-06 09:53:22 +01:00
committed by GitHub
parent ab2d02bbb6
commit c2ceefbc22
2 changed files with 83 additions and 3 deletions

View File

@@ -129,12 +129,31 @@ export function outNumber (number) {
return new BigNumber(number || 0);
}
export function outPeer (peer) {
const protocols = Object.keys(peer.protocols)
.reduce((obj, key) => {
if (peer.protocols[key]) {
obj[key] = {
...peer.protocols[key],
difficulty: outNumber(peer.protocols[key].difficulty)
};
}
return obj;
}, {});
return {
...peer,
protocols
};
}
export function outPeers (peers) {
return {
active: outNumber(peers.active),
connected: outNumber(peers.connected),
max: outNumber(peers.max),
peers: peers.peers.map(p => { Object.keys(p.protocols).forEach(k => { p.protocols[k].difficulty = outNumber(p.protocols[k].difficulty); }); return p; })
peers: peers.peers.map((peer) => outPeer(peer))
};
}