-
Notifications
You must be signed in to change notification settings - Fork 17
/
stack
executable file
·267 lines (226 loc) · 7.75 KB
/
stack
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OS_ARCH=$(uname -m | awk '{if ($0 ~ /arm64|aarch64/) print "arm64"; else if ($0 ~ /x86_64|amd64/) print "amd64"; else print "unsupported_arch"}')
############################################################################
# docker compose
############################################################################
function compose-env() {
export ADMIN_ADDRESS=${@:-"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}
export DISABLE_TELEMETRY=false
}
function compose-init() {
compose-env
chain-clean
if docker volume ls -q | grep -q "^lilypad_chain-data$"; then
docker volume rm lilypad_chain-data
fi
docker compose -f ./docker/docker-compose.base.yml up chain -d
chain-boot
}
# Use this for local development - will boot up non-lilypad serives
function compose-services() {
compose-env
docker compose -f ./docker/docker-compose.base.yml up "$@"
}
function compose-build() {
load-local-env
compose-env
get-build-version
docker compose -f ./docker/docker-compose.dev.yml build "$@"
}
function compose-up() {
load-local-env
compose-env
docker compose -f ./docker/docker-compose.dev.yml up "$@"
}
function compose-down() {
compose-env
docker compose -f ./docker/docker-compose.dev.yml down
}
############################################################################
# Load env variables from .local.dev
############################################################################
function load-local-env() {
while IFS= read -r line || [ -n "$line" ]; do
# Skip lines that are empty, start with a #, or are just whitespace
if [[ -n "$line" && ! "$line" =~ ^[[:space:]]*# ]]; then
export $line
fi
done < .local.dev
}
############################################################################
# Get build version info
############################################################################
function get-build-version() {
export VERSION=$(git rev-parse --abbrev-ref HEAD)
export COMMIT_SHA=$(git rev-parse HEAD)
}
############################################################################
# chain
############################################################################
function chain-boot() {
echo "- Install local dependencies"
cd hardhat && npm install -y
echo "- Fund services with ether"
npx hardhat run scripts/fund-services-ether.ts --network dev
echo "- Compile contracts"
npx hardhat compile --network dev
cd ..
go-bindings
echo "- Deploy contracts"
cd hardhat
npx hardhat deploy --network dev
echo "- Fund services with tokens"
npx hardhat run scripts/fund-services-tokens.ts --network dev
cd ..
echo "- Done"
}
function go-bindings() {
# check if the lilypad-solc image exists
# and only build it if it doesn't
if [[ -z $(docker images -q lilypad-solc) ]]; then
docker build -t lilypad-solc hardhat/solc
fi
rm -rf pkg/web3/bindings
mkdir -p pkg/web3/bindings
go-binding LilypadToken token
go-binding LilypadPayments payments
go-binding LilypadStorage storage
go-binding LilypadUsers users
go-binding LilypadMediationRandom mediation
go-binding LilypadOnChainJobCreator jobcreator
go-binding LilypadController controller
go-binding LilypadPow pow
echo "- Generated all go bindings pkg/contract/bindings/"
}
function go-binding() {
local name="$1"
local pkg="$2"
# compile the sol files into bytecode and ABI
docker run --rm \
-v $(pwd)/hardhat:/src \
-w /src \
--user $(id -u):$(id -g) \
--entrypoint solc \
lilypad-solc \
--base-path . \
--include-path node_modules \
--overwrite \
--abi --bin \
"contracts/$name.sol" \
-o artifacts
mkdir -p hardhat/artifacts/bindings/$pkg
# generate the go bindings
docker run --rm \
-v $(pwd)/hardhat:/src \
-w /src \
--user $(id -u):$(id -g) \
--entrypoint abigen \
lilypad-solc \
"--bin=artifacts/$name.bin" \
"--abi=artifacts/$name.abi" \
"--pkg=$pkg" "--out=artifacts/bindings/$pkg/$pkg.go"
cp -r hardhat/artifacts/bindings/$pkg pkg/web3/bindings/$pkg
echo "- Generated go binding hardhat/artifacts/bindings/$pkg/$pkg.go"
}
function chain-clean(){
rm -Rf $(pwd)/data/chain
rm -rf $(pwd)/hardhat/artifacts
rm -rf $(pwd)/hardhat/cache
rm -rf $(pwd)/hardhat/deployments/geth
rm -rf $(pwd)/hardhat/deployments/dev
rm -rf $(pwd)/hardhat/.openzeppelin
}
############################################################################
# helpers
############################################################################
function hardhat-script() {
(
set -euo pipefail
cd hardhat
npx hardhat run "$@"
)
}
function print-env() {
hardhat-script scripts/print-env.ts | grep export
}
function print-contract-env() {
hardhat-script scripts/print-contract-env.ts | grep export
}
function print-local-dev-env() {
print-contract-env
}
function run-cowsay-onchain() {
load-local-env
cd hardhat
npx hardhat run scripts/run-cowsay-onchain.ts
}
############################################################################
# solver
#
# Note: The presence of the WEB3_PRIVATE_KEY here is only necessary for local development. You are advised not to import this key into a wallet nor use it for anything other for testing Lilypad locally
############################################################################
function solver() {
load-local-env
export WEB3_PRIVATE_KEY=${SOLVER_PRIVATE_KEY}
export LOG_LEVEL=debug
go run . solver --network dev "$@"
}
############################################################################
# job creator
#
# Note: The presence of the WEB3_PRIVATE_KEY here is only necessary for local development. You are advised not to import this key into a wallet nor use it for anything other for testing Lilypad locally
############################################################################
function job-creator() {
load-local-env
export WEB3_PRIVATE_KEY=${JOB_CREATOR_PRIVATE_KEY}
export LOG_LEVEL=debug
go run . jobcreator --network dev
}
############################################################################
# resource provider
#
# Note: The presence of the WEB3_PRIVATE_KEY here is only necessary for local development. You are advised not to import this key into a wallet nor use it for anything other for testing Lilypad locally
############################################################################
function resource-provider() {
load-local-env
export WEB3_PRIVATE_KEY=${RESOURCE_PROVIDER_PRIVATE_KEY}
export LOG_LEVEL=debug
go run . resource-provider "$@" --network dev --disable-pow true
}
############################################################################
# mediator
############################################################################
function mediator() {
go run . mediator "$@"
}
############################################################################
# tests
############################################################################
function unit-tests() {
go test -v -tags="unit" -count 1 ./...
}
function unit-tests-hardhat() {
cd hardhat
npx hardhat test --network hardhat
}
# this assumes stack is running
# see LOCAL_DEVELOPMENT.md
function integration-tests() {
load-local-env
go test -v -tags="integration" -count 1 ./...
}
############################################################################
# run
#
# Note: The presence of the WEB3_PRIVATE_KEY here is only necessary for local development. You are advised not to import this key into a wallet nor use it for anything other for testing Lilypad locally
############################################################################
function run() {
load-local-env
export WEB3_PRIVATE_KEY=${RUN_PRIVATE_KEY}
export LOG_LEVEL=info
go run . run --network dev "$@"
}
eval "$@"