diff --git a/cmd/api/handlers/account.go b/cmd/api/handlers/account.go index 92b41939f..cf9590308 100644 --- a/cmd/api/handlers/account.go +++ b/cmd/api/handlers/account.go @@ -50,11 +50,14 @@ func GetInfo() gin.HandlerFunc { } } c.SecureJSON(http.StatusOK, AccountInfo{ - Address: acc.Address, - OperationsCount: acc.OperationsCount, - Balance: balance, - LastAction: acc.LastAction.UTC(), - AccountType: acc.Type.String(), + Address: acc.Address, + OperationsCount: acc.OperationsCount, + EventsCount: acc.EventsCount, + MigrationsCount: acc.MigrationsCount, + TicketUpdatesCount: acc.TicketUpdatesCount, + Balance: balance, + LastAction: acc.LastAction.UTC(), + AccountType: acc.Type.String(), }) } diff --git a/cmd/api/handlers/contract.go b/cmd/api/handlers/contract.go index 07532d396..7f3ea1b30 100644 --- a/cmd/api/handlers/contract.go +++ b/cmd/api/handlers/contract.go @@ -143,13 +143,7 @@ func contractWithStatsPostprocessing(c context.Context, ctx *config.Context, con if err != nil { return ContractWithStats{}, err } - res := ContractWithStats{contract, 0, 0, false} - - eventsCount, err := ctx.Operations.EventsCount(c, contractModel.AccountID) - if err != nil { - return res, err - } - res.EventsCount = eventsCount + res := ContractWithStats{contract, 0} stats, err := ctx.Domains.SameCount(c, contractModel, ctx.Config.API.Networks...) if err != nil { @@ -157,11 +151,5 @@ func contractWithStatsPostprocessing(c context.Context, ctx *config.Context, con } res.SameCount += int64(stats) - hasTicketUpdates, err := ctx.TicketUpdates.Has(c, contractModel.AccountID) - if err != nil { - return res, err - } - res.HasTicketUpdates = hasTicketUpdates - return res, nil } diff --git a/cmd/api/handlers/responses.go b/cmd/api/handlers/responses.go index f745c6dbf..b2bfc73af 100644 --- a/cmd/api/handlers/responses.go +++ b/cmd/api/handlers/responses.go @@ -177,7 +177,6 @@ func (c *Contract) FromModel(contract contract.Contract) { c.Delegate = contract.Delegate.Address c.Level = contract.Level c.Manager = contract.Manager.Address - c.MigrationsCount = contract.MigrationsCount c.Tags = contract.Tags.ToArray() c.Timestamp = contract.Timestamp @@ -200,9 +199,7 @@ func (c *Contract) FromModel(contract contract.Contract) { type ContractWithStats struct { Contract - SameCount int64 `json:"same_count"` - EventsCount int `json:"events_count"` - HasTicketUpdates bool `json:"has_ticket_updates"` + SameCount int64 `json:"same_count"` } // RecentlyCalledContract - @@ -459,11 +456,14 @@ type Screenshot struct { // AccountInfo - type AccountInfo struct { - Address string `json:"address"` - Balance int64 `json:"balance"` - OperationsCount int64 `json:"operations_count"` - LastAction time.Time `json:"last_action"` - AccountType string `json:"account_type"` + Address string `json:"address"` + Balance int64 `json:"balance"` + OperationsCount int64 `json:"operations_count"` + MigrationsCount int64 `json:"migrations_count"` + EventsCount int64 `json:"events_count"` + TicketUpdatesCount int64 `json:"ticket_updates_count"` + LastAction time.Time `json:"last_action"` + AccountType string `json:"account_type"` } // CountResponse - diff --git a/cmd/indexer/indexer/indexer.go b/cmd/indexer/indexer/indexer.go index 5cdc7e439..97390f0d5 100644 --- a/cmd/indexer/indexer/indexer.go +++ b/cmd/indexer/indexer/indexer.go @@ -20,6 +20,7 @@ import ( "github.com/baking-bad/bcdhub/internal/parsers/protocols" "github.com/baking-bad/bcdhub/internal/postgres" "github.com/baking-bad/bcdhub/internal/postgres/core" + "github.com/baking-bad/bcdhub/internal/postgres/store" "github.com/baking-bad/bcdhub/internal/rollback" "github.com/dipdup-io/workerpool" "github.com/pkg/errors" @@ -292,7 +293,7 @@ func (bi *BlockchainIndexer) handleBlock(ctx context.Context, block *Block) erro } func (bi *BlockchainIndexer) parseAndSaveBlock(ctx context.Context, block *Block) error { - store := postgres.NewStore(bi.StorageDB.DB, bi.Stats) + store := store.NewStore(bi.StorageDB.DB, bi.Stats) if err := bi.parseImplicitOperations(ctx, block, bi.currentProtocol, store); err != nil { return err } diff --git a/internal/models/account/model.go b/internal/models/account/model.go index 004e4afd3..628b0ace5 100644 --- a/internal/models/account/model.go +++ b/internal/models/account/model.go @@ -11,12 +11,15 @@ import ( type Account struct { bun.BaseModel `bun:"accounts"` - ID int64 `bun:"id,pk,notnull,autoincrement"` - Type types.AccountType `bun:"type,type:SMALLINT"` - Address string `bun:"address,unique:address_hash"` - Level int64 `bun:"level"` - OperationsCount int64 `bun:"operations_count"` - LastAction time.Time `bun:"last_action"` + ID int64 `bun:"id,pk,notnull,autoincrement"` + Type types.AccountType `bun:"type,type:SMALLINT"` + Address string `bun:"address,unique:address_hash"` + Level int64 `bun:"level"` + LastAction time.Time `bun:"last_action"` + OperationsCount int64 `bun:"operations_count"` + MigrationsCount int64 `bun:"migrations_count"` + EventsCount int64 `bun:"events_count"` + TicketUpdatesCount int64 `bun:"ticket_updates_count"` } // GetID - diff --git a/internal/models/contract/model.go b/internal/models/contract/model.go index 8c7cc0a54..6afd69fc6 100644 --- a/internal/models/contract/model.go +++ b/internal/models/contract/model.go @@ -25,8 +25,7 @@ type Contract struct { DelegateID int64 Delegate account.Account `bun:"rel:belongs-to"` - MigrationsCount int64 - Tags types.Tags + Tags types.Tags AlphaID int64 Alpha Script `bun:"rel:belongs-to"` diff --git a/internal/models/migration/model.go b/internal/models/migration/model.go index 6fe1d3caf..baf7017a9 100644 --- a/internal/models/migration/model.go +++ b/internal/models/migration/model.go @@ -20,7 +20,7 @@ type Migration struct { Level int64 Kind types.MigrationKind `bun:"kind,type:SMALLINT"` ContractID int64 - Contract *contract.Contract `bun:"rel:belongs-to"` + Contract contract.Contract `bun:"rel:belongs-to"` } // GetID - diff --git a/internal/models/mock/operation/mock.go b/internal/models/mock/operation/mock.go index 626d3e55a..8b86968de 100644 --- a/internal/models/mock/operation/mock.go +++ b/internal/models/mock/operation/mock.go @@ -39,45 +39,6 @@ func (m *MockRepository) EXPECT() *MockRepositoryMockRecorder { return m.recorder } -// EventsCount mocks base method. -func (m *MockRepository) EventsCount(ctx context.Context, accountID int64) (int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EventsCount", ctx, accountID) - ret0, _ := ret[0].(int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// EventsCount indicates an expected call of EventsCount. -func (mr *MockRepositoryMockRecorder) EventsCount(ctx, accountID any) *RepositoryEventsCountCall { - mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EventsCount", reflect.TypeOf((*MockRepository)(nil).EventsCount), ctx, accountID) - return &RepositoryEventsCountCall{Call: call} -} - -// RepositoryEventsCountCall wrap *gomock.Call -type RepositoryEventsCountCall struct { - *gomock.Call -} - -// Return rewrite *gomock.Call.Return -func (c *RepositoryEventsCountCall) Return(arg0 int, arg1 error) *RepositoryEventsCountCall { - c.Call = c.Call.Return(arg0, arg1) - return c -} - -// Do rewrite *gomock.Call.Do -func (c *RepositoryEventsCountCall) Do(f func(context.Context, int64) (int, error)) *RepositoryEventsCountCall { - c.Call = c.Call.Do(f) - return c -} - -// DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *RepositoryEventsCountCall) DoAndReturn(f func(context.Context, int64) (int, error)) *RepositoryEventsCountCall { - c.Call = c.Call.DoAndReturn(f) - return c -} - // GetByHash mocks base method. func (m *MockRepository) GetByHash(ctx context.Context, hash []byte) ([]operation.Operation, error) { m.ctrl.T.Helper() diff --git a/internal/models/mock/rollback.go b/internal/models/mock/rollback.go index 375150397..9edc2889c 100644 --- a/internal/models/mock/rollback.go +++ b/internal/models/mock/rollback.go @@ -11,11 +11,12 @@ package mock import ( context "context" reflect "reflect" - time "time" models "github.com/baking-bad/bcdhub/internal/models" + account "github.com/baking-bad/bcdhub/internal/models/account" bigmapdiff "github.com/baking-bad/bcdhub/internal/models/bigmapdiff" contract "github.com/baking-bad/bcdhub/internal/models/contract" + migration "github.com/baking-bad/bcdhub/internal/models/migration" operation "github.com/baking-bad/bcdhub/internal/models/operation" stats "github.com/baking-bad/bcdhub/internal/models/stats" gomock "go.uber.org/mock/gomock" @@ -241,6 +242,45 @@ func (c *RollbackGetLastActionCall) DoAndReturn(f func(context.Context, ...int64 return c } +// GetMigrations mocks base method. +func (m *MockRollback) GetMigrations(ctx context.Context, level int64) ([]migration.Migration, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMigrations", ctx, level) + ret0, _ := ret[0].([]migration.Migration) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetMigrations indicates an expected call of GetMigrations. +func (mr *MockRollbackMockRecorder) GetMigrations(ctx, level any) *RollbackGetMigrationsCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMigrations", reflect.TypeOf((*MockRollback)(nil).GetMigrations), ctx, level) + return &RollbackGetMigrationsCall{Call: call} +} + +// RollbackGetMigrationsCall wrap *gomock.Call +type RollbackGetMigrationsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *RollbackGetMigrationsCall) Return(arg0 []migration.Migration, arg1 error) *RollbackGetMigrationsCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *RollbackGetMigrationsCall) Do(f func(context.Context, int64) ([]migration.Migration, error)) *RollbackGetMigrationsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *RollbackGetMigrationsCall) DoAndReturn(f func(context.Context, int64) ([]migration.Migration, error)) *RollbackGetMigrationsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + // GetOperations mocks base method. func (m *MockRollback) GetOperations(ctx context.Context, level int64) ([]operation.Operation, error) { m.ctrl.T.Helper() @@ -551,17 +591,17 @@ func (c *RollbackStatesChangedAtLevelCall) DoAndReturn(f func(context.Context, i } // UpdateAccountStats mocks base method. -func (m *MockRollback) UpdateAccountStats(ctx context.Context, accountId int64, lastAction time.Time, txCount int64) error { +func (m *MockRollback) UpdateAccountStats(ctx context.Context, account account.Account) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateAccountStats", ctx, accountId, lastAction, txCount) + ret := m.ctrl.Call(m, "UpdateAccountStats", ctx, account) ret0, _ := ret[0].(error) return ret0 } // UpdateAccountStats indicates an expected call of UpdateAccountStats. -func (mr *MockRollbackMockRecorder) UpdateAccountStats(ctx, accountId, lastAction, txCount any) *RollbackUpdateAccountStatsCall { +func (mr *MockRollbackMockRecorder) UpdateAccountStats(ctx, account any) *RollbackUpdateAccountStatsCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAccountStats", reflect.TypeOf((*MockRollback)(nil).UpdateAccountStats), ctx, accountId, lastAction, txCount) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAccountStats", reflect.TypeOf((*MockRollback)(nil).UpdateAccountStats), ctx, account) return &RollbackUpdateAccountStatsCall{Call: call} } @@ -577,13 +617,13 @@ func (c *RollbackUpdateAccountStatsCall) Return(arg0 error) *RollbackUpdateAccou } // Do rewrite *gomock.Call.Do -func (c *RollbackUpdateAccountStatsCall) Do(f func(context.Context, int64, time.Time, int64) error) *RollbackUpdateAccountStatsCall { +func (c *RollbackUpdateAccountStatsCall) Do(f func(context.Context, account.Account) error) *RollbackUpdateAccountStatsCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *RollbackUpdateAccountStatsCall) DoAndReturn(f func(context.Context, int64, time.Time, int64) error) *RollbackUpdateAccountStatsCall { +func (c *RollbackUpdateAccountStatsCall) DoAndReturn(f func(context.Context, account.Account) error) *RollbackUpdateAccountStatsCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/internal/models/mock/ticket/mock.go b/internal/models/mock/ticket/mock.go index 8b777ac27..ada34a5a6 100644 --- a/internal/models/mock/ticket/mock.go +++ b/internal/models/mock/ticket/mock.go @@ -116,42 +116,3 @@ func (c *RepositoryGetCall) DoAndReturn(f func(context.Context, string, int64, i c.Call = c.Call.DoAndReturn(f) return c } - -// Has mocks base method. -func (m *MockRepository) Has(ctx context.Context, contractID int64) (bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Has", ctx, contractID) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Has indicates an expected call of Has. -func (mr *MockRepositoryMockRecorder) Has(ctx, contractID any) *RepositoryHasCall { - mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Has", reflect.TypeOf((*MockRepository)(nil).Has), ctx, contractID) - return &RepositoryHasCall{Call: call} -} - -// RepositoryHasCall wrap *gomock.Call -type RepositoryHasCall struct { - *gomock.Call -} - -// Return rewrite *gomock.Call.Return -func (c *RepositoryHasCall) Return(arg0 bool, arg1 error) *RepositoryHasCall { - c.Call = c.Call.Return(arg0, arg1) - return c -} - -// Do rewrite *gomock.Call.Do -func (c *RepositoryHasCall) Do(f func(context.Context, int64) (bool, error)) *RepositoryHasCall { - c.Call = c.Call.Do(f) - return c -} - -// DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *RepositoryHasCall) DoAndReturn(f func(context.Context, int64) (bool, error)) *RepositoryHasCall { - c.Call = c.Call.DoAndReturn(f) - return c -} diff --git a/internal/models/operation/model.go b/internal/models/operation/model.go index c97d01428..21c9dd6ec 100644 --- a/internal/models/operation/model.go +++ b/internal/models/operation/model.go @@ -33,27 +33,27 @@ type Operation struct { PaidStorageSizeDiff int64 Burned int64 AllocatedDestinationContractBurned int64 - ProtocolID int64 `bun:",type:SMALLINT"` + ProtocolID int64 `bun:"protocol_id,type:SMALLINT"` TicketUpdatesCount int BigMapDiffsCount int Tags types.Tags - Nonce *int64 + Nonce *int64 `bun:"nonce,nullzero"` InitiatorID int64 - Initiator account.Account `bun:",rel:belongs-to"` + Initiator account.Account `bun:"rel:belongs-to"` SourceID int64 - Source account.Account `bun:",rel:belongs-to"` + Source account.Account `bun:"rel:belongs-to"` DestinationID int64 - Destination account.Account `bun:",rel:belongs-to"` + Destination account.Account `bun:"rel:belongs-to"` DelegateID int64 - Delegate account.Account `bun:",rel:belongs-to"` + Delegate account.Account `bun:"rel:belongs-to"` Timestamp time.Time `bun:"timestamp,pk,notnull"` - Status types.OperationStatus `bun:",type:SMALLINT"` - Kind types.OperationKind `bun:",type:SMALLINT"` + Status types.OperationStatus `bun:"status,type:SMALLINT"` + Kind types.OperationKind `bun:"kind,type:SMALLINT"` - Entrypoint types.NullString `bun:",type:text"` - Tag types.NullString `bun:",type:text"` + Entrypoint types.NullString `bun:"entrypoint,type:text"` + Tag types.NullString `bun:"tag,type:text"` Hash []byte Parameters []byte DeffatedStorage []byte @@ -61,7 +61,7 @@ type Operation struct { PayloadType []byte Script []byte `bun:"-"` - Errors tezerrors.Errors `bun:",type:bytea"` + Errors tezerrors.Errors `bun:"errors,type:bytea"` AST *ast.Script `bun:"-"` diff --git a/internal/models/operation/repository.go b/internal/models/operation/repository.go index 388099c16..86436b10e 100644 --- a/internal/models/operation/repository.go +++ b/internal/models/operation/repository.go @@ -13,5 +13,4 @@ type Repository interface { Origination(ctx context.Context, accountID int64) (Operation, error) GetByID(ctx context.Context, id int64) (Operation, error) ListEvents(ctx context.Context, accountID int64, size, offset int64) ([]Operation, error) - EventsCount(ctx context.Context, accountID int64) (int, error) } diff --git a/internal/models/rollback.go b/internal/models/rollback.go index 9425a6d0f..09ee7f715 100644 --- a/internal/models/rollback.go +++ b/internal/models/rollback.go @@ -4,8 +4,10 @@ import ( "context" "time" + "github.com/baking-bad/bcdhub/internal/models/account" "github.com/baking-bad/bcdhub/internal/models/bigmapdiff" "github.com/baking-bad/bcdhub/internal/models/contract" + "github.com/baking-bad/bcdhub/internal/models/migration" "github.com/baking-bad/bcdhub/internal/models/operation" "github.com/baking-bad/bcdhub/internal/models/stats" ) @@ -23,8 +25,9 @@ type Rollback interface { LastDiff(ctx context.Context, ptr int64, keyHash string, skipRemoved bool) (bigmapdiff.BigMapDiff, error) SaveBigMapState(ctx context.Context, state bigmapdiff.BigMapState) error GetOperations(ctx context.Context, level int64) ([]operation.Operation, error) + GetMigrations(ctx context.Context, level int64) ([]migration.Migration, error) GetLastAction(ctx context.Context, addressIds ...int64) ([]LastAction, error) - UpdateAccountStats(ctx context.Context, accountId int64, lastAction time.Time, txCount int64) error + UpdateAccountStats(ctx context.Context, account account.Account) error GlobalConstants(ctx context.Context, level int64) ([]contract.GlobalConstant, error) Scripts(ctx context.Context, level int64) ([]contract.Script, error) DeleteScriptsConstants(ctx context.Context, scriptIds []int64, constantsIds []int64) error diff --git a/internal/models/ticket/repository.go b/internal/models/ticket/repository.go index e8d0b722d..a2781daac 100644 --- a/internal/models/ticket/repository.go +++ b/internal/models/ticket/repository.go @@ -5,6 +5,5 @@ import "context" //go:generate mockgen -source=$GOFILE -destination=../mock/ticket/mock.go -package=ticket -typed type Repository interface { Get(ctx context.Context, ticketer string, limit, offset int64) ([]TicketUpdate, error) - Has(ctx context.Context, contractID int64) (bool, error) ForOperation(ctx context.Context, operationId int64) ([]TicketUpdate, error) } diff --git a/internal/parsers/migrations/alpha.go b/internal/parsers/migrations/alpha.go index ca3865230..672801108 100644 --- a/internal/parsers/migrations/alpha.go +++ b/internal/parsers/migrations/alpha.go @@ -63,6 +63,7 @@ func (p *Alpha) Parse(ctx context.Context, script noderpc.Script, old *modelsCon m := &migration.Migration{ ContractID: old.ID, + Contract: *old, Level: next.StartLevel, ProtocolID: next.ID, PrevProtocolID: previous.ID, diff --git a/internal/parsers/migrations/babylon.go b/internal/parsers/migrations/babylon.go index 1191bcfc1..06405e2ca 100644 --- a/internal/parsers/migrations/babylon.go +++ b/internal/parsers/migrations/babylon.go @@ -72,6 +72,7 @@ func (p *Babylon) Parse(ctx context.Context, script noderpc.Script, old *modelsC m := &migration.Migration{ ContractID: old.ID, + Contract: *old, Level: next.StartLevel, ProtocolID: next.ID, PrevProtocolID: previous.ID, diff --git a/internal/parsers/migrations/carthage.go b/internal/parsers/migrations/carthage.go index beecc210b..abcb67fb3 100644 --- a/internal/parsers/migrations/carthage.go +++ b/internal/parsers/migrations/carthage.go @@ -64,6 +64,7 @@ func (p *Carthage) Parse(ctx context.Context, script noderpc.Script, old *models m := &migration.Migration{ ContractID: old.ID, + Contract: *old, Level: next.StartLevel, ProtocolID: next.ID, PrevProtocolID: previous.ID, diff --git a/internal/parsers/migrations/implicit.go b/internal/parsers/migrations/implicit.go index af1350827..3ffc4aa96 100644 --- a/internal/parsers/migrations/implicit.go +++ b/internal/parsers/migrations/implicit.go @@ -63,6 +63,9 @@ func (p *ImplicitParser) IsMigratable(address string) bool { } func (p *ImplicitParser) origination(ctx context.Context, implicit noderpc.ImplicitOperationsResult, head noderpc.Header, store parsers.Store) error { + if len(implicit.OriginatedContracts) == 0 { + return nil + } if _, err := p.contractsRepo.Get(ctx, implicit.OriginatedContracts[0]); err == nil { return nil } @@ -77,6 +80,7 @@ func (p *ImplicitParser) origination(ctx context.Context, implicit noderpc.Impli Level: head.Level, OperationsCount: 1, LastAction: head.Timestamp, + MigrationsCount: 1, }, ConsumedGas: implicit.ConsumedGas, PaidStorageSizeDiff: implicit.PaidStorageSizeDiff, @@ -102,7 +106,7 @@ func (p *ImplicitParser) origination(ctx context.Context, implicit noderpc.Impli Level: head.Level, Timestamp: head.Timestamp, Kind: types.MigrationKindBootstrap, - Contract: contracts[i], + Contract: *contracts[i], }) break } diff --git a/internal/parsers/migrations/jakarta.go b/internal/parsers/migrations/jakarta.go index d663314a5..b3334365f 100644 --- a/internal/parsers/migrations/jakarta.go +++ b/internal/parsers/migrations/jakarta.go @@ -115,6 +115,7 @@ func (p *Jakarta) Parse(ctx context.Context, script noderpc.Script, old *modelsC m := &migration.Migration{ ContractID: old.ID, + Contract: *old, Level: next.StartLevel, ProtocolID: next.ID, PrevProtocolID: previous.ID, diff --git a/internal/parsers/migrations/vesting.go b/internal/parsers/migrations/vesting.go index 70c2997dc..8f27ce03e 100644 --- a/internal/parsers/migrations/vesting.go +++ b/internal/parsers/migrations/vesting.go @@ -42,9 +42,10 @@ func (p *VestingParser) Parse(ctx context.Context, data noderpc.ContractData, he Level: head.Level, }, Destination: account.Account{ - Address: address, - Type: types.NewAccountType(address), - Level: head.Level, + Address: address, + Type: types.NewAccountType(address), + Level: head.Level, + MigrationsCount: 1, }, Delegate: account.Account{ Address: data.Delegate.Value, @@ -73,7 +74,7 @@ func (p *VestingParser) Parse(ctx context.Context, data noderpc.ContractData, he ProtocolID: p.protocol.ID, Timestamp: head.Timestamp, Kind: types.MigrationKindBootstrap, - Contract: contracts[i], + Contract: *contracts[i], }) break } diff --git a/internal/parsers/operations/event.go b/internal/parsers/operations/event.go index f994668b0..e458e1b6b 100644 --- a/internal/parsers/operations/event.go +++ b/internal/parsers/operations/event.go @@ -28,6 +28,7 @@ func (p Event) Parse(ctx context.Context, data noderpc.Operation, store parsers. Level: p.head.Level, OperationsCount: 1, LastAction: p.head.Timestamp, + EventsCount: 1, } event := operation.Operation{ diff --git a/internal/parsers/operations/migration.go b/internal/parsers/operations/migration.go index 2c9e44a00..6614dcab6 100644 --- a/internal/parsers/operations/migration.go +++ b/internal/parsers/operations/migration.go @@ -96,6 +96,7 @@ func (m Migration) fromLazyStorageDiff(ctx context.Context, data noderpc.Operati return err } if migration != nil { + operation.Destination.MigrationsCount += 1 store.AddMigrations(migration) logger.Info().Fields(migration.LogFields()).Msg("Migration detected") } @@ -125,6 +126,7 @@ func (m Migration) fromBigMapDiffs(ctx context.Context, data noderpc.Operation, return err } if migration != nil { + operation.Destination.MigrationsCount += 1 store.AddMigrations(migration) logger.Info().Fields(migration.LogFields()).Msg("Migration detected") } @@ -155,6 +157,7 @@ func (m Migration) createMigration(ctx context.Context, value []byte, operation } return &migration.Migration{ ContractID: c.ID, + Contract: c, Level: operation.Level, ProtocolID: operation.ProtocolID, Timestamp: operation.Timestamp, diff --git a/internal/parsers/operations/migration_test.go b/internal/parsers/operations/migration_test.go index 84de26f66..4ef315730 100644 --- a/internal/parsers/operations/migration_test.go +++ b/internal/parsers/operations/migration_test.go @@ -61,6 +61,7 @@ func TestMigration_Parse(t *testing.T) { Timestamp: timestamp, Hash: []byte("hash"), Kind: types.MigrationKindLambda, + Contract: contract.Contract{}, }, }, } @@ -72,7 +73,7 @@ func TestMigration_Parse(t *testing.T) { contractRepo. EXPECT(). - Get(gomock.Any(), gomock.Eq(tt.operation.Destination.Address)). + Get(gomock.Any(), tt.operation.Destination.Address). Return(contract.Contract{}, nil). AnyTimes() diff --git a/internal/parsers/operations/ticket_updates.go b/internal/parsers/operations/ticket_updates.go index 056557a32..6ef2a2eff 100644 --- a/internal/parsers/operations/ticket_updates.go +++ b/internal/parsers/operations/ticket_updates.go @@ -38,9 +38,10 @@ func (p *TicketUpdateParser) toModel(data noderpc.TicketUpdate, operation *opera Level: operation.Level, Timestamp: operation.Timestamp, Ticketer: account.Account{ - Address: data.TicketToken.Ticketer, - Type: types.NewAccountType(data.TicketToken.Ticketer), - Level: operation.Level, + Address: data.TicketToken.Ticketer, + Type: types.NewAccountType(data.TicketToken.Ticketer), + Level: operation.Level, + TicketUpdatesCount: 1, }, ContentType: data.TicketToken.ContentType, Content: data.TicketToken.Content, diff --git a/internal/parsers/protocols/migration.go b/internal/parsers/protocols/migration.go index 83d815111..72ae6cf3a 100644 --- a/internal/parsers/protocols/migration.go +++ b/internal/parsers/protocols/migration.go @@ -11,7 +11,7 @@ import ( "github.com/baking-bad/bcdhub/internal/models/types" "github.com/baking-bad/bcdhub/internal/noderpc" "github.com/baking-bad/bcdhub/internal/parsers/migrations" - "github.com/baking-bad/bcdhub/internal/postgres" + "github.com/baking-bad/bcdhub/internal/postgres/store" "github.com/pkg/errors" ) @@ -124,7 +124,7 @@ func (m Migration) vestingMigration(ctx context.Context, tx models.Transaction, } p := migrations.NewVestingParser(m.ctx, specific.ContractParser, currentProtocol) - store := postgres.NewStore(m.ctx.StorageDB.DB, m.ctx.Stats) + store := store.NewStore(m.ctx.StorageDB.DB, m.ctx.Stats) for _, address := range addresses { if !bcd.IsContract(address) { diff --git a/internal/postgres/core/transaction.go b/internal/postgres/core/transaction.go index bc1b61476..4e44efec6 100644 --- a/internal/postgres/core/transaction.go +++ b/internal/postgres/core/transaction.go @@ -94,9 +94,12 @@ func (t Transaction) Accounts(ctx context.Context, accounts ...*account.Account) return nil } _, err := t.tx.NewInsert().Model(&accounts). - Column("address", "level", "type", "operations_count", "last_action"). + Column("address", "level", "type", "operations_count", "last_action", "events_count", "migrations_count", "ticket_updates_count"). On("CONFLICT ON CONSTRAINT address_hash DO UPDATE"). Set("operations_count = EXCLUDED.operations_count + account.operations_count"). + Set("events_count = EXCLUDED.events_count + account.events_count"). + Set("migrations_count = EXCLUDED.migrations_count + account.migrations_count"). + Set("ticket_updates_count = EXCLUDED.ticket_updates_count + account.ticket_updates_count"). Set("last_action = EXCLUDED.last_action"). Returning("id"). Exec(ctx) diff --git a/internal/postgres/operation/storage.go b/internal/postgres/operation/storage.go index 2b6bce2d7..1625b08a7 100644 --- a/internal/postgres/operation/storage.go +++ b/internal/postgres/operation/storage.go @@ -9,7 +9,6 @@ import ( "github.com/baking-bad/bcdhub/internal/helpers" "github.com/baking-bad/bcdhub/internal/models/account" "github.com/baking-bad/bcdhub/internal/models/operation" - "github.com/baking-bad/bcdhub/internal/models/types" "github.com/baking-bad/bcdhub/internal/postgres/core" "github.com/uptrace/bun" ) @@ -286,20 +285,12 @@ func (storage *Storage) ListEvents(ctx context.Context, accountID int64, size, o return } -// EventsCount - -func (storage *Storage) EventsCount(ctx context.Context, accountID int64) (int, error) { - return storage.DB.NewSelect().Model((*operation.Operation)(nil)). - Where("source_id = ?", accountID). - Where("kind = 7"). - Count(ctx) -} - // Origination - func (storage *Storage) Origination(ctx context.Context, accountID int64) (result operation.Operation, err error) { err = storage.DB.NewSelect(). Model(&result). Where("destination_id = ?", accountID). - Where("kind = ?", types.OperationKindOrigination). + Where("kind = 2"). Limit(1). Scan(ctx) return result, err diff --git a/internal/postgres/rollback.go b/internal/postgres/rollback.go index 12d05c20c..9d3df5642 100644 --- a/internal/postgres/rollback.go +++ b/internal/postgres/rollback.go @@ -2,12 +2,12 @@ package postgres import ( "context" - "time" "github.com/baking-bad/bcdhub/internal/models" "github.com/baking-bad/bcdhub/internal/models/account" "github.com/baking-bad/bcdhub/internal/models/bigmapdiff" "github.com/baking-bad/bcdhub/internal/models/contract" + "github.com/baking-bad/bcdhub/internal/models/migration" "github.com/baking-bad/bcdhub/internal/models/operation" "github.com/baking-bad/bcdhub/internal/models/protocol" "github.com/baking-bad/bcdhub/internal/models/stats" @@ -107,11 +107,14 @@ func (r Rollback) GetLastAction(ctx context.Context, addressIds ...int64) (actio return } -func (r Rollback) UpdateAccountStats(ctx context.Context, addressId int64, lastAction time.Time, operationsCount int64) error { - _, err := r.tx.NewUpdate().Model((*account.Account)(nil)). - Where("id = ?", addressId). - Set("operations_count = operations_count - ?", operationsCount). - Set("last_action = ?", lastAction). +func (r Rollback) UpdateAccountStats(ctx context.Context, account account.Account) error { + _, err := r.tx.NewUpdate().Model(&account). + Where("id = ?id"). + Set("operations_count = operations_count - ?operations_count"). + Set("migrations_count = migrations_count - ?migrations_count"). + Set("events_count = events_count - ?events_count"). + Set("ticket_updates_count = ticket_updates_count - ?ticket_updates_count"). + Set("last_action = ?last_action"). Exec(ctx) return err } @@ -169,17 +172,26 @@ func (r Rollback) UpdateStats(ctx context.Context, stats stats.Stats) error { _, err := r.tx.NewUpdate(). Model(&stats). Where("id = ?id"). - Set("contracts_count = stats.contracts_count - ?contracts_count"). - Set("operations_count = stats.operations_count - ?operations_count"). - Set("events_count = stats.events_count - ?events_count"). - Set("tx_count = stats.tx_count - ?tx_count"). - Set("originations_count = stats.originations_count - ?originations_count"). - Set("sr_originations_count = stats.sr_originations_count - ?sr_originations_count"). - Set("register_global_constants_count = stats.register_global_constants_count - ?register_global_constants_count"). - Set("sr_executes_count = stats.sr_executes_count - ?sr_executes_count"). - Set("transfer_tickets_count = stats.transfer_tickets_count - ?transfer_tickets_count"). - Set("global_constants_count = stats.global_constants_count - ?global_constants_count"). - Set("smart_rollups_count = stats.smart_rollups_count - ?smart_rollups_count"). + Set("contracts_count = ?contracts_count"). + Set("operations_count = ?operations_count"). + Set("events_count = ?events_count"). + Set("tx_count = ?tx_count"). + Set("originations_count = ?originations_count"). + Set("sr_originations_count = ?sr_originations_count"). + Set("register_global_constants_count = ?register_global_constants_count"). + Set("sr_executes_count = ?sr_executes_count"). + Set("transfer_tickets_count = ?transfer_tickets_count"). + Set("global_constants_count = ?global_constants_count"). + Set("smart_rollups_count = ?smart_rollups_count"). Exec(ctx) return err } + +func (r Rollback) GetMigrations(ctx context.Context, level int64) (migrations []migration.Migration, err error) { + err = r.tx.NewSelect().Model(&migrations). + ColumnExpr("account_id AS contract__account_id, migration.*"). + Where("migration.level = ?", level). + Join("LEFT JOIN contracts ON contracts.id = contract_id"). + Scan(ctx) + return +} diff --git a/internal/postgres/store.go b/internal/postgres/store.go deleted file mode 100644 index be725f875..000000000 --- a/internal/postgres/store.go +++ /dev/null @@ -1,404 +0,0 @@ -package postgres - -import ( - "context" - - "github.com/baking-bad/bcdhub/internal/models" - "github.com/baking-bad/bcdhub/internal/models/account" - "github.com/baking-bad/bcdhub/internal/models/bigmapdiff" - "github.com/baking-bad/bcdhub/internal/models/block" - "github.com/baking-bad/bcdhub/internal/models/contract" - "github.com/baking-bad/bcdhub/internal/models/migration" - "github.com/baking-bad/bcdhub/internal/models/operation" - smartrollup "github.com/baking-bad/bcdhub/internal/models/smart_rollup" - "github.com/baking-bad/bcdhub/internal/models/stats" - "github.com/baking-bad/bcdhub/internal/models/types" - "github.com/baking-bad/bcdhub/internal/postgres/core" - "github.com/pkg/errors" - "github.com/uptrace/bun" -) - -// Store - -type Store struct { - Block *block.Block - BigMapState []*bigmapdiff.BigMapState - Contracts []*contract.Contract - Migrations []*migration.Migration - Operations []*operation.Operation - GlobalConstants []*contract.GlobalConstant - SmartRollups []*smartrollup.SmartRollup - Accounts map[string]*account.Account - Stats stats.Stats - - stats stats.Repository - db *bun.DB - accIds map[string]int64 -} - -// NewStore - -func NewStore(db *bun.DB, statsRepo stats.Repository) *Store { - return &Store{ - BigMapState: make([]*bigmapdiff.BigMapState, 0), - Contracts: make([]*contract.Contract, 0), - Migrations: make([]*migration.Migration, 0), - Operations: make([]*operation.Operation, 0), - GlobalConstants: make([]*contract.GlobalConstant, 0), - SmartRollups: make([]*smartrollup.SmartRollup, 0), - Accounts: make(map[string]*account.Account), - Stats: stats.Stats{}, - stats: statsRepo, - db: db, - accIds: make(map[string]int64), - } -} - -func (store *Store) SetBlock(block *block.Block) { - store.Block = block -} - -// AddBigMapStates - -func (store *Store) AddBigMapStates(states ...*bigmapdiff.BigMapState) { - store.BigMapState = append(store.BigMapState, states...) -} - -// AddContracts - -func (store *Store) AddContracts(contracts ...*contract.Contract) { - store.Contracts = append(store.Contracts, contracts...) - - store.Stats.ContractsCount += len(contracts) -} - -// AddMigrations - -func (store *Store) AddMigrations(migrations ...*migration.Migration) { - store.Migrations = append(store.Migrations, migrations...) -} - -// AddOperations - -func (store *Store) AddOperations(operations ...*operation.Operation) { - store.Operations = append(store.Operations, operations...) - - store.Stats.OperationsCount += len(operations) - for i := range operations { - switch operations[i].Kind { - case types.OperationKindEvent: - store.Stats.EventsCount += 1 - case types.OperationKindOrigination, types.OperationKindOriginationNew: - store.Stats.OriginationsCount += 1 - case types.OperationKindSrOrigination: - store.Stats.SrOriginationsCount += 1 - case types.OperationKindTransaction: - store.Stats.TransactionsCount += 1 - case types.OperationKindRegisterGlobalConstant: - store.Stats.RegisterGlobalConstantCount += 1 - case types.OperationKindSrExecuteOutboxMessage: - store.Stats.SrExecutesCount += 1 - } - } -} - -// AddGlobalConstants - -func (store *Store) AddGlobalConstants(constants ...*contract.GlobalConstant) { - store.GlobalConstants = append(store.GlobalConstants, constants...) - store.Stats.GlobalConstantsCount += len(constants) -} - -// AddSmartRollups - -func (store *Store) AddSmartRollups(rollups ...*smartrollup.SmartRollup) { - store.SmartRollups = append(store.SmartRollups, rollups...) - store.Stats.ContractsCount += len(rollups) -} - -// AddAccounts - -func (store *Store) AddAccounts(accounts ...*account.Account) { - for i := range accounts { - if account, ok := store.Accounts[accounts[i].Address]; !ok { - store.Accounts[accounts[i].Address] = accounts[i] - } else { - account.OperationsCount += accounts[i].OperationsCount - } - } -} - -// ListContracts - -func (store *Store) ListContracts() []*contract.Contract { - return store.Contracts -} - -// ListOperations - -func (store *Store) ListOperations() []*operation.Operation { - return store.Operations -} - -// Save - -func (store *Store) Save(ctx context.Context) error { - stats, err := store.stats.Get(ctx) - if err != nil { - return err - } - store.Stats.ID = stats.ID - - tx, err := core.NewTransaction(ctx, store.db) - if err != nil { - return err - } - - if err := tx.Block(ctx, store.Block); err != nil { - return errors.Wrap(err, "saving block") - } - - if err := store.saveAccounts(ctx, tx); err != nil { - return errors.Wrap(err, "saving accounts") - } - - if err := store.saveOperations(ctx, tx); err != nil { - return errors.Wrap(err, "saving operations") - } - - if err := store.saveContracts(ctx, tx); err != nil { - return errors.Wrap(err, "saving contracts") - } - - if err := store.saveMigrations(ctx, tx); err != nil { - return errors.Wrap(err, "saving migrations") - } - - if err := tx.BigMapStates(ctx, store.BigMapState...); err != nil { - return errors.Wrap(err, "saving bigmap states") - } - - if err := tx.GlobalConstants(ctx, store.GlobalConstants...); err != nil { - return errors.Wrap(err, "saving bigmap states") - } - - if err := store.saveSmartRollups(ctx, tx); err != nil { - return errors.Wrap(err, "saving smart rollups") - } - - if err := tx.UpdateStats(ctx, store.Stats); err != nil { - return errors.Wrap(err, "saving stats") - } - - return tx.Commit() -} - -func (store *Store) saveAccounts(ctx context.Context, tx models.Transaction) error { - if len(store.Accounts) == 0 { - return nil - } - - arr := make([]*account.Account, 0, len(store.Accounts)) - for _, acc := range store.Accounts { - if acc.IsEmpty() { - continue - } - arr = append(arr, acc) - } - - if err := tx.Accounts(ctx, arr...); err != nil { - return err - } - - for i := range arr { - store.accIds[arr[i].Address] = arr[i].ID - } - - return nil -} - -func (store *Store) saveMigrations(ctx context.Context, tx models.Transaction) error { - if len(store.Migrations) == 0 { - return nil - } - - for i := range store.Migrations { - if store.Migrations[i].ContractID == 0 { - store.Migrations[i].ContractID = store.Migrations[i].Contract.ID - } - } - - return tx.Migrations(ctx, store.Migrations...) -} - -func (store *Store) saveSmartRollups(ctx context.Context, tx models.Transaction) error { - if len(store.SmartRollups) == 0 { - return nil - } - - for i, rollup := range store.SmartRollups { - if !rollup.Address.IsEmpty() { - if id, ok := store.accIds[rollup.Address.Address]; ok { - store.SmartRollups[i].AddressId = id - } else { - return errors.Errorf("unknown smart rollup account: %s", rollup.Address.Address) - } - } - } - - return tx.SmartRollups(ctx, store.SmartRollups...) -} - -func (store *Store) saveOperations(ctx context.Context, tx models.Transaction) error { - if len(store.Operations) == 0 { - return nil - } - - for i, operation := range store.Operations { - if !operation.Source.IsEmpty() { - if id, ok := store.accIds[operation.Source.Address]; ok { - store.Operations[i].SourceID = id - } else { - return errors.Errorf("unknown source account: %s", operation.Source.Address) - } - } - if !operation.Destination.IsEmpty() { - if id, ok := store.accIds[operation.Destination.Address]; ok { - store.Operations[i].DestinationID = id - } else { - return errors.Errorf("unknown destination account: %s", operation.Destination.Address) - } - } - if !store.Operations[i].Initiator.IsEmpty() { - if id, ok := store.accIds[operation.Initiator.Address]; ok { - store.Operations[i].InitiatorID = id - } else { - return errors.Errorf("unknown initiator account: %s", operation.Initiator.Address) - } - } - if !store.Operations[i].Delegate.IsEmpty() { - if id, ok := store.accIds[operation.Delegate.Address]; ok { - store.Operations[i].DelegateID = id - } else { - return errors.Errorf("unknown delegate account: %s", operation.Delegate.Address) - } - } - } - - if err := tx.Operations(ctx, store.Operations...); err != nil { - return errors.Wrap(err, "saving operations") - } - - for i := range store.Operations { - for j := range store.Operations[i].BigMapDiffs { - store.Operations[i].BigMapDiffs[j].OperationID = store.Operations[i].ID - } - for j := range store.Operations[i].BigMapActions { - store.Operations[i].BigMapActions[j].OperationID = store.Operations[i].ID - } - for j, update := range store.Operations[i].TickerUpdates { - if !update.Account.IsEmpty() { - if id, ok := store.accIds[update.Account.Address]; ok { - store.Operations[i].TickerUpdates[j].AccountID = id - } else { - return errors.Errorf("unknown ticket update account: %s", update.Account.Address) - } - } - if !update.Ticketer.IsEmpty() { - if id, ok := store.accIds[update.Ticketer.Address]; ok { - store.Operations[i].TickerUpdates[j].TicketerID = id - } else { - return errors.Errorf("unknown ticket update ticketer account: %s", update.Ticketer.Address) - } - } - store.Operations[i].TickerUpdates[j].OperationID = store.Operations[i].ID - } - - if err := tx.BigMapDiffs(ctx, store.Operations[i].BigMapDiffs...); err != nil { - return errors.Wrap(err, "saving bigmap diffs") - } - if err := tx.BigMapActions(ctx, store.Operations[i].BigMapActions...); err != nil { - return errors.Wrap(err, "saving bigmap actions") - } - if err := tx.TickerUpdates(ctx, store.Operations[i].TickerUpdates...); err != nil { - return errors.Wrap(err, "saving ticket updates") - } - } - return nil -} - -func (store *Store) saveContracts(ctx context.Context, tx models.Transaction) error { - if len(store.Contracts) == 0 { - return nil - } - - for i := range store.Contracts { - if store.Contracts[i].Alpha.Code != nil { - if err := tx.Scripts(ctx, &store.Contracts[i].Alpha); err != nil { - return err - } - store.Contracts[i].AlphaID = store.Contracts[i].Alpha.ID - } - if store.Contracts[i].Babylon.Code != nil { - if store.Contracts[i].Alpha.Hash != store.Contracts[i].Babylon.Hash { - if err := tx.Scripts(ctx, &store.Contracts[i].Babylon); err != nil { - return err - } - store.Contracts[i].BabylonID = store.Contracts[i].Babylon.ID - - if len(store.Contracts[i].Babylon.Constants) > 0 { - for j := range store.Contracts[i].Babylon.Constants { - relation := contract.ScriptConstants{ - ScriptId: store.Contracts[i].BabylonID, - GlobalConstantId: store.Contracts[i].Babylon.Constants[j].ID, - } - if err := tx.ScriptConstant(ctx, &relation); err != nil { - return err - } - } - } - - } else { - store.Contracts[i].BabylonID = store.Contracts[i].Alpha.ID - } - } - if store.Contracts[i].Jakarta.Code != nil { - if store.Contracts[i].Babylon.Hash != store.Contracts[i].Jakarta.Hash { - if err := tx.Scripts(ctx, &store.Contracts[i].Jakarta); err != nil { - return err - } - store.Contracts[i].JakartaID = store.Contracts[i].Jakarta.ID - - if len(store.Contracts[i].Jakarta.Constants) > 0 { - for j := range store.Contracts[i].Jakarta.Constants { - relation := contract.ScriptConstants{ - ScriptId: store.Contracts[i].JakartaID, - GlobalConstantId: store.Contracts[i].Jakarta.Constants[j].ID, - } - if err := tx.ScriptConstant(ctx, &relation); err != nil { - return err - } - } - } - - } else { - store.Contracts[i].JakartaID = store.Contracts[i].Babylon.ID - } - } - - if id, ok := store.accIds[store.Contracts[i].Account.Address]; ok { - store.Contracts[i].AccountID = id - } else { - return errors.Errorf("unknown contract account: %s", store.Contracts[i].Account.Address) - } - - if !store.Contracts[i].Manager.IsEmpty() { - if id, ok := store.accIds[store.Contracts[i].Manager.Address]; ok { - store.Contracts[i].ManagerID = id - } else { - return errors.Errorf("unknown manager account: %s", store.Contracts[i].Manager.Address) - } - } - if !store.Contracts[i].Delegate.IsEmpty() { - if id, ok := store.accIds[store.Contracts[i].Delegate.Address]; ok { - store.Contracts[i].DelegateID = id - } else { - return errors.Errorf("unknown delegate account: %s", store.Contracts[i].Delegate.Address) - } - } - } - - if err := tx.Contracts(ctx, store.Contracts...); err != nil { - return err - } - - return nil -} diff --git a/internal/postgres/store/operations.go b/internal/postgres/store/operations.go new file mode 100644 index 000000000..bd1e02ef1 --- /dev/null +++ b/internal/postgres/store/operations.go @@ -0,0 +1,29 @@ +package store + +import ( + "github.com/baking-bad/bcdhub/internal/models/operation" + "github.com/baking-bad/bcdhub/internal/models/types" +) + +// AddOperations - +func (store *Store) AddOperations(operations ...*operation.Operation) { + store.Operations = append(store.Operations, operations...) + + store.Stats.OperationsCount += len(operations) + for i := range operations { + switch operations[i].Kind { + case types.OperationKindEvent: + store.Stats.EventsCount += 1 + case types.OperationKindOrigination, types.OperationKindOriginationNew: + store.Stats.OriginationsCount += 1 + case types.OperationKindSrOrigination: + store.Stats.SrOriginationsCount += 1 + case types.OperationKindTransaction: + store.Stats.TransactionsCount += 1 + case types.OperationKindRegisterGlobalConstant: + store.Stats.RegisterGlobalConstantCount += 1 + case types.OperationKindSrExecuteOutboxMessage: + store.Stats.SrExecutesCount += 1 + } + } +} diff --git a/internal/postgres/store/save.go b/internal/postgres/store/save.go new file mode 100644 index 000000000..09fe4527e --- /dev/null +++ b/internal/postgres/store/save.go @@ -0,0 +1,305 @@ +package store + +import ( + "context" + + "github.com/baking-bad/bcdhub/internal/models" + "github.com/baking-bad/bcdhub/internal/models/account" + "github.com/baking-bad/bcdhub/internal/models/bigmapaction" + "github.com/baking-bad/bcdhub/internal/models/bigmapdiff" + "github.com/baking-bad/bcdhub/internal/models/contract" + "github.com/baking-bad/bcdhub/internal/models/operation" + "github.com/baking-bad/bcdhub/internal/models/ticket" + "github.com/baking-bad/bcdhub/internal/postgres/core" + "github.com/pkg/errors" +) + +// Save - +func (store *Store) Save(ctx context.Context) error { + stats, err := store.stats.Get(ctx) + if err != nil { + return err + } + store.Stats.ID = stats.ID + + tx, err := core.NewTransaction(ctx, store.db) + if err != nil { + return err + } + + if err := tx.Block(ctx, store.Block); err != nil { + return errors.Wrap(err, "saving block") + } + + if err := store.saveAccounts(ctx, tx); err != nil { + return errors.Wrap(err, "saving accounts") + } + + if err := store.saveOperations(ctx, tx); err != nil { + return errors.Wrap(err, "saving operations") + } + + if err := store.saveContracts(ctx, tx); err != nil { + return errors.Wrap(err, "saving contracts") + } + + if err := store.saveMigrations(ctx, tx); err != nil { + return errors.Wrap(err, "saving migrations") + } + + if err := tx.BigMapStates(ctx, store.BigMapState...); err != nil { + return errors.Wrap(err, "saving bigmap states") + } + + if err := tx.GlobalConstants(ctx, store.GlobalConstants...); err != nil { + return errors.Wrap(err, "saving bigmap states") + } + + if err := store.saveSmartRollups(ctx, tx); err != nil { + return errors.Wrap(err, "saving smart rollups") + } + + if err := tx.UpdateStats(ctx, store.Stats); err != nil { + return errors.Wrap(err, "saving stats") + } + + return tx.Commit() +} + +func (store *Store) saveAccounts(ctx context.Context, tx models.Transaction) error { + if len(store.Accounts) == 0 { + return nil + } + + arr := make([]*account.Account, 0, len(store.Accounts)) + for _, acc := range store.Accounts { + if acc.IsEmpty() { + continue + } + arr = append(arr, acc) + } + + if err := tx.Accounts(ctx, arr...); err != nil { + return err + } + + for i := range arr { + store.accIds[arr[i].Address] = arr[i].ID + } + + return nil +} + +func (store *Store) saveMigrations(ctx context.Context, tx models.Transaction) error { + if len(store.Migrations) == 0 { + return nil + } + + for i := range store.Migrations { + if store.Migrations[i].ContractID == 0 { + store.Migrations[i].ContractID = store.Migrations[i].Contract.ID + } + } + + return tx.Migrations(ctx, store.Migrations...) +} + +func (store *Store) saveSmartRollups(ctx context.Context, tx models.Transaction) error { + if len(store.SmartRollups) == 0 { + return nil + } + + for i, rollup := range store.SmartRollups { + if id, ok := store.getAccountId(rollup.Address); ok { + store.SmartRollups[i].AddressId = id + } else { + return errors.Errorf("unknown smart rollup account: %s", rollup.Address.Address) + } + } + + return tx.SmartRollups(ctx, store.SmartRollups...) +} + +func (store *Store) saveOperations(ctx context.Context, tx models.Transaction) error { + if len(store.Operations) == 0 { + return nil + } + + for i := range store.Operations { + if err := store.setOperationAccountsId(store.Operations[i]); err != nil { + return err + } + } + + if err := tx.Operations(ctx, store.Operations...); err != nil { + return errors.Wrap(err, "saving operations") + } + + var ( + bigMapDiffs = make([]*bigmapdiff.BigMapDiff, 0) + bigMapActions = make([]*bigmapaction.BigMapAction, 0) + ticketUpdates = make([]*ticket.TicketUpdate, 0) + ) + + for _, operation := range store.Operations { + for j := range operation.BigMapDiffs { + operation.BigMapDiffs[j].OperationID = operation.ID + } + bigMapDiffs = append(bigMapDiffs, operation.BigMapDiffs...) + + for j := range operation.BigMapActions { + operation.BigMapActions[j].OperationID = operation.ID + } + bigMapActions = append(bigMapActions, operation.BigMapActions...) + + for j, update := range operation.TickerUpdates { + if id, ok := store.getAccountId(update.Account); ok { + operation.TickerUpdates[j].AccountID = id + } else { + return errors.Errorf("unknown ticket update account: %s", update.Account.Address) + } + + if id, ok := store.getAccountId(update.Ticketer); ok { + operation.TickerUpdates[j].TicketerID = id + } else { + return errors.Errorf("unknown ticket update ticketer account: %s", update.Ticketer.Address) + } + + operation.TickerUpdates[j].OperationID = operation.ID + } + + ticketUpdates = append(ticketUpdates, operation.TickerUpdates...) + } + + if err := tx.BigMapDiffs(ctx, bigMapDiffs...); err != nil { + return errors.Wrap(err, "saving bigmap diffs") + } + if err := tx.BigMapActions(ctx, bigMapActions...); err != nil { + return errors.Wrap(err, "saving bigmap actions") + } + if err := tx.TickerUpdates(ctx, ticketUpdates...); err != nil { + return errors.Wrap(err, "saving ticket updates") + } + return nil +} + +func (store *Store) setOperationAccountsId(operation *operation.Operation) error { + if id, ok := store.getAccountId(operation.Source); ok { + operation.SourceID = id + } else { + return errors.Errorf("unknown source account: %s", operation.Source.Address) + } + + if id, ok := store.getAccountId(operation.Destination); ok { + operation.DestinationID = id + } else { + return errors.Errorf("unknown destination account: %s", operation.Destination.Address) + } + + if id, ok := store.getAccountId(operation.Initiator); ok { + operation.InitiatorID = id + } else { + return errors.Errorf("unknown initiator account: %s", operation.Initiator.Address) + } + + if id, ok := store.getAccountId(operation.Delegate); ok { + operation.DelegateID = id + } else { + return errors.Errorf("unknown delegate account: %s", operation.Delegate.Address) + } + + return nil +} + +func (store *Store) getAccountId(acc account.Account) (int64, bool) { + if acc.IsEmpty() { + return 0, true + } + id, ok := store.accIds[acc.Address] + return id, ok +} + +func (store *Store) saveContracts(ctx context.Context, tx models.Transaction) error { + if len(store.Contracts) == 0 { + return nil + } + + for i := range store.Contracts { + if store.Contracts[i].Alpha.Code != nil { + if err := tx.Scripts(ctx, &store.Contracts[i].Alpha); err != nil { + return err + } + store.Contracts[i].AlphaID = store.Contracts[i].Alpha.ID + } + if store.Contracts[i].Babylon.Code != nil { + if store.Contracts[i].Alpha.Hash != store.Contracts[i].Babylon.Hash { + if err := tx.Scripts(ctx, &store.Contracts[i].Babylon); err != nil { + return err + } + store.Contracts[i].BabylonID = store.Contracts[i].Babylon.ID + + if len(store.Contracts[i].Babylon.Constants) > 0 { + for j := range store.Contracts[i].Babylon.Constants { + relation := contract.ScriptConstants{ + ScriptId: store.Contracts[i].BabylonID, + GlobalConstantId: store.Contracts[i].Babylon.Constants[j].ID, + } + if err := tx.ScriptConstant(ctx, &relation); err != nil { + return err + } + } + } + + } else { + store.Contracts[i].BabylonID = store.Contracts[i].Alpha.ID + } + } + if store.Contracts[i].Jakarta.Code != nil { + if store.Contracts[i].Babylon.Hash != store.Contracts[i].Jakarta.Hash { + if err := tx.Scripts(ctx, &store.Contracts[i].Jakarta); err != nil { + return err + } + store.Contracts[i].JakartaID = store.Contracts[i].Jakarta.ID + + if len(store.Contracts[i].Jakarta.Constants) > 0 { + for j := range store.Contracts[i].Jakarta.Constants { + relation := contract.ScriptConstants{ + ScriptId: store.Contracts[i].JakartaID, + GlobalConstantId: store.Contracts[i].Jakarta.Constants[j].ID, + } + if err := tx.ScriptConstant(ctx, &relation); err != nil { + return err + } + } + } + + } else { + store.Contracts[i].JakartaID = store.Contracts[i].Babylon.ID + } + } + + if id, ok := store.getAccountId(store.Contracts[i].Account); ok { + store.Contracts[i].AccountID = id + } else { + return errors.Errorf("unknown contract account: %s", store.Contracts[i].Account.Address) + } + + if id, ok := store.getAccountId(store.Contracts[i].Manager); ok { + store.Contracts[i].ManagerID = id + } else { + return errors.Errorf("unknown manager account: %s", store.Contracts[i].Manager.Address) + } + + if id, ok := store.getAccountId(store.Contracts[i].Delegate); ok { + store.Contracts[i].DelegateID = id + } else { + return errors.Errorf("unknown delegate account: %s", store.Contracts[i].Delegate.Address) + } + } + + if err := tx.Contracts(ctx, store.Contracts...); err != nil { + return err + } + + return nil +} diff --git a/internal/postgres/store/store.go b/internal/postgres/store/store.go new file mode 100644 index 000000000..f17adfb70 --- /dev/null +++ b/internal/postgres/store/store.go @@ -0,0 +1,116 @@ +package store + +import ( + "github.com/baking-bad/bcdhub/internal/models/account" + "github.com/baking-bad/bcdhub/internal/models/bigmapdiff" + "github.com/baking-bad/bcdhub/internal/models/block" + "github.com/baking-bad/bcdhub/internal/models/contract" + "github.com/baking-bad/bcdhub/internal/models/migration" + "github.com/baking-bad/bcdhub/internal/models/operation" + smartrollup "github.com/baking-bad/bcdhub/internal/models/smart_rollup" + "github.com/baking-bad/bcdhub/internal/models/stats" + "github.com/uptrace/bun" +) + +// Store - +type Store struct { + Block *block.Block + BigMapState []*bigmapdiff.BigMapState + Contracts []*contract.Contract + Migrations []*migration.Migration + Operations []*operation.Operation + GlobalConstants []*contract.GlobalConstant + SmartRollups []*smartrollup.SmartRollup + Accounts map[string]*account.Account + Stats stats.Stats + + stats stats.Repository + db *bun.DB + accIds map[string]int64 +} + +// NewStore - +func NewStore(db *bun.DB, statsRepo stats.Repository) *Store { + return &Store{ + BigMapState: make([]*bigmapdiff.BigMapState, 0), + Contracts: make([]*contract.Contract, 0), + Migrations: make([]*migration.Migration, 0), + Operations: make([]*operation.Operation, 0), + GlobalConstants: make([]*contract.GlobalConstant, 0), + SmartRollups: make([]*smartrollup.SmartRollup, 0), + Accounts: make(map[string]*account.Account), + Stats: stats.Stats{}, + stats: statsRepo, + db: db, + accIds: make(map[string]int64), + } +} + +func (store *Store) SetBlock(block *block.Block) { + store.Block = block +} + +// AddBigMapStates - +func (store *Store) AddBigMapStates(states ...*bigmapdiff.BigMapState) { + store.BigMapState = append(store.BigMapState, states...) +} + +// AddContracts - +func (store *Store) AddContracts(contracts ...*contract.Contract) { + store.Contracts = append(store.Contracts, contracts...) + + store.Stats.ContractsCount += len(contracts) +} + +// AddMigrations - +func (store *Store) AddMigrations(migrations ...*migration.Migration) { + store.Migrations = append(store.Migrations, migrations...) + + for i := range migrations { + if migrations[i].Contract.Account.IsEmpty() { + continue + } + + if account, ok := store.Accounts[migrations[i].Contract.Account.Address]; !ok { + store.Accounts[migrations[i].Contract.Account.Address] = &migrations[i].Contract.Account + } else { + account.MigrationsCount += 1 + } + } +} + +// AddGlobalConstants - +func (store *Store) AddGlobalConstants(constants ...*contract.GlobalConstant) { + store.GlobalConstants = append(store.GlobalConstants, constants...) + store.Stats.GlobalConstantsCount += len(constants) +} + +// AddSmartRollups - +func (store *Store) AddSmartRollups(rollups ...*smartrollup.SmartRollup) { + store.SmartRollups = append(store.SmartRollups, rollups...) + store.Stats.ContractsCount += len(rollups) +} + +// AddAccounts - +func (store *Store) AddAccounts(accounts ...*account.Account) { + for i := range accounts { + if account, ok := store.Accounts[accounts[i].Address]; !ok { + store.Accounts[accounts[i].Address] = accounts[i] + } else { + account.OperationsCount += accounts[i].OperationsCount + account.EventsCount += accounts[i].EventsCount + account.MigrationsCount += accounts[i].MigrationsCount + account.TicketUpdatesCount += accounts[i].TicketUpdatesCount + } + } +} + +// ListContracts - +func (store *Store) ListContracts() []*contract.Contract { + return store.Contracts +} + +// ListOperations - +func (store *Store) ListOperations() []*operation.Operation { + return store.Operations +} diff --git a/internal/postgres/tests/fixtures/accounts.yml b/internal/postgres/tests/fixtures/accounts.yml index 1b82c3774..c1e9992c7 100644 --- a/internal/postgres/tests/fixtures/accounts.yml +++ b/internal/postgres/tests/fixtures/accounts.yml @@ -4,704 +4,1058 @@ level: 1 operations_count: 0 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1AafHA1C1vk959wvHWBispY9Y2f3fxBUUo id: 3 last_action: 0001-01-01T00:00:00Z level: 1 operations_count: 0 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5 id: 2 last_action: 2022-01-25T17:01:51Z level: 1 operations_count: 39 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz28zXKvosLUdFyYZKQU1vPxcedWzjRypApr id: 35 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2EeYh11ZkpkaY7CxqhVGRygcwbEQZZHmF3 id: 36 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2Gw352Tj8pdu3EPrd8K9jDh4JmndbDGYVx id: 38 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2DTRTbhRx6Yp1pVXpwSZPiHZwudpEaYYyU id: 39 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1Bc3T8ZcYPTTZHLTrAh2exfw6hyaTriMpQ id: 40 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1W3fGSo8XfRSESPAg3Jngzt3D8xpPqW64i id: 41 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2WFEmgnWqFY6FWBMFgrS4MW4c3pJRS8nzU id: 42 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1Ugw1u7ytn4YsWx8hFGcBFrddf3U6EsYTS id: 43 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2VK6tUXWA6y4QGNEVW4FPDiPu4nHNAabzj id: 44 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1CMJQmuwwJopNnLhSDHXT3zQVUrNPLA8br id: 45 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2JJACvm6AzjV7m313kRJie5ZwY74EKTRiT id: 46 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1Pz65ssbPF7Zv9Dh7ggqUkgAYNSuJ9iia7 id: 47 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1JFFa3ARM7cGxjLJ4CuynKq2pmYv1GupFM id: 48 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT18cv2aErkY6yf6SspaK9koxiDKJKfuacrD id: 49 last_action: 2022-01-25T16:45:09Z level: 33 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2PkJNxRVc7fFnjTRrtyxWTLRf4buUCjPM5 id: 50 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1Gv5StW6rsCfuMW8kXN6XcZbbnxJP1SjKs id: 51 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2CSAMfsuGQYtYoSZHsXkgDpbzSkyVyuMKZ id: 53 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1L6qnSbi7gCqbwKzGBqzbepxHNC5zR9Egj id: 54 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1BNS3XGWDJM2Yghm3CYosKStE9reNscbfE id: 55 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2DjmnH4NawbMmaJfBiqnDPUjAkv8Wtoc6A id: 56 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1N2EjRy5vmT6if7c6rx5g9BSsx3iUnTD4U id: 57 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1M1HSELdzFjFdrea4xAwzG1bG3pNtWLcjc id: 58 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1QyWsqRDsucjbjYvDa3Yr122oecdu3DEiC id: 59 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2FdYpfM1bv5R9N36tbov96nco7pH3G4ZfP id: 60 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2LGccCpDMTbDB3RVABT2kp93H4ayvmWqKL id: 61 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2P3CUbKHsKUWTnhGGYFCXFnB1WAr41TEhN id: 62 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2L7g8Mbi25WjF7Rgc1YqUZUToqQkqgyTQa id: 63 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1WTSLx8VnUNFMJGegUELLdg54zpvt82trD id: 64 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2McXsY5sJk8aupG53MT8VoG8XkS4QhjGLE id: 65 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1SsjnMpj4NJvUZZgEi3PkwB7dsqJviUH55 id: 66 last_action: 2022-01-25T16:47:37Z level: 34 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2GtWZf4emNRmcmQNsKu7XmAWMXhSyjc4qm id: 67 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1PH3UK1BFzYYCbSrarpai9wnVMGr57A6fn id: 68 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1BZJFEifWnscmwTPQonMufy7WZGKvzVhza id: 69 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1J8Ar7hfJEbbao4MfYhegTCgjtNaKTNTAx id: 71 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1KBbnu8MKKMmaH7i2VPZAB6PYZ7LGAMak9 id: 72 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2NgBSz3K3waxZoRSBjY8VtnWdtztRQotKX id: 73 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2UH4fxCq1Lq5GyzBmgye4pxXSTU7Qr5crU id: 74 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2NGd6dy3RHrLc8UkGAC2YaouPebutRpPz3 id: 75 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2XP666xYuWttBWJLT1RnfniAL2hgLDsgmj id: 76 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1EtstqV7RgirhbB25uJruV83pGkZkEFQCe id: 77 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2CUyGyhjS5A4SJoRiJBFrTCNgtCwuAcvUf id: 78 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1XKhK1QZWLrLntWhaDpaqEkuR57CYuWKk3 id: 79 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2Ka219QMSec5qq5nYP7FcTju55Dqz3iSNu id: 80 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1H59QHJgqmiZ2Cfvw3MUUaPFxjWcowFVhY id: 81 last_action: 2022-01-25T16:49:57Z level: 35 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1Cpif3AepmaRe17AQtHiQ1Bt6P1CwzgX1j id: 82 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2FyXQJyBKxn5zmpcbczWskW6nhkmQto5sF id: 83 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz28tMBu8yTiRukhnjJE6g5VMXWKdMbZ4XH2 id: 84 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1S1k4CKmLn6Bz95NT6HmeRzzJwaaRyCY7Q id: 85 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2WKMzRRFrsWzi5MUH4bhx2ZBwu2y36hQhJ id: 86 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1F6hdHeL6ceJtKHGnWj397SMqP4x4v3Mas id: 87 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1EM1ae3RznqNYjvuRvepdrveogsq2SoPpF id: 89 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2H48i7m5BBFZddm1Ek6dUYcjKzXcU7SzLe id: 90 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1MpEYtKWzgmpjFxryKvBC3dMuvD64Bt7pv id: 93 last_action: 2022-01-25T16:52:19Z level: 36 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1RPs9iqAj4rRDyecoDz6RqhF2dVfRtWi78 id: 95 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz3SCFL6gjXrSAzT2cvN9bemgPBdJCpf9r6B id: 96 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1JHuz6B6HC5gaot8AGHd2UhkUd9Z2BgYW5 id: 97 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1UjbtbMAXR29QgyRus71pniSjL4R7c1EML id: 98 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1JNf4bXhbz8WZTATQvmdTxGE5k5qBV9q82 id: 99 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz3iiAKWuACM7DDXZ3kDnRh6vkF2Sx2rQLNF id: 100 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT19WNvB1Wt6XRevhDNQ9vNTUN4A8Jqx16w4 id: 101 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2CMxYEv6PY2asiihtoSF8a1Hbi95wtHGbQ id: 92 last_action: 2022-01-25T16:54:35Z level: 36 operations_count: 2 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT18sWFGnjvobw9BiHrm9bjpWr3AFAAVas9w id: 88 last_action: 2022-01-25T16:54:35Z level: 36 operations_count: 3 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2M6ERPpdK2xpgZahXTF99MV5Bw8DmUg56M id: 104 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2MQ4tKVdEYxN69FcATE6cUgv9nfRHYxRva id: 105 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2P74gV25xGQrrLA9yru2RLDPpciirJ94Qv id: 94 last_action: 2022-01-25T16:54:35Z level: 36 operations_count: 2 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz28nwcXsECuhiRwNR5cT83Shj75WszMpKFK id: 108 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1LBiP4VgzuV9BV62wHiGhetE6saTbs4XSk id: 109 last_action: 2022-01-25T16:54:35Z level: 37 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1K4FMgPePdryt7g4vh4ckFWuwbVQYMDLLL id: 111 last_action: 2022-01-25T16:56:47Z level: 38 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2V2gbEzZUJ4orVzw74BdLTXGXJc1y8vxK4 id: 112 last_action: 2022-01-25T16:56:47Z level: 38 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1RzNBqpENY1D8cKXvbAA2G1oavw49J8pYG id: 113 last_action: 2022-01-25T16:56:47Z level: 38 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2M3Jt5X57D7i6v6QNJ6ZipdnRjnRM3pPyh id: 114 last_action: 2022-01-25T16:56:47Z level: 38 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1WfndvipjhvmJ7XoHTHJYDvTncPkgdEGWm id: 118 last_action: 2022-01-25T16:56:47Z level: 38 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2FgaxCo6yfLSuFRQ1bEy1zSntv9wKWX1b6 id: 119 last_action: 2022-01-25T16:56:47Z level: 38 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1MXcocFTwXV2emtgHAC7tCUt4Zc3EPPZAE id: 120 last_action: 2022-01-25T16:56:47Z level: 38 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2AGpSkHSMKw7G1q7roseheDVYmmRjNCkb5 id: 126 last_action: 2022-01-25T16:59:07Z level: 39 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1PA9pnZvJRHRxNhw1KqofBRBSTsgt6NeMz id: 122 last_action: 2022-01-25T16:59:07Z level: 38 operations_count: 7 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2GGf91VB3gK7MaaP8Xua6ohhHAhH4hTCvm id: 124 last_action: 2022-01-25T16:59:07Z level: 38 operations_count: 5 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1SnnGQTcQFv55Bkw7CKnVmr1rrvN4ZRkve id: 129 last_action: 2022-01-25T16:59:07Z level: 39 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1MWHRFxLq7gnToNvhKCCsiiic5BypKzkmW id: 116 last_action: 2022-01-25T16:59:07Z level: 38 operations_count: 3 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1BrG24EYvtYGeGgd615Yzhvoa14BNPLZzu id: 132 last_action: 2022-01-25T16:59:07Z level: 39 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1SM849krq9FFxGWCZyc7X5GvAz8XnRmXnf id: 133 last_action: 2022-01-25T16:59:07Z level: 39 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2Ciu1uCBQDgeBM1HSzzeWzihzxZ1RRADpy id: 123 last_action: 2022-01-25T16:59:07Z level: 38 operations_count: 5 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2CA5QvX5UyFkxkW5ySXT8gLoyyBdhJ8h2f id: 135 last_action: 2022-01-25T16:59:07Z level: 39 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2X3jvMNLAwU54d1UWkJX1ntQNpCuT4Uexk id: 117 last_action: 2022-01-25T16:59:07Z level: 38 operations_count: 2 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2QYqyuBciQWA6nH2pB4XU9zyg1bREnorzc id: 139 last_action: 2022-01-25T16:59:07Z level: 39 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1Cec7gww3sHZZ9zHFMPi5U5HqKdi5ytL13 id: 110 last_action: 2022-01-25T16:59:07Z level: 38 operations_count: 7 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1EcQVhDC7izqW3uiGVrqbus6qBt78btyHv id: 141 last_action: 2022-01-25T16:59:07Z level: 39 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2W7qKNpsUDLs64KenWdt9HsgXigHvtMDT6 id: 115 last_action: 2022-01-25T16:59:07Z level: 38 operations_count: 2 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1FwXdpRRQstV7XWweSKLReB3C5Fy52dLvE id: 137 last_action: 2022-01-25T17:01:51Z level: 39 operations_count: 7 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2SKuR2hfqMFo7gKuzFSL9jUXefsucj28Zp id: 144 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1TYdptHAspE8JSB2XmzVrNze4gbCA2AuDN id: 145 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1UF6hwuvFAxwcwLsXJyiu1q1T1KDZ3yZez id: 146 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2FizizmVED2T4D5y5wn4B9kpZLaE66zSAp id: 147 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1DWPyUzA7z2iDKrFpVvRdWPZKEEYueRoAg id: 148 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2BauU3guWNGbn2qCQWK2UaAE74AdSMRwnX id: 149 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1NSpRTVR4MUwx64XCADXDUmpMGQw5yVNK1 id: 150 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2KJHRduQNH3fBrmywJ3HWHqPHMu3fmaKc5 id: 151 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2MeNdvFPELDgbnmhLdiKHh9196gTfruEdy id: 130 last_action: 2022-01-25T17:01:51Z level: 39 operations_count: 5 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh id: 125 last_action: 2022-01-25T17:01:51Z level: 39 operations_count: 3 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1FEMzUropmcrhNJ3Zw1iduatxZxkLCiqCd id: 154 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT18vZxXVGtyZWRHaka7hivkE14wBbYLXhVC id: 156 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2JPf1WqpTd5MoSmyKtRL2UAZJ9mvjZabjp id: 157 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2DBVWEam4raYjJR1bXpKyULNDz8RkyRmuw id: 158 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: tz2LS1eviDvwKXoXAFn7cWrkc3uVW22cCimt id: 159 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 1 type: 2 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - address: KT1FQE7EtHEkmDTw5iRoUgeveVW6PiPUH9pC id: 160 last_action: 2022-01-25T17:01:51Z level: 40 operations_count: 2 type: 1 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 - id: 344 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr1BP9kkXc1T4sRpX4kZuQoWKauLkMjijEDv level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 345 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr1EAHRyUgVPp2zaXXfth9fMKUBYKv3x9cLQ level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 346 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr17vi6kNWjJu1U5kHzoiBwZR5ycjmnArLRy level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 347 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr1UnsiEmcERkhXeFZubggtsUdjhmyoFpHdd level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 348 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr1UW2LkwV7KvxAQ92N9BhJZDN1ktMEy7LTq level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 349 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr1JjAGxzcDkUbsrm1uzn2FoddJKFZPD6EYQ level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 350 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr195QGbURK29Jn5RojRaE198B8F4XvM7KBD level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 351 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr1J21xQ1mP2npCmJuYnX3pvxZ7G3Axacyt6 level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 352 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr1Nw5X1t6X7hWAdZrsgnPGF8VSQTXPMP983 level: 48 operations_count: 2 last_action: '2022-01-25T17:19:59.000Z' - id: 353 type: 4 + events_count: 0 + migrations_count: 0 + ticket_updates_count: 0 address: sr1EWwrq1qm6irxkE9Ti18sL2qgvgDPhanWH level: 48 operations_count: 2 diff --git a/internal/postgres/tests/fixtures/contracts.yml b/internal/postgres/tests/fixtures/contracts.yml index b8d35ec9d..8d8feaeb9 100644 --- a/internal/postgres/tests/fixtures/contracts.yml +++ b/internal/postgres/tests/fixtures/contracts.yml @@ -6,7 +6,6 @@ jakarta_id: 0 level: 1 manager_id: 0 - migrations_count: 0 tags: 192 timestamp: 2022-01-25T15:03:39Z - account_id: 2 @@ -17,7 +16,6 @@ jakarta_id: 0 level: 1 manager_id: 0 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T15:03:39Z - account_id: 3 @@ -28,7 +26,6 @@ jakarta_id: 0 level: 1 manager_id: 0 - migrations_count: 0 tags: 192 timestamp: 2022-01-25T15:03:39Z - account_id: 45 @@ -39,7 +36,6 @@ jakarta_id: 0 level: 33 manager_id: 38 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:45:09Z - account_id: 41 @@ -50,7 +46,6 @@ jakarta_id: 0 level: 33 manager_id: 39 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:45:09Z - account_id: 40 @@ -61,7 +56,6 @@ jakarta_id: 0 level: 33 manager_id: 46 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:45:09Z - account_id: 47 @@ -72,7 +66,6 @@ jakarta_id: 0 level: 33 manager_id: 42 - migrations_count: 0 tags: 16640 timestamp: 2022-01-25T16:45:09Z - account_id: 49 @@ -83,7 +76,6 @@ jakarta_id: 0 level: 33 manager_id: 35 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:45:09Z - account_id: 48 @@ -94,7 +86,6 @@ jakarta_id: 0 level: 33 manager_id: 36 - migrations_count: 0 tags: 16664 timestamp: 2022-01-25T16:45:09Z - account_id: 43 @@ -105,7 +96,6 @@ jakarta_id: 0 level: 33 manager_id: 44 - migrations_count: 0 tags: 16664 timestamp: 2022-01-25T16:45:09Z - account_id: 58 @@ -116,7 +106,6 @@ jakarta_id: 0 level: 34 manager_id: 53 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:47:37Z - account_id: 64 @@ -127,7 +116,6 @@ jakarta_id: 0 level: 34 manager_id: 65 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:47:37Z - account_id: 54 @@ -138,7 +126,6 @@ jakarta_id: 0 level: 34 manager_id: 63 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:47:37Z - account_id: 59 @@ -149,7 +136,6 @@ jakarta_id: 0 level: 34 manager_id: 50 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:47:37Z - account_id: 55 @@ -160,7 +146,6 @@ jakarta_id: 0 level: 34 manager_id: 56 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:47:37Z - account_id: 57 @@ -171,7 +156,6 @@ jakarta_id: 0 level: 34 manager_id: 60 - migrations_count: 0 tags: 4 timestamp: 2022-01-25T16:47:37Z - account_id: 66 @@ -182,7 +166,6 @@ jakarta_id: 0 level: 34 manager_id: 61 - migrations_count: 0 tags: 16640 timestamp: 2022-01-25T16:47:37Z - account_id: 51 @@ -193,7 +176,6 @@ jakarta_id: 0 level: 34 manager_id: 62 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:47:37Z - account_id: 71 @@ -204,7 +186,6 @@ jakarta_id: 0 level: 35 manager_id: 67 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:49:57Z - account_id: 72 @@ -215,7 +196,6 @@ jakarta_id: 0 level: 35 manager_id: 75 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:49:57Z - account_id: 77 @@ -226,7 +206,6 @@ jakarta_id: 0 level: 35 manager_id: 76 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:49:57Z - account_id: 68 @@ -237,7 +216,6 @@ jakarta_id: 0 level: 35 manager_id: 78 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:49:57Z - account_id: 79 @@ -248,7 +226,6 @@ jakarta_id: 0 level: 35 manager_id: 80 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:49:57Z - account_id: 81 @@ -259,7 +236,6 @@ jakarta_id: 0 level: 35 manager_id: 73 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:49:57Z - account_id: 69 @@ -270,7 +246,6 @@ jakarta_id: 0 level: 35 manager_id: 74 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:49:57Z - account_id: 88 @@ -281,7 +256,6 @@ jakarta_id: 0 level: 36 manager_id: 92 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:52:19Z - account_id: 89 @@ -292,7 +266,6 @@ jakarta_id: 0 level: 36 manager_id: 84 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:52:19Z - account_id: 82 @@ -303,7 +276,6 @@ jakarta_id: 0 level: 36 manager_id: 90 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:52:19Z - account_id: 85 @@ -314,7 +286,6 @@ jakarta_id: 0 level: 36 manager_id: 83 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:52:19Z - account_id: 93 @@ -325,7 +296,6 @@ jakarta_id: 0 level: 36 manager_id: 86 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:52:19Z - account_id: 87 @@ -336,7 +306,6 @@ jakarta_id: 0 level: 36 manager_id: 94 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:52:19Z - account_id: 99 @@ -347,7 +316,6 @@ jakarta_id: 0 level: 37 manager_id: 96 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:54:35Z - account_id: 101 @@ -358,7 +326,6 @@ jakarta_id: 0 level: 37 manager_id: 100 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:54:35Z - account_id: 98 @@ -369,7 +336,6 @@ jakarta_id: 0 level: 37 manager_id: 104 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:54:35Z - account_id: 97 @@ -380,7 +346,6 @@ jakarta_id: 0 level: 37 manager_id: 105 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:54:35Z - account_id: 95 @@ -391,7 +356,6 @@ jakarta_id: 0 level: 37 manager_id: 108 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:54:35Z - account_id: 109 @@ -402,7 +366,6 @@ jakarta_id: 0 level: 37 manager_id: 94 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:54:35Z - account_id: 116 @@ -413,7 +376,6 @@ jakarta_id: 0 level: 38 manager_id: 117 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:56:47Z - account_id: 122 @@ -424,7 +386,6 @@ jakarta_id: 0 level: 38 manager_id: 123 - migrations_count: 0 tags: 4 timestamp: 2022-01-25T16:56:47Z - account_id: 110 @@ -435,7 +396,6 @@ jakarta_id: 0 level: 38 manager_id: 124 - migrations_count: 0 tags: 4 timestamp: 2022-01-25T16:56:47Z - account_id: 113 @@ -446,7 +406,6 @@ jakarta_id: 0 level: 38 manager_id: 114 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:56:47Z - account_id: 111 @@ -457,7 +416,6 @@ jakarta_id: 0 level: 38 manager_id: 112 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:56:47Z - account_id: 118 @@ -468,7 +426,6 @@ jakarta_id: 0 level: 38 manager_id: 119 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T16:56:47Z - account_id: 120 @@ -479,7 +436,6 @@ jakarta_id: 0 level: 38 manager_id: 115 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:56:47Z - account_id: 137 @@ -490,7 +446,6 @@ jakarta_id: 0 level: 39 manager_id: 130 - migrations_count: 0 tags: 4 timestamp: 2022-01-25T16:59:07Z - account_id: 132 @@ -501,7 +456,6 @@ jakarta_id: 0 level: 39 manager_id: 126 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:59:07Z - account_id: 133 @@ -512,7 +466,6 @@ jakarta_id: 0 level: 39 manager_id: 139 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:59:07Z - account_id: 129 @@ -523,7 +476,6 @@ jakarta_id: 0 level: 39 manager_id: 135 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:59:07Z - account_id: 141 @@ -534,7 +486,6 @@ jakarta_id: 0 level: 39 manager_id: 115 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T16:59:07Z - account_id: 156 @@ -545,7 +496,6 @@ jakarta_id: 0 level: 40 manager_id: 158 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:01:51Z - account_id: 145 @@ -556,7 +506,6 @@ jakarta_id: 0 level: 40 manager_id: 159 - migrations_count: 0 tags: 4 timestamp: 2022-01-25T17:01:51Z - account_id: 146 @@ -567,7 +516,6 @@ jakarta_id: 0 level: 40 manager_id: 157 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:01:51Z - account_id: 148 @@ -578,7 +526,6 @@ jakarta_id: 0 level: 40 manager_id: 151 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:01:51Z - account_id: 160 @@ -589,7 +536,6 @@ jakarta_id: 0 level: 40 manager_id: 149 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:01:51Z - account_id: 154 @@ -600,7 +546,6 @@ jakarta_id: 0 level: 40 manager_id: 144 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:01:51Z - account_id: 150 @@ -611,7 +556,6 @@ jakarta_id: 0 level: 40 manager_id: 147 - migrations_count: 0 tags: 256 timestamp: 2022-01-25T17:01:51Z - account_id: 182 @@ -622,7 +566,6 @@ jakarta_id: 0 level: 41 manager_id: 167 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:04:35Z - account_id: 188 @@ -633,7 +576,6 @@ jakarta_id: 0 level: 41 manager_id: 176 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:04:35Z - account_id: 172 @@ -644,7 +586,6 @@ jakarta_id: 0 level: 41 manager_id: 190 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:04:35Z - account_id: 168 @@ -655,7 +596,6 @@ jakarta_id: 0 level: 41 manager_id: 191 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:04:35Z - account_id: 184 @@ -666,7 +606,6 @@ jakarta_id: 0 level: 41 manager_id: 185 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:04:35Z - account_id: 162 @@ -677,7 +616,6 @@ jakarta_id: 0 level: 41 manager_id: 163 - migrations_count: 0 tags: 16 timestamp: 2022-01-25T17:04:35Z - account_id: 179 @@ -688,7 +626,6 @@ jakarta_id: 0 level: 41 manager_id: 180 - migrations_count: 0 tags: 16 timestamp: 2022-01-25T17:04:35Z - account_id: 164 @@ -699,7 +636,6 @@ jakarta_id: 0 level: 41 manager_id: 147 - migrations_count: 0 tags: 256 timestamp: 2022-01-25T17:04:35Z - account_id: 186 @@ -710,7 +646,6 @@ jakarta_id: 0 level: 41 manager_id: 169 - migrations_count: 0 tags: 192 timestamp: 2022-01-25T17:04:35Z - account_id: 187 @@ -721,7 +656,6 @@ jakarta_id: 0 level: 41 manager_id: 165 - migrations_count: 0 tags: 16640 timestamp: 2022-01-25T17:04:35Z - account_id: 166 @@ -732,7 +666,6 @@ jakarta_id: 0 level: 41 manager_id: 181 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:04:35Z - account_id: 171 @@ -743,7 +676,6 @@ jakarta_id: 0 level: 41 manager_id: 174 - migrations_count: 0 tags: 16664 timestamp: 2022-01-25T17:04:35Z - account_id: 173 @@ -754,7 +686,6 @@ jakarta_id: 0 level: 41 manager_id: 170 - migrations_count: 0 tags: 16664 timestamp: 2022-01-25T17:04:35Z - account_id: 195 @@ -765,7 +696,6 @@ jakarta_id: 0 level: 42 manager_id: 210 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:07:03Z - account_id: 211 @@ -776,7 +706,6 @@ jakarta_id: 0 level: 42 manager_id: 212 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:07:03Z - account_id: 201 @@ -787,7 +716,6 @@ jakarta_id: 0 level: 42 manager_id: 193 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:07:03Z - account_id: 196 @@ -798,7 +726,6 @@ jakarta_id: 0 level: 42 manager_id: 213 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:07:03Z - account_id: 198 @@ -809,7 +736,6 @@ jakarta_id: 0 level: 42 manager_id: 214 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:07:03Z - account_id: 199 @@ -820,7 +746,6 @@ jakarta_id: 0 level: 42 manager_id: 207 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:07:03Z - account_id: 208 @@ -831,7 +756,6 @@ jakarta_id: 0 level: 42 manager_id: 200 - migrations_count: 0 tags: 4 timestamp: 2022-01-25T17:07:03Z - account_id: 197 @@ -842,7 +766,6 @@ jakarta_id: 0 level: 42 manager_id: 209 - migrations_count: 0 tags: 16640 timestamp: 2022-01-25T17:07:03Z - account_id: 205 @@ -853,7 +776,6 @@ jakarta_id: 0 level: 42 manager_id: 206 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:07:03Z - account_id: 225 @@ -864,7 +786,6 @@ jakarta_id: 0 level: 43 manager_id: 226 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:09:21Z - account_id: 218 @@ -875,7 +796,6 @@ jakarta_id: 0 level: 43 manager_id: 221 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:09:21Z - account_id: 222 @@ -886,7 +806,6 @@ jakarta_id: 0 level: 43 manager_id: 223 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:09:21Z - account_id: 227 @@ -897,7 +816,6 @@ jakarta_id: 0 level: 43 manager_id: 219 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:09:21Z - account_id: 220 @@ -908,7 +826,6 @@ jakarta_id: 0 level: 43 manager_id: 217 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:09:21Z - account_id: 228 @@ -919,7 +836,6 @@ jakarta_id: 0 level: 43 manager_id: 215 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:09:21Z - account_id: 216 @@ -930,7 +846,6 @@ jakarta_id: 0 level: 43 manager_id: 229 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:09:21Z - account_id: 232 @@ -941,7 +856,6 @@ jakarta_id: 0 level: 44 manager_id: 243 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:11:23Z - account_id: 251 @@ -952,7 +866,6 @@ jakarta_id: 0 level: 44 manager_id: 244 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:11:23Z - account_id: 245 @@ -963,7 +876,6 @@ jakarta_id: 0 level: 44 manager_id: 252 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:11:23Z - account_id: 253 @@ -974,7 +886,6 @@ jakarta_id: 0 level: 44 manager_id: 246 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:11:23Z - account_id: 254 @@ -985,7 +896,6 @@ jakarta_id: 0 level: 44 manager_id: 247 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:11:23Z - account_id: 239 @@ -996,7 +906,6 @@ jakarta_id: 0 level: 44 manager_id: 233 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:11:23Z - account_id: 248 @@ -1007,7 +916,6 @@ jakarta_id: 0 level: 44 manager_id: 234 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:11:23Z - account_id: 249 @@ -1018,7 +926,6 @@ jakarta_id: 0 level: 44 manager_id: 240 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:11:23Z - account_id: 250 @@ -1029,7 +936,6 @@ jakarta_id: 0 level: 44 manager_id: 236 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:11:23Z - account_id: 241 @@ -1040,7 +946,6 @@ jakarta_id: 0 level: 44 manager_id: 237 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:11:23Z - account_id: 238 @@ -1051,7 +956,6 @@ jakarta_id: 0 level: 44 manager_id: 230 - migrations_count: 0 tags: 16664 timestamp: 2022-01-25T17:11:23Z - account_id: 242 @@ -1062,7 +966,6 @@ jakarta_id: 0 level: 44 manager_id: 235 - migrations_count: 0 tags: 16664 timestamp: 2022-01-25T17:11:23Z - account_id: 283 @@ -1073,7 +976,6 @@ jakarta_id: 0 level: 45 manager_id: 270 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:13:29Z - account_id: 272 @@ -1084,7 +986,6 @@ jakarta_id: 0 level: 45 manager_id: 280 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:13:29Z - account_id: 279 @@ -1095,7 +996,6 @@ jakarta_id: 0 level: 45 manager_id: 267 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:13:29Z - account_id: 261 @@ -1106,7 +1006,6 @@ jakarta_id: 0 level: 45 manager_id: 255 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:13:29Z - account_id: 271 @@ -1117,7 +1016,6 @@ jakarta_id: 0 level: 45 manager_id: 268 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:13:29Z - account_id: 278 @@ -1128,7 +1026,6 @@ jakarta_id: 0 level: 45 manager_id: 277 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:13:29Z - account_id: 256 @@ -1139,7 +1036,6 @@ jakarta_id: 0 level: 45 manager_id: 262 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:13:29Z - account_id: 257 @@ -1150,7 +1046,6 @@ jakarta_id: 0 level: 45 manager_id: 260 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:13:29Z - account_id: 281 @@ -1161,7 +1056,6 @@ jakarta_id: 0 level: 45 manager_id: 263 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:13:29Z - account_id: 273 @@ -1172,7 +1066,6 @@ jakarta_id: 0 level: 45 manager_id: 274 - migrations_count: 0 tags: 4 timestamp: 2022-01-25T17:13:29Z - account_id: 275 @@ -1183,7 +1076,6 @@ jakarta_id: 0 level: 45 manager_id: 236 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:13:29Z - account_id: 269 @@ -1194,7 +1086,6 @@ jakarta_id: 0 level: 45 manager_id: 264 - migrations_count: 0 tags: 16640 timestamp: 2022-01-25T17:13:29Z - account_id: 265 @@ -1205,7 +1096,6 @@ jakarta_id: 0 level: 45 manager_id: 276 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:13:29Z - account_id: 307 @@ -1216,7 +1106,6 @@ jakarta_id: 0 level: 47 manager_id: 287 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:17:47Z - account_id: 303 @@ -1227,7 +1116,6 @@ jakarta_id: 0 level: 47 manager_id: 295 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:17:47Z - account_id: 289 @@ -1238,7 +1126,6 @@ jakarta_id: 0 level: 47 manager_id: 290 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:17:47Z - account_id: 291 @@ -1249,7 +1136,6 @@ jakarta_id: 0 level: 47 manager_id: 288 - migrations_count: 0 tags: 4 timestamp: 2022-01-25T17:17:47Z - account_id: 285 @@ -1260,7 +1146,6 @@ jakarta_id: 0 level: 47 manager_id: 292 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:17:47Z - account_id: 286 @@ -1271,7 +1156,6 @@ jakarta_id: 0 level: 47 manager_id: 301 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:17:47Z - account_id: 304 @@ -1282,7 +1166,6 @@ jakarta_id: 0 level: 47 manager_id: 293 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:17:47Z - account_id: 302 @@ -1293,7 +1176,6 @@ jakarta_id: 0 level: 47 manager_id: 294 - migrations_count: 0 tags: 8192 timestamp: 2022-01-25T17:17:47Z - account_id: 297 @@ -1304,7 +1186,6 @@ jakarta_id: 0 level: 47 manager_id: 268 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:17:47Z - account_id: 298 @@ -1315,7 +1196,6 @@ jakarta_id: 0 level: 47 manager_id: 305 - migrations_count: 0 tags: 16640 timestamp: 2022-01-25T17:17:47Z - account_id: 300 @@ -1326,6 +1206,5 @@ jakarta_id: 0 level: 47 manager_id: 296 - migrations_count: 0 tags: 0 timestamp: 2022-01-25T17:17:47Z diff --git a/internal/postgres/tests/operations_test.go b/internal/postgres/tests/operations_test.go index 7483038b4..e1b6df470 100644 --- a/internal/postgres/tests/operations_test.go +++ b/internal/postgres/tests/operations_test.go @@ -209,12 +209,3 @@ func (s *StorageTestSuite) TestOperationListEvents() { s.Require().NotEmpty(operation.PayloadType) s.Require().Equal(testsuite.MustHexDecode("3006fe3748e23bee8499ddd4ef69c3f910b1de0aa04080cc5be242b5123c1207"), operation.Hash) } - -func (s *StorageTestSuite) TestOperationEventsCount() { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - - count, err := s.operations.EventsCount(ctx, 37) - s.Require().NoError(err) - s.Require().EqualValues(count, 2) -} diff --git a/internal/postgres/tests/rollback_test.go b/internal/postgres/tests/rollback_test.go index 452c31c69..f6dcfa65e 100644 --- a/internal/postgres/tests/rollback_test.go +++ b/internal/postgres/tests/rollback_test.go @@ -167,7 +167,11 @@ func (s *StorageTestSuite) TestUpdateAccountStats() { ts := time.Now().UTC() - err = saver.UpdateAccountStats(ctx, 43, ts, 1) + err = saver.UpdateAccountStats(ctx, account.Account{ + ID: 43, + LastAction: ts, + OperationsCount: 1, + }) s.Require().NoError(err) err = saver.Commit() @@ -210,9 +214,9 @@ func (s *StorageTestSuite) TestRollbackUpdateStats() { err = saver.UpdateStats(ctx, stats.Stats{ ID: 1, ContractsCount: 1, - OperationsCount: 4, - OriginationsCount: 1, - TransactionsCount: 1, + OperationsCount: 188, + OriginationsCount: 119, + TransactionsCount: 71, EventsCount: 1, }) s.Require().NoError(err) @@ -223,10 +227,28 @@ func (s *StorageTestSuite) TestRollbackUpdateStats() { var stats stats.Stats err = s.storage.DB.NewSelect().Model(&stats).Limit(1).Scan(ctx) s.Require().NoError(err) - s.Require().EqualValues(119, stats.ContractsCount) + s.Require().EqualValues(1, stats.ContractsCount) s.Require().EqualValues(188, stats.OperationsCount) s.Require().EqualValues(71, stats.TransactionsCount) - s.Require().EqualValues(117, stats.OriginationsCount) + s.Require().EqualValues(119, stats.OriginationsCount) s.Require().EqualValues(1, stats.EventsCount) s.Require().EqualValues(0, stats.SrOriginationsCount) } + +func (s *StorageTestSuite) TestGetMigrations() { + saver, err := postgres.NewRollback(s.storage.DB) + s.Require().NoError(err) + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + migrations, err := saver.GetMigrations(ctx, 2) + s.Require().NoError(err) + + err = saver.Commit() + s.Require().NoError(err) + s.Require().Len(migrations, 3) + + migration := migrations[0] + s.Require().EqualValues(1, migration.Contract.AccountID) +} diff --git a/internal/postgres/tests/ticket_test.go b/internal/postgres/tests/ticket_test.go index 651e1795f..1fa956609 100644 --- a/internal/postgres/tests/ticket_test.go +++ b/internal/postgres/tests/ticket_test.go @@ -24,19 +24,6 @@ func (s *StorageTestSuite) TestTicketGet() { s.Require().NotEmpty(update.ContentType) } -func (s *StorageTestSuite) TestTicketHas() { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - - ok, err := s.ticketUpdates.Has(ctx, 133) - s.Require().NoError(err) - s.Require().True(ok) - - ok, err = s.ticketUpdates.Has(ctx, 1) - s.Require().NoError(err) - s.Require().False(ok) -} - func (s *StorageTestSuite) TestTicketForOperation() { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() diff --git a/internal/postgres/tests/transaction_test.go b/internal/postgres/tests/transaction_test.go index d25d0c1c0..ea5629ef9 100644 --- a/internal/postgres/tests/transaction_test.go +++ b/internal/postgres/tests/transaction_test.go @@ -158,17 +158,20 @@ func (s *StorageTestSuite) TestAccounts() { sc := []*account.Account{ { - Address: "address_1", - Type: types.AccountTypeContract, - Level: 100, + Address: "address_1", + Type: types.AccountTypeContract, + Level: 100, + TicketUpdatesCount: 2, }, { - Address: "address_12", - Type: types.AccountTypeSmartRollup, - Level: 100, + Address: "address_12", + Type: types.AccountTypeSmartRollup, + Level: 100, + MigrationsCount: 2, }, { - Address: "address_2", - Type: types.AccountTypeTz, - Level: 100, + Address: "address_2", + Type: types.AccountTypeTz, + Level: 100, + EventsCount: 2, }, } err = tx.Accounts(ctx, sc...) diff --git a/internal/postgres/ticket/storage.go b/internal/postgres/ticket/storage.go index 9489b1282..f65c4535d 100644 --- a/internal/postgres/ticket/storage.go +++ b/internal/postgres/ticket/storage.go @@ -37,27 +37,6 @@ func (storage *Storage) Get(ctx context.Context, ticketer string, limit, offset return } -// Has - -func (storage *Storage) Has(ctx context.Context, contractID int64) (bool, error) { - var id int64 - err := storage.DB. - NewSelect(). - Model((*ticket.TicketUpdate)(nil)). - Column("id"). - Where("ticketer_id = ?", contractID). - OrderExpr("id ASC"). - Limit(1). - Scan(ctx, &id) - - if err != nil { - if storage.IsRecordNotFound(err) { - return false, nil - } - return false, err - } - return true, nil -} - // ForOperation - func (storage *Storage) ForOperation(ctx context.Context, operationId int64) (response []ticket.TicketUpdate, err error) { err = storage.DB. diff --git a/internal/rollback/context.go b/internal/rollback/context.go new file mode 100644 index 000000000..c4e6ec5cb --- /dev/null +++ b/internal/rollback/context.go @@ -0,0 +1,110 @@ +package rollback + +import ( + "context" + + "github.com/baking-bad/bcdhub/internal/models" + "github.com/baking-bad/bcdhub/internal/models/account" + "github.com/baking-bad/bcdhub/internal/models/stats" +) + +type rollbackContext struct { + generalStats stats.Stats + accountStats map[int64]*account.Account +} + +func newRollbackContext(ctx context.Context, statsRepo stats.Repository) (rollbackContext, error) { + stats, err := statsRepo.Get(ctx) + if err != nil { + return rollbackContext{}, err + } + return rollbackContext{ + generalStats: stats, + accountStats: make(map[int64]*account.Account), + }, nil +} + +func (rCtx *rollbackContext) applyMigration(accountId int64) { + if acc, ok := rCtx.accountStats[accountId]; ok { + acc.MigrationsCount += 1 + } else { + rCtx.accountStats[accountId] = &account.Account{ + ID: accountId, + MigrationsCount: 1, + } + } +} + +func (rCtx *rollbackContext) applyEvent(accountId int64) { + if acc, ok := rCtx.accountStats[accountId]; ok { + acc.EventsCount += 1 + } else { + rCtx.accountStats[accountId] = &account.Account{ + ID: accountId, + EventsCount: 1, + } + } +} + +func (rCtx *rollbackContext) applyTicketUpdates(accountId int64, count int64) { + if count < 1 { + return + } + + if acc, ok := rCtx.accountStats[accountId]; ok { + acc.TicketUpdatesCount += count + } else { + rCtx.accountStats[accountId] = &account.Account{ + ID: accountId, + TicketUpdatesCount: count, + } + } +} + +func (rCtx *rollbackContext) applyOperationsCount(accountId int64, count int64) { + if acc, ok := rCtx.accountStats[accountId]; ok { + acc.OperationsCount += count + } else { + rCtx.accountStats[accountId] = &account.Account{ + ID: accountId, + OperationsCount: count, + } + } +} + +func (rCtx *rollbackContext) getLastActions(ctx context.Context, rollback models.Rollback) error { + addresses := make([]int64, 0, len(rCtx.accountStats)) + for _, acc := range rCtx.accountStats { + addresses = append(addresses, acc.ID) + } + + actions, err := rollback.GetLastAction(ctx, addresses...) + if err != nil { + return err + } + + for i := range actions { + if acc, ok := rCtx.accountStats[actions[i].AccountId]; ok { + acc.LastAction = actions[i].Time + } else { + rCtx.accountStats[actions[i].AccountId] = &account.Account{ + ID: actions[i].AccountId, + LastAction: actions[i].Time, + } + } + } + return nil +} + +func (rCtx *rollbackContext) update(ctx context.Context, rollback models.Rollback) error { + if err := rollback.UpdateStats(ctx, rCtx.generalStats); err != nil { + return err + } + + for _, acc := range rCtx.accountStats { + if err := rollback.UpdateAccountStats(ctx, *acc); err != nil { + return err + } + } + return nil +} diff --git a/internal/rollback/operations.go b/internal/rollback/operations.go index 766b5fab6..0bf188848 100644 --- a/internal/rollback/operations.go +++ b/internal/rollback/operations.go @@ -5,11 +5,10 @@ import ( "github.com/baking-bad/bcdhub/internal/logger" "github.com/baking-bad/bcdhub/internal/models/operation" - "github.com/baking-bad/bcdhub/internal/models/stats" "github.com/baking-bad/bcdhub/internal/models/types" ) -func (rm Manager) rollbackOperations(ctx context.Context, level int64, stats *stats.Stats) error { +func (rm Manager) rollbackOperations(ctx context.Context, level int64, rCtx *rollbackContext) error { logger.Info().Msg("rollback operations...") ops, err := rm.rollback.GetOperations(ctx, level) @@ -24,61 +23,45 @@ func (rm Manager) rollbackOperations(ctx context.Context, level int64, stats *st if err != nil { return err } - stats.OperationsCount -= count + rCtx.generalStats.OperationsCount -= count - accounts := make(map[int64]int64) for i := range ops { if !ops[i].Destination.IsEmpty() { - if _, ok := accounts[ops[i].DestinationID]; !ok { - accounts[ops[i].DestinationID] = 1 - } else { - accounts[ops[i].DestinationID] += 1 - } + rCtx.applyOperationsCount(ops[i].DestinationID, 1) + rCtx.applyTicketUpdates(ops[i].DestinationID, int64(ops[i].TicketUpdatesCount)) } if !ops[i].Source.IsEmpty() { - if _, ok := accounts[ops[i].SourceID]; !ok { - accounts[ops[i].SourceID] = 1 - } else { - accounts[ops[i].SourceID] += 1 - } + rCtx.applyOperationsCount(ops[i].SourceID, 1) } switch ops[i].Kind { case types.OperationKindEvent: - stats.EventsCount -= 1 + rCtx.generalStats.EventsCount -= 1 + rCtx.applyEvent(ops[i].SourceID) + case types.OperationKindOrigination: - stats.OriginationsCount -= 1 + rCtx.generalStats.OriginationsCount -= 1 + case types.OperationKindSrOrigination: - stats.SrOriginationsCount -= 1 + rCtx.generalStats.SrOriginationsCount -= 1 + case types.OperationKindTransaction: - stats.TransactionsCount -= 1 - } - } + rCtx.generalStats.TransactionsCount -= 1 - if len(accounts) == 0 { - return nil - } + case types.OperationKindRegisterGlobalConstant: + rCtx.generalStats.RegisterGlobalConstantCount -= 1 - addresses := make([]int64, 0, len(accounts)) - for address := range accounts { - addresses = append(addresses, address) - } + case types.OperationKindSrExecuteOutboxMessage: + rCtx.generalStats.SrExecutesCount -= 1 - actions, err := rm.rollback.GetLastAction(ctx, addresses...) - if err != nil { - return err - } - - for i := range actions { - count, ok := accounts[actions[i].AccountId] - if !ok { - count = 1 + case types.OperationKindTransferTicket: + rCtx.generalStats.TransferTicketsCount -= 1 } + } - if err := rm.rollback.UpdateAccountStats(ctx, actions[i].AccountId, actions[i].Time, count); err != nil { - return err - } + if err := rCtx.getLastActions(ctx, rm.rollback); err != nil { + return err } return nil diff --git a/internal/rollback/rollback.go b/internal/rollback/rollback.go index d03fbcaaf..08f4352db 100644 --- a/internal/rollback/rollback.go +++ b/internal/rollback/rollback.go @@ -67,12 +67,12 @@ func (rm Manager) Rollback(ctx context.Context, network types.Network, fromState } func (rm Manager) rollbackBlock(ctx context.Context, level int64) error { - stats, err := rm.statsRepo.Get(ctx) + rollbackCtx, err := newRollbackContext(ctx, rm.statsRepo) if err != nil { return err } - if err := rm.rollbackOperations(ctx, level, &stats); err != nil { + if err := rm.rollbackOperations(ctx, level, &rollbackCtx); err != nil { return err } if err := rm.rollbackBigMapState(ctx, level); err != nil { @@ -81,26 +81,48 @@ func (rm Manager) rollbackBlock(ctx context.Context, level int64) error { if err := rm.rollbackScripts(ctx, level); err != nil { return err } - if err := rm.rollbackAll(ctx, level, &stats); err != nil { + if err := rm.rollbackMigrations(ctx, level, &rollbackCtx); err != nil { + return err + } + if err := rm.rollbackAll(ctx, level, &rollbackCtx); err != nil { return err } if err := rm.rollback.Protocols(ctx, level); err != nil { return err } - if err := rm.rollback.UpdateStats(ctx, stats); err != nil { + if err := rollbackCtx.update(ctx, rm.rollback); err != nil { + return err + } + return nil +} + +func (rm Manager) rollbackMigrations(ctx context.Context, level int64, rCtx *rollbackContext) error { + migrations, err := rm.rollback.GetMigrations(ctx, level) + if err != nil { + return nil + } + if len(migrations) == 0 { + return nil + } + + for i := range migrations { + rCtx.applyMigration(migrations[i].Contract.AccountID) + } + + if _, err := rm.rollback.DeleteAll(ctx, (*migration.Migration)(nil), level); err != nil { return err } + logger.Info().Msg("rollback migrations") return nil } -func (rm Manager) rollbackAll(ctx context.Context, level int64, stats *stats.Stats) error { +func (rm Manager) rollbackAll(ctx context.Context, level int64, rCtx *rollbackContext) error { for _, model := range []models.Model{ (*block.Block)(nil), (*bigmapdiff.BigMapDiff)(nil), (*bigmapaction.BigMapAction)(nil), (*smartrollup.SmartRollup)(nil), (*ticket.TicketUpdate)(nil), - (*migration.Migration)(nil), (*account.Account)(nil), } { if _, err := rm.rollback.DeleteAll(ctx, model, level); err != nil { @@ -113,7 +135,7 @@ func (rm Manager) rollbackAll(ctx context.Context, level int64, stats *stats.Sta if err != nil { return err } - stats.ContractsCount -= contractsCount + rCtx.generalStats.ContractsCount -= contractsCount logger.Info().Msgf("rollback contracts") return nil diff --git a/internal/rollback/rollback_test.go b/internal/rollback/rollback_test.go index 495333581..036f643b3 100644 --- a/internal/rollback/rollback_test.go +++ b/internal/rollback/rollback_test.go @@ -11,6 +11,7 @@ import ( "github.com/baking-bad/bcdhub/internal/models/bigmapdiff" "github.com/baking-bad/bcdhub/internal/models/block" "github.com/baking-bad/bcdhub/internal/models/contract" + "github.com/baking-bad/bcdhub/internal/models/migration" "github.com/baking-bad/bcdhub/internal/models/mock" mock_block "github.com/baking-bad/bcdhub/internal/models/mock/block" mock_stats "github.com/baking-bad/bcdhub/internal/models/mock/stats" @@ -44,13 +45,14 @@ func TestManager_Rollback(t *testing.T) { statsRepo.EXPECT(). Get(gomock.Any()). Return(stats.Stats{ - ID: 1, - ContractsCount: 100, - OperationsCount: 100, - EventsCount: 10, - TransactionsCount: 70, - OriginationsCount: 10, - SrOriginationsCount: 10, + ID: 1, + ContractsCount: 100, + OperationsCount: 100, + EventsCount: 10, + TransactionsCount: 70, + OriginationsCount: 10, + SrOriginationsCount: 10, + TransferTicketsCount: 11, }, nil). Times(1) @@ -127,6 +129,29 @@ func TestManager_Rollback(t *testing.T) { }, SourceID: 3, Kind: types.OperationKindTransaction, + }, { + Source: account.Account{ + ID: 1, + Address: "address_1", + Type: types.AccountTypeContract, + }, + SourceID: 1, + Kind: types.OperationKindEvent, + }, { + Destination: account.Account{ + ID: 1, + Address: "address_1", + Type: types.AccountTypeContract, + }, + DestinationID: 1, + Source: account.Account{ + ID: 3, + Address: "address_3", + Type: types.AccountTypeTz, + }, + SourceID: 3, + Kind: types.OperationKindTransferTicket, + TicketUpdatesCount: 2, }, }, nil). Times(1) @@ -136,6 +161,18 @@ func TestManager_Rollback(t *testing.T) { Return(5, nil). Times(1) + rb.EXPECT(). + GetMigrations(gomock.Any(), level). + Return([]migration.Migration{ + { + ContractID: 1, + Contract: contract.Contract{ + AccountID: 1, + }, + }, + }, nil). + Times(1) + ts := time.Now().UTC() rb.EXPECT(). GetLastAction(gomock.Any(), gomock.Any()). @@ -143,6 +180,12 @@ func TestManager_Rollback(t *testing.T) { { AccountId: 4, Time: ts, + }, { + AccountId: 3, + Time: ts, + }, { + AccountId: 2, + Time: ts, }, { AccountId: 1, Time: ts, @@ -151,15 +194,43 @@ func TestManager_Rollback(t *testing.T) { Times(1) rb.EXPECT(). - UpdateAccountStats(gomock.Any(), int64(4), ts, int64(1)). + UpdateAccountStats(gomock.Any(), account.Account{ + ID: 4, + LastAction: ts, + OperationsCount: 1, + }). + Return(nil). + Times(1) + + rb.EXPECT(). + UpdateAccountStats(gomock.Any(), account.Account{ + ID: 3, + LastAction: ts, + OperationsCount: 4, + }). Return(nil). Times(1) rb.EXPECT(). - UpdateAccountStats(gomock.Any(), int64(1), ts, int64(3)). + UpdateAccountStats(gomock.Any(), account.Account{ + ID: 2, + LastAction: ts, + OperationsCount: 3, + }). Return(nil). Times(1) + rb.EXPECT(). + UpdateAccountStats(gomock.Any(), account.Account{ + ID: 1, + LastAction: ts, + OperationsCount: 5, + MigrationsCount: 1, + EventsCount: 1, + TicketUpdatesCount: 2, + }). + Times(1) + rb.EXPECT(). StatesChangedAtLevel(gomock.Any(), level). Return([]bigmapdiff.BigMapState{ @@ -279,13 +350,14 @@ func TestManager_Rollback(t *testing.T) { rb.EXPECT(). UpdateStats(gomock.Any(), stats.Stats{ - ID: 1, - ContractsCount: 100, - OperationsCount: 95, - EventsCount: 10, - TransactionsCount: 66, - OriginationsCount: 9, - SrOriginationsCount: 10, + ID: 1, + ContractsCount: 100, + OperationsCount: 95, + EventsCount: 9, + TransactionsCount: 66, + OriginationsCount: 9, + SrOriginationsCount: 10, + TransferTicketsCount: 10, }). Return(nil). Times(1)