Skip to content

Commit 8e2d12a

Browse files
committed
Added Policy-Option to mint/burn with Time(Slot)-Limit
New Option added to script 10_genPolicy.sh which allows users to generate Tokens in a limited TimeWindow -> Fixed amount of Tokens. Policy is automatically invalid after a given Time-Period (Slots)
1 parent 136459b commit 8e2d12a

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

cardano/testnet/10_genPolicy.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,30 @@
1010
# cardanonode Path to the cardano-node executable
1111
. "$(dirname "$0")"/00_common.sh
1212

13-
if [[ $# -eq 1 && ! $1 == "" ]]; then policyName=$1; else echo "ERROR - Usage: $0 <PolicyName>"; exit 2; fi
13+
case $# in
14+
15+
1|2 ) policyName=$1;;
16+
17+
* ) cat >&2 <<EOF
18+
Usage: $(basename $0) <PolicyName> [Optional valid xxx Slots, Policy invalid after xxx Slots (default=unlimited)]
19+
20+
21+
Example: $(basename $0) assets/mypolicy 600
22+
23+
This would generate Policy 'mypolicy' in the folder 'assets' limited to 600 Slots (600 Seconds) from now.
24+
No Token minting or burning would be possible after that time, starting now!
25+
26+
EOF
27+
exit 1;; esac
28+
29+
if [[ $# -eq 2 && $2 -gt 0 ]]; then validBefore=$(( $(get_currentTip) + ${2} )); else validBefore="unlimited"; fi
1430

1531
#warnings
1632
if [ -f "${policyName}.policy.vkey" ]; then echo -e "\e[35mWARNING - ${policyName}.policy.vkey already present, delete it or use another name !\e[0m"; exit 2; fi
1733
if [ -f "${policyName}.policy.skey" ]; then echo -e "\e[35mWARNING - ${policyName}.policy.skey already present, delete it or use another name !\e[0m"; exit 2; fi
1834
if [ -f "${policyName}.policy.script" ]; then echo -e "\e[35mWARNING - ${policyName}.policy.script already present, delete it or use another name !\e[0m"; exit 2; fi
1935
if [ -f "${policyName}.policy.id" ]; then echo -e "\e[35mWARNING - ${policyName}.policy.id already present, delete it or use another name !\e[0m"; exit 2; fi
2036

21-
2237
#Check if the destination directory for the policy exists, if not, try to make it
2338
policyDirName="$(dirname ${policyName})"; policyDirName=${policyDirName/#.\//};
2439
if [ ! -d "${policyDirName}" ]; then mkdir -p ${policyDirName}; checkError "$?"; fi
@@ -36,7 +51,18 @@ cat ${policyName}.policy.skey | jq
3651
echo
3752

3853
policyKeyHASH=$(${cardanocli} address key-hash --payment-verification-key-file ${policyName}.policy.vkey)
39-
echo "{ \"keyHash\": \"${policyKeyHASH}\", \"type\": \"sig\" }" > ${policyName}.policy.script
54+
55+
currentTip=$(get_currentTip)
56+
echo -e "\e[0mCurrent Slot-Height:\e[32m ${currentTip} \e[0m"
57+
echo -e "\e[0mPolicy valid before Slot-Height:\e[33m ${validBefore}\e[0m"
58+
echo
59+
60+
#Write out an unlimited SigningScript or a limited one
61+
if [[ "${validBefore}" == "unlimited" ]]; then
62+
echo "{ \"keyHash\": \"${policyKeyHASH}\", \"type\": \"sig\" }" > ${policyName}.policy.script
63+
else
64+
echo "{ \"type\": \"all\", \"scripts\": [ { \"slot\": ${validBefore}, \"type\": \"before\" }, { \"keyHash\": \"${policyKeyHASH}\", \"type\": \"sig\" } ] }" > ${policyName}.policy.script
65+
fi
4066
echo -e "\e[0mPolicy-Script: \e[32m ${policyName}.policy.script \e[90m"
4167
file_lock ${policyName}.policy.script
4268
cat ${policyName}.policy.script | jq

cardano/testnet/11a_mintAsset.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,20 @@ fi
5555
rxcnt="1"
5656

5757
echo -e "\e[0mMinting Asset \e[32m${assetMintAmount} '${assetMintName}'\e[0m with Policy \e[32m'${policyName}'\e[0m:"
58-
echo
5958

6059
#get live values
6160
currentTip=$(get_currentTip)
62-
ttl=$(get_currentTTL)
63-
currentEPOCH=$(get_currentEpoch)
6461

62+
#set timetolife (inherent hereafter) to the currentTTL or to the value set in the policy.script for the "before" slot (limited policy lifespan)
63+
ttlFromScript=$(cat ${policyName}.policy.script | jq -r ".scripts[] | select(.type == \"before\") | .slot" 2> /dev/null || echo "unlimited")
64+
if [[ ! ${ttlFromScript} == "unlimited" ]]; then ttl=${ttlFromScript}; else ttl=$(get_currentTTL); fi
65+
echo
66+
echo -e "\e[0mPolicy valid before Slot-Height:\e[33m ${ttlFromScript}\e[0m"
67+
echo
6568
echo -e "\e[0mCurrent Slot-Height:\e[32m ${currentTip} \e[0m(setting TTL[invalid_hereafter] to ${ttl})"
6669
echo
70+
if [[ ${ttl} -le ${currentTip} ]]; then echo -e "\e[35mError - Your given Policy has expired, you cannot use it anymore!\e[0m\n"; exit 2; fi
71+
6772

6873
sendFromAddr=$(cat ${fromAddr}.addr)
6974
sendToAddr=${sendFromAddr}
@@ -214,7 +219,7 @@ if ask "\e[33mDoes this look good for you, continue ?" N; then
214219
if [ ! -f "${assetFileName}" ]; then echo "{}" > ${assetFileName}; fi #generate an empty json if no file present
215220
oldValue=$(jq -r ".minted" ${assetFileName})
216221
newValue=$(( ${oldValue} + ${assetMintAmount} ))
217-
assetFileJSON=$( jq ". += {minted: ${newValue}, name: \"${assetMintName}\", policyID: \"${policyID}\", lastUpdate: \"$(date)\", lastAction: \"mint ${assetMintAmount}\"}" < ${assetFileName})
222+
assetFileJSON=$( jq ". += {minted: ${newValue}, name: \"${assetMintName}\", policyID: \"${policyID}\", policyValidBeforeSlot: \"${ttlFromScript}\", lastUpdate: \"$(date)\", lastAction: \"mint ${assetMintAmount}\"}" < ${assetFileName})
218223

219224
file_unlock ${assetFileName}
220225
echo -e "${assetFileJSON}" > ${assetFileName}
@@ -247,7 +252,7 @@ if ask "\e[33mDoes this look good for you, continue ?" N; then
247252
if [ ! -f "${assetFileName}" ]; then echo "{}" > ${assetFileName}; fi #generate an empty json if no file present
248253
oldValue=$(jq -r ".minted" ${assetFileName})
249254
newValue=$(( ${oldValue} + ${assetMintAmount} ))
250-
assetFileJSON=$( jq ". += {minted: ${newValue}, name: \"${assetMintName}\", policyID: \"${policyID}\", lastUpdate: \"$(date)\", lastAction: \"mint ${assetMintAmount}\"}" < ${assetFileName})
255+
assetFileJSON=$( jq ". += {minted: ${newValue}, name: \"${assetMintName}\", policyID: \"${policyID}\", policyValidBeforeSlot: \"${ttlFromScript}\", lastUpdate: \"$(date)\", lastAction: \"mint ${assetMintAmount}\"}" < ${assetFileName})
251256

252257
file_unlock ${assetFileName}
253258
echo -e "${assetFileJSON}" > ${assetFileName}

cardano/testnet/11b_burnAsset.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,20 @@ fi
5656
rxcnt="1"
5757

5858
echo -e "\e[0mBurning Asset \e[32m${assetBurnAmount} '${assetBurnName}'\e[0m with Policy \e[32m'${policyName}'\e[0m:"
59-
echo
6059

6160
#get live values
6261
currentTip=$(get_currentTip)
63-
ttl=$(get_currentTTL)
64-
currentEPOCH=$(get_currentEpoch)
6562

63+
#set timetolife (inherent hereafter) to the currentTTL or to the value set in the policy.script for the "before" slot (limited policy lifespan)
64+
ttlFromScript=$(cat ${policyName}.policy.script | jq -r ".scripts[] | select(.type == \"before\") | .slot" 2> /dev/null || echo "unlimited")
65+
if [[ ! ${ttlFromScript} == "unlimited" ]]; then ttl=${ttlFromScript}; else ttl=$(get_currentTTL); fi
66+
echo
67+
echo -e "\e[0mPolicy valid before Slot-Height:\e[33m ${ttlFromScript}\e[0m"
68+
echo
6669
echo -e "\e[0mCurrent Slot-Height:\e[32m ${currentTip} \e[0m(setting TTL[invalid_hereafter] to ${ttl})"
6770
echo
71+
if [[ ${ttl} -le ${currentTip} ]]; then echo -e "\e[35mError - Your given Policy has expired, you cannot use it anymore!\e[0m\n"; exit 2; fi
72+
6873

6974
sendFromAddr=$(cat ${fromAddr}.addr)
7075
sendToAddr=${sendFromAddr}

0 commit comments

Comments
 (0)