Skip to content

Commit

Permalink
internal: use V1Block
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Oct 10, 2023
1 parent f12e2db commit 819bdbd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
8 changes: 2 additions & 6 deletions internal/chain/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (m *Manager) Synced() bool {
// BlockAtHeight returns the block at the given height.
func (m *Manager) BlockAtHeight(height uint64) (types.Block, bool) {
sb, ok := m.cs.BlockAtHeight(stypes.BlockHeight(height))
var c types.V2Block
var c types.V1Block
convertToCore(sb, &c)
return types.Block(c), ok
}
Expand All @@ -131,11 +131,7 @@ func (m *Manager) TipState() consensus.State {
// AcceptBlock adds b to the consensus set.
func (m *Manager) AcceptBlock(b types.Block) error {
var sb stypes.Block
if b.V2 != nil {
convertToSiad(types.V2Block(b), &sb)
} else {
convertToSiad(types.V1Block(b), &sb)
}
convertToSiad(types.V1Block(b), &sb)
return m.cs.AcceptBlock(sb)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/test/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (m *Miner) mineBlock(addr stypes.UnlockHash) error {
return errFailedToSolve
}

var b types.V2Block
var b types.V1Block
convertToCore(&block, &b)
if err := m.consensus.AcceptBlock(types.Block(b)); err != nil {
return fmt.Errorf("failed to get block accepted: %w", err)
Expand Down
15 changes: 8 additions & 7 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,13 @@ func (sw *SingleAddressWallet) ProcessConsensusChange(cc modules.ConsensusChange
// calculate the block height of the first applied diff
blockHeight := uint64(cc.BlockHeight) - uint64(len(cc.AppliedBlocks)) + 1
for i := 0; i < len(cc.AppliedDiffs); i, blockHeight = i+1, blockHeight+1 {
var v2Block *types.V2Block
convertToCore(cc.AppliedBlocks[i], v2Block)
var v1Block types.V1Block
convertToCore(cc.AppliedBlocks[i], &v1Block)
block := types.Block(v1Block)

diff := cc.AppliedDiffs[i]
index := types.ChainIndex{
ID: (*types.Block)(v2Block).ID(),
ID: (&block).ID(),
Height: blockHeight,
}
// determine the source of each delayed output
Expand Down Expand Up @@ -632,12 +633,12 @@ func (sw *SingleAddressWallet) ProcessConsensusChange(cc modules.ConsensusChange
blockHeight = uint64(cc.BlockHeight) - uint64(len(cc.AppliedBlocks)) + 1
// apply transactions
for i := 0; i < len(cc.AppliedBlocks); i, blockHeight = i+1, blockHeight+1 {
var block types.V2Block
convertToCore(cc.AppliedBlocks[i], &block)
var v1Block types.V1Block
convertToCore(cc.AppliedBlocks[i], &v1Block)

bblock := types.Block(block)
block := types.Block(v1Block)
index := types.ChainIndex{
ID: (&bblock).ID(),
ID: (&block).ID(),
Height: blockHeight,
}

Expand Down

0 comments on commit 819bdbd

Please sign in to comment.