-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli-gen-policy-multisig.sh
45 lines (36 loc) · 1.45 KB
/
cli-gen-policy-multisig.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
set -o pipefail
#--------- Import common paths and functions ---------
source common-utils.sh
#--------- Verification ---------
# Verify correct number of arguments
if [[ "$#" -eq 0 || "$#" -ne 3 ]]; then error "Missing parameters" && info "Usage: gen-policy-multisig.sh <wallet-witness-1> <wallet-witness-2> <policy-name>"; exit 1; fi
# Get wallet name
wallet_origin1=${1}
wallet_origin2=${2}
# Get policy name
policy_name=${3}
# Verify if wallet vkey exists
[[ -f ${key_path}/${wallet_origin1}.vkey ]] && info "OK ${wallet_origin1}.vkey exists" || { error "${wallet_origin1}.vkey missing"; exit 1; }
[[ -f ${key_path}/${wallet_origin2}.vkey ]] && info "OK ${wallet_origin2}.vkey exists" || { error "${wallet_origin2}.vkey missing"; exit 1; }
#--------- Run program ---------
# Create policy script
info "Creating ${native_script_path}/${policy_name}.script from 2 witnesses ${wallet_origin1} and ${wallet_origin2}"
cat > ${native_script_path}/${policy_name}.script << EOF
{
"type": "all",
"scripts":
[
{
"type": "sig",
"keyHash": "$(${cardanocli} address key-hash --payment-verification-key-file ${key_path}/${wallet_origin1}.vkey)"
},
{
"type": "sig",
"keyHash": "$(${cardanocli} address key-hash --payment-verification-key-file ${key_path}/${wallet_origin2}.vkey)"
}
]
}
EOF
cat ${native_script_path}/${policy_name}.script
info "This policy requires 2 witnesses in order to spend the utxo from the native script"