From 323474bd5816b8fd08a060849ea36e0c48361410 Mon Sep 17 00:00:00 2001 From: Anthony Martin <github@martin-studio.com> Date: Fri, 19 Oct 2018 23:05:48 -0700 Subject: [PATCH] keep previously set esc key if already provided #163 --- tinman/txgen.py | 10 ++++++---- tinman/util.py | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tinman/txgen.py b/tinman/txgen.py index 860c96d..0facf58 100755 --- a/tinman/txgen.py +++ b/tinman/txgen.py @@ -425,7 +425,9 @@ def build_actions(conf, silent=True): print("WARNING: Older snapshot encountered.", file=sys.stderr) if backfill_file and os.path.exists(backfill_file) and os.path.isfile(backfill_file): - num_lines = sum(1 for line in open(backfill_file)) + with open(backfill_file, "r") as f: + num_lines = sum(1 for line in f) + if num_lines > 0: metadata["backfill_actions:count"] = num_lines metadata["actions:count"] += num_lines @@ -439,9 +441,9 @@ def build_actions(conf, silent=True): yield ["submit_transaction", {"tx" : tx}] if has_backfill: - with open(conf["backfill_file"], "rb") as f: - for line in input_file: - yield line + with open(backfill_file, "r") as f: + for line in f: + yield json.loads(line) for tx in update_witnesses(conf, keydb, "init"): yield ["submit_transaction", {"tx" : tx}] diff --git a/tinman/util.py b/tinman/util.py index 24850a1..605a832 100644 --- a/tinman/util.py +++ b/tinman/util.py @@ -130,6 +130,9 @@ def action_to_str(action): This serializes actions, picking a string that does not occur in the JSON serialization to escape public/private key notes. """ + if "esc" in action: + return json.dumps(action, separators=(",", ":"), sort_keys=True) + json_empty_esc = json.dumps(action, separators=(",", ":"), default=prockey.PubkeySerializer(esc=""), sort_keys=True) esc = find_non_substr(json_empty_esc, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") action[1]["esc"] = esc -- GitLab