Skip to content

Commit

Permalink
Merge 7b84d9f into 4b20833
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Oct 5, 2023
2 parents 4b20833 + 7b84d9f commit b251610
Show file tree
Hide file tree
Showing 7 changed files with 748 additions and 33 deletions.
94 changes: 94 additions & 0 deletions node/chainSimulator/dataComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package chainSimulator

import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/dataRetriever/provider"
"github.com/multiversx/mx-chain-go/factory"
)

// ArgsDataComponentsHolder will hold the components needed for data components
type ArgsDataComponentsHolder struct {
Chain data.ChainHandler
StorageService dataRetriever.StorageService
DataPool dataRetriever.PoolsHolder
InternalMarshaller marshal.Marshalizer
}

type dataComponentsHolder struct {
chain data.ChainHandler
storageService dataRetriever.StorageService
dataPool dataRetriever.PoolsHolder
miniBlockProvider factory.MiniBlockProvider
}

// CreateDataComponentsHolder will create the data components holder
func CreateDataComponentsHolder(args ArgsDataComponentsHolder) (factory.DataComponentsHolder, error) {
miniBlockStorer, err := args.StorageService.GetStorer(dataRetriever.MiniBlockUnit)
if err != nil {
return nil, err

Check warning on line 30 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L27-L30

Added lines #L27 - L30 were not covered by tests
}

arg := provider.ArgMiniBlockProvider{
MiniBlockPool: args.DataPool.MiniBlocks(),
MiniBlockStorage: miniBlockStorer,
Marshalizer: args.InternalMarshaller,

Check warning on line 36 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L33-L36

Added lines #L33 - L36 were not covered by tests
}

miniBlocksProvider, err := provider.NewMiniBlockProvider(arg)
if err != nil {
return nil, err

Check warning on line 41 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L39-L41

Added lines #L39 - L41 were not covered by tests
}

instance := &dataComponentsHolder{
chain: args.Chain,
storageService: args.StorageService,
dataPool: args.DataPool,
miniBlockProvider: miniBlocksProvider,

Check warning on line 48 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L44-L48

Added lines #L44 - L48 were not covered by tests
}

return instance, nil

Check warning on line 51 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L51

Added line #L51 was not covered by tests
}

// Blockchain will return the blockchain handler
func (d *dataComponentsHolder) Blockchain() data.ChainHandler {
return d.chain

Check warning on line 56 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L55-L56

Added lines #L55 - L56 were not covered by tests
}

// SetBlockchain will set the blockchain handler
func (d *dataComponentsHolder) SetBlockchain(chain data.ChainHandler) error {
d.chain = chain

Check warning on line 61 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L60-L61

Added lines #L60 - L61 were not covered by tests

return nil

Check warning on line 63 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L63

Added line #L63 was not covered by tests
}

// StorageService will return the storage service
func (d *dataComponentsHolder) StorageService() dataRetriever.StorageService {
return d.storageService

Check warning on line 68 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L67-L68

Added lines #L67 - L68 were not covered by tests
}

// Datapool will return the data pool
func (d *dataComponentsHolder) Datapool() dataRetriever.PoolsHolder {
return d.dataPool

Check warning on line 73 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L72-L73

Added lines #L72 - L73 were not covered by tests
}

// MiniBlocksProvider will return the mini blocks provider
func (d *dataComponentsHolder) MiniBlocksProvider() factory.MiniBlockProvider {
return d.miniBlockProvider

Check warning on line 78 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L77-L78

Added lines #L77 - L78 were not covered by tests
}

// Clone will clone the data components holder
func (d *dataComponentsHolder) Clone() interface{} {
return &dataComponentsHolder{
chain: d.chain,
storageService: d.storageService,
dataPool: d.dataPool,
miniBlockProvider: d.miniBlockProvider,

Check warning on line 87 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L82-L87

Added lines #L82 - L87 were not covered by tests
}
}

// IsInterfaceNil returns true if there is no value under the interface
func (d *dataComponentsHolder) IsInterfaceNil() bool {
return d == nil

Check warning on line 93 in node/chainSimulator/dataComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/dataComponents.go#L92-L93

Added lines #L92 - L93 were not covered by tests
}

0 comments on commit b251610

Please sign in to comment.