2020-11-10 09:08:42 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-04-23 14:43:00 +00:00
|
|
|
"io"
|
2020-11-10 09:08:42 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/rpc"
|
2020-11-10 09:08:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type allowListFile struct {
|
|
|
|
Allow rpc.AllowList `json:"allow"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseAllowListForRPC(path string) (rpc.AllowList, error) {
|
|
|
|
path = strings.TrimSpace(path)
|
|
|
|
if path == "" { // no file is provided
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
file, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
file.Close() //nolint: errcheck
|
|
|
|
}()
|
|
|
|
|
2022-04-23 14:43:00 +00:00
|
|
|
fileContents, err := io.ReadAll(file)
|
2020-11-10 09:08:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var allowListFileObj allowListFile
|
|
|
|
|
|
|
|
err = json.Unmarshal(fileContents, &allowListFileObj)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return allowListFileObj.Allow, nil
|
|
|
|
}
|