-
Notifications
You must be signed in to change notification settings - Fork 36
/
config.go
44 lines (37 loc) · 1.18 KB
/
config.go
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
package utils
import (
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/zksync-sdk/zksync2-go/types"
"log"
"os"
"strings"
)
// ReadStandardJson reads standard-json file generated as output from zksolc.
// Returns standard json configuration and extracted contracts abi and bytecode from config file.
func ReadStandardJson(path string) (*types.StandardConfiguration, abi.ABI, []byte, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, abi.ABI{}, nil, fmt.Errorf("error reading standard json file: %w", err)
}
var config types.StandardConfiguration
err = json.Unmarshal(data, &config)
if err != nil {
return nil, abi.ABI{}, nil, fmt.Errorf("error decoding standard json file: %w", err)
}
bytecode, err := hexutil.Decode(config.Bytecode)
if err != nil {
return nil, abi.ABI{}, nil, fmt.Errorf("error decoding bytcode from standard json file: %w", err)
}
abiJson, err := json.Marshal(config.Abi)
if err != nil {
log.Panic(err)
}
contractAbi, err := abi.JSON(strings.NewReader(string(abiJson)))
if err != nil {
log.Panic(err)
}
return &config, contractAbi, bytecode, nil
}