-
Notifications
You must be signed in to change notification settings - Fork 329
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
[blockindex]: change private to public #4205
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9ae2229
feat(blockindex): change private to public
hunshenshi c1edb90
feat(blockindex): fix ci
hunshenshi 168bcd5
feat(blockindex): fix ci
hunshenshi 0d3c7b0
feat(blockindex): add comment
hunshenshi c0cf984
Merge branch 'master' into issue4196
hunshenshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -15,34 +15,35 @@ import ( | |
"github.com/iotexproject/iotex-core/pkg/util/byteutil" | ||
) | ||
|
||
type blockIndex struct { | ||
// BlockIndex change private to public for mock Indexer | ||
type BlockIndex struct { | ||
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. comment |
||
hash []byte | ||
numAction uint32 | ||
tsfAmount *big.Int | ||
} | ||
|
||
// Hash returns the hash | ||
func (b *blockIndex) Hash() []byte { | ||
func (b *BlockIndex) Hash() []byte { | ||
return b.hash | ||
} | ||
|
||
// NumAction returns number of actions | ||
func (b *blockIndex) NumAction() uint32 { | ||
func (b *BlockIndex) NumAction() uint32 { | ||
return b.numAction | ||
} | ||
|
||
// TsfAmount returns transfer amount | ||
func (b *blockIndex) TsfAmount() *big.Int { | ||
func (b *BlockIndex) TsfAmount() *big.Int { | ||
return b.tsfAmount | ||
} | ||
|
||
// Serialize into byte stream | ||
func (b *blockIndex) Serialize() []byte { | ||
func (b *BlockIndex) Serialize() []byte { | ||
return byteutil.Must(proto.Marshal(b.toProto())) | ||
} | ||
|
||
// Desrialize from byte stream | ||
func (b *blockIndex) Deserialize(buf []byte) error { | ||
func (b *BlockIndex) Deserialize(buf []byte) error { | ||
pb := &indexpb.BlockIndex{} | ||
if err := proto.Unmarshal(buf, pb); err != nil { | ||
return err | ||
|
@@ -51,7 +52,7 @@ func (b *blockIndex) Deserialize(buf []byte) error { | |
} | ||
|
||
// toProto converts to protobuf | ||
func (b *blockIndex) toProto() *indexpb.BlockIndex { | ||
func (b *BlockIndex) toProto() *indexpb.BlockIndex { | ||
index := &indexpb.BlockIndex{ | ||
NumAction: b.numAction, | ||
Hash: b.hash, | ||
|
@@ -63,7 +64,7 @@ func (b *blockIndex) toProto() *indexpb.BlockIndex { | |
} | ||
|
||
// fromProto converts from protobuf | ||
func (b *blockIndex) fromProto(pbIndex *indexpb.BlockIndex) error { | ||
func (b *BlockIndex) fromProto(pbIndex *indexpb.BlockIndex) error { | ||
if pbIndex == nil { | ||
return errors.New("empty protobuf") | ||
} | ||
|
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
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 |
---|---|---|
|
@@ -53,8 +53,8 @@ type ( | |
Height() (uint64, error) | ||
GetBlockHash(height uint64) (hash.Hash256, error) | ||
GetBlockHeight(hash hash.Hash256) (uint64, error) | ||
GetBlockIndex(uint64) (*blockIndex, error) | ||
GetActionIndex([]byte) (*actionIndex, error) | ||
GetBlockIndex(uint64) (*BlockIndex, error) | ||
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. no external usage, delete it |
||
GetActionIndex([]byte) (*ActionIndex, error) | ||
GetTotalActions() (uint64, error) | ||
GetActionHashFromIndex(uint64, uint64) ([][]byte, error) | ||
GetActionCountByAddress(hash.Hash160) (uint64, error) | ||
|
@@ -103,7 +103,7 @@ func (x *blockIndexer) Start(ctx context.Context) error { | |
} | ||
if x.tbk.Size() == 0 { | ||
// insert genesis block | ||
if err = x.tbk.Add((&blockIndex{ | ||
if err = x.tbk.Add((&BlockIndex{ | ||
x.genesisHash[:], | ||
0, | ||
big.NewInt(0)}).Serialize(), false); err != nil { | ||
|
@@ -218,31 +218,31 @@ func (x *blockIndexer) GetBlockHeight(hash hash.Hash256) (uint64, error) { | |
} | ||
|
||
// GetBlockIndex return the index of block | ||
func (x *blockIndexer) GetBlockIndex(height uint64) (*blockIndex, error) { | ||
func (x *blockIndexer) GetBlockIndex(height uint64) (*BlockIndex, error) { | ||
x.mutex.RLock() | ||
defer x.mutex.RUnlock() | ||
|
||
v, err := x.tbk.Get(height) | ||
if err != nil { | ||
return nil, err | ||
} | ||
b := &blockIndex{} | ||
b := &BlockIndex{} | ||
if err := b.Deserialize(v); err != nil { | ||
return nil, err | ||
} | ||
return b, nil | ||
} | ||
|
||
// GetActionIndex return the index of action | ||
func (x *blockIndexer) GetActionIndex(h []byte) (*actionIndex, error) { | ||
func (x *blockIndexer) GetActionIndex(h []byte) (*ActionIndex, error) { | ||
x.mutex.RLock() | ||
defer x.mutex.RUnlock() | ||
|
||
v, err := x.kvStore.Get(_actionToBlockHashNS, h[_hashOffset:]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
a := &actionIndex{} | ||
a := &ActionIndex{} | ||
if err := a.Deserialize(v); err != nil { | ||
return nil, err | ||
} | ||
|
@@ -310,7 +310,7 @@ func (x *blockIndexer) putBlock(ctx context.Context, blk *block.Block) error { | |
x.batch.Put(_blockHashToHeightNS, hash[_hashOffset:], byteutil.Uint64ToBytesBigEndian(height), "failed to put hash -> height mapping") | ||
|
||
// index height --> block hash, number of actions, and total transfer amount | ||
bd := &blockIndex{ | ||
bd := &BlockIndex{ | ||
hash: hash[:], | ||
numAction: uint32(len(blk.Actions)), | ||
tsfAmount: blk.CalculateTransferAmount()} | ||
|
@@ -322,7 +322,7 @@ func (x *blockIndexer) putBlock(ctx context.Context, blk *block.Block) error { | |
} | ||
|
||
// store height of the block, so getReceiptByActionHash() can use height to directly pull receipts | ||
ad := (&actionIndex{ | ||
ad := (&ActionIndex{ | ||
blkHeight: blk.Height()}).Serialize() | ||
if err := x.tac.UseBatch(x.batch); err != nil { | ||
return err | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
comment