-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy.go
108 lines (90 loc) · 2.8 KB
/
deploy.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"context"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi"
cli "github.com/jawher/mow.cli"
log "github.com/xlab/suplog"
"github.com/InjectiveLabs/etherman/deployer"
)
func onDeploy(cmd *cli.Cmd) {
bytecodeOnly := cmd.BoolOpt("bytecode", false, "Produce hex-encoded contract bytecode only. Do not interact with RPC.")
await := cmd.BoolOpt("await", true, "Await transaction confirmation from the RPC.")
contractArgs := cmd.StringsArg("ARGS", []string{}, "Contract constructor's arguments. Will be ABI-encoded.")
cmd.Spec = "[--bytecode | --await] [ARGS...]"
cmd.Action = func() {
d, err := deployer.New(
deployer.OptionRPCTimeout(duration(*rpcTimeout, defaultRPCTimeout)),
deployer.OptionCallTimeout(duration(*callTimeout, defaultCallTimeout)),
deployer.OptionTxTimeout(duration(*txTimeout, defaultTxTimeout)),
// only options applicable to tx
deployer.OptionEVMRPCEndpoint(*evmEndpoint),
deployer.OptionGasPrice(big.NewInt(int64(*gasPrice))),
deployer.OptionGasLimit(uint64(*gasLimit)),
deployer.OptionNoCache(*noCache),
deployer.OptionBuildCacheDir(*buildCacheDir),
deployer.OptionSolcAllowedPaths(*solAllowedPaths),
deployer.OptionEnableCoverage(*coverage),
)
if err != nil {
log.WithError(err).Fatalln("failed to init deployer")
}
client, err := d.Backend()
if err != nil {
log.Fatalln(err)
}
chainCtx, cancelFn := context.WithTimeout(context.Background(), duration(*rpcTimeout, defaultRPCTimeout))
defer cancelFn()
chainID, err := client.ChainID(chainCtx)
if err != nil {
log.WithError(err).Fatalln("failed get valid chain ID")
}
fromAddress, signerFn, err := initEthereumAccountsManager(
chainID.Uint64(),
keystoreDir,
from,
fromPassphrase,
fromPrivKey,
useLedger,
)
if err != nil {
log.WithError(err).Fatalln("failed init SignerFn")
}
log.Debugln("sending from", fromAddress.Hex())
deployOpts := deployer.ContractDeployOpts{
From: fromAddress,
SignerFn: signerFn,
SolSource: *solSource,
ContractName: *contractName,
BytecodeOnly: *bytecodeOnly,
Await: *await,
}
if *coverage {
deployOpts.CoverageAgent = deployer.NewCoverageDataCollector(deployer.CoverageModeDefault)
}
txHash, contract, err := d.Deploy(
context.Background(),
deployOpts,
func(args abi.Arguments) []interface{} {
mappedArgs, err := mapStringArgs(args, *contractArgs)
if err != nil {
log.WithError(err).Fatalln("failed to map constructor args")
return nil
}
return mappedArgs
},
)
if err != nil {
log.Fatalln(err)
}
if *bytecodeOnly {
fmt.Println(contract.Bin)
return
}
if !*await {
log.WithField("txHash", txHash.Hex()).Infoln("contract address", contract.Address.Hex())
}
fmt.Println(contract.Address.Hex())
}
}