-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
executable file
·79 lines (54 loc) · 2.63 KB
/
script.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
#!/bin/bash
# Define the base directory where the .json files are located
BASE_DIR="$HOME/.primev/contracts"
# Create the abi directory if it doesn't exist
ABI_DIR="./abi"
mkdir -p "$ABI_DIR"
forge compile --root $BASE_DIR --via-ir
# Function to extract and save the ABI
extract_and_save_abi() {
local json_file="$1"
local abi_file="$2"
jq .abi "$json_file" > "$abi_file"
}
# Extract ABI for BidderRegistry.json
extract_and_save_abi "$BASE_DIR/out/BidderRegistry.sol/BidderRegistry.json" "$ABI_DIR/BidderRegistry.abi"
# Extract ABI for ProviderRegistry.json
extract_and_save_abi "$BASE_DIR/out/ProviderRegistry.sol/ProviderRegistry.json" "$ABI_DIR/ProviderRegistry.abi"
# Extract ABI for Oracle.json
extract_and_save_abi "$BASE_DIR/out/Oracle.sol/Oracle.json" "$ABI_DIR/Oracle.abi"
# Extract ABI for PreConfCommitmentStore.json
extract_and_save_abi "$BASE_DIR/out/PreConfirmations.sol/PreConfCommitmentStore.json" "$ABI_DIR/PreConfCommitmentStore.abi"
# Extract ABI for SettlementGateway.json
extract_and_save_abi "$BASE_DIR/out/SettlementGateway.sol/SettlementGateway.json" "$ABI_DIR/SettlementGateway.abi"
# Extract ABI for L1Gateway.json
extract_and_save_abi "$BASE_DIR/out/L1Gateway.sol/L1Gateway.json" "$ABI_DIR/L1Gateway.abi"
echo "ABI files extracted successfully."
ABI_DIR="./abi"
GO_CODE_BASE_DIR="./clients"
# Create the Go code base directory if it doesn't exist
mkdir -p "$GO_CODE_BASE_DIR"
# Function to generate Go code from ABI and place it in a separate folder
generate_go_code() {
local abi_file="$1"
local contract_name="$2"
local pkg_name="$3"
# Create a directory for the contract
local contract_dir="$GO_CODE_BASE_DIR/$contract_name"
mkdir -p "$contract_dir"
# Run abigen and output the Go code in the contract's directory
abigen --abi "$abi_file" --pkg "$pkg_name" --out "$contract_dir/$contract_name.go"
}
# Generate Go code for BidderRegistry.abi
generate_go_code "$ABI_DIR/BidderRegistry.abi" "BidderRegistry" "bidderregistry"
# Generate Go code for ProviderRegistry.abi
generate_go_code "$ABI_DIR/ProviderRegistry.abi" "ProviderRegistry" "providerregistry"
# Generate Go code for Oracle.abi
generate_go_code "$ABI_DIR/Oracle.abi" "Oracle" "oracle"
# Generate Go code for PreConfCommitmentStore.abi
generate_go_code "$ABI_DIR/PreConfCommitmentStore.abi" "PreConfCommitmentStore" "preconfcommitmentstore"
# Generate Go code for SettlementGateway.abi
generate_go_code "$ABI_DIR/SettlementGateway.abi" "SettlementGateway" "settlementgateway"
# Generate Go code for L1Gateway.abi
generate_go_code "$ABI_DIR/L1Gateway.abi" "L1Gateway" "l1gateway"
echo "Go code generated successfully in separate folders."