Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
8401cf5a
Commit
8401cf5a
authored
7 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[fix]
#1042
Fix returned JSON via websockets
parent
7f0cce70
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/modules/bma/lib/bma.ts
+64
-2
64 additions, 2 deletions
app/modules/bma/lib/bma.ts
app/modules/bma/lib/dtos.ts
+59
-0
59 additions, 0 deletions
app/modules/bma/lib/dtos.ts
with
123 additions
and
2 deletions
app/modules/bma/lib/bma.ts
+
64
−
2
View file @
8401cf5a
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
app/modules/bma/lib/dtos.ts
+
59
−
0
View file @
8401cf5a
...
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment