-
Notifications
You must be signed in to change notification settings - Fork 5
/
dc.sh
executable file
·206 lines (183 loc) · 8.95 KB
/
dc.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
while getopts 'p:v:c' OPTION; do
case "$OPTION" in
p)
PATH_TO_CONTRACTS="$OPTARG"
echo "Path to contracts you wish to publish: $OPTARG"
;;
v)
CONTRACTS_VERSION="$OPTARG"
echo "Version you wish to publish the contracts as: $OPTARG"
;;
c)
SETUP_SMART_CONTRACT=true
echo "Running setup with smart contracts."
;;
?)
echo "script usage: $(basename \$0) [-p <path to p8e contracts directory> -v <version to publish contracts as>]" >&2
exit 1
;;
esac
done
shift "$((OPTIND -1))"
function up {
source ./service/local-docker/vault/.env
docker-compose -p p8e-contract-execution-environment -f service/local-docker/dependencies.yaml up --build -d
sleep 2
VAULT_BINARY="docker exec -i --env-file ./service/local-docker/vault/.env $VAULT_DOCKER_CONTAINER_NAME vault"
if ! docker exec -i "$VAULT_DOCKER_CONTAINER_NAME" vault --help 2>/dev/null 1>&2
then
echo "No Docker container named '$VAULT_DOCKER_CONTAINER_NAME' was found running..."
if ! command -v vault &> /dev/null
then
echo "Vault must be running under an appropriately named Docker container or local machine installation"
exit 1
else
echo "Found a local installation of Vault to use instead."
VAULT_BINARY="vault"
fi
fi
sh service/local-docker/vault/init-and-unseal.sh "$VAULT_ADDR" "$SECRET_PATH"
until $VAULT_BINARY status; do echo "Awaiting vault to be unsealed..."; sleep 5; done
# local-originator
< service/local-docker/vault/secrets/local-originator.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/00000000-0000-0000-0000-000000000001 - > /dev/null
< service/local-docker/vault/secrets/local-originator.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/tp1qy2mqx5x22a400pgd5p6u7mq9shxzvh767jar0 - > /dev/null
# local-servicer
< service/local-docker/vault/secrets/local-servicer.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/00000000-0000-0000-0000-000000000002 - > /dev/null
< service/local-docker/vault/secrets/local-servicer.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/tp1xr3wfqzlcz469wkex5c3ylaq8pq97crhsg57gd - > /dev/null
# local-dart
< service/local-docker/vault/secrets/local-dart.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/00000000-0000-0000-0000-000000000003 - > /dev/null
< service/local-docker/vault/secrets/local-dart.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/tp1s2c62ke0mmwhqxguf7e2pt6e98yq38m4atwhwl - > /dev/null
# local-portfolio-manager
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/00000000-0000-0000-0000-000000000004 - > /dev/null
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/tp1mryqzguyelef5dae7k6l22tnls93cvrc60tjdc - > /dev/null
# local-controller-a
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/00000000-0000-0000-0000-000000000005 - > /dev/null
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/tp138jtpz5zxa6yc33s0fk2jy9vahqcuvvtwnrzge - > /dev/null
# local-controller-b
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/00000000-0000-0000-0000-000000000006 - > /dev/null
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/tp1pz4tt4j802j2y3avs5mwy9uyyxtx7k5r8qlehw - > /dev/null
# local-validator
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/00000000-0000-0000-0000-000000000007 - > /dev/null
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/tp1he6rfnxyx2ssqyknq4ayzf5j46dp29pqt6z708 - > /dev/null
# local-investor
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/00000000-0000-0000-0000-000000000008 - > /dev/null
< service/local-docker/vault/secrets/local-portfolio-manager.json $VAULT_BINARY kv put "$SECRET_PATH"/originators/tp1f99dgtxxjmgczjsuc48utq4lkk0uhx6eqfqju0 - > /dev/null
docker ps -a
if [ "$SETUP_SMART_CONTRACT" = true ]; then
echo "Setting up smart contracts!"
upload_classification_contract
fi
}
function publish() {
set -e
if [ -z ${PATH_TO_CONTRACTS+x} ]; then
echo "Provide a valid path to the contracts directory you wish to publish using the -p argument."
exit 1
fi
if [ -z "${CONTRACTS_VERSION}" ]; then
echo "Provide a valid version string you wish to publish the contracts as using the -v argument."
exit 1
fi
source ./service/local-docker/bootstrap.env
FULL_PATH=$(realpath "$PATH_TO_CONTRACTS")
export FULL_PATH
if [[ -d "$FULL_PATH" ]]; then
pushd "$PATH_TO_CONTRACTS" > /dev/null
./gradlew p8eClean p8eCheck p8eBootstrap --info && ./gradlew publishToMavenLocal -Pversion="$CONTRACTS_VERSION" -xsignMavenPublication --info
popd > /dev/null
else
echo "Invalid path. Provide a valid path to the contracts directory you wish to publish."
exit 1
fi
}
function down {
docker-compose -p p8e-contract-execution-environment -f service/local-docker/dependencies.yaml down
docker volume prune -f
}
function bounce {
down
up
}
function build_classification() {
set -e
if [ -z ${PATH_TO_CONTRACTS+x} ]; then
echo "Provide a valid path to the smart contracts directory you wish to store on provenance using the -p argument."
exit 1
fi
FULL_PATH=$(realpath "$PATH_TO_CONTRACTS")
export FULL_PATH
if [[ -d "$PATH_TO_CONTRACTS" ]]; then
pushd "$PATH_TO_CONTRACTS" > /dev/null
cargo build
make optimize
popd > /dev/null
cp "$PATH_TO_CONTRACTS"/artifacts/asset_classification_smart_contract.wasm service/local-docker/prov-init/contracts/asset_classification_smart_contract.wasm
else
echo "Invalid path. Provide a valid path to the contracts directory you wish to publish."
exit 1
fi
}
function setup() {
if ! command -v brew &> /dev/null
then
echo "This script can only install the prerequisite packages via Homebrew, which was not found in the path. Please manually install the packages instead."
exit 1
else
brew install coreutils
fi
if ! command -v docker &> /dev/null
then
brew install docker
fi
if ! command -v vault &> /dev/null
then
brew tap hashicorp/tap
brew install hashicorp/tap/vault
fi
if ! command -v rust &> /dev/null
then
brew install rust
fi
if ! command -v jq &> /dev/null
then
brew install jq
fi
}
function upload_classification_contract() {
echo "Uploading contract to provenance!"
upload=$(docker exec provenance provenanced tx wasm store contracts/asset_classification_smart_contract.wasm \
--instantiate-only-address tp1v5d9uek3qwqh25yrchj20mkgrksdfyyxhnsdag \
--from tp1v5d9uek3qwqh25yrchj20mkgrksdfyyxhnsdag \
--chain-id chain-local \
--gas auto \
--gas-prices="1905nhash" \
--gas-adjustment=1.1 \
--broadcast-mode block \
--testnet \
--output json \
--yes)
code_id=$(echo "$upload" | jq -r '.logs[] | select(.msg_index == 0) | .events[] | select(.type == "store_code") | .attributes[0].value')
echo "Upload complete. Code id: $code_id"
instantiate=$(docker exec provenance provenanced tx wasm instantiate "$code_id" \
'{
"base_contract_name": "assetclassificationalias.pb",
"bind_base_name": true,
"asset_definitions": '"$(cat service/local-docker/prov-init/contracts/asset_definitions.json)"',
"is_test": true
}' \
--admin "tp1v5d9uek3qwqh25yrchj20mkgrksdfyyxhnsdag" \
--from tp1v5d9uek3qwqh25yrchj20mkgrksdfyyxhnsdag \
--label examples \
--chain-id chain-local \
--gas auto \
--gas-prices="1905nhash" \
--gas-adjustment=1.1 \
--broadcast-mode block \
--testnet \
--output json \
--yes | jq)
contract_address=$(echo "$instantiate" | jq '.logs[] | select(.msg_index == 0) | .events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address") | .value')
echo "Asset classification contract fully setup! contract address: $contract_address"
}
${1}