Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
clients
python
DuniterPy
Commits
54d860b0
Commit
54d860b0
authored
4 years ago
by
Hugo Trentesaux
Committed by
Vincent Texier
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[ref] access target block from json
parent
9de47432
No related branches found
No related tags found
2 merge requests
!128
Release 0.62.0
,
!124
#130: Support reading Duniter's local json blockchain
Pipeline
#11055
waiting for manual action
Stage: format
Stage: test
Stage: build
Stage: release
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniterpy/helpers/blockchain.py
+20
-2
20 additions, 2 deletions
duniterpy/helpers/blockchain.py
with
20 additions
and
2 deletions
duniterpy/helpers/blockchain.py
+
20
−
2
View file @
54d860b0
...
...
@@ -77,6 +77,18 @@ class JsonBlockchain:
self
.
current_block_in_chunk
-
1
]
# return block (before incrementation)
def
current_block
(
self
):
"""
returns current block as a duniterpy block document
"""
json_block
=
self
.
chunk
[
self
.
current_block_in_chunk
]
return
Block
.
from_parsed_json
(
json_block
)
def
get_block_number
(
self
,
number
):
"""
get one precise block (do not use for iteration)
"""
self
.
current_chunk
=
number
//
CHUNK_SIZE
self
.
current_block_in_chunk
=
number
%
CHUNK_SIZE
self
.
parsechunk
()
return
self
.
current_block
()
def
Blockchain
(
json_blockchain
):
"""
convert json to duniterpy block document
"""
...
...
@@ -85,10 +97,16 @@ def Blockchain(json_blockchain):
yield
Block
.
from_parsed_json
(
jb
)
def
load_json
(
path
=
DEFAULT_PATH
):
"""
returns a JsonBlockchain object
"""
path
=
pathlib
.
Path
(
"
~
"
).
joinpath
(
path
).
expanduser
()
# expand path
jbc
=
JsonBlockchain
(
path
)
# gets an iterator over json blockchain
return
jbc
def
load
(
path
=
DEFAULT_PATH
):
"""
returns an iterator allowing to browse all the blockchain
in practice, it will load chunk by chunk and only keep one in memory at a time
"""
path
=
pathlib
.
Path
(
"
~
"
).
joinpath
(
path
).
expanduser
()
# expand path
jbc
=
JsonBlockchain
(
path
)
# gets an iterator over json blockchain
jbc
=
load_json
(
path
)
bc
=
Blockchain
(
jbc
)
# convert it to an iterator over blocks
return
bc
# returns
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