Skip to content

Commit

Permalink
go.mod: update neo-go version
Browse files Browse the repository at this point in the history
Use `io.BinaryWriter` and `io.BinaryReader` interfaces.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
  • Loading branch information
fyrchik committed Aug 4, 2021
1 parent 1b03241 commit 41b1d27
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 80 deletions.
6 changes: 3 additions & 3 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (b *neoBlock) Signature() []byte {
// 2. Two different blocks must have different hash data.
func (b *neoBlock) GetHashData() []byte {
w := io.NewBufBinWriter()
b.EncodeBinary(w.BinWriter)
b.EncodeBinary(w)

return w.Bytes()
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func (b *neoBlock) Hash() (h util.Uint256) {
}

// EncodeBinary implements io.Serializable interface.
func (b base) EncodeBinary(w *io.BinWriter) {
func (b base) EncodeBinary(w io.BinaryWriter) {
w.WriteU32LE(b.Version)
w.WriteBytes(b.PrevHash[:])
w.WriteBytes(b.MerkleRoot[:])
Expand All @@ -187,7 +187,7 @@ func (b base) EncodeBinary(w *io.BinWriter) {
}

// DecodeBinary implements io.Serializable interface.
func (b *base) DecodeBinary(r *io.BinReader) {
func (b *base) DecodeBinary(r io.BinaryReader) {
b.Version = r.ReadU32LE()
r.ReadBytes(b.PrevHash[:])
r.ReadBytes(b.MerkleRoot[:])
Expand Down
4 changes: 2 additions & 2 deletions block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestNeoBlock_Setters(t *testing.T) {

t.Run("marshal block", func(t *testing.T) {
w := io.NewBufBinWriter()
b.EncodeBinary(w.BinWriter)
require.NoError(t, w.Err)
b.EncodeBinary(w)
require.NoError(t, w.Error())

r := io.NewBinReaderFromBuf(w.Bytes())
newb := new(neoBlock)
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module github.com/nspcc-dev/dbft
go 1.14

require (
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09
github.com/nspcc-dev/neofs-crypto v0.2.3
github.com/pkg/errors v0.8.1
github.com/nspcc-dev/neo-go v0.97.1-pre.0.20210804110749-2993fdd8b59a
github.com/nspcc-dev/neofs-crypto v0.3.0
github.com/pkg/errors v0.9.1
github.com/spaolacci/murmur3 v1.1.0
github.com/stretchr/testify v1.4.0
go.uber.org/zap v1.10.0
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.18.1
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
)
305 changes: 264 additions & 41 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions payload/change_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ type changeView struct {
var _ ChangeView = (*changeView)(nil)

// EncodeBinary implements io.Serializable interface.
func (c changeView) EncodeBinary(w *io.BinWriter) {
func (c changeView) EncodeBinary(w io.BinaryWriter) {
w.WriteU32LE(c.timestamp)
}

// DecodeBinary implements io.Serializable interface.
func (c *changeView) DecodeBinary(r *io.BinReader) {
func (c *changeView) DecodeBinary(r io.BinaryReader) {
c.timestamp = r.ReadU32LE()
}

Expand Down
4 changes: 2 additions & 2 deletions payload/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const signatureSize = 64
var _ Commit = (*commit)(nil)

// EncodeBinary implements io.Serializable interface.
func (c commit) EncodeBinary(w *io.BinWriter) {
func (c commit) EncodeBinary(w io.BinaryWriter) {
w.WriteBytes(c.signature[:])
}

// DecodeBinary implements io.Serializable interface.
func (c *commit) DecodeBinary(r *io.BinReader) {
func (c *commit) DecodeBinary(r io.BinaryReader) {
r.ReadBytes(c.signature[:])
}

Expand Down
12 changes: 6 additions & 6 deletions payload/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,39 @@ type (
)

// EncodeBinary implements io.Serializable interface.
func (p changeViewCompact) EncodeBinary(w *io.BinWriter) {
func (p changeViewCompact) EncodeBinary(w io.BinaryWriter) {
w.WriteU16LE(p.validatorIndex)
w.WriteB(p.originalViewNumber)
w.WriteU32LE(p.timestamp)
}

// DecodeBinary implements io.Serializable interface.
func (p *changeViewCompact) DecodeBinary(r *io.BinReader) {
func (p *changeViewCompact) DecodeBinary(r io.BinaryReader) {
p.validatorIndex = r.ReadU16LE()
p.originalViewNumber = r.ReadB()
p.timestamp = r.ReadU32LE()
}

// EncodeBinary implements io.Serializable interface.
func (p commitCompact) EncodeBinary(w *io.BinWriter) {
func (p commitCompact) EncodeBinary(w io.BinaryWriter) {
w.WriteB(p.viewNumber)
w.WriteU16LE(p.validatorIndex)
w.WriteBytes(p.signature[:])
}

// DecodeBinary implements io.Serializable interface.
func (p *commitCompact) DecodeBinary(r *io.BinReader) {
func (p *commitCompact) DecodeBinary(r io.BinaryReader) {
p.viewNumber = r.ReadB()
p.validatorIndex = r.ReadU16LE()
r.ReadBytes(p.signature[:])
}

// EncodeBinary implements io.Serializable interface.
func (p preparationCompact) EncodeBinary(w *io.BinWriter) {
func (p preparationCompact) EncodeBinary(w io.BinaryWriter) {
w.WriteU16LE(p.validatorIndex)
}

// DecodeBinary implements io.Serializable interface.
func (p *preparationCompact) DecodeBinary(r *io.BinReader) {
func (p *preparationCompact) DecodeBinary(r io.BinaryReader) {
p.validatorIndex = r.ReadU16LE()
}
6 changes: 3 additions & 3 deletions payload/consensus_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ func (m MessageType) String() string {
}

// EncodeBinary implements io.Serializable interface.
func (m message) EncodeBinary(w *io.BinWriter) {
func (m message) EncodeBinary(w io.BinaryWriter) {
w.WriteB(byte(m.cmType))
w.WriteB(m.viewNumber)
m.payload.(io.Serializable).EncodeBinary(w)
}

// DecodeBinary implements io.Serializable interface.
func (m *message) DecodeBinary(r *io.BinReader) {
func (m *message) DecodeBinary(r io.BinaryReader) {
m.cmType = MessageType(r.ReadB())
m.viewNumber = r.ReadB()

Expand All @@ -109,7 +109,7 @@ func (m *message) DecodeBinary(r *io.BinReader) {
case RecoveryMessageType:
m.payload = new(recoveryMessage)
default:
r.Err = errors.Errorf("invalid type: 0x%02x", byte(m.cmType))
r.SetError(errors.Errorf("invalid type: 0x%02x", byte(m.cmType)))
return
}

Expand Down
8 changes: 4 additions & 4 deletions payload/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type (
var _ ConsensusPayload = (*Payload)(nil)

// EncodeBinary implements io.Serializable interface.
func (p Payload) EncodeBinary(w *io.BinWriter) {
func (p Payload) EncodeBinary(w io.BinaryWriter) {
ww := io.NewBufBinWriter()
p.message.EncodeBinary(ww.BinWriter)
p.message.EncodeBinary(ww)
data := ww.Bytes()

w.WriteU32LE(p.version)
Expand All @@ -55,7 +55,7 @@ func (p Payload) EncodeBinary(w *io.BinWriter) {
}

// DecodeBinary implements io.Serializable interface.
func (p *Payload) DecodeBinary(r *io.BinReader) {
func (p *Payload) DecodeBinary(r io.BinaryReader) {
p.version = r.ReadU32LE()
p.prevHash.DecodeBinary(r)
p.height = r.ReadU32LE()
Expand All @@ -69,7 +69,7 @@ func (p *Payload) DecodeBinary(r *io.BinReader) {
// MarshalUnsigned implements ConsensusPayload interface.
func (p Payload) MarshalUnsigned() []byte {
w := io.NewBufBinWriter()
p.EncodeBinary(w.BinWriter)
p.EncodeBinary(w)

return w.Bytes()
}
Expand Down
4 changes: 2 additions & 2 deletions payload/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ func TestMessageType_String(t *testing.T) {

func testEncodeDecode(t *testing.T, expected, actual io.Serializable) {
w := io.NewBufBinWriter()
expected.EncodeBinary(w.BinWriter)
require.NoError(t, w.Err)
expected.EncodeBinary(w)
require.NoError(t, w.Error())

buf := w.Bytes()
r := io.NewBinReaderFromBuf(buf)
Expand Down
4 changes: 2 additions & 2 deletions payload/prepare_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ type prepareRequest struct {
var _ PrepareRequest = (*prepareRequest)(nil)

// EncodeBinary implements io.Serializable interface.
func (p prepareRequest) EncodeBinary(w *io.BinWriter) {
func (p prepareRequest) EncodeBinary(w io.BinaryWriter) {
w.WriteU32LE(p.timestamp)
w.WriteU64LE(p.nonce)
w.WriteBytes(p.nextConsensus[:])
w.WriteArray(p.transactionHashes)
}

// DecodeBinary implements io.Serializable interface.
func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
func (p *prepareRequest) DecodeBinary(r io.BinaryReader) {
p.timestamp = r.ReadU32LE()
p.nonce = r.ReadU64LE()
r.ReadBytes(p.nextConsensus[:])
Expand Down
4 changes: 2 additions & 2 deletions payload/prepare_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type prepareResponse struct {
var _ PrepareResponse = (*prepareResponse)(nil)

// EncodeBinary implements io.Serializable interface.
func (p prepareResponse) EncodeBinary(w *io.BinWriter) {
func (p prepareResponse) EncodeBinary(w io.BinaryWriter) {
w.WriteBytes(p.preparationHash[:])
}

// DecodeBinary implements io.Serializable interface.
func (p *prepareResponse) DecodeBinary(r *io.BinReader) {
func (p *prepareResponse) DecodeBinary(r io.BinaryReader) {
r.ReadBytes(p.preparationHash[:])
}

Expand Down
6 changes: 3 additions & 3 deletions payload/recovery_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (m *recoveryMessage) GetCommits(p ConsensusPayload, _ []crypto.PublicKey) [
}

// EncodeBinary implements io.Serializable interface.
func (m recoveryMessage) EncodeBinary(w *io.BinWriter) {
func (m recoveryMessage) EncodeBinary(w io.BinaryWriter) {
w.WriteArray(m.changeViewPayloads)

hasReq := m.prepareRequest != nil
Expand All @@ -174,7 +174,7 @@ func (m recoveryMessage) EncodeBinary(w *io.BinWriter) {
}

// DecodeBinary implements io.Serializable interface.
func (m *recoveryMessage) DecodeBinary(r *io.BinReader) {
func (m *recoveryMessage) DecodeBinary(r io.BinaryReader) {
r.ReadArray(&m.changeViewPayloads)

if hasReq := r.ReadBool(); hasReq {
Expand All @@ -187,7 +187,7 @@ func (m *recoveryMessage) DecodeBinary(r *io.BinReader) {
m.preparationHash = new(util.Uint256)
m.preparationHash.DecodeBinary(r)
} else {
r.Err = errors.New("wrong util.Uint256 length")
r.SetError(errors.New("wrong util.Uint256 length"))
}
} else {
m.preparationHash = nil
Expand Down
4 changes: 2 additions & 2 deletions payload/recovery_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type recoveryRequest struct {
var _ RecoveryRequest = (*recoveryRequest)(nil)

// EncodeBinary implements io.Serializable interface.
func (m recoveryRequest) EncodeBinary(w *io.BinWriter) {
func (m recoveryRequest) EncodeBinary(w io.BinaryWriter) {
w.WriteU32LE(m.timestamp)
}

// DecodeBinary implements io.Serializable interface.
func (m *recoveryRequest) DecodeBinary(r *io.BinReader) {
func (m *recoveryRequest) DecodeBinary(r io.BinaryReader) {
m.timestamp = r.ReadU32LE()
}

Expand Down

0 comments on commit 41b1d27

Please sign in to comment.