Skip to content

Commit

Permalink
Account statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 27, 2023
1 parent 7466449 commit 145f5e7
Show file tree
Hide file tree
Showing 43 changed files with 1,246 additions and 820 deletions.
13 changes: 8 additions & 5 deletions cmd/api/handlers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand Down
14 changes: 1 addition & 13 deletions cmd/api/handlers/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,13 @@ 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 {
return res, err
}
res.SameCount += int64(stats)

hasTicketUpdates, err := ctx.TicketUpdates.Has(c, contractModel.AccountID)
if err != nil {
return res, err
}
res.HasTicketUpdates = hasTicketUpdates

return res, nil
}
18 changes: 9 additions & 9 deletions cmd/api/handlers/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 -
Expand Down Expand Up @@ -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 -
Expand Down
3 changes: 2 additions & 1 deletion cmd/indexer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 9 additions & 6 deletions internal/models/account/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
3 changes: 1 addition & 2 deletions internal/models/contract/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion internal/models/migration/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
39 changes: 0 additions & 39 deletions internal/models/mock/operation/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 47 additions & 7 deletions internal/models/mock/rollback.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 0 additions & 39 deletions internal/models/mock/ticket/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions internal/models/operation/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ 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
Payload []byte
PayloadType []byte
Script []byte `bun:"-"`

Errors tezerrors.Errors `bun:",type:bytea"`
Errors tezerrors.Errors `bun:"errors,type:bytea"`

AST *ast.Script `bun:"-"`

Expand Down
1 change: 0 additions & 1 deletion internal/models/operation/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading

0 comments on commit 145f5e7

Please sign in to comment.