Skip to content

Commit

Permalink
Merge pull request #67 from multiversx/small-block-data-fixes
Browse files Browse the repository at this point in the history
Additional bock data info
  • Loading branch information
ssd04 authored Feb 17, 2023
2 parents 266fa47 + 2c72293 commit 50ac6e5
Show file tree
Hide file tree
Showing 26 changed files with 427 additions and 411 deletions.
4 changes: 2 additions & 2 deletions api/groups/eventsData_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ func TestUnmarshallBlockDataV2(t *testing.T) {
Body: &block.Body{},
Header: &block.HeaderV2{},
TransactionsPool: &data.TransactionsPool{
Txs: map[string]data.TransactionWithOrder{
Txs: map[string]*data.NodeTransaction{
"hash2": {
TransactionHandler: &transaction.Transaction{
Nonce: 2,
},
ExecutionOrder: 1,
},
},
Scrs: map[string]data.SmartContractResultWithOrder{
Scrs: map[string]*data.NodeSmartContractResult{
"hash3": {
TransactionHandler: &smartContractResult.SmartContractResult{
Nonce: 3,
Expand Down
4 changes: 2 additions & 2 deletions api/groups/eventsGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ func TestEventsGroup_PushEvents(t *testing.T) {
Body: &block.Body{},
Header: &block.HeaderV2{},
TransactionsPool: &data.TransactionsPool{
Txs: map[string]data.TransactionWithOrder{
Txs: map[string]*data.NodeTransaction{
"hash2": {
TransactionHandler: &transaction.Transaction{
Nonce: 2,
},
ExecutionOrder: 1,
},
},
Scrs: map[string]data.SmartContractResultWithOrder{
Scrs: map[string]*data.NodeSmartContractResult{
"hash3": {
TransactionHandler: &smartContractResult.SmartContractResult{
Nonce: 3,
Expand Down
7 changes: 2 additions & 5 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const (
// PushLogsAndEvents defines the subscription event type for pushing block events
PushLogsAndEvents string = "all_events"

// PushBlockEvents defines the subscription event type for block info with logs and events
PushBlockEvents string = "block_events"
// BlockEvents defines the subscription event type for block info with logs and events
BlockEvents string = "block_events"

// RevertBlockEvents defines the subscription event type for revert block
RevertBlockEvents string = "revert_events"
Expand All @@ -35,9 +35,6 @@ const (
// BlockTxs defines the subscription event type for block txs
BlockTxs string = "block_txs"

// BlockEventsWithOrder defines the subscription event type for block events with order
BlockEventsWithOrder string = "block_events_with_order"

// BlockScrs defines the subscription event type for block scrs
BlockScrs string = "block_scrs"
)
95 changes: 95 additions & 0 deletions data/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package data

import (
"github.com/multiversx/mx-chain-core-go/core"
nodeData "github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/outport"
"github.com/multiversx/mx-chain-core-go/data/receipt"
"github.com/multiversx/mx-chain-core-go/data/rewardTx"
"github.com/multiversx/mx-chain-core-go/data/smartContractResult"
"github.com/multiversx/mx-chain-core-go/data/transaction"
)

// SaveBlockData holds the filtered block data that will be received on push events
type SaveBlockData struct {
Hash string `json:"hash"`
Txs map[string]*transaction.Transaction `json:"txs"`
Scrs map[string]*smartContractResult.SmartContractResult `json:"scrs"`
LogEvents []Event `json:"events"`
}

// InterceptorBlockData holds the block data needed for processing
type InterceptorBlockData struct {
Hash string
Body nodeData.BodyHandler
Header nodeData.HeaderHandler
Txs map[string]*transaction.Transaction
TxsWithOrder map[string]*NotifierTransaction
Scrs map[string]*smartContractResult.SmartContractResult
ScrsWithOrder map[string]*NotifierSmartContractResult
LogEvents []Event
}

// ArgsSaveBlockData holds the block data that will be received on push events
type ArgsSaveBlockData struct {
HeaderHash []byte
Body nodeData.BodyHandler
Header nodeData.HeaderHandler
SignersIndexes []uint64
NotarizedHeadersHashes []string
HeaderGasConsumption outport.HeaderGasConsumption
TransactionsPool *TransactionsPool
AlteredAccounts map[string]*outport.AlteredAccount
NumberOfShards uint32
IsImportDB bool
}

// ArgsSaveBlock holds block data with header type
type ArgsSaveBlock struct {
HeaderType core.HeaderType
ArgsSaveBlockData
}

// LogData holds the data needed for indexing logs and events
type LogData struct {
LogHandler *transaction.Log
TxHash string
}

// TransactionsPool holds all types of transaction
type TransactionsPool struct {
Txs map[string]*NodeTransaction
Scrs map[string]*NodeSmartContractResult
Rewards map[string]*NodeRewardTx
Invalid map[string]*NodeTransaction
Receipts map[string]*NodeReceipt
Logs []*LogData
}

// NodeTransaction defines a wrapper over transaction
type NodeTransaction struct {
TransactionHandler *transaction.Transaction
outport.FeeInfo
ExecutionOrder int
}

// NodeSmartContractResult defines a wrapper over scr
type NodeSmartContractResult struct {
TransactionHandler *smartContractResult.SmartContractResult
outport.FeeInfo
ExecutionOrder int
}

// NodeRewardTx defines a wrapper over rewardTx
type NodeRewardTx struct {
TransactionHandler *rewardTx.RewardTx
outport.FeeInfo
ExecutionOrder int
}

// NodeReceipt defines a wrapper over receipt
type NodeReceipt struct {
TransactionHandler *receipt.Receipt
outport.FeeInfo
ExecutionOrder int
}
97 changes: 97 additions & 0 deletions data/outport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package data

import (
"encoding/json"

"github.com/multiversx/mx-chain-core-go/data/outport"
"github.com/multiversx/mx-chain-core-go/data/receipt"
"github.com/multiversx/mx-chain-core-go/data/rewardTx"
"github.com/multiversx/mx-chain-core-go/data/smartContractResult"
"github.com/multiversx/mx-chain-core-go/data/transaction"
)

// WebSocketEvent defines a websocket event
type WebSocketEvent struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}

// Event holds event data
type Event struct {
Address string `json:"address"`
Identifier string `json:"identifier"`
Topics [][]byte `json:"topics"`
Data []byte `json:"data"`
TxHash string `json:"txHash"`
}

// BlockEvents holds events data for a block
type BlockEvents struct {
Hash string `json:"hash"`
ShardID uint32 `json:"shardId"`
TimeStamp uint64 `json:"timestamp"`
Events []Event `json:"events"`
}

// RevertBlock holds revert event data
type RevertBlock struct {
Hash string `json:"hash"`
Nonce uint64 `json:"nonce"`
Round uint64 `json:"round"`
Epoch uint32 `json:"epoch"`
}

// FinalizedBlock holds finalized block data
type FinalizedBlock struct {
Hash string `json:"hash"`
}

// BlockTxs holds the block transactions
type BlockTxs struct {
Hash string `json:"hash"`
Txs map[string]*transaction.Transaction `json:"txs"`
}

// BlockScrs holds the block smart contract results
type BlockScrs struct {
Hash string `json:"hash"`
Scrs map[string]*smartContractResult.SmartContractResult `json:"scrs"`
}

// BlockEventsWithOrder holds the block transactions with order
type BlockEventsWithOrder struct {
Hash string `json:"hash"`
ShardID uint32 `json:"shardID"`
TimeStamp uint64 `json:"timestamp"`
Txs map[string]*NotifierTransaction `json:"txs"`
Scrs map[string]*NotifierSmartContractResult `json:"scrs"`
Events []Event `json:"events"`
}

// NotifierTransaction defines a wrapper over transaction
type NotifierTransaction struct {
*transaction.Transaction
outport.FeeInfo
ExecutionOrder int
}

// NotifierSmartContractResult defines a wrapper over scr
type NotifierSmartContractResult struct {
*smartContractResult.SmartContractResult
outport.FeeInfo
ExecutionOrder int
}

// NotifierRewardTx defines a wrapper over rewardTx
type NotifierRewardTx struct {
*rewardTx.RewardTx
outport.FeeInfo
ExecutionOrder int
}

// NotifierReceipt defines a wrapper over receipt
type NotifierReceipt struct {
*receipt.Receipt
outport.FeeInfo
ExecutionOrder int
}
Loading

0 comments on commit 50ac6e5

Please sign in to comment.