Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
py-g1-migrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
tools
py-g1-migrator
Commits
4751d0b7
Commit
4751d0b7
authored
1 year ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
add tx export
parent
6c218cde
Branches
Branches containing commit
No related tags found
1 merge request
!5
Separate squid history from duniter genesis
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/functions.py
+45
-0
45 additions, 0 deletions
lib/functions.py
squid-block.py
+0
-1
0 additions, 1 deletion
squid-block.py
squid-tx.py
+26
-0
26 additions, 0 deletions
squid-tx.py
with
71 additions
and
1 deletion
lib/functions.py
+
45
−
0
View file @
4751d0b7
...
...
@@ -196,3 +196,48 @@ def get_blocks(leveldb_path: str) -> list:
blocks
.
append
(
sample
)
return
blocks
def
get_tx
(
leveldb_path
:
str
)
->
list
:
"""
Get tx,
return a list of tx
"""
# Get wallets balances data
blocks_repo
=
LevelDBBlocksRepository
(
leveldb_path
)
txs
=
[]
for
num
,
block
in
blocks_repo
:
if
num
%
100000
==
0
:
print
(
num
)
for
tx
in
block
.
get
(
"
transactions
"
):
outputs
=
tx
[
"
outputs
"
]
issuers
=
tx
[
"
issuers
"
]
comment
=
tx
[
"
comment
"
]
timestamp
=
tx
[
"
blockstampTime
"
]
# loop on issuers
for
issuer
in
issuers
:
# loop on outputs
for
output
in
outputs
:
outputparts
=
output
.
split
(
"
:
"
)
amount
=
outputparts
[
0
]
receiver
=
outputparts
[
2
]
# ignore non trivial unlock sources
# https://git.duniter.org/tools/py-g1-migrator/-/issues/3
if
"
&&
"
in
receiver
or
"
||
"
in
receiver
:
print
(
num
)
print
(
"
ignoring
"
+
receiver
)
continue
receiver
=
receiver
.
split
(
"
SIG(
"
)[
1
].
split
(
"
)
"
)[
0
]
sample
=
{
"
blockNumber
"
:
num
,
"
timestamp
"
:
timestamp
,
"
from
"
:
issuer
,
"
to
"
:
receiver
,
"
amount
"
:
amount
,
"
comment
"
:
comment
,
}
# do not include outputs that go back to sender
if
sample
[
"
from
"
]
!=
sample
[
"
to
"
]:
txs
.
append
(
sample
)
return
txs
This diff is collapsed.
Click to expand it.
squid-block.py
+
0
−
1
View file @
4751d0b7
...
...
@@ -2,7 +2,6 @@
import
json
import
os
import
sys
from
lib.functions
import
get_blocks
...
...
This diff is collapsed.
Click to expand it.
squid-tx.py
0 → 100755
+
26
−
0
View file @
4751d0b7
#!/usr/bin/env python3
import
json
import
os
from
lib.functions
import
get_tx
DEFAULT_LEVELDB_PATH
=
"
./leveldb
"
LEVELDB_PATH
=
os
.
getenv
(
"
LEVELDB_PATH
"
,
DEFAULT_LEVELDB_PATH
)
def
main
():
# get blocks
tx_hist
=
get_tx
(
LEVELDB_PATH
)
# Dump JSON to file
print
(
"
Exporting...
"
)
tx_hist_json
=
json
.
dumps
(
tx_hist
,
indent
=
2
).
encode
()
gtest_json
=
open
(
"
output/tx_hist.json
"
,
"
wb
"
)
gtest_json
.
write
(
tx_hist_json
)
if
__name__
==
"
__main__
"
:
print
(
"
Prepare tx for squid
"
)
main
()
print
(
"
Done
\n
"
)
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