-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
It's me, CI
committed
Oct 31, 2023
1 parent
f7c4c3c
commit 142d260
Showing
5 changed files
with
92 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -lt 1 ] || [ $# -gt 3 ]; then | ||
echo "Usage" $0 archive-db [data_file] [update_script] | ||
echo "'data_file' and 'update_script' are created when running this script" | ||
exit 0 | ||
fi | ||
|
||
ARCHIVE_DB=$1 | ||
DATA_FILE=${2:-data_file.tmp} | ||
UPDATE_SCRIPT=${3:-data_update.sql} | ||
|
||
echo "Migrating receipt chain hashes in account preconditions in archive db '"$ARCHIVE_DB"'" | ||
|
||
rm -f $DATA_FILE | ||
rm -f $UPDATE_SCRIPT | ||
|
||
echo "Creating temporary file with receipt chain hashes" "'"$DATA_FILE"'" | ||
echo "select id,receipt_chain_hash from zkapp_account_precondition where receipt_chain_hash is not null;" | \ | ||
psql --csv -t -q $ARCHIVE_DB > $DATA_FILE | ||
|
||
echo "Creating SQL script" "'"$UPDATE_SCRIPT"'" | ||
for line in `cat $DATA_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 "Receipt chain hash pass done!" | ||
|
||
rm -f $DATA_FILE | ||
|
||
echo "Creating temporary file with last_vrf_ouput" "'"$DATA_FILE"'" | ||
echo "select id,last_vrf_output from blocks;" | \ | ||
psql --csv -t -q $ARCHIVE_DB > $DATA_FILE | ||
|
||
echo "Adding to SQL script" "'"$UPDATE_SCRIPT"'" | ||
for line in `cat $DATA_FILE` | ||
do ( | ||
ID=$(echo $line | awk -F , '{print $1}'); | ||
FP=$(echo $line | awk -F , '{print $2}'); | ||
B64=$(echo $FP | _build/default/src/app/last_vrf_output_to_b64/last_vrf_output_to_b64.exe); | ||
echo -n . | ||
echo $ID "'"$B64"'" | awk '{print "UPDATE blocks SET last_vrf_output=" $2 " WHERE id=" $1 ";"}' >> $UPDATE_SCRIPT) | ||
done | ||
|
||
echo | ||
echo "Last VRF output pass done!" | ||
|
||
echo "Now run:" "psql -d" $ARCHIVE_DB "<" $UPDATE_SCRIPT |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(executable | ||
(package last_vrf_output_to_b64) | ||
(name last_vrf_output_to_b64) | ||
(public_name last_vrf_output_to_b64) | ||
(libraries | ||
;; opam libraries | ||
base64 | ||
core_kernel | ||
hex | ||
;; local libraries | ||
) | ||
(preprocessor_deps ../../config.mlh) | ||
(instrumentation (backend bisect_ppx)) | ||
(preprocess (pps ppx_mina ppx_version))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
open Core_kernel | ||
|
||
let () = | ||
let s = Stdlib.read_line () in | ||
let b64_check () = | ||
match Base64.decode ~alphabet:Base64.uri_safe_alphabet s with | ||
| Ok _ -> | ||
(* already base64 *) | ||
s | ||
| Error _ -> | ||
failwith "Bad Base64 encoding" | ||
in | ||
let b64 = | ||
(* try unhexing first, because hex chars are also base64 chars *) | ||
try | ||
match Hex.Safe.of_hex s with | ||
| Some unhexed -> | ||
Base64.encode_exn ~alphabet:Base64.uri_safe_alphabet unhexed | ||
| None -> | ||
b64_check () | ||
with _ -> b64_check () | ||
in | ||
Format.printf "%s@." b64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters