From f7c4c3c5fc2d5079987bde98785e8c6dcddb1f64 Mon Sep 17 00:00:00 2001 From: "It's me, CI" Date: Mon, 30 Oct 2023 11:18:50 -0700 Subject: [PATCH] allow already-migrated hashes --- scripts/migrate-receipt-chain-hashes.sh | 5 ++++- src/app/receipt_chain_hash_to_b58/dune | 1 + .../receipt_chain_hash_to_b58.ml | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/migrate-receipt-chain-hashes.sh b/scripts/migrate-receipt-chain-hashes.sh index 13192a3b546..e2d22db41b6 100755 --- a/scripts/migrate-receipt-chain-hashes.sh +++ b/scripts/migrate-receipt-chain-hashes.sh @@ -11,21 +11,24 @@ HASHES_FILE=${2:-hashes_file.tmp} UPDATE_SCRIPT=${3:-hashes_update.sql} echo "Migrating receipt chain hashes in account preconditions in archive db '"$ARCHIVE_DB"'" -echo "Using temporary file '"$HASHES_FILE"' and creating SQL script '"$UPDATE_SCRIPT"'" rm -f $HASHES_FILE rm -f $UPDATE_SCRIPT +echo "Creating temporary file" "'"$HASHES_FILE"'" echo "select id,receipt_chain_hash from zkapp_account_precondition where receipt_chain_hash is not null;" | \ psql --csv -t -q $ARCHIVE_DB > $HASHES_FILE +echo "Creating SQL script" "'"$UPDATE_SCRIPT"'" for line in `cat $HASHES_FILE` do ( ID=$(echo $line | awk -F , '{print $1}'); FP=$(echo $line | awk -F , '{print $2}'); B58=$(echo $FP | _build/default/src/app/receipt_chain_hash_to_b58/receipt_chain_hash_to_b58.exe); + echo -n . echo $ID "'"$B58"'" | awk '{print "UPDATE zkapp_account_precondition SET receipt_chain_hash=" $2 " WHERE id=" $1 ";"}' >> $UPDATE_SCRIPT) done +echo echo "Done!" echo "Now run:" "psql -d" $ARCHIVE_DB "<" $UPDATE_SCRIPT diff --git a/src/app/receipt_chain_hash_to_b58/dune b/src/app/receipt_chain_hash_to_b58/dune index 8dcf8756f11..4217bb626ad 100644 --- a/src/app/receipt_chain_hash_to_b58/dune +++ b/src/app/receipt_chain_hash_to_b58/dune @@ -4,6 +4,7 @@ (public_name receipt_chain_hash_to_b58) (libraries ;; opam libraries + core_kernel ;; local libraries mina_base kimchi_backend diff --git a/src/app/receipt_chain_hash_to_b58/receipt_chain_hash_to_b58.ml b/src/app/receipt_chain_hash_to_b58/receipt_chain_hash_to_b58.ml index a363c6dffff..59a3113cf5b 100644 --- a/src/app/receipt_chain_hash_to_b58/receipt_chain_hash_to_b58.ml +++ b/src/app/receipt_chain_hash_to_b58/receipt_chain_hash_to_b58.ml @@ -1,5 +1,15 @@ +open Core_kernel +open Mina_base + let () = let s = Stdlib.read_line () in - let fp = Kimchi_backend.Pasta.Basic.Fp.of_string s in - let receipt_chain_hash : Mina_base.Receipt.Chain_hash.t = fp in - Format.printf "%s@." (Mina_base.Receipt.Chain_hash.to_base58_check receipt_chain_hash) + let b58 = + match Receipt.Chain_hash.of_base58_check s with + | Ok _ -> + s + | Error _ -> + let fp = Kimchi_backend.Pasta.Basic.Fp.of_string s in + let receipt_chain_hash : Mina_base.Receipt.Chain_hash.t = fp in + Receipt.Chain_hash.to_base58_check receipt_chain_hash + in + Format.printf "%s@." b58