-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (70 loc) · 1.91 KB
/
main.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
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
79
80
81
package main
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
cli "github.com/jawher/mow.cli"
log "github.com/xlab/suplog"
)
var app = cli.App("etherman", "Deploys arbitrary contract on an arbitrary EVM. Requires solc 0.6.x or later.")
func main() {
readEnv()
readGlobalOptions(
&solcPathSet,
&solcPath,
&contractName,
&solSource,
&solAllowedPaths,
&evmEndpoint,
&rpcTimeout,
&txTimeout,
&callTimeout,
&gasPrice,
&gasLimit,
&buildCacheDir,
&noCache,
&coverage,
&logLevel,
)
readEthereumKeyOptions(
&keystoreDir,
&from,
&fromPassphrase,
&fromPrivKey,
&useLedger,
)
app.Action = func() {
fmt.Println("You should use either deploy, tx or logs command. See --help for more info.")
}
app.Before = func() {
log.DefaultLogger.SetLevel(toLogLevel(*logLevel))
}
app.Command("build", "Builds given contract and cached build artefacts. Optional step.", onBuild)
app.Command("deploy", "Deploys given contract on the EVM chain. Caches build artefacts.", onDeploy)
app.Command("tx", "Creates a transaction for particular contract method. Uses build cache.", onTx)
app.Command("call", "Calls method of a particular contract. Uses build cache.", onCall)
app.Command("logs", "Loads logs of a particular event from contract.", onLogs)
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
// readEnv is a special utility that reads `.env` file into actual environment variables
// of the current app, similar to `dotenv` Node package.
func readEnv() {
if envdata, _ := ioutil.ReadFile(".env"); len(envdata) > 0 {
s := bufio.NewScanner(bytes.NewReader(envdata))
for s.Scan() {
parts := strings.Split(s.Text(), "=")
if len(parts) != 2 {
continue
}
strValue := strings.Trim(parts[1], `"`)
if err := os.Setenv(parts[0], strValue); err != nil {
log.WithField("name", parts[0]).WithError(err).Warningln("failed to override ENV variable")
}
}
}
}