This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
/
deploy.go
140 lines (110 loc) · 4.41 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package commands
import (
"bytes"
"fmt"
pkgs "github.com/hyperledger/burrow/deploy"
"github.com/hyperledger/burrow/deploy/def"
"github.com/hyperledger/burrow/deploy/util"
cli "github.com/jawher/mow.cli"
log "github.com/sirupsen/logrus"
)
func Deploy(output Output) func(cmd *cli.Cmd) {
return func(cmd *cli.Cmd) {
chainUrlOpt := cmd.StringOpt("u chain-url", "127.0.0.1:10997", "chain-url to be used in IP:PORT format")
signerOpt := cmd.StringOpt("s keys", "",
"IP:PORT of Burrow GRPC service which jobs should or otherwise transaction submitted unsigned for mempool signing in Burrow")
mempoolSigningOpt := cmd.BoolOpt("p mempool-signing", false,
"Use Burrow's own keys connection to sign transactions - means that Burrow instance must have access to input account keys. "+
"Sequence numbers are set as transactions enter the mempool so concurrent transactions can be sent from same inputs.")
pathOpt := cmd.StringOpt("i dir", "", "root directory of app (will use pwd by default)")
defaultOutputOpt := cmd.StringOpt("o output", "deploy.output.json",
"filename for jobs output file. by default, this name will reflect the name passed in on the optional [--file]")
yamlPathOpt := cmd.StringOpt("f file", "deploy.yaml",
"path to package file which jobs should use. if also using the --dir flag, give the relative path to jobs file, which should be in the same directory")
defaultSetsOpt := cmd.StringsOpt("e set", []string{},
"default sets to use; operates the same way as the [set] jobs, only before the jobs file is ran (and after default address")
binPathOpt := cmd.StringOpt("b bin-path", "[dir]/bin",
"path to the bin directory jobs should use when saving binaries after the compile process defaults to --dir + /bin")
defaultGasOpt := cmd.StringOpt("g gas", "1111111111",
"default gas to use; can be overridden for any single job")
jobsOpt := cmd.IntOpt("j jobs", 2,
"default number of concurrent solidity compilers to run")
addressOpt := cmd.StringOpt("a address", "",
"default address to use; operates the same way as the [account] job, only before the deploy file is ran")
defaultFeeOpt := cmd.StringOpt("n fee", "9999", "default fee to use")
defaultAmountOpt := cmd.StringOpt("m amount", "9999",
"default amount to use")
verboseOpt := cmd.BoolOpt("v verbose", false, "verbose output")
debugOpt := cmd.BoolOpt("d debug", false, "debug level output")
proposalVerify := cmd.BoolOpt("proposal-verify", false, "Verify any proposal, do NOT create new proposal or vote")
proposalVote := cmd.BoolOpt("proposal-vote", false, "Vot for proposal, do NOT create new proposal")
cmd.Action = func() {
do := new(def.DeployArgs)
if *proposalVerify && *proposalVote {
output.Fatalf("Cannot combine --proposal-verify and --proposal-vote")
}
do.Path = *pathOpt
do.DefaultOutput = *defaultOutputOpt
do.YAMLPath = *yamlPathOpt
do.DefaultSets = *defaultSetsOpt
do.BinPath = *binPathOpt
do.DefaultGas = *defaultGasOpt
do.Address = *addressOpt
do.DefaultFee = *defaultFeeOpt
do.DefaultAmount = *defaultAmountOpt
do.Verbose = *verboseOpt
do.Debug = *debugOpt
do.Jobs = *jobsOpt
do.ProposeVerify = *proposalVerify
do.ProposeVote = *proposalVote
log.SetFormatter(new(PlainFormatter))
log.SetLevel(log.WarnLevel)
if do.Verbose {
log.SetLevel(log.InfoLevel)
} else if do.Debug {
log.SetLevel(log.DebugLevel)
}
client := def.NewClient(*chainUrlOpt, *signerOpt, *mempoolSigningOpt)
util.IfExit(pkgs.RunPackage(do, client))
}
}
}
type PlainFormatter struct{}
func (f *PlainFormatter) Format(entry *log.Entry) ([]byte, error) {
var b *bytes.Buffer
keys := make([]string, 0, len(entry.Data))
for k := range entry.Data {
keys = append(keys, k)
}
if entry.Buffer != nil {
b = entry.Buffer
} else {
b = &bytes.Buffer{}
}
f.appendMessage(b, entry.Message)
for _, key := range keys {
f.appendMessageData(b, key, entry.Data[key])
}
b.WriteByte('\n')
return b.Bytes(), nil
}
func (f *PlainFormatter) appendMessage(b *bytes.Buffer, message string) {
fmt.Fprintf(b, "%-44s", message)
}
func (f *PlainFormatter) appendMessageData(b *bytes.Buffer, key string, value interface{}) {
switch key {
case "":
b.WriteString("=> ")
case "=>":
b.WriteString(key)
b.WriteByte(' ')
default:
b.WriteString(key)
b.WriteString(" => ")
}
stringVal, ok := value.(string)
if !ok {
stringVal = fmt.Sprint(value)
}
b.WriteString(stringVal)
}