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
5454fb7a
Commit
5454fb7a
authored
8 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh] `export-bc` modularized
parent
ff35b718
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/cli.js
+0
-41
0 additions, 41 deletions
app/cli.js
app/modules/export-bc.js
+52
-0
52 additions, 0 deletions
app/modules/export-bc.js
index.js
+12
-6
12 additions, 6 deletions
index.js
with
64 additions
and
47 deletions
app/cli.js
+
0
−
41
View file @
5454fb7a
...
...
@@ -218,47 +218,6 @@ module.exports = () => {
});
})));
program
.
command
(
'
export-bc [upto]
'
)
.
description
(
'
Exports the whole blockchain as JSON array, up to [upto] block number (excluded).
'
)
.
action
(
subCommand
(
service
(
function
(
upto
,
server
)
{
return
co
(
function
*
()
{
try
{
let
CHUNK_SIZE
=
500
;
let
jsoned
=
[];
let
current
=
yield
server
.
dal
.
getCurrentBlockOrNull
();
let
lastNumber
=
current
?
current
.
number
+
1
:
-
1
;
if
(
upto
!==
undefined
&&
upto
.
match
(
/
\d
+/
))
{
lastNumber
=
Math
.
min
(
parseInt
(
upto
),
lastNumber
);
}
let
chunksCount
=
Math
.
floor
(
lastNumber
/
CHUNK_SIZE
);
let
chunks
=
[];
// Max-size chunks
for
(
let
i
=
0
,
len
=
chunksCount
;
i
<
len
;
i
++
)
{
chunks
.
push
({
start
:
i
*
CHUNK_SIZE
,
to
:
i
*
CHUNK_SIZE
+
CHUNK_SIZE
-
1
});
}
// A last chunk
if
(
lastNumber
>
chunksCount
*
CHUNK_SIZE
)
{
chunks
.
push
({
start
:
chunksCount
*
CHUNK_SIZE
,
to
:
lastNumber
});
}
for
(
const
chunk
of
chunks
)
{
let
blocks
=
yield
server
.
dal
.
getBlocksBetween
(
chunk
.
start
,
chunk
.
to
);
blocks
.
forEach
(
function
(
block
)
{
jsoned
.
push
(
_
(
new
Block
(
block
).
json
()).
omit
(
'
raw
'
));
});
}
if
(
!
program
.
nostdout
)
{
console
.
log
(
JSON
.
stringify
(
jsoned
,
null
,
"
"
));
}
yield
server
.
disconnect
();
return
jsoned
;
}
catch
(
err
)
{
logger
.
warn
(
err
.
message
||
err
);
yield
server
.
disconnect
();
}
});
},
NO_LOGS
)));
program
.
on
(
'
*
'
,
function
(
cmd
)
{
console
.
log
(
"
Unknown command '%s'. Try --help for a listing of commands & options.
"
,
cmd
);
...
...
This diff is collapsed.
Click to expand it.
app/modules/export-bc.js
0 → 100644
+
52
−
0
View file @
5454fb7a
"
use strict
"
;
const
co
=
require
(
'
co
'
);
const
_
=
require
(
'
underscore
'
);
const
Block
=
require
(
'
../lib/entity/block
'
);
module
.
exports
=
{
duniter
:
{
cli
:
[{
name
:
'
export-bc [upto]
'
,
desc
:
'
Exports the whole blockchain as JSON array, up to [upto] block number (excluded).
'
,
logs
:
false
,
onPluggedDALExecute
:
(
server
,
conf
,
program
,
params
)
=>
co
(
function
*
()
{
const
upto
=
params
[
0
];
const
logger
=
server
.
logger
;
try
{
let
CHUNK_SIZE
=
500
;
let
jsoned
=
[];
let
current
=
yield
server
.
dal
.
getCurrentBlockOrNull
();
let
lastNumber
=
current
?
current
.
number
+
1
:
-
1
;
if
(
upto
!==
undefined
&&
upto
.
match
(
/
\d
+/
))
{
lastNumber
=
Math
.
min
(
parseInt
(
upto
),
lastNumber
);
}
let
chunksCount
=
Math
.
floor
(
lastNumber
/
CHUNK_SIZE
);
let
chunks
=
[];
// Max-size chunks
for
(
let
i
=
0
,
len
=
chunksCount
;
i
<
len
;
i
++
)
{
chunks
.
push
({
start
:
i
*
CHUNK_SIZE
,
to
:
i
*
CHUNK_SIZE
+
CHUNK_SIZE
-
1
});
}
// A last chunk
if
(
lastNumber
>
chunksCount
*
CHUNK_SIZE
)
{
chunks
.
push
({
start
:
chunksCount
*
CHUNK_SIZE
,
to
:
lastNumber
});
}
for
(
const
chunk
of
chunks
)
{
let
blocks
=
yield
server
.
dal
.
getBlocksBetween
(
chunk
.
start
,
chunk
.
to
);
blocks
.
forEach
(
function
(
block
)
{
jsoned
.
push
(
_
(
new
Block
(
block
).
json
()).
omit
(
'
raw
'
));
});
}
if
(
!
program
.
nostdout
)
{
console
.
log
(
JSON
.
stringify
(
jsoned
,
null
,
"
"
));
}
yield
server
.
disconnect
();
return
jsoned
;
}
catch
(
err
)
{
logger
.
warn
(
err
.
message
||
err
);
yield
server
.
disconnect
();
}
})
}]
}
}
This diff is collapsed.
Click to expand it.
index.js
+
12
−
6
View file @
5454fb7a
...
...
@@ -18,6 +18,7 @@ const genDependency = require('./app/modules/gen');
const
syncDependency
=
require
(
'
./app/modules/synchronization
'
);
const
resetDependency
=
require
(
'
./app/modules/reset
'
);
const
checkConfDependency
=
require
(
'
./app/modules/check-config
'
);
const
exportBcDependency
=
require
(
'
./app/modules/export-bc
'
);
const
MINIMAL_DEPENDENCIES
=
[
{
name
:
'
duniter-config
'
,
required
:
configDependency
}
...
...
@@ -30,6 +31,7 @@ const DEFAULT_DEPENDENCIES = [
{
name
:
'
duniter-gen
'
,
required
:
genDependency
},
{
name
:
'
duniter-reset
'
,
required
:
resetDependency
},
{
name
:
'
duniter-chkconf
'
,
required
:
checkConfDependency
},
{
name
:
'
duniter-exportbc
'
,
required
:
exportBcDependency
},
{
name
:
'
duniter-keypair
'
,
required
:
dkeypairDependency
}
];
...
...
@@ -166,6 +168,10 @@ function Stack(dependencies) {
const
dbHome
=
program
.
home
;
const
home
=
directory
.
getHome
(
dbName
,
dbHome
);
if
(
command
.
logs
===
false
)
{
logger
.
mute
();
}
// Add log files for this instance
logger
.
addHomeLogs
(
home
);
...
...
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