-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert state changes. #25
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think state changes has to be covered also for meta outport block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is also covered. but since the structure is the same the metaOutportBlock object will be casted automatically. The handler function is strictly for the shardOutportBlocks. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"github.com/multiversx/mx-chain-core-go/data/block" | ||
"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/stateChange" | ||
"github.com/multiversx/mx-chain-core-go/marshal" | ||
|
||
"github.com/multiversx/mx-chain-ws-connector-firehose-go/data/hyperOutportBlocks" | ||
|
@@ -63,6 +64,7 @@ func (o *outportBlockConverter) HandleShardOutportBlockV2(outportBlock *outport. | |
} | ||
handleHeaderGasConsumption(outportBlock.HeaderGasConsumption, shardOutportBlock) | ||
handleAlteredAccounts(outportBlock.AlteredAccounts, shardOutportBlock) | ||
handleStateChanges(outportBlock.StateChanges, shardOutportBlock) | ||
|
||
shardOutportBlock.NotarizedHeadersHashes = outportBlock.NotarizedHeadersHashes | ||
shardOutportBlock.NumberOfShards = outportBlock.NumberOfShards | ||
|
@@ -384,6 +386,44 @@ func handleHeaderGasConsumption(consumption *outport.HeaderGasConsumption, shard | |
} | ||
} | ||
|
||
func handleStateChanges(stateChanges map[string]*stateChange.StateChanges, shardOutportBlock *hyperOutportBlocks.ShardOutportBlockV2) { | ||
if stateChanges == nil { | ||
return | ||
} | ||
|
||
shardStateChanges := make(map[string]*hyperOutportBlocks.StateChanges, len(stateChanges)) | ||
for key, scs := range stateChanges { | ||
ss := make([]*hyperOutportBlocks.StateChange, len(scs.StateChanges)) | ||
|
||
for i, sc := range scs.StateChanges { | ||
dtc := make([]*hyperOutportBlocks.DataTrieChange, len(sc.DataTrieChanges)) | ||
|
||
for j, dataTrieChange := range sc.DataTrieChanges { | ||
dtc[j] = &hyperOutportBlocks.DataTrieChange{ | ||
Type: dataTrieChange.Type, | ||
Key: dataTrieChange.Key, | ||
Val: dataTrieChange.Val, | ||
} | ||
} | ||
|
||
ss[i] = &hyperOutportBlocks.StateChange{ | ||
Type: sc.Type, | ||
Index: sc.Index, | ||
TxHash: sc.TxHash, | ||
MainTrieKey: sc.MainTrieKey, | ||
MainTrieVal: sc.MainTrieVal, | ||
Operation: sc.Operation, | ||
DataTrieChanges: dtc, | ||
} | ||
} | ||
|
||
s := &hyperOutportBlocks.StateChanges{StateChanges: ss} | ||
shardStateChanges[key] = s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please avoid single letter variable here, maybe set it directly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed. |
||
} | ||
|
||
shardOutportBlock.StateChanges = shardStateChanges | ||
} | ||
|
||
// HandleShardOutportBlock will convert an outport.OutportBlock to data.ShardOutportBlock. | ||
func (o *outportBlockConverter) HandleShardOutportBlock(outportBlock *outport.OutportBlock) (*hyperOutportBlocks.ShardOutportBlock, error) { | ||
headerType := outportBlock.BlockData.HeaderType | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should think of having enum for
Type
instead of stringThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also in mx-chain-go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified.