-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo_bind.sh
executable file
·58 lines (45 loc) · 1.68 KB
/
go_bind.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
#!/bin/bash
set -euo pipefail
sed_in_place() {
local pattern="$1"
local file="$2"
if [[ "$(uname)" == "Darwin" ]]; then
# macOS
sed -i '' "$pattern" "$file"
else
# Linux
sed -i "$pattern" "$file"
fi
}
abi() {
local json_file="$1"
local pkg_name="$2"
local output_file="$3"
local bin_file="./golang-types/${pkg_name}.bin"
if [[ ! -f "$json_file" ]]; then
echo "Error: File '$json_file' does not exist." >&2
exit 1
fi
jq -r '.bytecode' "$json_file" > "$bin_file"
# Generate the Go bindings directly from the JSON ABI
jq -r '.abi' "$json_file" | abigen --abi=/dev/stdin --pkg="$pkg_name" --out="$output_file" --bin="$bin_file"
echo "Successfully generated Go bindings for '$pkg_name' contract."
rm -f "$bin_file"
# Replace the package name in the generated file with "contracts"
sed_in_place "s/^package $pkg_name/package contracts/" "$output_file"
}
abi "./artifacts/src/OrganizationRegistry.sol/OrganizationRegistry.json" \
"OrganizationRegistry" \
"./golang-types/OrganizationRegistry.go"
abi "./artifacts/src/ProcessRegistry.sol/ProcessRegistry.json" \
"ProcessRegistry" \
"./golang-types/ProcessRegistry.go"
abi "./artifacts/src/non-proxy/OrganizationRegistry.sol/OrganizationRegistry.json" \
"OrganizationRegistry" \
"./golang-types/non-proxy/OrganizationRegistry.go"
abi "./artifacts/src/non-proxy/ProcessRegistry.sol/ProcessRegistry.json" \
"ProcessRegistry" \
"./golang-types/non-proxy/ProcessRegistry.go"
# abi "./artifacts/src/SequencerRegistry.sol/SequencerRegistry.json" \
# "SequencerRegistry" \
# "./golang-types/SequencerRegistry.go"