Browse Source

WIP

feature/serveapicli
Eduard S 3 years ago
committed by arnaubennassar
parent
commit
c4d5e8a7ab
2 changed files with 30 additions and 4 deletions
  1. +6
    -4
      cli/node/main.go
  2. +24
    -0
      config/config.go

+ 6
- 4
cli/node/main.go

@ -144,10 +144,15 @@ func cmdRun(c *cli.Context) error {
}
func cmdServeAPI(c *cli.Context) error {
cfg, err := parseCli(c)
cfgPath := c.String(flagCfg)
cfg, err := config.LoadAPIServer(cfgPath)
if err != nil {
if err := cli.ShowAppHelp(c); err != nil {
panic(err)
}
return tracerr.Wrap(fmt.Errorf("error parsing flags and config: %w", err))
}
node, err := node.NewNode(cfg.mode, cfg.node)
if err != nil {
return tracerr.Wrap(fmt.Errorf("error starting node: %w", err))
@ -261,9 +266,6 @@ func getConfig(c *cli.Context) (*Config, error) {
var cfg Config
mode := c.String(flagMode)
nodeCfgPath := c.String(flagCfg)
if nodeCfgPath == "" {
return nil, tracerr.Wrap(fmt.Errorf("required flag \"%v\" not set", flagCfg))
}
var err error
switch mode {
case modeSync:

+ 24
- 0
config/config.go

@ -338,6 +338,17 @@ type APIServer struct {
Coordinator bool
} `validate:"required"`
} `validate:"required"`
L2DB struct {
// MaxTxs is the maximum number of pending L2Txs that can be
// stored in the pool. Once this number of pending L2Txs is
// reached, inserts to the pool will be denied until some of
// the pending txs are forged.
MaxTxs uint32 `validate:"required"`
// MinFeeUSD is the minimum fee in USD that a tx must pay in
// order to be accepted into the pool. Txs with lower than
// minimum fee will be rejected at the API level.
MinFeeUSD float64
} `validate:"required"`
Debug NodeDebug `validate:"required"`
}
@ -382,3 +393,16 @@ func LoadNode(path string) (*Node, error) {
}
return &cfg, nil
}
// LoadAPIServer loads the APIServer configuration from path.
func LoadAPIServer(path string) (*APIServer, error) {
var cfg APIServer
if err := Load(path, &cfg); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("error loading apiServer configuration file: %w", err))
}
validate := validator.New()
if err := validate.Struct(cfg); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("error validating configuration file: %w", err))
}
return &cfg, nil
}

Loading…
Cancel
Save