mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Remove bigints from API
This commit is contained in:
12
api/api.go
12
api/api.go
@@ -22,12 +22,12 @@ const (
|
||||
// Status define status of the network
|
||||
type Status struct {
|
||||
sync.RWMutex
|
||||
Network Network `json:"network"`
|
||||
Metrics historydb.Metrics `json:"metrics"`
|
||||
Rollup common.RollupVariables `json:"rollup"`
|
||||
Auction common.AuctionVariables `json:"auction"`
|
||||
WithdrawalDelayer common.WDelayerVariables `json:"withdrawalDelayer"`
|
||||
RecommendedFee common.RecommendedFee `json:"recommendedFee"`
|
||||
Network Network `json:"network"`
|
||||
Metrics historydb.Metrics `json:"metrics"`
|
||||
Rollup historydb.RollupVariablesAPI `json:"rollup"`
|
||||
Auction common.AuctionVariables `json:"auction"`
|
||||
WithdrawalDelayer common.WDelayerVariables `json:"withdrawalDelayer"`
|
||||
RecommendedFee common.RecommendedFee `json:"recommendedFee"`
|
||||
}
|
||||
|
||||
// API serves HTTP requests to allow external interaction with the Hermez node
|
||||
|
||||
19
api/state.go
19
api/state.go
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/hermeznetwork/hermez-node/apitypes"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||
"github.com/hermeznetwork/tracerr"
|
||||
@@ -57,7 +58,23 @@ func (a *API) getState(c *gin.Context) {
|
||||
// SetRollupVariables set Status.Rollup variables
|
||||
func (a *API) SetRollupVariables(rollupVariables common.RollupVariables) {
|
||||
a.status.Lock()
|
||||
a.status.Rollup = rollupVariables
|
||||
var rollupVAPI historydb.RollupVariablesAPI
|
||||
rollupVAPI.EthBlockNum = rollupVariables.EthBlockNum
|
||||
rollupVAPI.FeeAddToken = apitypes.NewBigIntStr(rollupVariables.FeeAddToken)
|
||||
rollupVAPI.ForgeL1L2BatchTimeout = rollupVariables.ForgeL1L2BatchTimeout
|
||||
rollupVAPI.WithdrawalDelay = rollupVariables.WithdrawalDelay
|
||||
|
||||
for i, bucket := range rollupVariables.Buckets {
|
||||
var apiBucket historydb.BucketParamsAPI
|
||||
apiBucket.CeilUSD = apitypes.NewBigIntStr(bucket.CeilUSD)
|
||||
apiBucket.Withdrawals = apitypes.NewBigIntStr(bucket.Withdrawals)
|
||||
apiBucket.BlockWithdrawalRate = apitypes.NewBigIntStr(bucket.BlockWithdrawalRate)
|
||||
apiBucket.MaxWithdrawals = apitypes.NewBigIntStr(bucket.MaxWithdrawals)
|
||||
rollupVAPI.Buckets[i] = apiBucket
|
||||
}
|
||||
|
||||
rollupVAPI.SafeMode = rollupVariables.SafeMode
|
||||
a.status.Rollup = rollupVAPI
|
||||
a.status.Unlock()
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/hermeznetwork/hermez-node/apitypes"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -11,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
type testStatus struct {
|
||||
Network testNetwork `json:"network"`
|
||||
Metrics historydb.Metrics `json:"metrics"`
|
||||
Rollup common.RollupVariables `json:"rollup"`
|
||||
Auction common.AuctionVariables `json:"auction"`
|
||||
WithdrawalDelayer common.WDelayerVariables `json:"withdrawalDelayer"`
|
||||
RecommendedFee common.RecommendedFee `json:"recommendedFee"`
|
||||
Network testNetwork `json:"network"`
|
||||
Metrics historydb.Metrics `json:"metrics"`
|
||||
Rollup historydb.RollupVariablesAPI `json:"rollup"`
|
||||
Auction common.AuctionVariables `json:"auction"`
|
||||
WithdrawalDelayer common.WDelayerVariables `json:"withdrawalDelayer"`
|
||||
RecommendedFee common.RecommendedFee `json:"recommendedFee"`
|
||||
}
|
||||
|
||||
type testNetwork struct {
|
||||
@@ -29,9 +30,24 @@ type testNetwork struct {
|
||||
|
||||
func TestSetRollupVariables(t *testing.T) {
|
||||
rollupVars := &common.RollupVariables{}
|
||||
assert.Equal(t, *rollupVars, api.status.Rollup)
|
||||
assertEqualRollupVariables(t, *rollupVars, api.status.Rollup, true)
|
||||
api.SetRollupVariables(tc.rollupVars)
|
||||
assert.Equal(t, tc.rollupVars, api.status.Rollup)
|
||||
assertEqualRollupVariables(t, tc.rollupVars, api.status.Rollup, true)
|
||||
}
|
||||
|
||||
func assertEqualRollupVariables(t *testing.T, rollupVariables common.RollupVariables, apiVariables historydb.RollupVariablesAPI, checkBuckets bool) {
|
||||
assert.Equal(t, apitypes.NewBigIntStr(rollupVariables.FeeAddToken), apiVariables.FeeAddToken)
|
||||
assert.Equal(t, rollupVariables.ForgeL1L2BatchTimeout, apiVariables.ForgeL1L2BatchTimeout)
|
||||
assert.Equal(t, rollupVariables.WithdrawalDelay, apiVariables.WithdrawalDelay)
|
||||
assert.Equal(t, rollupVariables.SafeMode, apiVariables.SafeMode)
|
||||
if checkBuckets {
|
||||
for i, bucket := range rollupVariables.Buckets {
|
||||
assert.Equal(t, apitypes.NewBigIntStr(bucket.BlockWithdrawalRate), apiVariables.Buckets[i].BlockWithdrawalRate)
|
||||
assert.Equal(t, apitypes.NewBigIntStr(bucket.CeilUSD), apiVariables.Buckets[i].CeilUSD)
|
||||
assert.Equal(t, apitypes.NewBigIntStr(bucket.MaxWithdrawals), apiVariables.Buckets[i].MaxWithdrawals)
|
||||
assert.Equal(t, apitypes.NewBigIntStr(bucket.Withdrawals), apiVariables.Buckets[i].Withdrawals)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetWDelayerVariables(t *testing.T) {
|
||||
@@ -88,8 +104,8 @@ func TestUpdateNetworkInfo(t *testing.T) {
|
||||
assert.Equal(t, lastBatchNum, api.status.Network.LastBatch.BatchNum)
|
||||
assert.Equal(t, currentSlotNum, api.status.Network.CurrentSlot)
|
||||
assert.Equal(t, int(api.status.Auction.ClosedAuctionSlots)+1, len(api.status.Network.NextForgers))
|
||||
assert.Equal(t, api.status.Rollup.Buckets[0].Withdrawals, big.NewInt(123))
|
||||
assert.Equal(t, api.status.Rollup.Buckets[2].Withdrawals, big.NewInt(43))
|
||||
assert.Equal(t, api.status.Rollup.Buckets[0].Withdrawals, apitypes.NewBigIntStr(big.NewInt(123)))
|
||||
assert.Equal(t, api.status.Rollup.Buckets[2].Withdrawals, apitypes.NewBigIntStr(big.NewInt(43)))
|
||||
}
|
||||
|
||||
func TestUpdateMetrics(t *testing.T) {
|
||||
@@ -141,10 +157,9 @@ func TestGetState(t *testing.T) {
|
||||
|
||||
// SC vars
|
||||
// UpdateNetworkInfo will overwrite buckets withdrawal values
|
||||
// So we restore them before comparing, they are checked at
|
||||
// So they won't be checked here, they are checked at
|
||||
// TestUpdateNetworkInfo
|
||||
status.Rollup.Buckets = tc.rollupVars.Buckets
|
||||
assert.Equal(t, tc.rollupVars, status.Rollup)
|
||||
assertEqualRollupVariables(t, tc.rollupVars, status.Rollup, false)
|
||||
assert.Equal(t, tc.auctionVars, status.Auction)
|
||||
assert.Equal(t, tc.wdelayerVars, status.WithdrawalDelayer)
|
||||
// Network
|
||||
|
||||
@@ -2693,7 +2693,7 @@ components:
|
||||
description: Max Ethereum blocks after the last L1-L2-batch, when exceeds the timeout only L1-L2-batch are allowed.
|
||||
example: 5
|
||||
feeAddToken:
|
||||
type: integer
|
||||
type: string
|
||||
description: Fee to pay when registering tokens into the network.
|
||||
example: 5698
|
||||
withdrawalDelay:
|
||||
@@ -2707,19 +2707,19 @@ components:
|
||||
type: object
|
||||
properties:
|
||||
ceilUSD:
|
||||
type: integer
|
||||
type: string
|
||||
description: Max USD value
|
||||
example: 1000
|
||||
withdrawals:
|
||||
type: integer
|
||||
type: string
|
||||
description: Available withdrawals of the bucket
|
||||
example: 4
|
||||
blockWithdrawalRate:
|
||||
type: integer
|
||||
type: string
|
||||
description: Every `blockWithdrawalRate` blocks add 1 withdrawal
|
||||
example: 8
|
||||
maxWithdrawals:
|
||||
type: integer
|
||||
type: string
|
||||
description: Max withdrawals the bucket can hold
|
||||
example: 4
|
||||
additionalProperties: false
|
||||
|
||||
Reference in New Issue
Block a user