From 14ead3ddf12a87dfaa34a79fd595757f57724263 Mon Sep 17 00:00:00 2001 From: Mikelle Date: Wed, 24 Mar 2021 22:20:46 +0300 Subject: [PATCH] added chainId to config API --- api/accountcreationauths.go | 2 +- api/api.go | 3 +-- api/api_test.go | 1 + api/config.go | 1 + api/swagger.yml | 5 +++++ api/txspool.go | 2 +- 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api/accountcreationauths.go b/api/accountcreationauths.go index f5a562d..46e55a8 100644 --- a/api/accountcreationauths.go +++ b/api/accountcreationauths.go @@ -21,7 +21,7 @@ func (a *API) postAccountCreationAuth(c *gin.Context) { } // API to common + verify signature commonAuth := accountCreationAuthAPIToCommon(&apiAuth) - if !commonAuth.VerifySignature(a.chainID, a.hermezAddress) { + if !commonAuth.VerifySignature(a.cg.ChainID, a.hermezAddress) { retBadReq(errors.New("invalid signature"), c) return } diff --git a/api/api.go b/api/api.go index 926bc86..4399534 100644 --- a/api/api.go +++ b/api/api.go @@ -15,7 +15,6 @@ type API struct { h *historydb.HistoryDB cg *configAPI l2 *l2db.L2DB - chainID uint16 hermezAddress ethCommon.Address } @@ -44,9 +43,9 @@ func NewAPI( RollupConstants: *newRollupConstants(consts.Rollup), AuctionConstants: consts.Auction, WDelayerConstants: consts.WDelayer, + ChainID: consts.ChainID, }, l2: l2db, - chainID: consts.ChainID, hermezAddress: consts.HermezAddress, } diff --git a/api/api_test.go b/api/api_test.go index a6ff1a9..7c6c05c 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -215,6 +215,7 @@ func TestMain(m *testing.M) { chainID := uint16(0) _config := getConfigTest(chainID) config = configAPI{ + ChainID: chainID, RollupConstants: *newRollupConstants(_config.RollupConstants), AuctionConstants: _config.AuctionConstants, WDelayerConstants: _config.WDelayerConstants, diff --git a/api/config.go b/api/config.go index 93292c9..7efd056 100644 --- a/api/config.go +++ b/api/config.go @@ -57,6 +57,7 @@ type Config struct { } type configAPI struct { + ChainID uint16 `json:"chainId"` RollupConstants rollupConstants `json:"hermez"` AuctionConstants common.AuctionConstants `json:"auction"` WDelayerConstants common.WDelayerConstants `json:"withdrawalDelayer"` diff --git a/api/swagger.yml b/api/swagger.yml index a1e70e8..04e430b 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -3040,10 +3040,15 @@ components: - maxEmergencyModeTime - hermezRollup additionalProperties: false + chainId: + type: integer + description: Id of the chain + example: 27 required: - hermez - auction - withdrawalDelayer + - chainId additionalProperties: false Error: type: object diff --git a/api/txspool.go b/api/txspool.go index 11cd878..06d5224 100644 --- a/api/txspool.go +++ b/api/txspool.go @@ -187,7 +187,7 @@ func (a *API) verifyPoolL2TxWrite(txw *l2db.PoolL2TxWrite) error { poolTx.TokenID, account.TokenID)) } // Check signature - if !poolTx.VerifySignature(a.chainID, account.BJJ) { + if !poolTx.VerifySignature(a.cg.ChainID, account.BJJ) { return tracerr.Wrap(errors.New("wrong signature")) } return nil