-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5625 from multiversx/data-components-and-process
Data components and process components
- Loading branch information
Showing
7 changed files
with
748 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
arg := provider.ArgMiniBlockProvider{ | ||
MiniBlockPool: args.DataPool.MiniBlocks(), | ||
MiniBlockStorage: miniBlockStorer, | ||
Marshalizer: args.InternalMarshaller, | ||
} | ||
|
||
miniBlocksProvider, err := provider.NewMiniBlockProvider(arg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
instance := &dataComponentsHolder{ | ||
chain: args.Chain, | ||
storageService: args.StorageService, | ||
dataPool: args.DataPool, | ||
miniBlockProvider: miniBlocksProvider, | ||
} | ||
|
||
return instance, nil | ||
} | ||
|
||
// Blockchain will return the blockchain handler | ||
func (d *dataComponentsHolder) Blockchain() data.ChainHandler { | ||
return d.chain | ||
} | ||
|
||
// SetBlockchain will set the blockchain handler | ||
func (d *dataComponentsHolder) SetBlockchain(chain data.ChainHandler) error { | ||
d.chain = chain | ||
|
||
return nil | ||
} | ||
|
||
// StorageService will return the storage service | ||
func (d *dataComponentsHolder) StorageService() dataRetriever.StorageService { | ||
return d.storageService | ||
} | ||
|
||
// Datapool will return the data pool | ||
func (d *dataComponentsHolder) Datapool() dataRetriever.PoolsHolder { | ||
return d.dataPool | ||
} | ||
|
||
// MiniBlocksProvider will return the mini blocks provider | ||
func (d *dataComponentsHolder) MiniBlocksProvider() factory.MiniBlockProvider { | ||
return d.miniBlockProvider | ||
} | ||
|
||
// 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, | ||
} | ||
} | ||
|
||
// IsInterfaceNil returns true if there is no value under the interface | ||
func (d *dataComponentsHolder) IsInterfaceNil() bool { | ||
return d == nil | ||
} |
Oops, something went wrong.