consensus.Block: removed unnecessary setters

As far as we have consensus context in NewBlockFromContext, we don't
need them anymore.
This commit is contained in:
Anna Shaleva 2020-04-24 19:33:45 +03:00
parent 6db4ca874d
commit dbda721599
4 changed files with 12 additions and 40 deletions

2
go.mod
View file

@ -7,7 +7,7 @@ require (
github.com/go-redis/redis v6.10.2+incompatible
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/mr-tron/base58 v1.1.2
github.com/nspcc-dev/dbft v0.0.0-20200427132226-342f23599814
github.com/nspcc-dev/dbft v0.0.0-20200427132226-05feeca847dd
github.com/nspcc-dev/rfc6979 v0.2.0
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.2.1

2
go.sum
View file

@ -131,6 +131,8 @@ github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1 h1:yEx9WznS+rjE0jl0
github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ=
github.com/nspcc-dev/dbft v0.0.0-20200303183127-36d3da79c682 h1:63OWUolW4GcjJR7cThq8hLnMLTwL+sjO3Qf4fo4sx8w=
github.com/nspcc-dev/dbft v0.0.0-20200303183127-36d3da79c682/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E=
github.com/nspcc-dev/dbft v0.0.0-20200427132226-05feeca847dd h1:4XKbXahJWlhjVx2cETQz9edHQfe3BQ2JjNdvSKFBelY=
github.com/nspcc-dev/dbft v0.0.0-20200427132226-05feeca847dd/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E=
github.com/nspcc-dev/dbft v0.0.0-20200427132226-15a7927772a4 h1:3cFSp4v2u9+S7K1GdLUOP1680EiGEHSBvSI6G2n8XzY=
github.com/nspcc-dev/dbft v0.0.0-20200427132226-15a7927772a4/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E=
github.com/nspcc-dev/dbft v0.0.0-20200427132226-342f23599814 h1:iNqBioi0RU2VX9UiGl/GfQKBbZrDWq5KSxQG+dgTaqo=

View file

@ -58,49 +58,23 @@ func (n *neoBlock) SetTransactions(txes []block.Transaction) {
// Version implements block.Block interface.
func (n *neoBlock) Version() uint32 { return n.Block.Version }
// SetVersion implements block.Block interface.
func (n *neoBlock) SetVersion(v uint32) { n.Block.Version = v }
// PrevHash implements block.Block interface.
func (n *neoBlock) PrevHash() util.Uint256 { return n.Block.PrevHash }
// SetPrevHash implements block.Block interface.
func (n *neoBlock) SetPrevHash(h util.Uint256) { n.Block.PrevHash = h }
// MerkleRoot implements block.Block interface.
func (n *neoBlock) MerkleRoot() util.Uint256 { return n.Block.MerkleRoot }
// SetMerkleRoot implements block.Block interface.
func (n *neoBlock) SetMerkleRoot(r util.Uint256) { n.Block.MerkleRoot = r }
// Timestamp implements block.Block interface.
func (n *neoBlock) Timestamp() uint64 { return n.Block.Timestamp * 1000000 }
// SetTimestamp implements block.Block interface.
func (n *neoBlock) SetTimestamp(ts uint64) { n.Block.Timestamp = ts / 1000000 }
// Index implements block.Block interface.
func (n *neoBlock) Index() uint32 { return n.Block.Index }
// SetIndex implements block.Block interface.
func (n *neoBlock) SetIndex(i uint32) { n.Block.Index = i }
// ConsensusData implements block.Block interface.
func (n *neoBlock) ConsensusData() uint64 { return n.Block.ConsensusData.Nonce }
// SetConsensusData implements block.Block interface.
func (n *neoBlock) SetConsensusData(nonce uint64) { n.Block.ConsensusData.Nonce = nonce }
// NextConsensus implements block.Block interface.
func (n *neoBlock) NextConsensus() util.Uint160 { return n.Block.NextConsensus }
// SetNextConsensus implements block.Block interface.
func (n *neoBlock) SetNextConsensus(h util.Uint160) { n.Block.NextConsensus = h }
// Signature implements block.Block interface.
func (n *neoBlock) Signature() []byte { return n.signature }
// SetPrimaryIndex is an auxiliary setter for ConsensusData's PrimaryIndex
func (n *neoBlock) SetPrimaryIndex(primaryIndex uint32) {
n.Block.ConsensusData.PrimaryIndex = primaryIndex
}

View file

@ -22,30 +22,26 @@ func TestNeoBlock_Sign(t *testing.T) {
func TestNeoBlock_Setters(t *testing.T) {
b := new(neoBlock)
b.SetVersion(1)
b.Block.Version = 1
require.EqualValues(t, 1, b.Version())
b.SetIndex(12)
b.Block.Index = 12
require.EqualValues(t, 12, b.Index())
b.SetTimestamp(777)
// 777ns -> 0ms -> 0ns
require.EqualValues(t, 0, b.Timestamp())
b.Block.Timestamp = 777
// 777ms -> 777000000ns
require.EqualValues(t, 777000000, b.Timestamp())
b.SetTimestamp(7777777)
// 7777777ns -> 7ms -> 7000000ns
require.EqualValues(t, 7000000, b.Timestamp())
b.SetConsensusData(456)
b.Block.ConsensusData.Nonce = 456
require.EqualValues(t, 456, b.ConsensusData())
b.SetMerkleRoot(util.Uint256{1, 2, 3, 4})
b.Block.MerkleRoot = util.Uint256{1, 2, 3, 4}
require.Equal(t, util.Uint256{1, 2, 3, 4}, b.MerkleRoot())
b.SetNextConsensus(util.Uint160{9, 2})
b.Block.NextConsensus = util.Uint160{9, 2}
require.Equal(t, util.Uint160{9, 2}, b.NextConsensus())
b.SetPrevHash(util.Uint256{9, 8, 7})
b.Block.PrevHash = util.Uint256{9, 8, 7}
require.Equal(t, util.Uint256{9, 8, 7}, b.PrevHash())
txx := []block.Transaction{transaction.NewIssueTX()}