-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcompile_contracts.sh
executable file
·63 lines (54 loc) · 1.39 KB
/
compile_contracts.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
#! /usr/bin/env sh
# Move to the script directory
DIR=$(dirname "$0")
cd "$DIR"
# Variables
JAVA_BASE_DIRECTORY="dom/src/main/java"
CONTRACTS_PACKAGE="org.incode.eurocommercial.contactapp.dom.audit.contracts.generated"
TRUFFLE_DIR="truffle"
declare -a CONTRACT_FILES=()
main() {
pushd $TRUFFLE_DIR &>/dev/null
compile
deploy
popd &>/dev/null
generate
}
# Compile smart contracts and save the ones that have been compiled
compile() {
OUTPUT=$(truffle compile)
EXIT_STATUS=$?
echo "${OUTPUT}"
add_contract_files "${OUTPUT}"
exit_if_failed $EXIT_STATUS
}
# Deploy if the --deploy flag is set
deploy() {
if [[ $* == *--deploy* ]]; then
truffle deploy
fi
exit_if_failed $?
}
# Generate web3j contract objects only from the contracts that were compiled
generate() {
for contract in ${CONTRACT_FILES[@]}; do
web3j truffle generate $contract -o $JAVA_BASE_DIRECTORY -p $CONTRACTS_PACKAGE
done
}
# Add compiled contract json files to the list to be generated
add_contract_files() {
while read line; do
if [[ $line != Compiling* ]]; then
continue
fi
CONTRACT=${line##"Compiling ./contracts/"}
CONTRACT=${CONTRACT%%".sol..."}
CONTRACT_FILES+=("$TRUFFLE_DIR/build/contracts/$CONTRACT.json")
done <<< "$1"
}
exit_if_failed() {
if [[ $1 -ne 0 ]]; then
exit $1
fi
}
main "$@"