diff --git a/cmd/api/docs/docs.go b/cmd/api/docs/docs.go index 876127b..0ad9463 100644 --- a/cmd/api/docs/docs.go +++ b/cmd/api/docs/docs.go @@ -2649,6 +2649,10 @@ const docTemplate = `{ "type": "integer", "example": 101 }, + "bridge_count": { + "type": "integer", + "example": 2 + }, "first_height": { "type": "integer", "example": 100 diff --git a/cmd/api/docs/swagger.json b/cmd/api/docs/swagger.json index c9f8565..f5a9305 100644 --- a/cmd/api/docs/swagger.json +++ b/cmd/api/docs/swagger.json @@ -2639,6 +2639,10 @@ "type": "integer", "example": 101 }, + "bridge_count": { + "type": "integer", + "example": 2 + }, "first_height": { "type": "integer", "example": 100 diff --git a/cmd/api/docs/swagger.yaml b/cmd/api/docs/swagger.yaml index a8ba9f9..e7d85df 100644 --- a/cmd/api/docs/swagger.yaml +++ b/cmd/api/docs/swagger.yaml @@ -311,6 +311,9 @@ definitions: actions_count: example: 101 type: integer + bridge_count: + example: 2 + type: integer first_height: example: 100 type: integer diff --git a/cmd/api/handler/block_test.go b/cmd/api/handler/block_test.go index 2221017..2401836 100644 --- a/cmd/api/handler/block_test.go +++ b/cmd/api/handler/block_test.go @@ -81,6 +81,7 @@ var ( FirstHeight: 100, AstriaId: testsuite.RandomHash(32), ActionsCount: 1, + BridgeCount: 1, Size: 10, } testRollupURLHash = base64.URLEncoding.EncodeToString(testRollup.AstriaId) diff --git a/cmd/api/handler/responses/rollup.go b/cmd/api/handler/responses/rollup.go index cbd69ea..812252a 100644 --- a/cmd/api/handler/responses/rollup.go +++ b/cmd/api/handler/responses/rollup.go @@ -13,6 +13,7 @@ type Rollup struct { FirstHeight types.Level `example:"100" json:"first_height" swaggertype:"integer"` AstriaId []byte `example:"O0Ia+lPYYMf3iFfxBaWXCSdlhphc6d4ZoBXINov6Tjc=" json:"hash" swaggertype:"string"` ActionsCount int64 `example:"101" json:"actions_count" swaggertype:"integer"` + BridgeCount int64 `example:"2" json:"bridge_count" swaggertype:"integer"` Size int64 `example:"100" json:"size" swaggertype:"integer"` } @@ -22,6 +23,7 @@ func NewRollup(rollup *storage.Rollup) Rollup { AstriaId: rollup.AstriaId, FirstHeight: rollup.FirstHeight, ActionsCount: rollup.ActionsCount, + BridgeCount: rollup.BridgeCount, Size: rollup.Size, } diff --git a/cmd/api/handler/rollup_test.go b/cmd/api/handler/rollup_test.go index 61fd1ef..ece8388 100644 --- a/cmd/api/handler/rollup_test.go +++ b/cmd/api/handler/rollup_test.go @@ -77,6 +77,7 @@ func (s *RollupTestSuite) TestGet() { s.Require().NoError(err) s.Require().EqualValues(1, rollup.Id) s.Require().EqualValues(1, rollup.ActionsCount) + s.Require().EqualValues(1, rollup.BridgeCount) s.Require().EqualValues(100, rollup.FirstHeight) s.Require().EqualValues(10, rollup.Size) s.Require().Equal(testRollup.AstriaId, rollup.AstriaId) diff --git a/internal/storage/postgres/transaction.go b/internal/storage/postgres/transaction.go index 1412c9f..34c259c 100644 --- a/internal/storage/postgres/transaction.go +++ b/internal/storage/postgres/transaction.go @@ -141,9 +141,10 @@ func (tx Transaction) SaveRollups(ctx context.Context, rollups ...*models.Rollup } query := tx.Tx().NewInsert().Model(&rs). - Column("first_height", "astria_id", "actions_count", "size"). + Column("first_height", "astria_id", "actions_count", "bridge_count", "size"). On("CONFLICT ON CONSTRAINT rollup_id DO UPDATE"). Set("actions_count = added_rollup.actions_count + EXCLUDED.actions_count"). + Set("bridge_count = added_rollup.bridge_count + EXCLUDED.bridge_count"). Set("size = added_rollup.size + EXCLUDED.size") if _, err := query.Returning("xmax, id").Exec(ctx); err != nil { diff --git a/internal/storage/rollup.go b/internal/storage/rollup.go index 765c33a..e0fdb74 100644 --- a/internal/storage/rollup.go +++ b/internal/storage/rollup.go @@ -33,6 +33,7 @@ type Rollup struct { AstriaId []byte `bun:"astria_id,unique:rollup_id" comment:"Astria rollup identity"` FirstHeight types.Level `bun:"first_height" comment:"Block number of the first rollup occurrence"` ActionsCount int64 `bun:"actions_count" comment:"Count of actions in which the rollup was involved"` + BridgeCount int64 `bun:"bridge_count" comment:"Count of connected bridges"` Size int64 `bun:"size" comment:"Count bytes which was saved in the rollup"` } diff --git a/pkg/indexer/decode/actions.go b/pkg/indexer/decode/actions.go index e8ea1e5..068af84 100644 --- a/pkg/indexer/decode/actions.go +++ b/pkg/indexer/decode/actions.go @@ -414,6 +414,7 @@ func parseInitBridgeAccount(body *astria.Action_InitBridgeAccountAction, from st Address: ctx.Addresses.Set(from, height, decimal.Zero, "", 0, 0), Rollup: rollup, } + rollup.BridgeCount += 1 action.Data["rollup_id"] = rollupId action.Data["fee_asset"] = bridge.FeeAsset diff --git a/pkg/indexer/decode/actions_test.go b/pkg/indexer/decode/actions_test.go index 8892689..ceb191c 100644 --- a/pkg/indexer/decode/actions_test.go +++ b/pkg/indexer/decode/actions_test.go @@ -786,6 +786,7 @@ func TestDecodeActions(t *testing.T) { AstriaId: message.InitBridgeAccountAction.GetRollupId().GetInner(), FirstHeight: 1000, ActionsCount: 1, + BridgeCount: 1, }, }, Addresses: make([]*storage.AddressAction, 0), @@ -845,6 +846,7 @@ func TestDecodeActions(t *testing.T) { AstriaId: message.InitBridgeAccountAction.GetRollupId().GetInner(), FirstHeight: 1000, ActionsCount: 1, + BridgeCount: 1, }, }, }