/
options.go
45 lines (38 loc) · 1.03 KB
/
options.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
45
package app
import (
"crypto/ecdsa"
"fmt"
"path/filepath"
"strconv"
ethcmn "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
func SetEthConfig(isValidator bool, privkeyFile, rootchainAddr, nodeURL, finality string) func(*ChildChain) {
var privkey *ecdsa.PrivateKey
var rootchain ethcmn.Address
var blockFinality uint64
if isValidator {
path, err := filepath.Abs(privkeyFile)
if err != nil {
errMsg := fmt.Sprintf("Could not resolve provided private key file path: %v", err)
panic(errMsg)
}
privkey, err = crypto.LoadECDSA(path)
if err != nil {
errMsg := fmt.Sprintf("Could not load provided private key file to ecdsa private key: %v", err)
panic(errMsg)
}
}
blockFinality, err := strconv.ParseUint(finality, 10, 64)
if err != nil {
panic(err)
}
rootchain = ethcmn.HexToAddress(rootchainAddr)
return func(cc *ChildChain) {
cc.validatorPrivKey = privkey
cc.isValidator = isValidator
cc.rootchain = rootchain
cc.nodeURL = nodeURL
cc.blockFinality = blockFinality
}
}