# Depends: OpenTimestamps 0.7.0 (see https://opentimestamps.org )
# GNU Coreutils 8.32
# NOTE: This script does not verify OTS files; it assumes the contents of OTS files fed to it are valid.
# Depends: OpenTimestamps 0.7.0 (see https://opentimestamps.org )
# GNU Coreutils 8.32
# NOTE: This script does not verify OTS files; it assumes the contents of OTS files fed to it are valid.
if output="$( "$(which ots)" info "$1" | \
grep -E "^File sha256 hash: " | \
head -n1 | \
sed -E -e 's/(^File sha256 hash: )([0-9a-f]+$)/\2/g'; )" && \
if output="$( "$(which ots)" info "$1" | \
grep -E "^File sha256 hash: " | \
head -n1 | \
sed -E -e 's/(^File sha256 hash: )([0-9a-f]+$)/\2/g'; )" && \
if output="$( "$(which ots)" info "$1" | \
grep -E "verify BitcoinBlockHeaderAttestation\([0-9]+\)" | \
sort | head -n1 | \
sed -E -e 's/(^ verify BitcoinBlockHeaderAttestation)\(([0-9]+)(\))/\2/g'; )" && \
if output="$( "$(which ots)" info "$1" | \
grep -E "verify BitcoinBlockHeaderAttestation\([0-9]+\)" | \
sort | head -n1 | \
sed -E -e 's/(^ verify BitcoinBlockHeaderAttestation)\(([0-9]+)(\))/\2/g'; )" && \
if ! { blk_provid="$block"; blk_stored="$(get_ots_oldestblock "$pout"; )"; }; then
yell "ERROR:Could not read block numbers from OTS files: $(declare -p fhash block pout )";
fi;
if ! { blk_provid="$block"; blk_stored="$(get_ots_oldestblock "$pout"; )"; }; then
yell "ERROR:Could not read block numbers from OTS files: $(declare -p fhash block pout )";
fi;
# Copy provided OTS if matching OTS found stored but provided is older
if [[ "$blk_provid" -lt "$blk_stored" ]]; then
# Copy provided OTS if matching OTS found stored but provided is older
if [[ "$blk_provid" -lt "$blk_stored" ]]; then
digest="$1";
mapfile -t otsStorePaths < <(find "$pathOtsStore" -type f -name "${digest}*.otsu"; );
if [[ "${#otsStorePaths[@]}" -le 0 ]]; then
digest="$1";
mapfile -t otsStorePaths < <(find "$pathOtsStore" -type f -name "${digest}*.otsu"; );
if [[ "${#otsStorePaths[@]}" -le 0 ]]; then
for ((i=0; i<"${#otsStorePaths[@]}"; i++ )); do
blockNum="$( get_block_num_from_stored_ots_path "${otsStorePaths[$i]}" )";
for ((i=0; i<"${#otsStorePaths[@]}"; i++ )); do
blockNum="$( get_block_num_from_stored_ots_path "${otsStorePaths[$i]}" )";
## Check for OTS file accompanying provided file
if [[ -f "${pathFileIn}.ots" ]]; then
vbm "STATUS:An OTS file is next to provided file ${pathFileIn}.";
## Check for OTS file accompanying provided file
if [[ -f "${pathFileIn}.ots" ]]; then
vbm "STATUS:An OTS file is next to provided file ${pathFileIn}.";
if [[ "$blk_stored" -lt "$blk_provid" ]]; then
vbm "STATUS:An older timestamp in OTS store found. Replacing ${pathFileIn}.ots (block ${blk_provid}) with ${path_stored_ots} (block ${blk_stored}).";
if [[ ! -f "${pathFileIn}.ots.baku" ]]; then
if [[ "$blk_stored" -lt "$blk_provid" ]]; then
vbm "STATUS:An older timestamp in OTS store found. Replacing ${pathFileIn}.ots (block ${blk_provid}) with ${path_stored_ots} (block ${blk_stored}).";
if [[ ! -f "${pathFileIn}.ots.baku" ]]; then