@@ -29,12 +29,73 @@ echo "Containers size: $START_CONTAINERS_SIZE"
29
29
echo " Volumes size: $START_VOLUMES_SIZE "
30
30
echo " =============================================="
31
31
32
- # Your existing script starts here
33
32
container_running () {
34
33
docker ps --format ' {{.Names}}' | grep -q " ^$1 $"
35
34
return $?
36
35
}
37
36
37
+ # Function to fund the escrow smart contract
38
+ # 1. first read .env variables from local-network/.env
39
+ # 2. then read contract addresses from local-network/contracts.json
40
+ # 3. finally, use the cast command to approve and deposit GRT to the escrow
41
+ # this should be done just after deploying the gateway
42
+ # otherwise it does not move forward in its setup process
43
+ # causing false error during deployment of our local testnet
44
+ fund_escrow () {
45
+ echo " Funding escrow for sender..."
46
+
47
+ if [ -f " local-network/.env" ]; then
48
+ source local-network/.env
49
+ else
50
+ echo " Error: local-network/.env file not found"
51
+ return 1
52
+ fi
53
+
54
+ GRAPH_TOKEN=$( jq -r ' ."1337".GraphToken.address' local-network/contracts.json)
55
+ TAP_ESCROW=$( jq -r ' ."1337".TAPEscrow.address' local-network/contracts.json)
56
+
57
+ if [ -z " $GRAPH_TOKEN " ] || [ -z " $TAP_ESCROW " ]; then
58
+ echo " Error: Could not read contract addresses from contracts.json"
59
+ return 1
60
+ fi
61
+
62
+ # Use constants from .env
63
+ SENDER_ADDRESS=" $ACCOUNT0_ADDRESS "
64
+ SENDER_KEY=" $ACCOUNT0_SECRET "
65
+ AMOUNT=" 10000000000000000000"
66
+
67
+ echo " Using GraphToken at: $GRAPH_TOKEN "
68
+ echo " Using TapEscrow at: $TAP_ESCROW "
69
+ echo " Using sender address: $SENDER_ADDRESS "
70
+
71
+ # Approve GRT for escrow
72
+ echo " Approving GRT..."
73
+ docker exec chain cast send \
74
+ --rpc-url http://localhost:8545 \
75
+ --private-key $SENDER_KEY \
76
+ $GRAPH_TOKEN " approve(address,uint256)" $TAP_ESCROW $AMOUNT
77
+
78
+ # Deposit to escrow
79
+ echo " Depositing to escrow..."
80
+ docker exec chain cast send \
81
+ --rpc-url http://localhost:8545 \
82
+ --private-key $SENDER_KEY \
83
+ $TAP_ESCROW " deposit(address,uint256)" $SENDER_ADDRESS $AMOUNT
84
+
85
+ # Verify deposit
86
+ echo " Verifying deposit..."
87
+ ESCROW_BALANCE=$( docker exec chain cast call \
88
+ --rpc-url http://localhost:8545 \
89
+ $TAP_ESCROW " getEscrowAmount(address,address)(uint256)" $SENDER_ADDRESS $SENDER_ADDRESS )
90
+ echo " Escrow balance: $ESCROW_BALANCE "
91
+ if [[ " $ESCROW_BALANCE " == " 0" ]]; then
92
+ echo " Error: Failed to fund escrow"
93
+ return 1
94
+ fi
95
+ echo " Successfully funded escrow"
96
+ return 0
97
+ }
98
+
38
99
if container_running " indexer-service" && container_running " tap-agent" && container_running " gateway" ; then
39
100
echo " ====================================================================================="
40
101
echo " All services are already running. To test changes to your indexer code, you can use:"
@@ -171,10 +232,6 @@ rm docker-compose.override.yml
171
232
timeout 30 bash -c ' until docker ps | grep indexer | grep -q healthy; do sleep 5; done'
172
233
timeout 30 bash -c ' until docker ps | grep tap-agent | grep -q healthy; do sleep 5; done'
173
234
174
- # Mine some blocks
175
- # This is important for the gateway
176
- (./local-network/scripts/mine-block.sh 10) 2> /dev/null || true
177
-
178
235
echo " Building gateway image..."
179
236
docker build -t local-gateway:latest ./local-network/gateway
180
237
@@ -190,6 +247,18 @@ docker run -d --name gateway \
190
247
191
248
echo " Waiting for gateway to be available..."
192
249
250
+ # Try to fund escrow up to 3 times
251
+ for i in {1..3}; do
252
+ echo " Attempt $i to fund escrow..."
253
+ if fund_escrow; then
254
+ break
255
+ fi
256
+ if [ $i -lt 3 ]; then
257
+ echo " Waiting before retry..."
258
+ sleep 10
259
+ fi
260
+ done
261
+
193
262
# Ensure gateway is ready before testing
194
263
timeout 100 bash -c ' until curl -f http://localhost:7700/ > /dev/null 2>&1; do echo "Waiting for gateway service..."; sleep 5; done'
195
264
0 commit comments