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
117f185b
Commit
117f185b
authored
4 years ago
by
Hugo Trentesaux
Committed by
Vincent Texier
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[feat] allow building block from local json
parent
86e38051
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!128
Release 0.62.0
,
!124
#130: Support reading Duniter's local json blockchain
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/documents/block.py
+56
-0
56 additions, 0 deletions
duniterpy/documents/block.py
tests/documents/test_block.py
+1360
-0
1360 additions, 0 deletions
tests/documents/test_block.py
with
1416 additions
and
0 deletions
duniterpy/documents/block.py
+
56
−
0
View file @
117f185b
...
@@ -252,6 +252,62 @@ class Block(Document):
...
@@ -252,6 +252,62 @@ class Block(Document):
def
blockUID
(
self
)
->
BlockUID
:
def
blockUID
(
self
)
->
BlockUID
:
return
BlockUID
(
self
.
number
,
self
.
proof_of_work
())
return
BlockUID
(
self
.
number
,
self
.
proof_of_work
())
@classmethod
def
from_parsed_json
(
cls
:
Type
[
BlockType
],
parsed_json_block
:
dict
)
->
BlockType
:
"""
return a block from the python structure produced when parsing json
"""
b
=
parsed_json_block
# alias for readability
version
=
b
[
"
version
"
]
currency
=
b
[
"
currency
"
]
arguments
=
{
# arguments used to create block
"
version
"
:
b
[
"
version
"
],
"
currency
"
:
b
[
"
currency
"
],
"
number
"
:
b
[
"
number
"
],
"
powmin
"
:
b
[
"
powMin
"
],
"
time
"
:
b
[
"
time
"
],
"
mediantime
"
:
b
[
"
medianTime
"
],
"
ud
"
:
b
[
"
dividend
"
],
"
unit_base
"
:
b
[
"
unitbase
"
],
"
issuer
"
:
b
[
"
issuer
"
],
"
issuers_frame
"
:
b
[
"
issuersFrame
"
],
"
issuers_frame_var
"
:
b
[
"
issuersFrameVar
"
],
"
different_issuers_count
"
:
b
[
"
issuersCount
"
],
"
prev_hash
"
:
b
[
"
previousHash
"
],
"
prev_issuer
"
:
b
[
"
previousIssuer
"
],
"
parameters
"
:
b
[
"
parameters
"
],
"
members_count
"
:
b
[
"
membersCount
"
],
"
identities
"
:
b
[
"
identities
"
],
"
joiners
"
:
b
[
"
joiners
"
],
"
actives
"
:
b
[
"
actives
"
],
"
leavers
"
:
b
[
"
leavers
"
],
"
revokations
"
:
b
[
"
revoked
"
],
"
excluded
"
:
b
[
"
excluded
"
],
"
certifications
"
:
b
[
"
certifications
"
],
"
transactions
"
:
b
[
"
transactions
"
],
"
inner_hash
"
:
b
[
"
inner_hash
"
],
"
nonce
"
:
b
[
"
nonce
"
],
"
signature
"
:
b
[
"
signature
"
],
}
# parameters: Optional[Sequence[str]]
if
arguments
[
"
parameters
"
]:
arguments
[
"
parameters
"
]
=
arguments
[
"
parameters
"
].
split
(
"
:
"
)
# identities: List[Identity]
arguments
[
"
identities
"
]
=
[
Identity
.
from_inline
(
version
,
currency
,
i
+
'
\n
'
)
for
i
in
arguments
[
"
identities
"
]]
# joiners: List[Membership]
arguments
[
"
joiners
"
]
=
[
Membership
.
from_inline
(
version
,
currency
,
"
IN
"
,
i
+
'
\n
'
)
for
i
in
arguments
[
"
joiners
"
]]
# actives: List[Membership]
arguments
[
"
actives
"
]
=
[
Membership
.
from_inline
(
version
,
currency
,
"
IN
"
,
i
+
'
\n
'
)
for
i
in
arguments
[
"
actives
"
]]
# leavers: List[Membership]
arguments
[
"
leavers
"
]
=
[
Membership
.
from_inline
(
version
,
currency
,
"
OUT
"
,
i
+
'
\n
'
)
for
i
in
arguments
[
"
leavers
"
]]
# revokations: List[Revocation]
arguments
[
"
revokations
"
]
=
[
Revocation
.
from_inline
(
version
,
currency
,
i
+
'
\n
'
)
for
i
in
arguments
[
"
revokations
"
]]
# certifications: List[Certification]
arguments
[
"
certifications
"
]
=
[
Certification
.
from_inline
(
version
,
currency
,
arguments
[
"
inner_hash
"
],
i
+
'
\n
'
)
for
i
in
arguments
[
"
certifications
"
]]
# transactions: List[Transaction]
arguments
[
"
transactions
"
]
=
[
Transaction
.
from_bma_history
(
currency
,
i
)
for
i
in
arguments
[
"
transactions
"
]]
# now that the arguments are ready, return the block
return
cls
(
**
arguments
)
@classmethod
@classmethod
def
from_signed_raw
(
cls
:
Type
[
BlockType
],
signed_raw
:
str
)
->
BlockType
:
def
from_signed_raw
(
cls
:
Type
[
BlockType
],
signed_raw
:
str
)
->
BlockType
:
lines
=
signed_raw
.
splitlines
(
True
)
lines
=
signed_raw
.
splitlines
(
True
)
...
...
This diff is collapsed.
Click to expand it.
tests/documents/test_block.py
+
1360
−
0
View file @
117f185b
Source diff could not be displayed: it is too large. Options to address this:
view the blob
.
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