-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtx-post.sh
executable file
·68 lines (61 loc) · 1.88 KB
/
tx-post.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
#!/bin/bash
# set -e
ejsId=0
# wait for the block formation to start check for block 1 to be build
# We should curl and get genesis hash, but for now lets assume it will be provided
BLOCK1_HASH=""
while [ ! -n "$BLOCK1_HASH" ] || [ "$BLOCK1_HASH" == "null" ]
do
sleep 6
echo "Checking if block 0x01 has been build ..."
ejsId=$(( ejsId +1 ))
responseCmd="curl --location --request POST 'http://localhost:8545' --header 'Content-Type: application/json' --data-raw '{
\"jsonrpc\": \"2.0\",
\"method\": \"eth_getBlockByNumber\",
\"params\": [
\"0x1\",
true
],
\"id\": $ejsId
}' 2>/dev/null | jq \".result.hash\""
# echo "$responseCmd"
BLOCK1_HASH=$(eval "$responseCmd")
done;
echo "BLOCK1_HASH=$BLOCK1_HASH"
# run txs
rawTxs=$(cat $1 | jq ".[].serialized")
rawTxs=($rawTxs)
for rawTx in "${rawTxs[@]}"
do
echo "Raw tx is $rawTx"
TX_HASH=""
TX_RECEIPT=""
while [ ! -n "$TX_HASH" ] || [ "$TX_HASH" == "null" ]
do
sleep 6
echo "Post tx to EL ..."
ejsId=$(( ejsId +1 ))
txResponseCmd="curl --location --request POST 'http://127.0.0.1:8545' --header 'Content-Type: application/json' --data-raw '{
\"jsonrpc\": \"2.0\",
\"method\": \"eth_sendRawTransaction\",
\"params\": [$rawTx],
\"id\": $ejsId
}' 2>/dev/null | jq \".result\""
TX_HASH=$(eval "$txResponseCmd")
done;
echo "tx: $TX_HASH"
while [ ! -n "$TX_RECEIPT" ] || [ "$TX_RECEIPT" == "null" ]
do
sleep 6
echo "Fetching tx receipt from EL ..."
ejsId=$(( ejsId +1 ))
txResponseCmd="curl --location --request POST 'http://127.0.0.1:8545' --header 'Content-Type: application/json' --data-raw '{
\"jsonrpc\": \"2.0\",
\"method\": \"eth_getTransactionReceipt\",
\"params\": [$TX_HASH],
\"id\": $ejsId
}' 2>/dev/null | jq \".result.blockHash\""
TX_RECEIPT=$(eval "$txResponseCmd")
done;
echo "tx included in block: $TX_RECEIPT"
done