Skip to content
Snippets Groups Projects
Commit b81ca373 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

add cert export

parent 4751d0b7
No related branches found
No related tags found
1 merge request!5Separate squid history from duniter genesis
......@@ -214,13 +214,16 @@ def get_tx(leveldb_path: str) -> list:
issuers = tx["issuers"]
comment = tx["comment"]
timestamp = tx["blockstampTime"]
# loop on issuers
issuers_count = len(issuers)
# loop on issuers. If multiple issuers, approximate amount
for issuer in issuers:
# loop on outputs
for output in outputs:
outputparts = output.split(":")
amount = outputparts[0]
amount = int(outputparts[0])
receiver = outputparts[2]
if issuers_count > 1:
amount = floor(amout/issuers_count) # approximation
# ignore non trivial unlock sources
# https://git.duniter.org/tools/py-g1-migrator/-/issues/3
if "&&" in receiver or "||" in receiver:
......@@ -239,5 +242,31 @@ def get_tx(leveldb_path: str) -> list:
# do not include outputs that go back to sender
if sample["from"] != sample["to"]:
txs.append(sample)
return txs
def get_cert(leveldb_path: str) -> list:
"""
Get cert,
return a list of cert, but does not tell if it is a new cert or a renewal
"""
# Get wallets balances data
blocks_repo = LevelDBBlocksRepository(leveldb_path)
certs = []
for num, block in blocks_repo:
if num % 100000 == 0:
print(num)
for cert in block.get("certifications"):
parts = cert.split(":")
issuer = parts[0]
receiver = parts[1]
block = parts[2]
sample = {
"blockNumberCreated": int(block), # block number of the document creation
"blockNumberWritten": num, # block in which the certification is written
"issuer": issuer,
"receiver": receiver,
}
certs.append(sample)
return certs
#!/usr/bin/env python3
import json
import os
from lib.functions import get_cert
DEFAULT_LEVELDB_PATH = "./leveldb"
LEVELDB_PATH = os.getenv("LEVELDB_PATH", DEFAULT_LEVELDB_PATH)
def main():
# get blocks
cert_hist = get_cert(LEVELDB_PATH)
# Dump JSON to file
print("Exporting...")
cert_hist_json = json.dumps(cert_hist, indent=2).encode()
gtest_json = open("output/cert_hist.json", "wb")
gtest_json.write(cert_hist_json)
if __name__ == "__main__":
print("Prepare cert for squid")
main()
print("Done\n")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment