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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
aa39119b
Commit
aa39119b
authored
7 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[fix]
#1037
Migrating Entity Merkle
parent
65adbcfe
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/lib/dal/fileDAL.ts
+2
-2
2 additions, 2 deletions
app/lib/dal/fileDAL.ts
app/lib/dto/MerkleDTO.ts
+24
-24
24 additions, 24 deletions
app/lib/dto/MerkleDTO.ts
test/fast/merkle.js
+3
-3
3 additions, 3 deletions
test/fast/merkle.js
test/integration/cli.js
+2
-2
2 additions, 2 deletions
test/integration/cli.js
with
31 additions
and
31 deletions
app/lib/dal/fileDAL.ts
+
2
−
2
View file @
aa39119b
...
...
@@ -13,6 +13,7 @@ import {DBWallet} from "./sqliteDAL/WalletDAL"
import
{
DBTx
}
from
"
./sqliteDAL/TxsDAL
"
import
{
DBBlock
}
from
"
../db/DBBlock
"
import
{
DBMembership
}
from
"
./sqliteDAL/MembershipDAL
"
import
{
MerkleDTO
}
from
"
../dto/MerkleDTO
"
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
...
...
@@ -22,7 +23,6 @@ const common = require('duniter-common');
const
indexer
=
require
(
'
../indexer
'
).
Indexer
const
logger
=
require
(
'
../logger
'
).
NewLogger
(
'
filedal
'
);
const
Configuration
=
require
(
'
../entity/configuration
'
);
const
Merkle
=
require
(
'
../entity/merkle
'
);
const
Transaction
=
require
(
'
../entity/transaction
'
);
const
constants
=
require
(
'
../constants
'
);
...
...
@@ -702,7 +702,7 @@ export class FileDAL {
async
merkleForPeers
()
{
let
peers
=
await
this
.
listAllPeersWithStatusNewUP
();
const
leaves
=
peers
.
map
((
peer
:
DBPeer
)
=>
peer
.
hash
);
const
merkle
=
new
Merkle
();
const
merkle
=
new
Merkle
DTO
();
merkle
.
initialize
(
leaves
);
return
merkle
;
}
...
...
This diff is collapsed.
Click to expand it.
app/lib/
entity/merkle.j
s
→
app/lib/
dto/MerkleDTO.t
s
+
24
−
24
View file @
aa39119b
"
use strict
"
;
const
_
=
require
(
'
underscore
'
);
const
merkle
=
require
(
'
merkle
'
);
module
.
exports
=
M
erkle
;
const
merkle
=
require
(
'
m
erkle
'
)
;
function
Merkle
(
json
)
{
export
class
Merkle
DTO
{
_
(
json
||
{}).
keys
().
forEach
((
key
)
=>
{
let
value
=
json
[
key
];
if
(
key
==
"
number
"
)
{
value
=
parseInt
(
value
);
}
this
[
key
]
=
value
;
});
private
levels
:
any
[]
nodes
:
any
[]
depth
:
number
this
.
initialize
=
(
leaves
)
=>
{
initialize
(
leaves
:
string
[])
{
const
tree
=
merkle
(
'
sha256
'
).
sync
(
leaves
);
this
.
depth
=
tree
.
depth
();
this
.
nodes
=
tree
.
nodes
();
...
...
@@ -23,9 +17,9 @@ function Merkle(json) {
this
.
levels
[
i
]
=
tree
.
level
(
i
);
}
return
this
;
}
;
}
this
.
remove
=
(
leaf
)
=>
{
remove
(
leaf
:
string
)
{
// If leaf IS present
if
(
~
this
.
levels
[
this
.
depth
].
indexOf
(
leaf
)){
const
leaves
=
this
.
leaves
();
...
...
@@ -37,10 +31,10 @@ function Merkle(json) {
leaves
.
sort
();
this
.
initialize
(
leaves
);
}
}
;
}
this
.
removeMany
=
(
leaves
)
=>
{
leaves
.
forEach
((
leaf
)
=>
{
removeMany
(
leaves
:
string
[])
{
leaves
.
forEach
((
leaf
:
string
)
=>
{
// If leaf IS present
if
(
~
this
.
levels
[
this
.
depth
].
indexOf
(
leaf
)){
const
theLeaves
=
this
.
leaves
();
...
...
@@ -55,7 +49,7 @@ function Merkle(json) {
this
.
initialize
(
leaves
);
};
this
.
push
=
(
leaf
,
previous
)
=>
{
push
(
leaf
:
string
,
previous
:
string
)
{
// If leaf is not present
if
(
this
.
levels
[
this
.
depth
].
indexOf
(
leaf
)
==
-
1
){
const
leaves
=
this
.
leaves
();
...
...
@@ -71,9 +65,9 @@ function Merkle(json) {
leaves
.
sort
();
this
.
initialize
(
leaves
);
}
}
;
}
this
.
pushMany
=
(
leaves
)
=>
{
pushMany
(
leaves
:
string
[])
{
leaves
.
forEach
((
leaf
)
=>
{
// If leaf is not present
if
(
this
.
levels
[
this
.
depth
].
indexOf
(
leaf
)
==
-
1
){
...
...
@@ -82,11 +76,17 @@ function Merkle(json) {
});
leaves
.
sort
();
this
.
initialize
(
leaves
);
}
;
}
this
.
root
=
()
=>
this
.
levels
.
length
>
0
?
this
.
levels
[
0
][
0
]
:
''
;
root
()
{
return
this
.
levels
.
length
>
0
?
this
.
levels
[
0
][
0
]
:
''
}
this
.
leaves
=
()
=>
this
.
levels
[
this
.
depth
];
leaves
()
{
return
this
.
levels
[
this
.
depth
]
}
this
.
count
=
()
=>
this
.
leaves
().
length
;
count
()
{
return
this
.
leaves
().
length
}
}
This diff is collapsed.
Click to expand it.
test/fast/merkle.js
+
3
−
3
View file @
aa39119b
...
...
@@ -2,11 +2,11 @@
var
should
=
require
(
'
should
'
);
var
assert
=
require
(
'
assert
'
);
var
Merkle
=
require
(
'
../../app/lib/
entity/merkle
'
);
var
Merkle
DTO
=
require
(
'
../../app/lib/
dto/MerkleDTO
'
).
MerkleDTO
describe
(
"
Merkle ['a', 'b', 'c', 'd', 'e']
"
,
function
(){
var
m
=
new
Merkle
({
type
:
'
CollectionName
'
,
criteria
:
'
{}
'
}
);
var
m
=
new
Merkle
DTO
(
);
m
.
initialize
([
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
]);
it
(
'
should have root 16E6BEB3E080910740A2923D6091618CAA9968AEAD8A52D187D725D199548E2C
'
,
function
(){
...
...
@@ -40,7 +40,7 @@ describe("Merkle ['a', 'b', 'c', 'd', 'e']", function(){
describe
(
"
Merkle []
"
,
function
(){
var
m
=
new
Merkle
({
type
:
'
CollectionName
'
,
criteria
:
'
{}
'
}
);
var
m
=
new
Merkle
DTO
(
);
m
.
initialize
([]);
it
(
'
should have root empty
'
,
function
(){
...
...
This diff is collapsed.
Click to expand it.
test/integration/cli.js
+
2
−
2
View file @
aa39119b
...
...
@@ -10,7 +10,7 @@ const duniter = require('../../index');
const
merkleh
=
require
(
'
../../app/lib/helpers/merkle
'
);
const
hashf
=
require
(
'
duniter-common
'
).
hashf
;
const
constants
=
require
(
'
../../app/lib/constants
'
);
const
Merkle
=
require
(
'
../../app/lib/
entity/merkle
'
);
const
Merkle
DTO
=
require
(
'
../../app/lib/
dto/MerkleDTO
'
).
MerkleDTO
const
DB_NAME
=
"
unit_tests
"
;
...
...
@@ -31,7 +31,7 @@ describe("CLI", function() {
const
onReadBlockchainChunk
=
(
count
,
from
)
=>
Promise
.
resolve
(
blockchain
.
blocks
.
slice
(
from
,
from
+
count
));
const
onReadParticularBlock
=
(
number
)
=>
Promise
.
resolve
(
blockchain
.
blocks
[
number
]);
const
onPeersRequested
=
(
req
)
=>
co
(
function
*
()
{
const
merkle
=
new
Merkle
();
const
merkle
=
new
Merkle
DTO
();
merkle
.
initialize
(
leaves
);
merkle
.
leaf
=
{
"
hash
"
:
req
.
params
.
leaf
,
...
...
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