Skip to content

Commit

Permalink
Refactoring: Contract.tx_count -> Account.operations_count
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 26, 2023
1 parent 19384cc commit ffce081
Show file tree
Hide file tree
Showing 62 changed files with 11,919 additions and 5,863 deletions.
15 changes: 6 additions & 9 deletions cmd/api/handlers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ func GetInfo() gin.HandlerFunc {
if handleError(c, ctx.Storage, err, 0) {
return
}
stats, err := ctx.Operations.ContractStats(c.Request.Context(), acc.Address)
if handleError(c, ctx.Storage, err, 0) {
return
}

var balance int64
if !(bcd.IsRollupAddressLazy(acc.Address) || bcd.IsSmartRollupAddressLazy(acc.Address)) {
block, err := ctx.Blocks.Last(c.Request.Context())
Expand All @@ -53,11 +50,11 @@ func GetInfo() gin.HandlerFunc {
}
}
c.SecureJSON(http.StatusOK, AccountInfo{
Address: acc.Address,
TxCount: stats.Count,
Balance: balance,
LastAction: stats.LastAction.UTC(),
AccountType: acc.Type.String(),
Address: acc.Address,
OperationsCount: acc.OperationsCount,
Balance: balance,
LastAction: acc.LastAction.UTC(),
AccountType: acc.Type.String(),
})
}

Expand Down
15 changes: 5 additions & 10 deletions cmd/api/handlers/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ type Contract struct {
func (c *Contract) FromModel(contract contract.Contract) {
c.Address = contract.Account.Address
c.Delegate = contract.Delegate.Address
c.TxCount = contract.TxCount
c.LastAction = contract.LastAction

c.Level = contract.Level
c.Manager = contract.Manager.Address
c.MigrationsCount = contract.MigrationsCount
Expand Down Expand Up @@ -218,8 +215,6 @@ type RecentlyCalledContract struct {
// FromModel -
func (c *RecentlyCalledContract) FromModel(contract contract.Contract) {
c.Address = contract.Account.Address
c.TxCount = contract.TxCount
c.LastAction = contract.LastAction
c.ID = contract.ID
}

Expand Down Expand Up @@ -429,11 +424,11 @@ type Screenshot struct {

// AccountInfo -
type AccountInfo struct {
Address string `json:"address"`
Balance int64 `json:"balance"`
TxCount int64 `json:"tx_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"`
LastAction time.Time `json:"last_action"`
AccountType string `json:"account_type"`
}

// CountResponse -
Expand Down
12 changes: 8 additions & 4 deletions internal/models/account/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package account

import (
"time"

"github.com/baking-bad/bcdhub/internal/models/types"
"github.com/uptrace/bun"
)
Expand All @@ -9,10 +11,12 @@ 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"`
Level int64 `bun:"level"`
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"`
}

// GetID -
Expand Down
2 changes: 0 additions & 2 deletions internal/models/contract/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ type Contract struct {
DelegateID int64
Delegate account.Account `bun:"rel:belongs-to"`

TxCount int64
LastAction time.Time
MigrationsCount int64
Tags types.Tags

Expand Down
1 change: 0 additions & 1 deletion internal/models/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type Transaction interface {
Operations(ctx context.Context, operations ...*operation.Operation) error
TickerUpdates(ctx context.Context, updates ...*ticket.TicketUpdate) error
Contracts(ctx context.Context, contracts ...*contract.Contract) error
UpdateContracts(ctx context.Context, updates ...*contract.Update) error
Scripts(ctx context.Context, scripts ...*contract.Script) error
ScriptConstant(ctx context.Context, data ...*contract.ScriptConstants) error
Block(ctx context.Context, block *block.Block) error
Expand Down
43 changes: 0 additions & 43 deletions internal/models/mock/general.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/operation/mock.go

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

48 changes: 24 additions & 24 deletions internal/models/mock/rollback.go

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

1 change: 0 additions & 1 deletion internal/models/operation/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ type Repository interface {

ListEvents(ctx context.Context, accountID int64, size, offset int64) ([]Operation, error)
EventsCount(ctx context.Context, accountID int64) (int, error)
ContractStats(ctx context.Context, address string) (ContractStats, error)
}
4 changes: 2 additions & 2 deletions internal/models/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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)
GetContractsLastAction(ctx context.Context, addressIds ...int64) ([]LastAction, error)
UpdateContractStats(ctx context.Context, accountId int64, lastAction time.Time, txCount int64) error
GetLastAction(ctx context.Context, addressIds ...int64) ([]LastAction, error)
UpdateAccountStats(ctx context.Context, accountId int64, lastAction time.Time, txCount int64) 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
Expand Down
13 changes: 6 additions & 7 deletions internal/parsers/contract/alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@ func (p *Alpha) Parse(ctx context.Context, operation *operation.Operation, store
}

contract := contract.Contract{
Level: operation.Level,
Timestamp: operation.Timestamp,
Manager: operation.Source,
Account: operation.Destination,
Delegate: operation.Delegate,
LastAction: operation.Timestamp,
Level: operation.Level,
Timestamp: operation.Timestamp,
Manager: operation.Source,
Account: operation.Destination,
Delegate: operation.Delegate,
}

if err := p.computeMetrics(ctx, operation, &contract); err != nil {
return err
}

store.AddContracts(&contract)
store.AddAccounts(&contract.Account, &contract.Delegate, &contract.Manager)
store.AddAccounts(&contract.Account)
return nil
}

Expand Down
13 changes: 6 additions & 7 deletions internal/parsers/contract/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@ func (p *Babylon) Parse(ctx context.Context, operation *operation.Operation, sto
}

contract := contract.Contract{
Level: operation.Level,
Timestamp: operation.Timestamp,
Manager: operation.Source,
Account: operation.Destination,
Delegate: operation.Delegate,
LastAction: operation.Timestamp,
Level: operation.Level,
Timestamp: operation.Timestamp,
Manager: operation.Source,
Account: operation.Destination,
Delegate: operation.Delegate,
}

if err := p.computeMetrics(ctx, operation, &contract); err != nil {
return err
}

store.AddContracts(&contract)
store.AddAccounts(&contract.Account, &contract.Delegate, &contract.Manager)
store.AddAccounts(&contract.Account)
return nil
}

Expand Down
Loading

0 comments on commit ffce081

Please sign in to comment.