#!/bin/bash

# Use common authentication utility
source common_auth.sh "$@"

##### get the max round with this command but sometimes the opensAt date is in the future...
#curl -s -X GET http://localhost:5003/api/validator/v0/scan-proxy/open-and-issuing-mining-rounds \
#    -H "Authorization: Bearer $CANTON_TOKEN" | jq '.open_mining_rounds | max_by(.contract.payload.round.number | tonumber)'

#### so for now we take the last but one
curl -s -X GET $WALLET_ENDPOINT/api/validator/v0/scan-proxy/open-and-issuing-mining-rounds -H "Authorization: Bearer $CANTON_TOKEN" | jq '
  .open_mining_rounds
  | map({number: (.contract.payload.round.number | tonumber), full: .})
  | sort_by(.number)
  | reverse
  | .[1].full
'
