diff --git a/.vscode/launch.json b/.vscode/launch.json index 66635ed..785c6db 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "program": "${workspaceFolder}/cmd/mempool", "args": [ "-c", - "../../build/dipdup.mainnet.yml" + "../../build/dipdup.testnet.yml" ], "envFile": "${workspaceFolder}/.env" } diff --git a/build/dipdup.testnet.yml b/build/dipdup.testnet.yml index a87e3e6..b6ad4f9 100644 --- a/build/dipdup.testnet.yml +++ b/build/dipdup.testnet.yml @@ -57,11 +57,54 @@ mempool: - set_deposits_limit - preendorsement - double_preendorsement_evidence + - tx_rollup_commit + - tx_rollup_dispatch_tickets + - tx_rollup_finalize_commitment + - tx_rollup_origination + - tx_rollup_rejection + - tx_rollup_remove_commitment + - tx_rollup_return_bond + - tx_rollup_submit_batch + - transfer_ticket datasources: tzkt: https://api.ghostnet.tzkt.io rpc: - https://rpc.tzkt.io/ghostnet + kathmandunet: + filters: + kinds: + - endorsement + - transaction + - activate_account + - ballot + - delegation + - double_baking_evidence + - double_endorsement_evidence + - origination + - proposals + - reveal + - seed_nonce_revelation + - register_global_constant + - set_deposits_limit + - preendorsement + - double_preendorsement_evidence + - tx_rollup_commit + - tx_rollup_dispatch_tickets + - tx_rollup_finalize_commitment + - tx_rollup_origination + - tx_rollup_rejection + - tx_rollup_remove_commitment + - tx_rollup_return_bond + - tx_rollup_submit_batch + - transfer_ticket + - vdf_revelation + - Increase_paid_storage + datasources: + tzkt: https://api.kathmandunet.tzkt.io + rpc: + - https://rpc.tzkt.io/kathmandunet + database: kind: postgres host: ${POSTGRES_HOST:-db} diff --git a/cmd/mempool/block_queue.go b/cmd/mempool/block_queue.go index c5e4913..d6b2261 100644 --- a/cmd/mempool/block_queue.go +++ b/cmd/mempool/block_queue.go @@ -92,3 +92,9 @@ func (bq *BlockQueue) ExpirationLevel(hash string) uint64 { } return 0 } + +// Contains - +func (bq *BlockQueue) Contains(hash string) bool { + _, ok := bq.levels[hash] + return ok +} diff --git a/cmd/mempool/handlers.go b/cmd/mempool/handlers.go index c68e11b..d24af91 100644 --- a/cmd/mempool/handlers.go +++ b/cmd/mempool/handlers.go @@ -211,9 +211,11 @@ func (indexer *Indexer) handleContent(tx pg.DBI, content node.Content, operation case node.KindActivation: return handleActivateAccount(tx, content, operation, indexer.filters.Accounts...) case node.KindBallot: - return handleBallot(tx, content, operation) + var model models.Ballot + return defaultHandler(tx, content, operation, &model) case node.KindDelegation: - return handleDelegation(tx, content, operation) + var model models.Delegation + return defaultHandler(tx, content, operation, &model) case node.KindDoubleBaking: return handleDoubleBaking(tx, content, operation) case node.KindDoubleEndorsing: @@ -223,7 +225,8 @@ func (indexer *Indexer) handleContent(tx pg.DBI, content node.Content, operation case node.KindEndorsementWithSlot: return indexer.handleEndorsementWithSlot(tx, content, operation) case node.KindNonceRevelation: - return handleNonceRevelation(tx, content, operation) + var model models.NonceRevelation + return defaultHandler(tx, content, operation, &model) case node.KindOrigination: return handleOrigination(tx, content, operation) case node.KindProposal: @@ -233,39 +236,57 @@ func (indexer *Indexer) handleContent(tx pg.DBI, content node.Content, operation case node.KindTransaction: return handleTransaction(tx, content, operation, indexer.filters.Accounts...) case node.KindRegisterGlobalConstant: - return handleRegisterGloabalConstant(tx, content, operation) + var model models.RegisterGlobalConstant + return defaultHandler(tx, content, operation, &model) case node.KindDoublePreendorsement: - return handleDoublePreendorsement(tx, content, operation) + var model models.DoublePreendorsing + return defaultHandler(tx, content, operation, &model) case node.KindPreendorsement: - return handlePreendorsement(tx, content, operation) + var model models.Preendorsement + return defaultHandler(tx, content, operation, &model) case node.KindSetDepositsLimit: return handleSetDepositsLimit(tx, content, operation, indexer.filters.Accounts...) case node.KindTransferTicket: - return handleTransferTicket(tx, content, operation) + var model models.TransferTicket + return defaultHandler(tx, content, operation, &model) case node.KindTxRollupCommit: - return handleTxRollupCommit(tx, content, operation) + var model models.TxRollupCommit + return defaultHandler(tx, content, operation, &model) case node.KindTxRollupDispatchTickets: - return handleTxRollupDispatchTickets(tx, content, operation) + var model models.TxRollupDispatchTickets + return defaultHandler(tx, content, operation, &model) case node.KindTxRollupFinalizeCommitment: - return handleTxRollupFinalizeCommitment(tx, content, operation) + var model models.TxRollupFinalizeCommitment + return defaultHandler(tx, content, operation, &model) case node.KindTxRollupOrigination: - return handleTxRollupOrigination(tx, content, operation) + var model models.TxRollupOrigination + return defaultHandler(tx, content, operation, &model) case node.KindTxRollupRejection: - return handleTxRollupRejection(tx, content, operation) + var model models.TxRollupRejection + return defaultHandler(tx, content, operation, &model) case node.KindTxRollupRemoveCommitment: - return handleTxRollupRemoveCommitment(tx, content, operation) + var model models.TxRollupRemoveCommitment + return defaultHandler(tx, content, operation, &model) case node.KindTxRollupReturnBond: - return handleTxRollupReturnBond(tx, content, operation) + var model models.TxRollupReturnBond + return defaultHandler(tx, content, operation, &model) case node.KindTxRollupSubmitBatch: - return handleTxRollupSubmitBatch(tx, content, operation) - + var model models.TxRollupSubmitBatch + return defaultHandler(tx, content, operation, &model) + case node.KindIncreasePaidStorage: + var model models.IncreasePaidStorage + return defaultHandler(tx, content, operation, &model) + case node.KindVdfRevelation: + var model models.VdfRevelation + return defaultHandler(tx, content, operation, &model) + case node.KindEvent: default: indexer.warn().Str("kind", content.Kind).Msg("unknown operation kind") - return nil } + return nil } -func createModel(db pg.DBI, model interface{}) error { +func createModel(db pg.DBI, model any) error { _, err := db.Model(model).OnConflict("DO NOTHING").Insert() return err } @@ -363,24 +384,6 @@ func handleReveal(tx pg.DBI, content node.Content, operation models.MempoolOpera return createModel(tx, &reveal) } -func handleBallot(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var ballot models.Ballot - if err := json.Unmarshal(content.Body, &ballot); err != nil { - return err - } - ballot.MempoolOperation = operation - return createModel(tx, &ballot) -} - -func handleDelegation(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var delegation models.Delegation - if err := json.Unmarshal(content.Body, &delegation); err != nil { - return err - } - delegation.MempoolOperation = operation - return createModel(tx, &delegation) -} - func handleDoubleBaking(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { var doubleBaking models.DoubleBaking if err := json.Unmarshal(content.Body, &doubleBaking); err != nil { @@ -401,15 +404,6 @@ func handleDoubleEndorsing(tx pg.DBI, content node.Content, operation models.Mem return createModel(tx, &doubleEndorsing) } -func handleNonceRevelation(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var nonceRevelation models.NonceRevelation - if err := json.Unmarshal(content.Body, &nonceRevelation); err != nil { - return err - } - nonceRevelation.MempoolOperation = operation - return createModel(tx, &nonceRevelation) -} - func handleOrigination(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { var origination models.Origination if err := json.Unmarshal(content.Body, &origination); err != nil { @@ -442,33 +436,6 @@ func handleProposal(tx pg.DBI, content node.Content, operation models.MempoolOpe return nil } -func handleRegisterGloabalConstant(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var registerGlobalConstant models.RegisterGlobalConstant - if err := json.Unmarshal(content.Body, ®isterGlobalConstant); err != nil { - return err - } - registerGlobalConstant.MempoolOperation = operation - return createModel(tx, ®isterGlobalConstant) -} - -func handlePreendorsement(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var preendorsement models.Preendorsement - if err := json.Unmarshal(content.Body, &preendorsement); err != nil { - return err - } - preendorsement.MempoolOperation = operation - return createModel(tx, &preendorsement) -} - -func handleDoublePreendorsement(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var doublePreendorsement models.DoublePreendorsing - if err := json.Unmarshal(content.Body, &doublePreendorsement); err != nil { - return err - } - doublePreendorsement.MempoolOperation = operation - return createModel(tx, &doublePreendorsement) -} - func handleSetDepositsLimit(tx pg.DBI, content node.Content, operation models.MempoolOperation, accounts ...string) error { var setDepositsLimit models.SetDepositsLimit if err := json.Unmarshal(content.Body, &setDepositsLimit); err != nil { @@ -489,85 +456,12 @@ func handleSetDepositsLimit(tx pg.DBI, content node.Content, operation models.Me return createModel(tx, &setDepositsLimit) } -func handleTransferTicket(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var transferTicket models.TransferTicket - if err := json.Unmarshal(content.Body, &transferTicket); err != nil { - return err - } - transferTicket.MempoolOperation = operation - return createModel(tx, &transferTicket) -} - -func handleTxRollupCommit(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var t models.TxRollupCommit - if err := json.Unmarshal(content.Body, &t); err != nil { - return err - } - t.MempoolOperation = operation - return createModel(tx, &t) -} - -func handleTxRollupDispatchTickets(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var t models.TxRollupDispatchTickets - if err := json.Unmarshal(content.Body, &t); err != nil { - return err - } - t.MempoolOperation = operation - return createModel(tx, &t) -} - -func handleTxRollupFinalizeCommitment(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var t models.TxRollupFinalizeCommitment - if err := json.Unmarshal(content.Body, &t); err != nil { - return err - } - t.MempoolOperation = operation - return createModel(tx, &t) -} - -func handleTxRollupOrigination(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var t models.TxRollupOrigination - if err := json.Unmarshal(content.Body, &t); err != nil { - return err - } - t.MempoolOperation = operation - return createModel(tx, &t) -} - -func handleTxRollupRejection(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var t models.TxRollupRejection - if err := json.Unmarshal(content.Body, &t); err != nil { - return err - } - t.MempoolOperation = operation - return createModel(tx, &t) -} - -func handleTxRollupRemoveCommitment(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var t models.TxRollupRemoveCommitment - if err := json.Unmarshal(content.Body, &t); err != nil { - return err - } - t.MempoolOperation = operation - return createModel(tx, &t) -} - -func handleTxRollupReturnBond(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var t models.TxRollupReturnBond - if err := json.Unmarshal(content.Body, &t); err != nil { - return err - } - t.MempoolOperation = operation - return createModel(tx, &t) -} - -func handleTxRollupSubmitBatch(tx pg.DBI, content node.Content, operation models.MempoolOperation) error { - var t models.TxRollupSubmitBatch - if err := json.Unmarshal(content.Body, &t); err != nil { +func defaultHandler[M models.ChangableMempoolOperation](tx pg.DBI, content node.Content, operation models.MempoolOperation, model M) error { + if err := json.Unmarshal(content.Body, model); err != nil { return err } - t.MempoolOperation = operation - return createModel(tx, &t) + model.SetMempoolOperation(operation) + return createModel(tx, model) } func (indexer *Indexer) isKindAvailiable(kind string) bool { diff --git a/cmd/mempool/main.go b/cmd/mempool/main.go index 916b215..700f721 100644 --- a/cmd/mempool/main.go +++ b/cmd/mempool/main.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "io/ioutil" "os" "os/signal" "strings" @@ -159,7 +158,7 @@ func main() { } func createViews(ctx context.Context, database libCfg.Database) ([]string, error) { - files, err := ioutil.ReadDir("views") + files, err := os.ReadDir("views") if err != nil { return nil, err } @@ -177,7 +176,7 @@ func createViews(ctx context.Context, database libCfg.Database) ([]string, error } path := fmt.Sprintf("views/%s", files[i].Name()) - raw, err := ioutil.ReadFile(path) + raw, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/cmd/mempool/models/ballot.go b/cmd/mempool/models/ballot.go index 14f47a6..6b6fd4c 100644 --- a/cmd/mempool/models/ballot.go +++ b/cmd/mempool/models/ballot.go @@ -8,3 +8,8 @@ type Ballot struct { Period int64 `json:"period"` Ballot string `json:"ballot"` } + +// SetMempoolOperation - +func (i *Ballot) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/delegation.go b/cmd/mempool/models/delegation.go index 5415450..ab9a8e9 100644 --- a/cmd/mempool/models/delegation.go +++ b/cmd/mempool/models/delegation.go @@ -6,9 +6,14 @@ type Delegation struct { tableName struct{} `pg:"delegations"` MempoolOperation Fee int64 `json:"fee,string"` - Counter int64 `pg:",pk" json:"counter,string"` + Counter int64 `json:"counter,string" pg:",pk"` GasLimit int64 `json:"gas_limit,string"` StorageLimit int64 `json:"storage_limit,string"` Delegate string `json:",omitempty"` Source string `json:"source,omitempty" index:"delegation_source_idx"` } + +// SetMempoolOperation - +func (i *Delegation) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/double_preendorsing.go b/cmd/mempool/models/double_preendorsing.go index e44e65b..0148666 100644 --- a/cmd/mempool/models/double_preendorsing.go +++ b/cmd/mempool/models/double_preendorsing.go @@ -32,3 +32,8 @@ func (mde *DoublePreendorsing) Fill() { mde.Op2Kind = mde.Op2.Operations.Kind mde.Op2Level = mde.Op2.Operations.Level } + +// SetMempoolOperation - +func (mde *DoublePreendorsing) SetMempoolOperation(operaiton MempoolOperation) { + mde.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/increase_paid_storage.go b/cmd/mempool/models/increase_paid_storage.go new file mode 100644 index 0000000..47c37b6 --- /dev/null +++ b/cmd/mempool/models/increase_paid_storage.go @@ -0,0 +1,14 @@ +package models + +// IncreasePaidStorage - +type IncreasePaidStorage struct { + //nolint + tableName struct{} `pg:"increase_paid_storage"` + + MempoolOperation +} + +// SetMempoolOperation - +func (i *IncreasePaidStorage) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/mempool_operation.go b/cmd/mempool/models/mempool_operation.go index 310c516..a9ae70a 100644 --- a/cmd/mempool/models/mempool_operation.go +++ b/cmd/mempool/models/mempool_operation.go @@ -21,8 +21,15 @@ const ( // DefaultConstraint - type DefaultConstraint interface { - TransferTicket | TxRollupCommit | TxRollupDispatchTickets | TxRollupFinalizeCommitment | TxRollupOrigination | - TxRollupRejection | TxRollupRemoveCommitment | TxRollupReturnBond | TxRollupSubmitBatch + Ballot | ActivateAccount | Delegation | DoubleBaking | DoubleEndorsing | DoublePreendorsing | Endorsement | + NonceRevelation | Origination | Preendorsement | Proposal | RegisterGlobalConstant | Reveal | SetDepositsLimit | + Transaction | TransferTicket | TxRollupCommit | TxRollupDispatchTickets | TxRollupFinalizeCommitment | TxRollupOrigination | + TxRollupRejection | TxRollupRemoveCommitment | TxRollupReturnBond | TxRollupSubmitBatch | VdfRevelation | IncreasePaidStorage +} + +// ChangableMempoolOperation - +type ChangableMempoolOperation interface { + SetMempoolOperation(operation MempoolOperation) } // MempoolOperation - @@ -238,6 +245,10 @@ func getModelByKind(kind string) (interface{}, error) { return &TxRollupReturnBond{}, nil case node.KindTxRollupSubmitBatch: return &TxRollupSubmitBatch{}, nil + case node.KindIncreasePaidStorage: + return &IncreasePaidStorage{}, nil + case node.KindVdfRevelation: + return &VdfRevelation{}, nil default: return nil, errors.Wrap(node.ErrUnknownKind, kind) diff --git a/cmd/mempool/models/nonce_revelation.go b/cmd/mempool/models/nonce_revelation.go index 8dfacc0..f16a8f2 100644 --- a/cmd/mempool/models/nonce_revelation.go +++ b/cmd/mempool/models/nonce_revelation.go @@ -8,3 +8,8 @@ type NonceRevelation struct { Level int `json:"level"` Nonce string `json:"nonce"` } + +// SetMempoolOperation - +func (i *NonceRevelation) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/preendorsement.go b/cmd/mempool/models/preendorsement.go index adf1e46..7e72a8f 100644 --- a/cmd/mempool/models/preendorsement.go +++ b/cmd/mempool/models/preendorsement.go @@ -6,3 +6,8 @@ type Preendorsement struct { tableName struct{} `pg:"preendorsements"` MempoolOperation } + +// SetMempoolOperation - +func (i *Preendorsement) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/register_global_constant.go b/cmd/mempool/models/register_global_constant.go index 0aeeaed..edaec96 100644 --- a/cmd/mempool/models/register_global_constant.go +++ b/cmd/mempool/models/register_global_constant.go @@ -12,3 +12,8 @@ type RegisterGlobalConstant struct { StorageLimit string `json:"storage_limit"` Value JSONB `json:"value" pg:"value,type:jsonb"` } + +// SetMempoolOperation - +func (i *RegisterGlobalConstant) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/transfer_ticket.go b/cmd/mempool/models/transfer_ticket.go index 13fbdec..a9c108b 100644 --- a/cmd/mempool/models/transfer_ticket.go +++ b/cmd/mempool/models/transfer_ticket.go @@ -12,3 +12,8 @@ type TransferTicket struct { StorageLimit int64 `json:"storage_limit,string"` Source string `json:"source,omitempty" index:"transfer_ticket_source_idx"` } + +// SetMempoolOperation - +func (i *TransferTicket) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/tx_rollup_commit.go b/cmd/mempool/models/tx_rollup_commit.go index f5d23b7..b764fe1 100644 --- a/cmd/mempool/models/tx_rollup_commit.go +++ b/cmd/mempool/models/tx_rollup_commit.go @@ -13,3 +13,8 @@ type TxRollupCommit struct { Source string `json:"source,omitempty" index:"tx_rollup_commit_source_idx"` Rollup string `json:"rollup,omitempty" index:"tx_rollup_commit_rollup_idx"` } + +// SetMempoolOperation - +func (i *TxRollupCommit) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/tx_rollup_dispatch_tickets.go b/cmd/mempool/models/tx_rollup_dispatch_tickets.go index 641b6e4..eadfe04 100644 --- a/cmd/mempool/models/tx_rollup_dispatch_tickets.go +++ b/cmd/mempool/models/tx_rollup_dispatch_tickets.go @@ -13,3 +13,8 @@ type TxRollupDispatchTickets struct { Source string `json:"source,omitempty" index:"tx_rollup_dispatch_tickets_source_idx"` TxRollup string `json:"tx_rollup,omitempty" index:"tx_rollup_dispatch_tickets_rollup_idx"` } + +// SetMempoolOperation - +func (i *TxRollupDispatchTickets) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/tx_rollup_finalize_commitment.go b/cmd/mempool/models/tx_rollup_finalize_commitment.go index 2d55a3a..4284d89 100644 --- a/cmd/mempool/models/tx_rollup_finalize_commitment.go +++ b/cmd/mempool/models/tx_rollup_finalize_commitment.go @@ -13,3 +13,8 @@ type TxRollupFinalizeCommitment struct { Source string `json:"source,omitempty" index:"tx_rollup_finalize_commitment_source_idx"` Rollup string `json:"rollup,omitempty" index:"tx_rollup_finalize_commitment_rollup_idx"` } + +// SetMempoolOperation - +func (i *TxRollupFinalizeCommitment) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/tx_rollup_origination.go b/cmd/mempool/models/tx_rollup_origination.go index c6f90d2..ee96a70 100644 --- a/cmd/mempool/models/tx_rollup_origination.go +++ b/cmd/mempool/models/tx_rollup_origination.go @@ -12,3 +12,8 @@ type TxRollupOrigination struct { StorageLimit int64 `json:"storage_limit,string"` Source string `json:"source,omitempty" index:"ttx_rollup_origination_source_idx"` } + +// SetMempoolOperation - +func (i *TxRollupOrigination) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/tx_rollup_rejection.go b/cmd/mempool/models/tx_rollup_rejection.go index fd90bd2..79f5517 100644 --- a/cmd/mempool/models/tx_rollup_rejection.go +++ b/cmd/mempool/models/tx_rollup_rejection.go @@ -12,3 +12,8 @@ type TxRollupRejection struct { StorageLimit int64 `json:"storage_limit,string"` Source string `json:"source,omitempty" index:"ttx_rollup_rejection_source_idx"` } + +// SetMempoolOperation - +func (i *TxRollupRejection) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/tx_rollup_remove_commitment.go b/cmd/mempool/models/tx_rollup_remove_commitment.go index d4e0113..e77664f 100644 --- a/cmd/mempool/models/tx_rollup_remove_commitment.go +++ b/cmd/mempool/models/tx_rollup_remove_commitment.go @@ -13,3 +13,8 @@ type TxRollupRemoveCommitment struct { Source string `json:"source,omitempty" index:"tx_rollup_remove_commitment_source_idx"` Rollup string `json:"rollup,omitempty" index:"tx_rollup_remove_commitment_rollup_idx"` } + +// SetMempoolOperation - +func (i *TxRollupRemoveCommitment) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/tx_rollup_return_bond.go b/cmd/mempool/models/tx_rollup_return_bond.go index b99917c..fbc2a82 100644 --- a/cmd/mempool/models/tx_rollup_return_bond.go +++ b/cmd/mempool/models/tx_rollup_return_bond.go @@ -12,3 +12,8 @@ type TxRollupReturnBond struct { StorageLimit int64 `json:"storage_limit,string"` Source string `json:"source,omitempty" index:"ttx_rollup_return_bond_source_idx"` } + +// SetMempoolOperation - +func (i *TxRollupReturnBond) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/tx_rollup_submit_batch.go b/cmd/mempool/models/tx_rollup_submit_batch.go index 4589894..a82027d 100644 --- a/cmd/mempool/models/tx_rollup_submit_batch.go +++ b/cmd/mempool/models/tx_rollup_submit_batch.go @@ -13,3 +13,8 @@ type TxRollupSubmitBatch struct { Source string `json:"source,omitempty" index:"tx_rollup_submit_batch_source_idx"` Rollup string `json:"rollup,omitempty" index:"tx_rollup_submit_batch_rollup_idx"` } + +// SetMempoolOperation - +func (i *TxRollupSubmitBatch) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/models/vdf_revelation.go b/cmd/mempool/models/vdf_revelation.go new file mode 100644 index 0000000..a061563 --- /dev/null +++ b/cmd/mempool/models/vdf_revelation.go @@ -0,0 +1,14 @@ +package models + +// VdfRevelation - +type VdfRevelation struct { + //nolint + tableName struct{} `pg:"vdf_revelation"` + + MempoolOperation +} + +// SetMempoolOperation - +func (i *VdfRevelation) SetMempoolOperation(operaiton MempoolOperation) { + i.MempoolOperation = operaiton +} diff --git a/cmd/mempool/tzkt/data.go b/cmd/mempool/tzkt/data.go index 52e2a82..b0f84d8 100644 --- a/cmd/mempool/tzkt/data.go +++ b/cmd/mempool/tzkt/data.go @@ -32,6 +32,8 @@ var toNodeKinds = map[string]string{ data.KindTxRollupRejection: node.KindTxRollupRejection, data.KindTxRollupRemoveCommitment: node.KindTxRollupRemoveCommitment, data.KindSetDepositsLimit: node.KindSetDepositsLimit, + data.KindIncreasePaidStorage: node.KindIncreasePaidStorage, + data.KindVdfRevelation: node.KindVdfRevelation, } var toTzKTKinds = map[string]string{ @@ -57,6 +59,8 @@ var toTzKTKinds = map[string]string{ node.KindTxRollupRejection: data.KindTxRollupRejection, node.KindTxRollupRemoveCommitment: data.KindTxRollupRemoveCommitment, node.KindSetDepositsLimit: data.KindSetDepositsLimit, + node.KindIncreasePaidStorage: data.KindIncreasePaidStorage, + node.KindVdfRevelation: data.KindVdfRevelation, } // OperationMessage - diff --git a/cmd/mempool/tzkt/processors.go b/cmd/mempool/tzkt/processors.go index daec966..4938aae 100644 --- a/cmd/mempool/tzkt/processors.go +++ b/cmd/mempool/tzkt/processors.go @@ -253,3 +253,25 @@ func operationFromTransferTicket(model data.TransferTicket) data.Operation { Block: model.Block, } } + +func operationFromIncreasePaidStorage(model data.IncreasePaidStorage) data.Operation { + return data.Operation{ + Type: node.KindIncreasePaidStorage, + Level: model.Level, + ID: model.ID, + Hash: model.Hash, + Block: model.Block, + GasUsed: &model.GasUsed, + BakerFee: &model.BakerFee, + } +} + +func operationFromVdfRevelation(model data.VdfRevelation) data.Operation { + return data.Operation{ + Type: node.KindVdfRevelation, + Level: model.Level, + ID: model.ID, + Hash: model.Hash, + Block: model.Block, + } +} diff --git a/cmd/mempool/tzkt/tzkt.go b/cmd/mempool/tzkt/tzkt.go index 2761ca5..f061372 100644 --- a/cmd/mempool/tzkt/tzkt.go +++ b/cmd/mempool/tzkt/tzkt.go @@ -52,7 +52,7 @@ func NewTzKT(url string, accounts []string, kinds []string) *TzKT { // Connect - func (tzkt *TzKT) Connect(ctx context.Context) error { - if err := tzkt.client.Connect(); err != nil { + if err := tzkt.client.Connect(ctx); err != nil { return err } @@ -244,6 +244,12 @@ func (tzkt *TzKT) getAPIOperation(model interface{}) (data.Operation, error) { case *data.TxRollupSubmitBatch: return operationFromTxRollupSubmitBatch(*operation), nil + case *data.VdfRevelation: + return operationFromVdfRevelation(*operation), nil + + case *data.IncreasePaidStorage: + return operationFromIncreasePaidStorage(*operation), nil + default: return data.Operation{}, errors.Wrapf(ErrInvalidOperationType, "%T", model) } @@ -549,6 +555,10 @@ func (tzkt *TzKT) getTableData(ctx context.Context, table *tableState, indexerSt return getOperations(ctx, table, filters, tzkt.api.GetTxRollupRejection, operationFromTxRollupRejection) case data.KindTxRollupRemoveCommitment: return getOperations(ctx, table, filters, tzkt.api.GetTxRollupRemoveCommitment, operationFromTxRollupRemoveCommitment) + case data.KindVdfRevelation: + return getOperations(ctx, table, filters, tzkt.api.GetVdfRevelations, operationFromVdfRevelation) + case data.KindIncreasePaidStorage: + return getOperations(ctx, table, filters, tzkt.api.GetIncreasePaidStorage, operationFromIncreasePaidStorage) default: return errors.Wrap(ErrUnknownOperationKind, table.Table) } diff --git a/go.mod b/go.mod index 68299b2..f7eb790 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/btcsuite/btcutil v1.0.2 - github.com/dipdup-net/go-lib v0.2.14 + github.com/dipdup-net/go-lib v0.2.22 github.com/go-pg/pg/v10 v10.10.6 github.com/json-iterator/go v1.1.12 github.com/karlseguin/ccache v2.0.3+incompatible diff --git a/go.sum b/go.sum index e769c0e..4acb7b1 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dipdup-net/go-lib v0.2.14 h1:QlS3wjJefBqjse/EIkWfT2vO00Go5SumWNmZ7tqFYL0= -github.com/dipdup-net/go-lib v0.2.14/go.mod h1:RCYx6FV8+7qQkC1dCP8zn8WTlsFRXXx/D4N+2mw1GJg= +github.com/dipdup-net/go-lib v0.2.22 h1:VDo6Atzl7OkXHI6H15NpZB8sIv/+mzK1JGRYEVs+gH8= +github.com/dipdup-net/go-lib v0.2.22/go.mod h1:RCYx6FV8+7qQkC1dCP8zn8WTlsFRXXx/D4N+2mw1GJg= github.com/ebellocchia/go-base58 v0.1.0 h1:0w/ODEfZnOPW5KW0QY/Xpb1fxba/BxQJMUa5iYzpljk= github.com/ebellocchia/go-base58 v0.1.0/go.mod h1:RHE/6C6Ru6YAH9Tc+A9eHQ6ZKEooLC0jw+YLnpt3CAU= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=