You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
970 B

Allow serving API only via new cli command - Add new command to the cli/node: `serveapi` that alows serving the API just by connecting to the PostgreSQL database. The mode flag should me passed in order to select whether we are connecting to a synchronizer database or a coordinator database. If `coord` is chosen as mode, the coordinator endpoints can be activated in order to allow inserting l2txs and authorizations into the L2DB. Summary of the implementation details - New SQL table with 3 columns (plus `item_id` pk). The table only contains a single row with `item_id` = 1. Columns: - state: historydb.StateAPI in JSON. This is the struct that is served via the `/state` API endpoint. The node will periodically update this struct and store it int he DB. The api server will query it from the DB to serve it. - config: historydb.NodeConfig in JSON. This struct contains node configuration parameters that the API needs to be aware of. It's updated once every time the node starts. - constants: historydb.Constants in JSON. This struct contains all the hermez network constants gathered via the ethereum client by the node. It's written once every time the node starts. - The HistoryDB contains methods to get and update each one of these columns individually. - The HistoryDB contains all methods that query the DB and prepare objects that will appear in the StateAPI endpoint. - The configuration used in for the `serveapi` cli/node command is defined in `config.APIServer`, and is a subset of `node.Config` in order to allow reusing the same configuration file of the node if desired. - A new object is introduced in the api: `StateAPIUpdater`, which contains all the necessary information to update the StateAPI in the DB periodically by the node. - Moved the types `SCConsts`, `SCVariables` and `SCVariablesPtr` from `syncrhonizer` to `common` for convenience.
3 years ago
  1. package common
  2. // SCVariables joins all the smart contract variables in a single struct
  3. type SCVariables struct {
  4. Rollup RollupVariables `validate:"required"`
  5. Auction AuctionVariables `validate:"required"`
  6. WDelayer WDelayerVariables `validate:"required"`
  7. }
  8. // AsPtr returns the SCVariables as a SCVariablesPtr using pointers to the
  9. // original SCVariables
  10. func (v *SCVariables) AsPtr() *SCVariablesPtr {
  11. return &SCVariablesPtr{
  12. Rollup: &v.Rollup,
  13. Auction: &v.Auction,
  14. WDelayer: &v.WDelayer,
  15. }
  16. }
  17. // SCVariablesPtr joins all the smart contract variables as pointers in a single
  18. // struct
  19. type SCVariablesPtr struct {
  20. Rollup *RollupVariables `validate:"required"`
  21. Auction *AuctionVariables `validate:"required"`
  22. WDelayer *WDelayerVariables `validate:"required"`
  23. }
  24. // SCConsts joins all the smart contract constants in a single struct
  25. type SCConsts struct {
  26. Rollup RollupConstants
  27. Auction AuctionConstants
  28. WDelayer WDelayerConstants
  29. }